fix build failure
[apps/native/tizen-things-daemon.git] / lib / things-service / src / things-service.c
index 192649e..4835eb3 100644 (file)
@@ -21,6 +21,7 @@
 #include <gio/gio.h>
 #include <gio/gunixsocketaddress.h>
 #include <app_common.h>
+#include <json.h>
 #include "log-private.h"
 #include "things-service.h"
 #include "common-app-inf.h"
@@ -29,6 +30,7 @@
 struct _ts_data {
        char *app_id;
        char *token;
+       char *project;
        GSocket *socket;
        GSocketAddress *addr;
        GSocket *cl_socket;
@@ -75,9 +77,9 @@ __add_timebased_int_to_json_object(gpointer data, gpointer user_data)
        ret_if(!a_obj);
 
        obj = json_object_new_object();
-       retv_if(!obj);
+       ret_if(!obj);
 
-       time_o = json_object_new_int64(tb_int->time);
+       time_o = json_object_new_int64(tb_int->i_time);
        goto_if(!time_o, ERROR);
        json_object_object_add(obj, "x", time_o);
 
@@ -102,13 +104,13 @@ __add_timebased_double_to_json_object(gpointer data, gpointer user_data)
        struct json_object *value_o = NULL;
        struct json_object *time_o = NULL;
 
-       ret_if(!tb_int);
+       ret_if(!tb_double);
        ret_if(!a_obj);
 
        obj = json_object_new_object();
-       retv_if(!obj, NULL);
+       ret_if(!obj);
 
-       time_o = json_object_new_int64(tb_double->time);
+       time_o = json_object_new_int64(tb_double->i_time);
        goto_if(!time_o, ERROR);
        json_object_object_add(obj, "x", time_o);
 
@@ -130,8 +132,6 @@ static char *__timebased_data_to_json(timebased_data *tb_data)
        struct json_object *obj = NULL;
        struct json_object *a_obj = NULL;
        char *json_str = NULL;
-       int i = 0;
-       GList *temp_l = NULL;
 
        retv_if(!tb_data, NULL);
        retvm_if(!((tb_data->type == TS_VALUE_TYPE_INT) ||
@@ -156,7 +156,7 @@ static char *__timebased_data_to_json(timebased_data *tb_data)
                break;
        default:
                _E("invalid type [%d]", tb_data->type);
-               goto ERROR:
+               goto ERROR;
                break;
        }
 
@@ -236,6 +236,9 @@ static void _ts_handle_free(ts_handle handle)
        if (handle->app_id)
                g_free(handle->app_id);
 
+       if (handle->project)
+               g_free(handle->project);
+
        if (handle->token)
                g_free(handle->token);
 
@@ -328,12 +331,14 @@ static int __client_method_call(const char *method, ts_handle handle)
 {
        GVariant *response = NULL;
        int ret = 0;
+       const char *ret_msg = 0;
        GError *error = NULL;
 
        _D("call method [%s]", method);
        response = g_dbus_proxy_call_sync(handle->proxy,
                method,
-               g_variant_new("(ssu)", handle->token, handle->app_id, (guint)getpid()),
+               g_variant_new("(sssu)",
+                       handle->project, handle->token, handle->app_id, (guint)getpid()),
                G_DBUS_CALL_FLAGS_NONE,
                -1, /* The timeout in milliseconds or -1 to use the proxy default timeout. */
                NULL, /* cancellable */
@@ -343,11 +348,14 @@ static int __client_method_call(const char *method, ts_handle handle)
                g_error_free(error);
                return -1;
        }
-       g_variant_get(response, "(i)", ret);
-       _D("method[%s] get response ret[%d]", method, ret);
+       if (!response)
+               return -1;
+
+       g_variant_get(response, "(i&s)", ret, &ret_msg);
+       _D("method[%s] get response ret[%d] - %s", method, ret, ret_msg);
        g_variant_unref(response);
 
-       return 0;
+       return ret;
 }
 
 static int _client_call_register(ts_handle handle)
@@ -360,7 +368,7 @@ static int _client_call_unregister(ts_handle handle)
        return __client_method_call(TTD_APP_INF_METHOD_UNREG, handle);
 }
 
-int things_service_init(ts_handle *handle)
+int things_service_init(ts_handle *handle, const char *project)
 {
        ts_handle _handle = NULL;
        GError *error = NULL;
@@ -369,6 +377,7 @@ int things_service_init(ts_handle *handle)
        retv_if(!handle, -1);
 
        _handle = g_try_malloc0(sizeof(ts_handle));
+       _handle->project = g_strdup(project);
        _handle->app_id = _get_app_id();
        if (!_handle->app_id) {
                _E("failed to get app id");
@@ -528,11 +537,7 @@ void thing_service_timebased_data_free(timebased_data *tb_data)
 {
        ret_if(!tb_data);
 
-       t_data = g_try_malloc0(sizeof(timebased_data));
-       if (!t_data)
-               return NULL;
-
-       if (t_data->v_list)
+       if (tb_data->v_list)
                g_list_free_full(tb_data->v_list, __timebase_value_free);
 
        g_free(tb_data);