2929#include < sys/epoll.h>
3030#include < unistd.h>
3131
32- #include < spdlog/spdlog.h >
32+ #include " ../utils/logging.h "
3333
3434// ---------------------------------------------------------------------------
3535// RAII wrappers for libudev handles
@@ -72,8 +72,7 @@ class UdevMonitor {
7272 callback)
7373 : sub_systems_(std::move(sub_systems)), callback_(callback) {
7474 if (pipe (pipe_fds_) == -1 ) {
75- spdlog::error (" Failed to create pipe: {} ({})" , std::strerror (errno),
76- errno);
75+ LOG_ERROR (" Failed to create pipe: {} ({})" , std::strerror (errno), errno);
7776 pipe_fds_[0 ] = -1 ;
7877 pipe_fds_[1 ] = -1 ;
7978 return ;
@@ -125,8 +124,8 @@ class UdevMonitor {
125124 // Signal the worker thread to exit
126125 if (pipe_fds_[1 ] != -1 ) {
127126 if (const ssize_t wrote = write (pipe_fds_[1 ], " x" , 1 ); wrote == -1 ) {
128- spdlog::error (" Failed to write to stop pipe: {} ({})" ,
129- std::strerror (errno), errno);
127+ LOG_ERROR (" Failed to write to stop pipe: {} ({})" , std::strerror (errno) ,
128+ errno);
130129 }
131130 }
132131 }
@@ -142,15 +141,15 @@ class UdevMonitor {
142141 // RAII: udev context — automatically udev_unref'd on scope exit
143142 const UdevPtr udev (udev_new ());
144143 if (!udev) {
145- spdlog::error (" Failed to create udev context" );
144+ LOG_ERROR (" Failed to create udev context" );
146145 is_running_ = false ;
147146 return ;
148147 }
149148
150149 // RAII: udev monitor — automatically udev_monitor_unref'd on scope exit
151150 const UdevMonitorPtr mon (udev_monitor_new_from_netlink (udev.get (), " udev" ));
152151 if (!mon) {
153- spdlog::error (" Failed to create udev monitor" );
152+ LOG_ERROR (" Failed to create udev monitor" );
154153 is_running_ = false ;
155154 return ;
156155 }
@@ -159,7 +158,7 @@ class UdevMonitor {
159158 if (int res = udev_monitor_filter_add_match_subsystem_devtype (
160159 mon.get (), sub_system.c_str (), nullptr );
161160 res != 0 ) {
162- spdlog::error (
161+ LOG_ERROR (
163162 " udev_monitor_filter_add_match_subsystem_devtype failed on {} = {}" ,
164163 sub_system, res);
165164 }
@@ -170,8 +169,7 @@ class UdevMonitor {
170169 // RAII: epoll fd — automatically closed on scope exit
171170 const EpollFd epoll_fd (epoll_create1 (0 ));
172171 if (!epoll_fd.valid ()) {
173- spdlog::error (" Failed to create epoll: {} ({})" , std::strerror (errno),
174- errno);
172+ LOG_ERROR (" Failed to create epoll: {} ({})" , std::strerror (errno), errno);
175173 is_running_ = false ;
176174 return ;
177175 }
@@ -180,16 +178,16 @@ class UdevMonitor {
180178 ev.events = EPOLLIN;
181179 ev.data .fd = fd;
182180 if (epoll_ctl (epoll_fd.get (), EPOLL_CTL_ADD, fd, &ev) == -1 ) {
183- spdlog::error (" Failed to add udev fd to epoll: {} ({})" ,
184- std::strerror (errno), errno);
181+ LOG_ERROR (" Failed to add udev fd to epoll: {} ({})" , std::strerror (errno) ,
182+ errno);
185183 is_running_ = false ;
186184 return ;
187185 }
188186
189187 ev.data .fd = pipe_fds_[0 ];
190188 if (epoll_ctl (epoll_fd.get (), EPOLL_CTL_ADD, pipe_fds_[0 ], &ev) == -1 ) {
191- spdlog::error (" Failed to add pipe fd to epoll: {} ({})" ,
192- std::strerror (errno), errno);
189+ LOG_ERROR (" Failed to add pipe fd to epoll: {} ({})" , std::strerror (errno) ,
190+ errno);
193191 is_running_ = false ;
194192 return ;
195193 }
@@ -202,14 +200,13 @@ class UdevMonitor {
202200 if (errno == EINTR) {
203201 continue ; // Interrupted by signal, retry
204202 }
205- spdlog::error (" epoll_wait failed: {} ({})" , std::strerror (errno),
206- errno);
203+ LOG_ERROR (" epoll_wait failed: {} ({})" , std::strerror (errno), errno);
207204 break ;
208205 }
209206
210207 for (int n = 0 ; n < triggered_event_count; ++n) {
211208 if (events[n].data .fd == pipe_fds_[0 ]) {
212- spdlog::info (" Pipe was written to, exiting the loop" );
209+ LOG_INFO (" Pipe was written to, exiting the loop" );
213210 is_running_ = false ;
214211 break ;
215212 }
@@ -225,7 +222,7 @@ class UdevMonitor {
225222 if (action && subsystem) {
226223 callback_ (action, devnode, subsystem);
227224 } else {
228- spdlog::debug (
225+ LOG_DEBUG (
229226 " Skipping callback for device with missing properties: "
230227 " action={}, devnode={}, subsystem={}" ,
231228 action ? action : " null" , devnode ? devnode : " null" ,
@@ -239,7 +236,7 @@ class UdevMonitor {
239236 }
240237
241238 // All resources (epoll_fd, mon, udev) are released by their destructors.
242- spdlog::debug (" UdevMonitor worker thread exiting" );
239+ LOG_DEBUG (" UdevMonitor worker thread exiting" );
243240 }
244241};
245242
0 commit comments