--- /dev/null
+/*
+ * 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__ */
--- /dev/null
+/*
+ * 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);
+}