예제 #1
0
파일: backend.cpp 프로젝트: milaq/rockbox
HWStubBackendHelper::~HWStubBackendHelper()
{
#ifndef LIBUSB_NO_HOTPLUG
    if(m_hotplug)
        libusb_hotplug_deregister_callback(NULL, m_hotplug_handle);
#endif /* LIBUSB_NO_HOTPLUG */
}
예제 #2
0
HotplugCallbackAdapter::~HotplugCallbackAdapter() {
    if(_p->handle) {
        libusb_hotplug_deregister_callback(NULL, _p->handle);
        qDebug() << "deregistered hotplug callback";
    }
    
    delete _p;
    _p = 0;
}
예제 #3
0
파일: main.cpp 프로젝트: 117303/set-output
void finish (int res, const char *msg)
{
    if (msg)
        fprintf (stderr, "%s\n", msg);

   if (cb_handle_initialized) {
       libusb_hotplug_deregister_callback(NULL, cb_handle);
   }

    if (device_initialized) {
       device_deinit();
    }
    exit (res);
}
예제 #4
0
void Shutdown()
{
	StopScanThread();
	if (s_libusb_hotplug_enabled)
		libusb_hotplug_deregister_callback(s_libusb_context, s_hotplug_handle);
	Reset();

	if (s_libusb_context)
	{
		libusb_exit(s_libusb_context);
		s_libusb_context = nullptr;
	}

	s_libusb_driver_not_supported = false;
}
예제 #5
0
static void libusb_hid_free(void *data)
{
   libusb_hid_t *hid = (libusb_hid_t*)data;

   while(adapters.next)
      if (remove_adapter(hid, adapters.next->device) == -1)
         RARCH_ERR("could not remove device %p\n",
               adapters.next->device);

   if (hid->poll_thread)
   {
      hid->quit = 1;
      sthread_join(hid->poll_thread);
   }

   pad_connection_destroy(hid->slots);

   libusb_hotplug_deregister_callback(hid->ctx, hid->hp);

   libusb_exit(hid->ctx);
   free(hid);
}
예제 #6
0
static void
g_usb_context_dispose (GObject *object)
{
	GUsbContext *context = G_USB_CONTEXT (object);
	GUsbContextPrivate *priv = context->priv;

	/* this is safe to call even when priv->hotplug_id is unset */
	if (g_atomic_int_dec_and_test (&priv->thread_event_run)) {
		libusb_hotplug_deregister_callback (priv->ctx, priv->hotplug_id);
		g_thread_join (priv->thread_event);
	}

	if (priv->hotplug_poll_id > 0) {
		g_source_remove (priv->hotplug_poll_id);
		priv->hotplug_poll_id = 0;
	}

	g_clear_pointer (&priv->main_ctx, g_main_context_unref);
	g_clear_pointer (&priv->devices, g_ptr_array_unref);
	g_clear_pointer (&priv->dict_usb_ids, g_hash_table_unref);
	g_clear_pointer (&priv->ctx, libusb_exit);

	G_OBJECT_CLASS (g_usb_context_parent_class)->dispose (object);
}
예제 #7
0
int API_EXPORTED libusb_hotplug_register_callback(libusb_context *ctx,
	libusb_hotplug_event events, libusb_hotplug_flag flags,
	int vendor_id, int product_id, int dev_class,
	libusb_hotplug_callback_fn cb_fn, void *user_data,
	libusb_hotplug_callback_handle *handle)
{
	libusb_hotplug_callback *new_callback;
	static int handle_id = 1;

	/* check for hotplug support */
	if (!libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)) {
		return LIBUSB_ERROR_NOT_SUPPORTED;
	}

	/* check for sane values */
	if ((LIBUSB_HOTPLUG_MATCH_ANY != vendor_id && (~0xffff & vendor_id)) ||
	    (LIBUSB_HOTPLUG_MATCH_ANY != product_id && (~0xffff & product_id)) ||
	    (LIBUSB_HOTPLUG_MATCH_ANY != dev_class && (~0xff & dev_class)) ||
	    !cb_fn) {
		return LIBUSB_ERROR_INVALID_PARAM;
	}

	USBI_GET_CONTEXT(ctx);

	new_callback = (libusb_hotplug_callback *)calloc(1, sizeof (*new_callback));
	if (!new_callback) {
		return LIBUSB_ERROR_NO_MEM;
	}

	new_callback->ctx = ctx;
	new_callback->vendor_id = vendor_id;
	new_callback->product_id = product_id;
	new_callback->dev_class = dev_class;
	new_callback->flags = flags;
	new_callback->events = events;
	new_callback->cb = cb_fn;
	new_callback->user_data = user_data;
	new_callback->needs_free = 0;

	usbi_mutex_lock(&ctx->hotplug_cbs_lock);

	/* protect the handle by the context hotplug lock. it doesn't matter if the same handle
	 * is used for different contexts only that the handle is unique for this context */
	new_callback->handle = handle_id++;

	list_add(&new_callback->list, &ctx->hotplug_cbs);

	usbi_mutex_unlock(&ctx->hotplug_cbs_lock);


	if (flags & LIBUSB_HOTPLUG_ENUMERATE) {
		int i, len;
		struct libusb_device **devs;

		len = (int) libusb_get_device_list(ctx, &devs);
		if (len < 0) {
			libusb_hotplug_deregister_callback(ctx,
							new_callback->handle);
			return len;
		}

		for (i = 0; i < len; i++) {
			usbi_hotplug_match_cb(ctx, devs[i],
					LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED,
					new_callback);
		}

		libusb_free_device_list(devs, 1);
	}


	if (handle) {
		*handle = new_callback->handle;
	}

	return LIBUSB_SUCCESS;
}