Lines Matching refs:context

118 static void watch_existing_subdirs(struct usb_host_context *context,  in watch_existing_subdirs()  argument
123 wds[0] = inotify_add_watch(context->fd, USB_FS_DIR, IN_CREATE | IN_DELETE); in watch_existing_subdirs()
129 ret = inotify_add_watch(context->fd, path, IN_CREATE | IN_DELETE); in watch_existing_subdirs()
136 struct usb_host_context *context = calloc(1, sizeof(struct usb_host_context)); in usb_host_init() local
137 if (!context) { in usb_host_init()
141 context->fd = inotify_init(); in usb_host_init()
142 if (context->fd < 0) { in usb_host_init()
144 free(context); in usb_host_init()
147 return context; in usb_host_init()
149 void usb_host_cleanup(struct usb_host_context *context) in usb_host_cleanup() argument
151 close(context->fd); in usb_host_cleanup()
152 free(context); in usb_host_cleanup()
154 int usb_host_get_fd(struct usb_host_context *context) in usb_host_get_fd() argument
156 return context->fd; in usb_host_get_fd()
158 int usb_host_load(struct usb_host_context *context, in usb_host_load() argument
166 context->cb_added = added_cb; in usb_host_load()
167 context->cb_removed = removed_cb; in usb_host_load()
168 context->data = client_data; in usb_host_load()
171 context->wddbus = -1; in usb_host_load()
173 context->wds[i] = -1; in usb_host_load()
175 context->wdd = inotify_add_watch(context->fd, DEV_DIR, IN_CREATE | IN_DELETE); in usb_host_load()
176 if (context->wdd < 0) { in usb_host_load()
182 watch_existing_subdirs(context, context->wds, MAX_USBFS_WD_COUNT); in usb_host_load()
189 int usb_host_read_event(struct usb_host_context *context) in usb_host_read_event() argument
197 ret = read(context->fd, event_buf, sizeof(event_buf)); in usb_host_read_event()
203 if (wd == context->wdd) { in usb_host_read_event()
205context->wddbus = inotify_add_watch(context->fd, DEV_BUS_DIR, IN_CREATE | IN_DELETE); in usb_host_read_event()
206 if (context->wddbus < 0) { in usb_host_read_event()
209 watch_existing_subdirs(context, context->wds, MAX_USBFS_WD_COUNT); in usb_host_read_event()
210 done = find_existing_devices(context->cb_added, context->data); in usb_host_read_event()
213 } else if (wd == context->wddbus) { in usb_host_read_event()
215 watch_existing_subdirs(context, context->wds, MAX_USBFS_WD_COUNT); in usb_host_read_event()
216 done = find_existing_devices(context->cb_added, context->data); in usb_host_read_event()
219 if (context->wds[i] >= 0) { in usb_host_read_event()
220 inotify_rm_watch(context->fd, context->wds[i]); in usb_host_read_event()
221 context->wds[i] = -1; in usb_host_read_event()
225 } else if (wd == context->wds[0]) { in usb_host_read_event()
233 local_ret = inotify_add_watch(context->fd, path, in usb_host_read_event()
236 context->wds[i] = local_ret; in usb_host_read_event()
237 done = find_existing_devices_bus(path, context->cb_added, in usb_host_read_event()
238 context->data); in usb_host_read_event()
240 inotify_rm_watch(context->fd, context->wds[i]); in usb_host_read_event()
241 context->wds[i] = -1; in usb_host_read_event()
246 if (wd == context->wds[i]) { in usb_host_read_event()
250 done = context->cb_added(path, context->data); in usb_host_read_event()
253 done = context->cb_removed(path, context->data); in usb_host_read_event()
263 void usb_host_run(struct usb_host_context *context, in usb_host_run() argument
270 done = usb_host_load(context, added_cb, removed_cb, discovery_done_cb, client_data); in usb_host_run()
272 done = usb_host_read_event(context); in usb_host_run()