|
Tizen Native API
10.0
|
This API is used to register callbacks to be called when devices are connected or disconnected.
This API allows us to receive information on appearing and disappearing devices.
Overview
Functions described here can be used to register callbacks to be called on events such as device connection or disconnection.
Related Features
This API is related with the following features:
- http://tizen.org/feature/usb.host
It is recommended to design feature related codes in your application for reliability.
You can check if a device supports the related features for this API by using System Information, thereby controlling the procedure of your application.
To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.
More details on featuring your application can be found from Feature Element.
Functions | |
| int | usb_host_set_hotplug_cb (usb_host_context_h ctx, usb_host_hotplug_cb cb, usb_host_hotplug_event_e event, void *user_data, usb_host_hotplug_h *handle) |
| Sets a callback function to be invoked when a device is connected or disconnected. | |
| int | usb_host_unset_hotplug_cb (usb_host_hotplug_h handle) |
| Unsets the (dis)connection hotplug callback function. | |
Typedefs | |
| typedef struct usb_host_hotplug_s * | usb_host_hotplug_h |
| An opaque handle representing a USB hotplug callback manager. | |
| typedef void(* | usb_host_hotplug_cb )(usb_host_device_h dev, void *user_data) |
| An type representing a USB hotplug callback handler. | |
Typedef Documentation
| typedef void(* usb_host_hotplug_cb)(usb_host_device_h dev, void *user_data) |
An type representing a USB hotplug callback handler.
The device handle should be unreffed with usb_host_unref_device() when no longer needed.
- Since :
- 4.0
- Parameters:
-
[in] dev Device which was connected/disconnected [in] user_data User data pointer passed on callback registration
| typedef struct usb_host_hotplug_s* usb_host_hotplug_h |
An opaque handle representing a USB hotplug callback manager.
This handle is used for managing registered hotplug callbacks.
- Since :
- 4.0
Enumeration Type Documentation
Function Documentation
| int usb_host_set_hotplug_cb | ( | usb_host_context_h | ctx, |
| usb_host_hotplug_cb | cb, | ||
| usb_host_hotplug_event_e | event, | ||
| void * | user_data, | ||
| usb_host_hotplug_h * | handle | ||
| ) |
Sets a callback function to be invoked when a device is connected or disconnected.
After this call, a callback function will be invoked whenever a device is connected or disconnected.
- Since :
- 4.0
- Parameters:
-
[in] ctx Context handle [in] cb The callback function to be registered [in] event Event that will trigger registered callback [in] user_data The user data to be passed to the callback function [out] handle Handle of the registered callback
- Returns:
- 0 on success, negative error code on error
- Return values:
-
USB_HOST_ERROR_NONE Successful USB_HOST_ERROR_NOT_SUPPORTED Not supported USB_HOST_ERROR_INVALID_PARAMETER Invalid parameter was passed USB_HOST_ERROR_OUT_OF_MEMORY Out of memory
#include <usb_host.h> void hotplug_callback(usb_host_device_h dev, void *user_data) { struct our_data_type *callback_data = user_data; process_new_device(data); } usb_host_hotplug_h set_callback(usb_host_context_h ctx) { struct our_data_type *callback_data = create_callback_data(); int ret; usb_host_hotplug_h handle; ret = usb_host_set_hotplug_cb(ctx, hotplug_callback, USB_HOST_HOTPLUG_EVENT_ATTACH, callback_data, &handle); if (ret != USB_HOST_ERROR_NONE) handle_error(ret); return handle; }
| int usb_host_unset_hotplug_cb | ( | usb_host_hotplug_h | handle | ) |
Unsets the (dis)connection hotplug callback function.
After this call, the callback will not be connected anymore.
- Since :
- 4.0
- Parameters:
-
[in] handle Handle of the callback to be unregistered
- Returns:
- 0 on success, negative error code on error
- Return values:
-
USB_HOST_ERROR_NONE Successful USB_HOST_ERROR_INVALID_PARAMETER Invalid parameter was passed USB_HOST_ERROR_NOT_SUPPORTED Not supported
#include <usb_host.h> void unset_callback(usb_host_hotplug_h handle, struct our_data_type *callback_data) { int ret = usb_host_unset_hotplug_cb(handle); if (ret != USB_HOST_ERROR_NONE) handle_error(ret); // Make sure the callback is not running in parallel! destroy_callback_data(callback_data); }