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);
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
}
#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;
return 1;
}
-
+#endif