diff options
author | Jehun Lim <jehun.lim@samsung.com> | 2015-12-30 13:31:00 +0900 |
---|---|---|
committer | Jehun Lim <jehun.lim@samsung.com> | 2015-12-31 12:49:54 +0900 |
commit | 0a05fef409220af27db5fb6d71fb63cc5ced204d (patch) | |
tree | d49e7573809809d18a5c19c83d33096db476efa0 /src/util | |
parent | 387bda6e97f1f33b4c0fb6eebde4ade3469006e9 (diff) | |
download | air_mediahub-0a05fef409220af27db5fb6d71fb63cc5ced204d.tar.gz air_mediahub-0a05fef409220af27db5fb6d71fb63cc5ced204d.tar.bz2 air_mediahub-0a05fef409220af27db5fb6d71fb63cc5ced204d.zip |
usb: add DeviceBlocked signal callback
Change-Id: Iff966d5659abb89334effac3154ae36c75b908d8
Signed-off-by: Jehun Lim <jehun.lim@samsung.com>
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/usb.c | 121 |
1 files changed, 95 insertions, 26 deletions
diff --git a/src/util/usb.c b/src/util/usb.c index 001b72d..90fafb1 100644 --- a/src/util/usb.c +++ b/src/util/usb.c @@ -19,32 +19,61 @@ #include <app_debug.h> #include <gio/gio.h> -#define DEVICED_BUS_NAME "org.tizen.system.deviced" +#include "util/usb.h" + #define DEVICED_INTERFACE_BLOCK "org.tizen.system.deviced.Block" +#define SIGNAL_DEVICE_BLOCKED "DeviceBlocked" #define SIGNAL_DEVICE_CHANGED "DeviceChanged" -struct _changed_cb { +typedef void (*sig_cb_func)(GDBusConnection *connection, + const gchar *sender_name, const gchar *object_path, + const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data); + +static void _device_blocked_cb(GDBusConnection *, const gchar *, const gchar *, + const gchar *, const gchar *, GVariant *, gpointer); +static void _device_changed_cb(GDBusConnection *, const gchar *, const gchar *, + const gchar *, const gchar *, GVariant *, gpointer); + +struct _signal_info { + const char *interface; + const char *sig_name; + sig_cb_func sig_cb; +}; + +static struct _signal_info g_signal_info[E_SIGNAL_MAX] = { + [E_DEVICE_BLOCKED] = { + DEVICED_INTERFACE_BLOCK, + SIGNAL_DEVICE_BLOCKED, + _device_blocked_cb + }, + [E_DEVICE_CHANGED] = { + DEVICED_INTERFACE_BLOCK, + SIGNAL_DEVICE_CHANGED, + _device_changed_cb + } +}; + +struct _cb_data { void (*func)(void *data, int state); void *data; }; struct usb { GDBusConnection *conn; - guint id; - struct _changed_cb cb; + int sub_id[E_SIGNAL_MAX]; + struct _cb_data cb[E_SIGNAL_MAX]; }; -static void _device_changed_cb(GDBusConnection *connection, +static void _device_blocked_cb(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data) { - const gchar *devNode, *sysPath, *fsUsage, *fsType, *fsVer, *fsUuid; - const gchar *mountPoint; - gint32 blockType, readOnly, state; - gboolean primary; + const gchar *uuid, *mount_point; struct usb *m; + int sig; if (!parameters || !user_data) { _ERR("invalid argument"); @@ -53,35 +82,69 @@ static void _device_changed_cb(GDBusConnection *connection, m = user_data; - g_variant_get(parameters, "(issssssisib)", &blockType, &devNode, - &sysPath, &fsUsage, &fsType, &fsVer, &fsUuid, - &readOnly, &mountPoint, &state, &primary); + g_variant_get(parameters, "(ss)", &uuid, &mount_point); + + sig = E_DEVICE_BLOCKED; - if (m->cb.func) - m->cb.func(m->cb.data, state); + if (m->cb[sig].func) + m->cb[sig].func(m->cb[sig].data, USB_REMOVED); } -void usb_set_callback(void *handle, void (*func)(void *, int), void *data) +static void _device_changed_cb(GDBusConnection *connection, + const gchar *sender_name, const gchar *object_path, + const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) { + const gchar *dev_node, *sys_path; + const gchar *fs_usage, *fs_type, *fs_ver, *fs_uuid; + const gchar *mount_point; + gint32 block_type, read_only, state; + gboolean primary; struct usb *m; + int sig; - if (!handle) { + if (!parameters || !user_data) { + _ERR("invalid argument"); + return; + } + + m = user_data; + + g_variant_get(parameters, "(issssssisib)", &block_type, &dev_node, + &sys_path, &fs_usage, &fs_type, &fs_ver, + &fs_uuid, &read_only, &mount_point, + &state, &primary); + + sig = E_DEVICE_CHANGED; + + if (m->cb[sig].func) + m->cb[sig].func(m->cb[sig].data, state); +} + +void usb_set_callback(struct usb *m, int sig, + void (*func)(void *, int), void *data) +{ + if (!m) { _ERR("failed to get usb handle"); return; } - m = handle; + if (sig < 0 || sig >= E_SIGNAL_MAX) { + _ERR("invalid argument"); + return; + } - m->cb.func = func; - m->cb.data = data; + m->cb[sig].func = func; + m->cb[sig].data = data; } struct usb *usb_create(void) { GDBusConnection *conn; GError *error; - guint id; struct usb *m; + struct _signal_info si; + int i; m = calloc(1, sizeof(*m)); if (!m) { @@ -100,25 +163,31 @@ struct usb *usb_create(void) return NULL; } - id = g_dbus_connection_signal_subscribe(conn, NULL, - DEVICED_INTERFACE_BLOCK, SIGNAL_DEVICE_CHANGED, - NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE, - _device_changed_cb, m, NULL); + for (i = 0; i < E_SIGNAL_MAX; i++) { + si = g_signal_info[i]; + + m->sub_id[i] = g_dbus_connection_signal_subscribe(conn, NULL, + si.interface, si.sig_name, NULL, NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + si.sig_cb, m, NULL); + } m->conn = conn; - m->id = id; return m; } void usb_destroy(struct usb *m) { + int i; + if (!m) { _ERR("failed to get usb handle"); return; } - g_dbus_connection_signal_unsubscribe(m->conn, m->id); + for (i = 0; i < E_SIGNAL_MAX; i++) + g_dbus_connection_signal_unsubscribe(m->conn, m->sub_id[i]); free(m); } |