summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJehun Lim <jehun.lim@samsung.com>2015-12-14 11:04:38 (GMT)
committerJehun Lim <jehun.lim@samsung.com>2015-12-14 11:04:38 (GMT)
commita167d7f44c54bd229a306ffce4106616c9d19993 (patch)
treea6863feeb734329fa11795b48242607bf6277a6d
parentd5e2f084be25e70fa9a089a9dc17e491fed4105d (diff)
downloadair_mediahub-a167d7f44c54bd229a306ffce4106616c9d19993.zip
air_mediahub-a167d7f44c54bd229a306ffce4106616c9d19993.tar.gz
air_mediahub-a167d7f44c54bd229a306ffce4106616c9d19993.tar.bz2
add usb util to get usb device changed signalrefs/changes/67/54267/1
Change-Id: If0f0128234af530eda7d02f36a337b4d09b49026 Signed-off-by: Jehun Lim <jehun.lim@samsung.com>
-rw-r--r--CMakeLists.txt2
-rw-r--r--include/util/usb.h28
-rw-r--r--packaging/org.tizen.mediahub.spec1
-rw-r--r--src/util/usb.c124
4 files changed, 155 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8d9e4da..b75a26d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,6 +19,7 @@ PROJECT("mediahub" C)
INCLUDE(FindPkgConfig)
pkg_check_modules(PKGS REQUIRED
glib-2.0
+ gio-2.0
elementary
capi-appfw-application
capi-media-player
@@ -71,6 +72,7 @@ src/layout/music.c
src/util/controller.c
src/util/listmgr.c
src/util/timeout_handler.c
+src/util/usb.c
src/util/util.c
src/util/playermgr.c
src/util/ctxpopup.c
diff --git a/include/util/usb.h b/include/util/usb.h
new file mode 100644
index 0000000..cc19546
--- /dev/null
+++ b/include/util/usb.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __AIR_MEDIAHUB_USB_H__
+#define __AIR_MEDIAHUB_USB_H__
+
+struct usb;
+
+struct usb *usb_create(void);
+void usb_destroy(struct usb *m);
+
+int usb_set_callback(struct usb *m, void (*func)(void *, int),
+ void *data);
+
+#endif /* __AIR_MEDIAHUB_USB_H__ */
diff --git a/packaging/org.tizen.mediahub.spec b/packaging/org.tizen.mediahub.spec
index 978ad20..6058c18 100644
--- a/packaging/org.tizen.mediahub.spec
+++ b/packaging/org.tizen.mediahub.spec
@@ -9,6 +9,7 @@ Source1: %{name}.manifest
BuildRequires: cmake
BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(gio-2.0)
BuildRequires: pkgconfig(elementary)
BuildRequires: pkgconfig(capi-appfw-application)
BuildRequires: pkgconfig(capi-media-player)
diff --git a/src/util/usb.c b/src/util/usb.c
new file mode 100644
index 0000000..001b72d
--- /dev/null
+++ b/src/util/usb.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <stdbool.h>
+#include <app_debug.h>
+#include <gio/gio.h>
+
+#define DEVICED_BUS_NAME "org.tizen.system.deviced"
+#define DEVICED_INTERFACE_BLOCK "org.tizen.system.deviced.Block"
+
+#define SIGNAL_DEVICE_CHANGED "DeviceChanged"
+
+struct _changed_cb {
+ void (*func)(void *data, int state);
+ void *data;
+};
+
+struct usb {
+ GDBusConnection *conn;
+ guint id;
+ struct _changed_cb cb;
+};
+
+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 *devNode, *sysPath, *fsUsage, *fsType, *fsVer, *fsUuid;
+ const gchar *mountPoint;
+ gint32 blockType, readOnly, state;
+ gboolean primary;
+ struct usb *m;
+
+ if (!parameters || !user_data) {
+ _ERR("invalid argument");
+ return;
+ }
+
+ m = user_data;
+
+ g_variant_get(parameters, "(issssssisib)", &blockType, &devNode,
+ &sysPath, &fsUsage, &fsType, &fsVer, &fsUuid,
+ &readOnly, &mountPoint, &state, &primary);
+
+ if (m->cb.func)
+ m->cb.func(m->cb.data, state);
+}
+
+void usb_set_callback(void *handle, void (*func)(void *, int), void *data)
+{
+ struct usb *m;
+
+ if (!handle) {
+ _ERR("failed to get usb handle");
+ return;
+ }
+
+ m = handle;
+
+ m->cb.func = func;
+ m->cb.data = data;
+}
+
+struct usb *usb_create(void)
+{
+ GDBusConnection *conn;
+ GError *error;
+ guint id;
+ struct usb *m;
+
+ m = calloc(1, sizeof(*m));
+ if (!m) {
+ _ERR("failed to alloc usb");
+ return NULL;
+ }
+
+ error = NULL;
+
+ conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (!conn) {
+ _ERR("failed to get bus connection: %s",
+ error ? error->message : "");
+ g_error_free(error);
+ free(m);
+ 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);
+
+ m->conn = conn;
+ m->id = id;
+
+ return m;
+}
+
+void usb_destroy(struct usb *m)
+{
+ if (!m) {
+ _ERR("failed to get usb handle");
+ return;
+ }
+
+ g_dbus_connection_signal_unsubscribe(m->conn, m->id);
+
+ free(m);
+}