Lines Matching refs:context
138 static void watch_existing_subdirs(struct usb_host_context *context, in watch_existing_subdirs() argument
144 wds[0] = inotify_add_watch(context->fd, USB_FS_DIR, IN_CREATE | IN_DELETE); in watch_existing_subdirs()
151 ret = inotify_add_watch(context->fd, path, IN_CREATE | IN_DELETE); in watch_existing_subdirs()
159 struct usb_host_context *context = calloc(1, sizeof(struct usb_host_context)); in usb_host_init() local
160 if (!context) { in usb_host_init()
164 context->fd = inotify_init(); in usb_host_init()
165 if (context->fd < 0) { in usb_host_init()
167 free(context); in usb_host_init()
170 return context; in usb_host_init()
173 void usb_host_cleanup(struct usb_host_context *context) in usb_host_cleanup() argument
175 close(context->fd); in usb_host_cleanup()
176 free(context); in usb_host_cleanup()
179 int usb_host_get_fd(struct usb_host_context *context) in usb_host_get_fd() argument
181 return context->fd; in usb_host_get_fd()
184 int usb_host_load(struct usb_host_context *context, in usb_host_load() argument
193 context->cb_added = added_cb; in usb_host_load()
194 context->cb_removed = removed_cb; in usb_host_load()
195 context->data = client_data; in usb_host_load()
200 context->wddbus = -1; in usb_host_load()
202 context->wds[i] = -1; in usb_host_load()
205 context->wdd = inotify_add_watch(context->fd, DEV_DIR, IN_CREATE | IN_DELETE); in usb_host_load()
206 if (context->wdd < 0) { in usb_host_load()
213 watch_existing_subdirs(context, context->wds, MAX_USBFS_WD_COUNT); in usb_host_load()
223 int usb_host_read_event(struct usb_host_context *context) in usb_host_read_event() argument
232 ret = read(context->fd, event_buf, sizeof(event_buf)); in usb_host_read_event()
238 if (wd == context->wdd) { in usb_host_read_event()
240 … context->wddbus = inotify_add_watch(context->fd, DEV_BUS_DIR, IN_CREATE | IN_DELETE); in usb_host_read_event()
241 if (context->wddbus < 0) { in usb_host_read_event()
244 watch_existing_subdirs(context, context->wds, MAX_USBFS_WD_COUNT); in usb_host_read_event()
245 done = find_existing_devices(context->cb_added, context->data); in usb_host_read_event()
248 } else if (wd == context->wddbus) { in usb_host_read_event()
250 watch_existing_subdirs(context, context->wds, MAX_USBFS_WD_COUNT); in usb_host_read_event()
251 done = find_existing_devices(context->cb_added, context->data); in usb_host_read_event()
254 if (context->wds[i] >= 0) { in usb_host_read_event()
255 inotify_rm_watch(context->fd, context->wds[i]); in usb_host_read_event()
256 context->wds[i] = -1; in usb_host_read_event()
260 } else if (wd == context->wds[0]) { in usb_host_read_event()
268 local_ret = inotify_add_watch(context->fd, path, in usb_host_read_event()
271 context->wds[i] = local_ret; in usb_host_read_event()
272 done = find_existing_devices_bus(path, context->cb_added, in usb_host_read_event()
273 context->data); in usb_host_read_event()
275 inotify_rm_watch(context->fd, context->wds[i]); in usb_host_read_event()
276 context->wds[i] = -1; in usb_host_read_event()
281 if (wd == context->wds[i]) { in usb_host_read_event()
285 done = context->cb_added(path, context->data); in usb_host_read_event()
288 done = context->cb_removed(path, context->data); in usb_host_read_event()
301 void usb_host_run(struct usb_host_context *context, in usb_host_run() argument
309 done = usb_host_load(context, added_cb, removed_cb, discovery_done_cb, client_data); in usb_host_run()
313 done = usb_host_read_event(context); in usb_host_run()