Fix documentation for storage_get_internal_memory_size and storage_get_external_memor...
[platform/core/system/libstorage.git] / src / storage-external-dbus.c
index f070e8f..5d45189 100755 (executable)
@@ -51,6 +51,11 @@ struct storage_ext_callback {
        guint block_id;
 };
 
+typedef struct {
+        dbus_pending_cb func;
+        void *data;
+} pending_call_data;
+
 static dd_list *changed_list;
 
 static void storage_ext_release_internal(storage_ext_device *dev)
@@ -118,6 +123,79 @@ static GDBusConnection *get_dbus_connection(void)
        return conn;
 }
 
+static void _cb_pending(GDBusConnection *conn,
+                       GAsyncResult *res,
+                       gpointer user_data)
+{
+       GVariant *reply = NULL;
+       GError *err = NULL;
+       pending_call_data *data = (pending_call_data *)user_data;
+
+       reply = g_dbus_connection_call_finish(conn, res, &err);
+       if (!reply || err) {
+               if (!err)
+                       g_set_error(&err, G_IO_ERROR, G_IO_ERROR_FAILED,
+                               "Error during g_dbus_connection_call");
+
+               if (data && data->func)
+                       data->func(NULL, data->data, err);
+               goto out;
+       }
+
+       if (data && data->func)
+               data->func(reply, data->data, err);
+out:
+       if (err)
+               g_error_free(err);
+       if (data)
+               free(data);
+}
+
+int dbus_method_async_with_reply_var(const char *dest, const char *path,
+               const char *iface, const char *method, GVariant *param,
+               dbus_pending_cb cb, int timeout, void *data)
+{
+       GDBusConnection *conn;
+       pending_call_data *pdata = NULL;
+       int ret = 0;
+
+       if (!dest || !path || !iface || !method)
+               return -EINVAL;
+
+       if (timeout < -1) {
+               _E("wrong timeout %d", timeout);
+               return -EINVAL;
+       }
+
+       conn = get_dbus_connection();
+       if (!conn) {
+               _E("fail to get dbus connection"); //LCOV_EXCL_LINE
+               return -1;
+       }
+
+       if (cb) {
+               pdata = (pending_call_data*)malloc(sizeof(pending_call_data));
+               if (!pdata) {
+                       ret = -ENOMEM;
+                       goto err;
+               }
+
+               pdata->func = cb;
+               pdata->data = data;
+       }
+
+       g_dbus_connection_call(conn, dest, path, iface, method,
+                       param, NULL, G_DBUS_CALL_FLAGS_NONE, timeout, NULL,
+                       (GAsyncReadyCallback)_cb_pending,
+                       pdata);
+
+       return ret;
+err:
+       if (param)
+               g_variant_unref(param);
+       return ret;
+}
+
 GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path,
                                const gchar *iface, const gchar *method, GVariant *param)
 {