Add async API 29/177029/1 sangnamja
authorjunkyu han <junkyu.han@samsung.com>
Tue, 24 Apr 2018 23:21:36 +0000 (08:21 +0900)
committerjunkyu han <junkyu.han@samsung.com>
Tue, 24 Apr 2018 23:21:59 +0000 (08:21 +0900)
Change-Id: I12cd65d19556ca1bf1d4280dcc68280b36d8d973

daemon/src/tizen-things-daemon.c
daemon/tizen-things-daemon-dbus.xml
lib/include/ttsd-worker-lib.h
lib/src/ttsd-worker-lib.c

index 33e53e7..6794d8d 100644 (file)
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
+
 int main(int argc, char* argv[])
 {
-
        return 0;
 }
index 91b6ee2..9632f45 100644 (file)
@@ -9,6 +9,11 @@
 
                <!-- Method definitions -->
 
+               <method name="ttsd_worker_submit_report_async">
+                       <arg type="s" name="report" direction="in"/>
+                       <arg type="i" name="ret" direction="out"/>
+               </method>
+
                <method name="ttsd_worker_submit_report">
                        <arg type="s" name="report" direction="in"/>
                        <arg type="i" name="ret" direction="out"/>
index 26c5e96..6f9229c 100644 (file)
@@ -19,6 +19,9 @@
 #ifndef __TTSD_WORKER_LIB_H__
 #define __TTSD_WORKER_LIB_H__
 
+typedef void(*ttsd_worker_submit_report_completed_cb)(char *result, void *user_data);
+
+int ttsd_worker_submit_report_async(char *report, ttsd_worker_submit_report_completed_cb completed_cb);
 int ttsd_worker_submit_report(char *report);
 
 #endif /* __TTSD_WORKER_LIB_H__ */
index 2503008..81ef310 100644 (file)
@@ -30,10 +30,12 @@ typedef struct {
        GCancellable *cancellable;
        GDBusConnection *client_bus;
        GDBusProxy *client_bus_proxy;
+       ttsd_worker_submit_report_completed_cb completed_cb;
 } dbus_h;
 
 static dbus_h *__make_dbus_connection(void);
 static void __destroy_dbus_connection(dbus_h *h);
+static void __submit_completed_cb(GObject *source_object, GAsyncResult *res, gpointer user_data);
 
 static void __destroy_dbus_connection(dbus_h *h)
 {
@@ -90,6 +92,52 @@ ERROR:
        return NULL;
 }
 
+static void __submit_completed_cb(GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+       GError *g_error = NULL;
+       GVariant *g_var;
+       dbus_h *h = user_data;
+       char *result = NULL;
+
+       _D("Send completed");
+
+       if (h == NULL) {
+               _E("There's no user_data for dbus_h");
+               return;
+       }
+
+       g_var = g_dbus_proxy_call_finish(h->client_bus_proxy, res, &g_error);
+       if (g_error) {
+               _E("DBus proxy call is failed[%s]", g_error->message);
+               result = strdup("Failed to submit report");
+               g_error_free(g_error);
+       } else {
+               result = strdup("Success to submit report");
+               g_variant_unref(g_var);
+       }
+
+       h->completed_cb(result, NULL);
+
+       __destroy_dbus_connection(h);
+}
+
+int ttsd_worker_submit_report_async(char *report, ttsd_worker_submit_report_completed_cb completed_cb)
+{
+       dbus_h *h = NULL;
+
+       h = __make_dbus_connection();
+       if (!h) {
+               _E("Failed to make dbus connection");
+               return -1;
+       }
+
+       h->completed_cb = completed_cb;
+
+       g_dbus_proxy_call(h->client_bus_proxy, "ttsd_worker_submit_report_async", g_variant_new("(s)", report), G_DBUS_CALL_FLAGS_NONE, -1, h->cancellable, (GAsyncReadyCallback) __submit_completed_cb, h);
+
+       return 0;
+}
+
 int ttsd_worker_submit_report(char *report)
 {
        dbus_h *h = NULL;