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 | |
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>
-rw-r--r-- | include/util/usb.h | 13 | ||||
-rw-r--r-- | src/util/usb.c | 121 | ||||
-rw-r--r-- | src/view/base.c | 32 |
3 files changed, 127 insertions, 39 deletions
diff --git a/include/util/usb.h b/include/util/usb.h index cc19546..0166495 100644 --- a/include/util/usb.h +++ b/include/util/usb.h @@ -17,12 +17,21 @@ #ifndef __AIR_MEDIAHUB_USB_H__ #define __AIR_MEDIAHUB_USB_H__ +#define USB_ADDED 1 +#define USB_REMOVED 0 + struct usb; +enum usb_signal { + E_DEVICE_BLOCKED, + E_DEVICE_CHANGED, + E_SIGNAL_MAX +}; + struct usb *usb_create(void); void usb_destroy(struct usb *m); -int usb_set_callback(struct usb *m, void (*func)(void *, int), - void *data); +void usb_set_callback(struct usb *m, int sig, + void (*func)(void *, int), void *data); #endif /* __AIR_MEDIAHUB_USB_H__ */ 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); } diff --git a/src/view/base.c b/src/view/base.c index b44b498..abb826a 100644 --- a/src/view/base.c +++ b/src/view/base.c @@ -41,9 +41,6 @@ #define TEXT_USB_ADDED "USB Connected" #define TEXT_USB_REMOVED "USB Disconnected" -#define USB_ADDED 1 -#define USB_REMOVED 0 - #define BOX_PADDING_SIZE 80 #define TIME_TOAST 5.0 @@ -832,10 +829,21 @@ static void _media_db_updated_cb(media_content_error_e error, _hide_toast(priv); } +static void _show_base_view(void) +{ + struct view_update_data vdata; + + vdata.status = E_PLAYER_STOP; + viewmgr_update_view(VIEW_MPLAYER, UPDATE_PLAYER, &vdata); + + /* to show base view */ + while (viewmgr_active_view_count() > 1) + viewmgr_pop_view(); +} + static void _usb_changed_cb(void *data, int state) { media_content_noti_h noti_h; - struct view_update_data vdata; struct _priv *priv; int r; @@ -851,16 +859,17 @@ static void _usb_changed_cb(void *data, int state) priv->noti_h = noti_h; - vdata.status = E_PLAYER_STOP; - viewmgr_update_view(VIEW_MPLAYER, UPDATE_PLAYER, &vdata); - - /* to show base view */ - while (viewmgr_active_view_count() > 1) - viewmgr_pop_view(); + if (state == USB_ADDED) + _show_base_view(); _show_toast_usb(priv, state); } +static void _usb_blocked_cb(void *data, int state) +{ + _show_base_view(); +} + static Evas_Object *_create(Evas_Object *win, void *data) { struct usb *usb_h; @@ -904,7 +913,8 @@ static Evas_Object *_create(Evas_Object *win, void *data) return NULL; } - usb_set_callback(usb_h, _usb_changed_cb, priv); + usb_set_callback(usb_h, E_DEVICE_BLOCKED, _usb_blocked_cb, priv); + usb_set_callback(usb_h, E_DEVICE_CHANGED, _usb_changed_cb, priv); priv->usb_h = usb_h; |