summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2015-05-28 08:27:57 +0100
committerRichard Hughes <richard@hughsie.com>2015-05-28 08:28:21 +0100
commitb13e742aaf19136b886de6b1c4bfdd268636081e (patch)
tree2a2865253c0efb60553d6cbab56686e2858cd9a1
parenta08964148f8f12564065bae1aabc46a7756f32ba (diff)
downloadcolord-sensor-hid.tar.gz
colorhug: Add ch_device_closesensor-hid
This closes the device and rebinds any suitable kernel driver.
-rw-r--r--lib/colorhug/ch-device.c22
-rw-r--r--lib/colorhug/ch-device.h3
-rw-r--r--lib/colorhug/ch-self-test.c21
3 files changed, 39 insertions, 7 deletions
diff --git a/lib/colorhug/ch-device.c b/lib/colorhug/ch-device.c
index 0063f44..2f937d5 100644
--- a/lib/colorhug/ch-device.c
+++ b/lib/colorhug/ch-device.c
@@ -71,6 +71,28 @@ ch_device_open (GUsbDevice *device, GError **error)
}
/**
+ * ch_device_close:
+ *
+ * Since: 1.2.11
+ **/
+gboolean
+ch_device_close (GUsbDevice *device, GError **error)
+{
+ g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ /* unload device */
+ if (!g_usb_device_release_interface (device,
+ CH_USB_INTERFACE,
+ G_USB_DEVICE_CLAIM_INTERFACE_BIND_KERNEL_DRIVER,
+ error))
+ return FALSE;
+ if (!g_usb_device_close (device, error))
+ return FALSE;
+ return TRUE;
+}
+
+/**
* ch_device_is_colorhug:
*
* Since: 0.1.29
diff --git a/lib/colorhug/ch-device.h b/lib/colorhug/ch-device.h
index 9d27790..2f1e3c6 100644
--- a/lib/colorhug/ch-device.h
+++ b/lib/colorhug/ch-device.h
@@ -39,6 +39,9 @@ GQuark ch_device_error_quark (void);
gboolean ch_device_open (GUsbDevice *device,
GError **error)
G_GNUC_WARN_UNUSED_RESULT;
+gboolean ch_device_close (GUsbDevice *device,
+ GError **error)
+ G_GNUC_WARN_UNUSED_RESULT;
gboolean ch_device_is_colorhug (GUsbDevice *device);
ChDeviceMode ch_device_get_mode (GUsbDevice *device);
void ch_device_write_command_async (GUsbDevice *device,
diff --git a/lib/colorhug/ch-self-test.c b/lib/colorhug/ch-self-test.c
index cdef73f..cfd46e8 100644
--- a/lib/colorhug/ch-self-test.c
+++ b/lib/colorhug/ch-self-test.c
@@ -643,7 +643,7 @@ ch_test_state_func (void)
}
/* close */
- ret = g_usb_device_close (device, &error);
+ ret = ch_device_close (device, &error);
g_assert_no_error (error);
g_assert (ret);
@@ -674,7 +674,7 @@ ch_test_eeprom_func (void)
/* load the device */
device = ch_client_get_default (&error);
if (device != NULL && g_usb_device_get_pid (device) != CH_USB_PID_FIRMWARE) {
- ret = g_usb_device_close (device, &error);
+ ret = ch_device_close (device, &error);
g_assert_no_error (error);
g_assert (ret);
g_debug ("not capable device, skipping tests");
@@ -917,6 +917,9 @@ ch_test_eeprom_func (void)
g_assert (ret);
#endif
+ ret = ch_device_close (device, &error);
+ g_assert_no_error (error);
+ g_assert (ret);
g_object_unref (device);
g_object_unref (device_queue);
}
@@ -983,7 +986,7 @@ ch_test_reading_func (void)
g_assert_cmpint (take_reading, >, 0);
/* close */
- ret = g_usb_device_close (device, &error);
+ ret = ch_device_close (device, &error);
g_assert_no_error (error);
g_assert (ret);
@@ -1010,7 +1013,7 @@ ch_test_reading_xyz_func (void)
/* load the device */
device = ch_client_get_default (&error);
if (device != NULL && g_usb_device_get_pid (device) != CH_USB_PID_FIRMWARE) {
- ret = g_usb_device_close (device, &error);
+ ret = ch_device_close (device, &error);
g_assert_no_error (error);
g_assert (ret);
g_debug ("not capable device, skipping tests");
@@ -1130,7 +1133,7 @@ ch_test_reading_xyz_func (void)
}
/* close */
- ret = g_usb_device_close (device, &error);
+ ret = ch_device_close (device, &error);
g_assert_no_error (error);
g_assert (ret);
@@ -1158,7 +1161,7 @@ ch_test_incomplete_request_func (void)
/* load the device */
device = ch_client_get_default (&error);
if (device != NULL && g_usb_device_get_pid (device) != CH_USB_PID_FIRMWARE) {
- ret = g_usb_device_close (device, &error);
+ ret = ch_device_close (device, &error);
g_assert_no_error (error);
g_assert (ret);
g_debug ("not capable device, skipping tests");
@@ -1229,8 +1232,12 @@ ch_test_incomplete_request_func (void)
g_assert_cmpint (buffer[0], ==, CH_ERROR_INCOMPLETE_REQUEST);
g_assert_cmpint (buffer[1], ==, CH_CMD_GET_FIRMWARE_VERSION);
out:
- if (device != NULL)
+ if (device != NULL) {
+ ret = ch_device_close (device, &error);
+ g_assert_no_error (error);
+ g_assert (ret);
g_object_unref (device);
+ }
}
/**