Lines Matching refs:context

146 static void watch_existing_subdirs(struct usb_host_context *context,
152 wds[0] = inotify_add_watch(context->fd, USB_FS_DIR, IN_CREATE | IN_DELETE);
159 ret = inotify_add_watch(context->fd, path, IN_CREATE | IN_DELETE);
167 struct usb_host_context *context = calloc(1, sizeof(struct usb_host_context));
168 if (!context) {
172 context->fd = inotify_init();
173 if (context->fd < 0) {
175 free(context);
178 return context;
181 void usb_host_cleanup(struct usb_host_context *context)
183 close(context->fd);
184 free(context);
187 int usb_host_get_fd(struct usb_host_context *context)
189 return context->fd;
192 int usb_host_load(struct usb_host_context *context,
201 context->cb_added = added_cb;
202 context->cb_removed = removed_cb;
203 context->data = client_data;
208 context->wddbus = -1;
210 context->wds[i] = -1;
213 context->wdd = inotify_add_watch(context->fd, DEV_DIR, IN_CREATE | IN_DELETE);
214 if (context->wdd < 0) {
221 watch_existing_subdirs(context, context->wds, MAX_USBFS_WD_COUNT);
231 int usb_host_read_event(struct usb_host_context *context)
240 ret = read(context->fd, event_buf, sizeof(event_buf));
246 if (wd == context->wdd) {
248 context->wddbus = inotify_add_watch(context->fd, DEV_BUS_DIR, IN_CREATE | IN_DELETE);
249 if (context->wddbus < 0) {
252 watch_existing_subdirs(context, context->wds, MAX_USBFS_WD_COUNT);
253 done = find_existing_devices(context->cb_added, context->data);
256 } else if (wd == context->wddbus) {
258 watch_existing_subdirs(context, context->wds, MAX_USBFS_WD_COUNT);
259 done = find_existing_devices(context->cb_added, context->data);
262 if (context->wds[i] >= 0) {
263 inotify_rm_watch(context->fd, context->wds[i]);
264 context->wds[i] = -1;
268 } else if (wd == context->wds[0]) {
276 local_ret = inotify_add_watch(context->fd, path,
279 context->wds[i] = local_ret;
280 done = find_existing_devices_bus(path, context->cb_added,
281 context->data);
283 inotify_rm_watch(context->fd, context->wds[i]);
284 context->wds[i] = -1;
289 if (wd == context->wds[i]) {
293 done = context->cb_added(path, context->data);
296 done = context->cb_removed(path, context->data);
309 void usb_host_run(struct usb_host_context *context,
317 done = usb_host_load(context, added_cb, removed_cb, discovery_done_cb, client_data);
321 done = usb_host_read_event(context);