replace gdbus to app_control 27/162427/1
authorSang-Hun Chung <sanghun.chung@samsung.com>
Fri, 1 Dec 2017 04:34:12 +0000 (13:34 +0900)
committerSang-Hun Chung <sanghun.chung@samsung.com>
Fri, 1 Dec 2017 04:34:12 +0000 (13:34 +0900)
Change-Id: I34e42439e7783ffd0845374be545c98780a33908

inc/staticlibrary.h
src/tizen-service-enabler-common.c
src/tizen-service-enabler-lib.c

index acc33b4c22a1074cf645c7dabfadcbdff2d7c4ba..8990bd2d11d932e14badfc86344cf0be595d05fe 100755 (executable)
 extern "C" {
 #endif
 
+typedef void (*hello_cb)(int error, char *result, void* user_data);
+
 // This method is exported from staticlibrary.a
 int test_sum(int a, int b);
 
-int hello(char *hi, char **echo);
-
-typedef void (*bye_cb)(int error, char *echo, void* user_data);
-
-int bye(char* str, bye_cb user_cb, void* user_data);
+int hello(hello_cb user_cb, void* user_data);
 
 extern int get_name_by_id(int id, char** name);
 
@@ -31,6 +29,10 @@ typedef enum {
 int http_download_file(const char *download_url, const char *download_path);
 int http_send_request(fmwup_http_req_e type, char *req_url, char **res_header, char **res_body);
 
+#if 0
+typedef void (*bye_cb)(int error, char *echo, void* user_data);
+int bye(char* str, bye_cb user_cb, void* user_data);
+#endif
 
 #ifdef __cplusplus
 }
index 191549ca75e5245f809b5c9d3c6a92605559ec1d..c39ec125debddeaeea6508cde250e0bc604d93f6 100755 (executable)
@@ -22,6 +22,7 @@
 #define DBUS_PATH_DBUS "/org/freedesktop/DBus"
 #define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
 
+#if 0
 static GDBusConnection *__gdbus_conn = NULL;
 
 
@@ -335,5 +336,5 @@ out:
 
        return registration_id;
 }
-
+#endif
 
index bbbf612357964f9661133bf35fa1ac8ccb41ac4c..f6c62bc0b8fa6aa0bf2b9c5f84f37d83f8f9749c 100755 (executable)
 #include <glib.h>
 #include <sqlite3.h>
 
-#include "staticlibrary.h"
 #include "static_internal.h"
 
-#include <gio/gio.h>
-
-#define SERVICE_ENABLER_NAME "org.example.TizenServiceEnabler"
-#define SERVICE_ENABLER_PATH "/org/example/TizenServiceEnabler"
-#define SERVICE_ENABLER_INTERFACE "org.example.TizenServiceEnabler"
-
-
 
 #ifdef  LOG_TAG
 #undef  LOG_TAG
                dlog_print(DLOG_INFO, LOG_TAG, "%s : %s(%d) > "fmt, rindex(__FILE__, '/')+1, __FUNCTION__, __LINE__,##__VA_ARGS__);\
        } while (0)
 
+#define ERROR_LOG(fmt, ...) do { \
+               dlog_print(DLOG_INFO, LOG_TAG, "%s : %s(%d) > "fmt, rindex(__FILE__, '/')+1, __FUNCTION__, __LINE__,##__VA_ARGS__);\
+       } while (0)
+
+
+
+typedef struct {
+       hello_cb _cb;
+       void* _data;
+} result_t;
+
+
+// This is an example of an exported method.
+int
+test_sum(int a, int b)
+{
+       return a+b;
+}
+
+static void
+_wrapper_cb(app_control_h request, app_control_h reply,
+               app_control_result_e result_error, void *user_data)
+{
+       DEBUG_LOG("");
+       result_t *_ud = (result_t*) user_data;
+       hello_cb func = _ud->_cb;
+
+       int error = (result_error == APP_CONTROL_ERROR_NONE)? 0 : result_error;
+       DEBUG_LOG("result_error %d", result_error);
+
+       char *result = NULL;
+       int ret = app_control_get_extra_data(reply, "result", &result);
+       if (ret != APP_CONTROL_ERROR_NONE) {
+               ERROR_LOG("app_control_get_extra_data error[%d]", ret);
+       }
+
+       func(error, result, _ud->_data);
+       g_free(result);
+}
+
+
+int send_request(char *uri, char *json, hello_cb user_cb, void* user_data)
+{
+
+}
+
+int
+hello(hello_cb user_cb, void* user_data)
+{
+       DEBUG_LOG("hello called");
+       int ret = 0;
+
+//     send_request(uri, input, user_cb, user_data);
+
+       result_t *_result = (void*) malloc(sizeof(result_t));
+       _result->_cb = user_cb;
+       _result->_data = user_data;
+
+// http://org.example.tizen-service-enabler/appcontrol/operation/hello
+
+       app_control_h request;
+       app_control_create(&request);
+//     app_control_set_app_id(request, "org.example.tizen-service-enabler");
+//     app_control_set_operation(request, "http://tizen.org/appcontrol/operation/hello");
+
+       app_control_set_app_id(request, "org.example.tizen-service-enabler");
+       app_control_set_operation(request, "http://org.example.tizen-service-enabler/appcontrol/operation/hello");
+
+
+       ret = app_control_send_launch_request(request, _wrapper_cb, (void*)_result);
+       if (ret != APP_CONTROL_ERROR_NONE) {
+               DEBUG_LOG("app_control_send_launch_request error %d", ret);
+               return ret;
+       }
+       return ret;
+}
+
+
+//access other module's DB
+int get_name_by_id(int id, char** name)
+{
+       sqlite3_stmt *stmt = NULL;
+       char *errmsg = NULL;
+       char *query = sqlite3_mprintf("SELECT * FROM test_tbl WHERE id = %d;", id);
+
+//     char *db_path ="/opt/usr/home/owner/apps_rw/org.example.tizen-service-enabler/shared/trusted/test.db"; // shared trusted data
+       char *db_path ="/opt/usr/home/owner/apps_rw/org.example.tizen-service-enabler/shared/data/test.db"; // shared data
+//     char *db_path ="/opt/usr/home/owner/apps_rw/org.example.tizen-service-enabler/data/test.db"; // private data
+       sqlite3 *db = NULL;
+       int rc = sqlite3_open_v2(db_path, &db, SQLITE_OPEN_READONLY, NULL);
+       if (rc != SQLITE_OK) {
+               DEBUG_LOG("sqlite3_open error: %s\n", sqlite3_errmsg(db));
+               DEBUG_LOG("sqlite3_open path: %s\n", db_path);
+               return false;
+       }
+
+       rc = sqlite3_prepare(db, query, strlen(query), &stmt, (const char**)&errmsg);
+       if (rc != SQLITE_OK) {
+               DEBUG_LOG("sqlite3_prepare error: msg[%s], err[%d], SQLITE_BUSY [%d]", errmsg, rc, SQLITE_BUSY);
+               return -1;
+       }
+
+       rc = sqlite3_step(stmt);
+       if (rc != SQLITE_ROW || rc == SQLITE_DONE) {
+               DEBUG_LOG("No records found");
+               return -1;
+       }
+
+       *name = g_strdup((char *) sqlite3_column_text(stmt, 1));
+       DEBUG_LOG("name [%s]", *name);
+
+       return 1;
+}
+
+#if 0
+
+#include <gio/gio.h>
+
+#define SERVICE_ENABLER_NAME "org.example.TizenServiceEnabler"
+#define SERVICE_ENABLER_PATH "/org/example/TizenServiceEnabler"
+#define SERVICE_ENABLER_INTERFACE "org.example.TizenServiceEnabler"
+
+
 typedef struct {
        bye_cb _cb;
        void* _data;
@@ -136,4 +251,4 @@ int get_name_by_id(int id, char** name)
 
        return 1;
 }
-
+#endif