--- /dev/null
+#ifndef _AGENT_UTIL_H_
+#define _AGENT_UTIL_H_
+
+/**
+ * This header file is included to define _EXPORT_.
+ */
+#include <stdbool.h>
+#include <gio/gio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int send_request(char *appid, char *operation, char *json,
+ hello_cb user_cb, void* user_data);
+
+
+int proxy_send_command(const char *bus_name, const char *bus_obj, const char *bus_if,
+ int cmd_type, GVariant *cmd_param, GVariant **cmd_ret);
+
+
+typedef void (*proxy_cb)(int error, GVariant* ret, void* user_data);
+
+int proxy_send_command_async(const char *bus_name, const char *bus_obj, const char *bus_if,
+ int cmd_type, GVariant *data, proxy_cb user_cb, void *user_data);
+
+
+int dbus_init();
+
+int register_dbus_interface(const char *bus_name, const char *bus_obj, const char *bus_if);
+
+#define SERVICE_ENABLER_NAME "org.example.TizenServiceEnabler"
+#define SERVICE_ENABLER_PATH "/org/example/TizenServiceEnabler"
+#define SERVICE_ENABLER_INTERFACE "org.example.TizenServiceEnabler"
+
+#ifdef __cplusplus
+}
+#endif
+#endif // _AGENT_UTIL_H_
+
--- /dev/null
+#ifndef _SSA_API_H_
+#define _SSA_API_H_
+
+/**
+ * This header file is included to define _EXPORT_.
+ */
+#include <stdbool.h>
+
+#ifdef __cplusplus
+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 *json, hello_cb user_cb, void* user_data);
+
+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);
+
+typedef enum ERROR_CODE {
+ SSE_ERROR_NONE = 0,
+ SSE_ERROR_APP_CONTROL,
+ SSE_ERROR_NULL_PTR,
+ SSE_ERROR_MEM_ALLOC,
+ SSE_ERROR_NOT_SUPPORTED,
+} error_t ;
+
+
+#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
+}
+#endif
+#endif // _SSA_API_H_
\ No newline at end of file
+++ /dev/null
-#ifndef _STATIC_INTERNAL_H_
-#define _STATIC_INTERNAL_H_
-
-/**
- * This header file is included to define _EXPORT_.
- */
-#include <stdbool.h>
-#include <gio/gio.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int proxy_send_command(const char *bus_name, const char *bus_obj, const char *bus_if,
- int cmd_type, GVariant *cmd_param, GVariant **cmd_ret);
-
-
-typedef void (*proxy_cb)(int error, GVariant* ret, void* user_data);
-
-int proxy_send_command_async(const char *bus_name, const char *bus_obj, const char *bus_if,
- int cmd_type, GVariant *data, proxy_cb user_cb, void *user_data);
-
-
-int dbus_init();
-
-int register_dbus_interface(const char *bus_name, const char *bus_obj, const char *bus_if);
-
-#define SERVICE_ENABLER_NAME "org.example.TizenServiceEnabler"
-#define SERVICE_ENABLER_PATH "/org/example/TizenServiceEnabler"
-#define SERVICE_ENABLER_INTERFACE "org.example.TizenServiceEnabler"
-
-#ifdef __cplusplus
-}
-#endif
-#endif // _STATIC_INTERNAL_H_
-
+++ /dev/null
-#ifndef _STATICLIBRARY_H_
-#define _STATICLIBRARY_H_
-
-/**
- * This header file is included to define _EXPORT_.
- */
-#include <stdbool.h>
-
-#ifdef __cplusplus
-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(hello_cb user_cb, void* user_data);
-
-extern int get_name_by_id(int id, char** name);
-
-typedef enum {
- FMWUP_HTTP_GET = 0,
- FMWUP_HTTP_POST,
- FMWUP_HTTP_PUT,
- FMWUP_HTTP_DELETE
-} fmwup_http_req_e;
-
-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
-}
-#endif
-#endif // _STATICLIBRARY_H_
-
--- /dev/null
+#include <dlog.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <stdlib.h>
+#include <app_control.h>
+#include "service_agent_lib.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "SSE_COMMON"
+#define DEBUG_LOG(fmt, ...) do { \
+ 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;
+
+static void
+_wrapper_cb(app_control_h request, app_control_h reply,
+ app_control_result_e result_error, void *user_data)
+{
+ DEBUG_LOG("enter");
+ 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 *appid, char *operation, char *json,
+ hello_cb user_cb, void* user_data)
+{
+ if (!appid || !operation) {
+ ERROR_LOG("uri NULL[%p], operation NULL[%p]", appid, operation);
+ return SSE_ERROR_NULL_PTR; //temp:error_code NULL
+ }
+
+ int ret = 0; //temp:error_code sucess
+ app_control_h request = NULL;
+ result_t *_result = (void*) malloc(sizeof(result_t));
+ if (!_result) {
+ ERROR_LOG("malloc error");
+ return -1; //temp:error_code malloc
+ }
+ _result->_cb = user_cb;
+ _result->_data = user_data;
+
+ if ((ret = app_control_create(&request)) != APP_CONTROL_ERROR_NONE) {
+ ERROR_LOG("app_control_create error[%d]", ret);
+ ret = -1; //temp: error_code other module
+ goto out;
+ }
+ if ((ret=app_control_set_app_id(request, appid)) != APP_CONTROL_ERROR_NONE) {
+ ERROR_LOG("app_control_set_app_id error[%d]", ret);
+ ret = -1; //temp: error_code other module
+ goto out;
+ }
+ if ((ret=app_control_set_operation(request, operation)) != APP_CONTROL_ERROR_NONE) {
+ ERROR_LOG("app_control_set_operation error[%d]", ret);
+ ret = -1; //temp: error_code other module
+ goto out;
+ }
+
+ ret = app_control_send_launch_request(request, _wrapper_cb, (void*)_result);
+ if (ret != APP_CONTROL_ERROR_NONE) {
+ ERROR_LOG("app_control_send_launch_request error[%d]", ret);
+ ret = -1; //temp: error_code other module
+ }
+
+out:
+ if (ret != 0)
+ g_free(_result);
+
+ app_control_destroy(request);
+ return ret;
+}
+
+
+
+#if 0
+#define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
+#define DBUS_PATH_DBUS "/org/freedesktop/DBus"
+#define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
+
+
+
+static GDBusConnection *__gdbus_conn = NULL;
+
+
+int default_handler(int cmd_type, GVariant *input, GVariant **cmd_ret)
+{
+ char *hi;
+ int err = 0;
+
+ if (!cmd_ret) {
+ return -1; // error code required
+ }
+
+ g_variant_get(input, "s", &hi);
+ DEBUG_LOG("cmd_type[%d], param[%s]", cmd_type, hi);
+
+ char *tmp = g_strdup_printf("you said [%s]", hi);
+ *cmd_ret = g_variant_new("s", tmp);
+
+ return err;
+}
+
+GVariant* stub_send_command(GVariant *parameters)
+{
+ DEBUG_LOG("called");
+ if (!parameters) {
+ ERROR_LOG("NULL param");
+ return NULL;
+ }
+
+ gint cmd_type;
+ GVariant *val;
+ GVariant *ret = NULL;
+ GVariant *cmd_ret = NULL;
+ int cmd_error = 0;
+
+ DEBUG_LOG("1");
+ g_variant_get(parameters, "(iv)", &cmd_type, &val);
+ DEBUG_LOG("2");
+
+ switch (cmd_type) {
+ case 20: {
+ cmd_error = default_handler(cmd_type, val, &cmd_ret);
+ break;
+ }
+ case 30: {
+ cmd_error = default_handler(cmd_type, val, &cmd_ret);
+ break;
+ }
+ }
+
+ if (cmd_error != 0) {
+ cmd_ret = g_variant_new("s", " ");
+ }
+ ret = g_variant_new("(iv)", cmd_error, cmd_ret );
+
+ return ret;
+}
+
+
+int proxy_send_command(const char *bus_name, const char *bus_obj, const char *bus_if,
+ int cmd_type, GVariant *cmd_param, GVariant **cmd_ret)
+{
+ DEBUG_LOG("cmd[%d]", cmd_type);
+ if(!__gdbus_conn)
+ dbus_init();
+
+ int ret = 0;
+
+ GError *gerror = NULL;
+ GCancellable *proxy_cancel = g_cancellable_new();
+ DEBUG_LOG("cmd[%d]", cmd_type);
+ GVariant *params = g_variant_new("(iv)", cmd_type, cmd_param);
+
+
+ GVariant *result = g_dbus_connection_call_sync(
+ __gdbus_conn,
+ bus_name,
+ bus_obj,
+ bus_if,
+ "send_command",
+ params,
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ proxy_cancel,
+ &gerror);
+
+ if (!result) {
+ DEBUG_LOG("g_dbus_proxy_call_sync 'send_command' error [%s]",
+ (gerror ? gerror->message : "null"));
+ ret = -1; // error code required
+ goto EXIT;
+ }
+
+ g_variant_get(result, "(iv)", &ret, cmd_ret);
+ DEBUG_LOG("error[%d]", ret);
+
+EXIT:
+ return ret;
+}
+
+
+typedef struct {
+ proxy_cb _cb;
+ void* _data;
+} proxy_data_t;
+
+
+void _proxy_wrapper_cb (GObject *gobj, GAsyncResult *res, gpointer user_data)
+{
+ DEBUG_LOG ("");
+
+ GError *gerror;
+ GVariant *result, *val;
+ int error = 0; // error enum required
+
+ gerror = NULL;
+ result = g_dbus_connection_call_finish (__gdbus_conn, res, &gerror);
+ if (!result) {
+ error = -1; // error enum required
+ val = g_variant_new("()");
+ DEBUG_LOG("g_dbus_connection_call_finish error [%s]",
+ (gerror ? gerror->message : "null"));
+ }
+ else {
+ g_variant_get (result, "(iv)", &error, &val); // error type passing required
+ }
+ proxy_data_t *_wrapper = (proxy_data_t*) user_data;
+ _wrapper->_cb(error, val, _wrapper->_data);
+}
+
+
+int proxy_send_command_async(const char *bus_name, const char *bus_obj, const char *bus_if,
+ int cmd_type, GVariant *data, proxy_cb user_cb, void* user_data)
+{
+ DEBUG_LOG("async begin");
+ if(!__gdbus_conn)
+ dbus_init();
+
+ int ret = 0;
+
+ GCancellable *proxy_cancel = g_cancellable_new();
+ DEBUG_LOG("cmd[%d]", cmd_type);
+ GVariant *params = g_variant_new("(iv)", cmd_type, data);
+
+ proxy_data_t *_wrapper = (void*) malloc(sizeof(proxy_data_t));
+ if (!_wrapper) {
+ DEBUG_LOG("malloc error");
+ return -1; // error enum required
+ }
+ _wrapper->_cb = user_cb;
+ _wrapper->_data = user_data;
+
+
+ g_dbus_connection_call(
+ __gdbus_conn,
+ bus_name,
+ bus_obj,
+ bus_if,
+ "send_command",
+ params,
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ proxy_cancel,
+ _proxy_wrapper_cb,
+ _wrapper);
+
+
+ return ret;
+}
+
+
+static void __dbus_method_call_handler(GDBusConnection *conn,
+ const gchar *sender, const gchar *object_path,
+ const gchar *iface_name, const gchar *method_name,
+ GVariant *parameters, GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ DEBUG_LOG("method_name: %s", method_name);
+/* gpointer sender_pid = g_hash_table_lookup(__sender_appid_hash, sender);
+ if (sender_pid == NULL) {
+ if (!__check_sender_validation(parameters, sender, conn))
+ goto out;
+ }
+*/
+ GVariant *ret = NULL;
+ if (g_strcmp0(method_name, "send_command") == 0)
+ ret = stub_send_command(parameters);
+
+ g_dbus_method_invocation_return_value(invocation, ret);
+}
+
+
+static const GDBusInterfaceVTable interface_vtable = {
+ __dbus_method_call_handler,
+ NULL,
+ NULL
+};
+
+
+int dbus_init()
+{
+ if (__gdbus_conn) return 0;
+ DEBUG_LOG("");
+ int ret = -1;
+ GError *error = NULL;
+
+ __gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
+ if (__gdbus_conn == NULL) {
+ if (error != NULL) {
+ DEBUG_LOG("g_bus_get_sync error [%s]", error->message);
+ g_error_free(error);
+ }
+ goto out;
+ }
+
+ ret = 0;
+
+out:
+ if (!__gdbus_conn)
+ g_object_unref(__gdbus_conn);
+
+ return ret;
+
+}
+
+
+int register_dbus_interface(const char *bus_name, const char *bus_obj, const char *bus_if)
+{
+ /* check param */
+ DEBUG_LOG("%s %s %s", bus_name, bus_obj, bus_if);
+ GDBusNodeInfo *introspection_data = NULL;
+ int registration_id = 0;
+
+
+ static gchar introspection_prefix[] =
+ "<node>"
+ " <interface name='";
+
+ static gchar introspection_postfix[] =
+ "'>"
+ " <method name='send_command'>"
+ " <arg type='i' name='cmd' direction='in'/>"
+ " <arg type='v' name='data' direction='in'/>"
+ " <arg type='i' name='error' direction='out'/>"
+ " <arg type='v' name='ret' direction='out'/>"
+ " </method>"
+ " </interface>"
+ "</node>";
+
+ char *introspection_xml = g_strdup_printf("%s%s%s",
+ introspection_prefix, bus_if, introspection_postfix);
+ int owner_id = 0;
+ GError *error = NULL;
+ GVariant *result = NULL;
+
+ DEBUG_LOG("xml[%s]", introspection_xml);
+
+
+ result = g_dbus_connection_call_sync(
+ __gdbus_conn,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS,
+ "RequestName",
+ g_variant_new("(su)", bus_name, G_BUS_NAME_OWNER_FLAGS_NONE),
+ G_VARIANT_TYPE("(u)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ if (error) {
+ DEBUG_LOG("RequestName fail : %s", error->message);
+ goto out;
+ }
+ if (result == NULL) {
+ DEBUG_LOG("fail to get name NULL");
+ goto out;
+ }
+ g_variant_get(result, "(u)", &owner_id);
+ if (owner_id == 0) {
+ DEBUG_LOG("Acquiring the own name is failed");
+ goto out;
+ }
+
+ DEBUG_LOG("Acquiring the own name : %d", owner_id);
+
+ introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
+ if (!introspection_data) {
+ DEBUG_LOG("g_dbus_node_info_new_for_xml() is failed.");
+ goto out;
+ }
+
+ registration_id = g_dbus_connection_register_object(__gdbus_conn,
+ bus_obj, introspection_data->interfaces[0],
+ &interface_vtable, NULL, NULL, NULL);
+
+ DEBUG_LOG("registration_id %d", registration_id);
+
+ if (registration_id == 0) {
+ DEBUG_LOG("Failed to g_dbus_connection_register_object");
+ goto out;
+ }
+
+out:
+ if (introspection_data)
+ g_dbus_node_info_unref(introspection_data);
+ if (result)
+ g_variant_unref(result);
+
+ return registration_id;
+}
+#endif
+
+++ /dev/null
-#include <curl/curl.h>
-#include <glib.h>
-#include "staticlibrary.h"
-//#include <fmwup_resource_internal.h>
-
-
-
-
-static size_t _gather_data(void *downloaded_data,
- size_t size,
- size_t nmemb,
- void *user_data)
-{
- size_t total_size = size * nmemb;
- g_byte_array_append((GByteArray *)user_data, (const unsigned char *) downloaded_data, total_size);
- return total_size;
-}
-
-
-void _curl_set_response(CURL *curl,
- GByteArray *response_header,
- GByteArray *response_body,
- char **res_header,
- char **res_body,
- void *user_data)
-{
- CURLcode curl_ret_code;
-
- long response = 0;
- curl_ret_code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
- if (CURLE_OK != curl_ret_code)
- return;
-
- char *tmp_header = g_strndup((const gchar *)response_header->data, response_header->len);
- char *tmp_body = g_strndup((const gchar *)response_body->data, response_body->len);
-
- *res_header = tmp_header;
- *res_body = tmp_body;
-}
-
-
-void _curl_set_common_option(CURL *curl,
- const char *url,
- GByteArray **response_header_ptr,
- GByteArray **response_body_ptr)
-{
- //LOG("_curl_set_common_option()");
- CURLcode curl_ret_code;
-
- //LOG("set URL = [%s]", url);
- curl_ret_code = curl_easy_setopt(curl, CURLOPT_URL, url);
- if (CURLE_OK != curl_ret_code) {
- //LOG("curl_easy_setopt: CURLOPT_URL failed!! curl_ret_code[%d]", curl_ret_code);
- }
-
- GByteArray *response_header_data = g_byte_array_new();
- curl_ret_code = curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, _gather_data);
- if (CURLE_OK != curl_ret_code) {
- //LOG("curl_easy_setopt: CURLOPT_HEADERFUNCTION failed!! curl_ret_code[%d]", curl_ret_code);
- }
-
- curl_ret_code = curl_easy_setopt(curl, CURLOPT_HEADERDATA, response_header_data);
- if (CURLE_OK != curl_ret_code) {
- //LOG("curl_easy_setopt: CURLOPT_HEADERDATA failed!! curl_ret_code[%d]", curl_ret_code);
- }
-
- GByteArray *response_body_data = g_byte_array_new();
-
- curl_ret_code = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _gather_data);
- if (CURLE_OK != curl_ret_code) {
- //LOG("curl_easy_setopt: CURLOPT_WRITEFUNCTION failed!! curl_ret_code[%d]", curl_ret_code);
- }
-
- curl_ret_code = curl_easy_setopt(curl, CURLOPT_WRITEDATA, response_body_data);
- if (CURLE_OK != curl_ret_code) {
- //LOG("curl_easy_setopt: CURLOPT_WRITEDATA failed!! curl_ret_code[%d]", curl_ret_code);
- }
-
- curl_ret_code = curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
- if (CURLE_OK != curl_ret_code) {
- //LOG("curl_easy_setopt: CURLOPT_NOPROGRESS failed!! curl_ret_code[%d]", curl_ret_code);
- }
-
- *response_header_ptr = response_header_data;
- *response_body_ptr = response_body_data;
-
-#if 0
- curl_ret_code = curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
- if (CURLE_OK != curl_ret_code) {
- //LOG("curl_easy_setopt: CURLOPT_VERBOSE failed!! curl_ret_code[%d]", curl_ret_code);
- }
-
- curl_ret_code = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
- if (CURLE_OK != curl_ret_code) {
- //LOG("curl_easy_setopt: CURLOPT_SSL_VERIFYPEER failed!! curl_ret_code[%d]", curl_ret_code);
- }
-
- curl_ret_code = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, FALSE);
- if (CURLE_OK != curl_ret_code) {
- //LOG("curl_easy_setopt: CURLOPT_SSL_VERIFYHOST failed!! curl_ret_code[%d]", curl_ret_code);
- }
-
- curl_ret_code = curl_easy_setopt(curl, CURLOPT_CERTINFO, 0L);
- if (CURLE_OK != curl_ret_code) {
- //LOG("curl_easy_setopt: CURLOPT_CERTINFO failed!! curl_ret_code[%d]", curl_ret_code);
- }
-#endif
-}
-
-
-static void _curl_set_request_headers(CURL *curl)
-{
- struct curl_slist *header = NULL;
-
- char *tmp_header = NULL;
-
- tmp_header = g_strconcat("Content-Type: ", "application/json", NULL);
- //LOG("header=[%s]", tmp_header);
- header = curl_slist_append(header, tmp_header);
- g_free(tmp_header);
-
- curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
-}
-
-
-int http_send_request(fmwup_http_req_e type, char *req_url, char **res_header, char **res_body)
-{
- //LOG("Enter http_send_request()");
-
- CURL *curl;
- GByteArray *response_header = NULL;
- GByteArray *response_body= NULL;
- CURLcode error_code;
- int ret = 0;
-
- // Start a libcurl easy session
- curl = curl_easy_init();
-
- //LOG("curl_easy_init()");
-
- _curl_set_request_headers(curl);
-
- if (type == FMWUP_HTTP_GET) {
- curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
- } else if (type == FMWUP_HTTP_POST) {
- curl_easy_setopt(curl, CURLOPT_HTTPPOST, 1);
- } else {
- return -1;
- }
-
- _curl_set_common_option(curl, (const char *)req_url, &response_header, &response_body);
-
- //LOG("Start curl_easy_perform......");
- error_code = curl_easy_perform(curl);
- //LOG("curl_easy_perform(curl): %s (%d)", curl_easy_strerror(error_code), error_code);
-
- if (error_code == CURLE_ABORTED_BY_CALLBACK) {
- ret = -1;
- goto _END_OF_FUNC_;
- } else if (error_code != CURLE_OK) {
- ret = -1;
- goto _END_OF_FUNC_;
- }
-
- _curl_set_response(curl, response_header, response_body, res_header, res_body, NULL);
-
-_END_OF_FUNC_:
- if (response_header) {
- g_byte_array_free(response_header, TRUE);
- }
- if (response_body) {
- g_byte_array_free(response_body, TRUE);
- }
-
- curl_easy_cleanup(curl);
- return ret;
-}
-
-
-int http_download_file(const char *download_url, const char *download_path)
-{
- //LOG("http_download_file() enter");
-
- if (!download_url)
- return -1;
-
- int ret = 0;
- CURL *curl;
- FILE *fp;
- CURLcode error_code;
-
- curl = curl_easy_init();
- if (curl)
- {
- fp = fopen(download_path, "wb");
- curl_easy_setopt(curl, CURLOPT_URL, download_url);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
- error_code = curl_easy_perform(curl);
- //LOG("curl_easy_perform() [%d]", error_code);
- curl_easy_cleanup(curl);
- fclose(fp);
-
- if (error_code != CURLE_OK) {
- remove(download_path);
- ret = -1;
- }
- } else {
- ret = -1;
- }
-
- return ret;
-}
--- /dev/null
+#include <curl/curl.h>
+#include <glib.h>
+//#include "staticlibrary.h"
+//#include <fmwup_resource_internal.h>
+
+
+typedef enum {
+ FMWUP_HTTP_GET = 0,
+ FMWUP_HTTP_POST,
+ FMWUP_HTTP_PUT,
+ FMWUP_HTTP_DELETE
+} fmwup_http_req_e;
+
+
+static size_t _gather_data(void *downloaded_data,
+ size_t size,
+ size_t nmemb,
+ void *user_data)
+{
+ size_t total_size = size * nmemb;
+ g_byte_array_append((GByteArray *)user_data, (const unsigned char *) downloaded_data, total_size);
+ return total_size;
+}
+
+
+void _curl_set_response(CURL *curl,
+ GByteArray *response_header,
+ GByteArray *response_body,
+ char **res_header,
+ char **res_body,
+ void *user_data)
+{
+ CURLcode curl_ret_code;
+
+ long response = 0;
+ curl_ret_code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
+ if (CURLE_OK != curl_ret_code)
+ return;
+
+ char *tmp_header = g_strndup((const gchar *)response_header->data, response_header->len);
+ char *tmp_body = g_strndup((const gchar *)response_body->data, response_body->len);
+
+ *res_header = tmp_header;
+ *res_body = tmp_body;
+}
+
+
+void _curl_set_common_option(CURL *curl,
+ const char *url,
+ GByteArray **response_header_ptr,
+ GByteArray **response_body_ptr)
+{
+ //LOG("_curl_set_common_option()");
+ CURLcode curl_ret_code;
+
+ //LOG("set URL = [%s]", url);
+ curl_ret_code = curl_easy_setopt(curl, CURLOPT_URL, url);
+ if (CURLE_OK != curl_ret_code) {
+ //LOG("curl_easy_setopt: CURLOPT_URL failed!! curl_ret_code[%d]", curl_ret_code);
+ }
+
+ GByteArray *response_header_data = g_byte_array_new();
+ curl_ret_code = curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, _gather_data);
+ if (CURLE_OK != curl_ret_code) {
+ //LOG("curl_easy_setopt: CURLOPT_HEADERFUNCTION failed!! curl_ret_code[%d]", curl_ret_code);
+ }
+
+ curl_ret_code = curl_easy_setopt(curl, CURLOPT_HEADERDATA, response_header_data);
+ if (CURLE_OK != curl_ret_code) {
+ //LOG("curl_easy_setopt: CURLOPT_HEADERDATA failed!! curl_ret_code[%d]", curl_ret_code);
+ }
+
+ GByteArray *response_body_data = g_byte_array_new();
+
+ curl_ret_code = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _gather_data);
+ if (CURLE_OK != curl_ret_code) {
+ //LOG("curl_easy_setopt: CURLOPT_WRITEFUNCTION failed!! curl_ret_code[%d]", curl_ret_code);
+ }
+
+ curl_ret_code = curl_easy_setopt(curl, CURLOPT_WRITEDATA, response_body_data);
+ if (CURLE_OK != curl_ret_code) {
+ //LOG("curl_easy_setopt: CURLOPT_WRITEDATA failed!! curl_ret_code[%d]", curl_ret_code);
+ }
+
+ curl_ret_code = curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
+ if (CURLE_OK != curl_ret_code) {
+ //LOG("curl_easy_setopt: CURLOPT_NOPROGRESS failed!! curl_ret_code[%d]", curl_ret_code);
+ }
+
+ *response_header_ptr = response_header_data;
+ *response_body_ptr = response_body_data;
+
+#if 0
+ curl_ret_code = curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+ if (CURLE_OK != curl_ret_code) {
+ //LOG("curl_easy_setopt: CURLOPT_VERBOSE failed!! curl_ret_code[%d]", curl_ret_code);
+ }
+
+ curl_ret_code = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
+ if (CURLE_OK != curl_ret_code) {
+ //LOG("curl_easy_setopt: CURLOPT_SSL_VERIFYPEER failed!! curl_ret_code[%d]", curl_ret_code);
+ }
+
+ curl_ret_code = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, FALSE);
+ if (CURLE_OK != curl_ret_code) {
+ //LOG("curl_easy_setopt: CURLOPT_SSL_VERIFYHOST failed!! curl_ret_code[%d]", curl_ret_code);
+ }
+
+ curl_ret_code = curl_easy_setopt(curl, CURLOPT_CERTINFO, 0L);
+ if (CURLE_OK != curl_ret_code) {
+ //LOG("curl_easy_setopt: CURLOPT_CERTINFO failed!! curl_ret_code[%d]", curl_ret_code);
+ }
+#endif
+}
+
+
+static void _curl_set_request_headers(CURL *curl)
+{
+ struct curl_slist *header = NULL;
+
+ char *tmp_header = NULL;
+
+ tmp_header = g_strconcat("Content-Type: ", "application/json", NULL);
+ //LOG("header=[%s]", tmp_header);
+ header = curl_slist_append(header, tmp_header);
+ g_free(tmp_header);
+
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
+}
+
+
+int http_send_request(fmwup_http_req_e type, char *req_url, char **res_header, char **res_body)
+{
+ //LOG("Enter http_send_request()");
+
+ CURL *curl;
+ GByteArray *response_header = NULL;
+ GByteArray *response_body= NULL;
+ CURLcode error_code;
+ int ret = 0;
+
+ // Start a libcurl easy session
+ curl = curl_easy_init();
+
+ //LOG("curl_easy_init()");
+
+ _curl_set_request_headers(curl);
+
+ if (type == FMWUP_HTTP_GET) {
+ curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
+ } else if (type == FMWUP_HTTP_POST) {
+ curl_easy_setopt(curl, CURLOPT_HTTPPOST, 1);
+ } else {
+ return -1;
+ }
+
+ _curl_set_common_option(curl, (const char *)req_url, &response_header, &response_body);
+
+ //LOG("Start curl_easy_perform......");
+ error_code = curl_easy_perform(curl);
+ //LOG("curl_easy_perform(curl): %s (%d)", curl_easy_strerror(error_code), error_code);
+
+ if (error_code == CURLE_ABORTED_BY_CALLBACK) {
+ ret = -1;
+ goto _END_OF_FUNC_;
+ } else if (error_code != CURLE_OK) {
+ ret = -1;
+ goto _END_OF_FUNC_;
+ }
+
+ _curl_set_response(curl, response_header, response_body, res_header, res_body, NULL);
+
+_END_OF_FUNC_:
+ if (response_header) {
+ g_byte_array_free(response_header, TRUE);
+ }
+ if (response_body) {
+ g_byte_array_free(response_body, TRUE);
+ }
+
+ curl_easy_cleanup(curl);
+ return ret;
+}
+
+
+int http_download_file(const char *download_url, const char *download_path)
+{
+ //LOG("http_download_file() enter");
+
+ if (!download_url)
+ return -1;
+
+ int ret = 0;
+ CURL *curl;
+ FILE *fp;
+ CURLcode error_code;
+
+ curl = curl_easy_init();
+ if (curl)
+ {
+ fp = fopen(download_path, "wb");
+ curl_easy_setopt(curl, CURLOPT_URL, download_url);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
+ error_code = curl_easy_perform(curl);
+ //LOG("curl_easy_perform() [%d]", error_code);
+ curl_easy_cleanup(curl);
+ fclose(fp);
+
+ if (error_code != CURLE_OK) {
+ remove(download_path);
+ ret = -1;
+ }
+ } else {
+ ret = -1;
+ }
+
+ return ret;
+}
--- /dev/null
+/**
+ * This file contains the exported symbol.
+ */
+#include <app_control.h>
+
+#include <dlog.h>
+#include <stdlib.h>
+#include <strings.h>
+#include <glib.h>
+#include <sqlite3.h>
+
+#include "service_agent_lib.h"
+#include "agent_util.h"
+
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "SSE_AGENT_LIB"
+#define DEBUG_LOG(fmt, ...) do { \
+ 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)
+
+
+
+// This is an example of an exported method.
+int test_sum(int a, int b)
+{
+ return a+b;
+}
+
+#if 0
+void _get_appid(char* uri, char **appid)
+{
+/*
+ char *start = index(uri, '/'); //http://
+ start++; start++;
+ DEBUG_LOG("appid:[%s]", start);
+ char *end = index(start,'/');
+ *appid = g_strndup(start, end-start);
+ DEBUG_LOG("uri[%s], appid:[%s]", uri, *appid);
+*/
+ char **token = g_strsplit(uri, "/", -1);
+ DEBUG_LOG("appid:[%s]", token[2]);
+ *appid = g_strdup(token[2]);
+ g_strfreev(token);
+ DEBUG_LOG("uri[%s], appid:[%s]", uri, *appid);
+}
+#endif
+
+
+int hello(char *indata, hello_cb user_cb, void* user_data)
+{
+ DEBUG_LOG("hello called");
+ int ret = 0;
+
+// char *uri = "http://org.example.tizen-service-enabler/appcontrol/operation/hello";
+ char *operation = "http://tizen.org/appcontrol/operation/samsung-service-agent/hello";
+ char *appid = "org.tizen.samsung-service-agent";
+
+ ret = send_request(appid, operation, indata, user_cb, user_data);
+
+#if 0
+ 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://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;
+ }
+#endif
+ 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;
+} result_t;
+
+
+// This is an example of an exported method.
+int
+test_sum(int a, int b)
+{
+ return a+b;
+}
+
+int
+hello(char *hi, char **echo)
+{
+ DEBUG_LOG("hello called");
+ int ret = 0;
+
+ int cmd_type = 20;
+ GVariant *param = g_variant_new("s", hi);
+ GVariant *cmd_ret = NULL;
+ ret = proxy_send_command(SERVICE_ENABLER_NAME, SERVICE_ENABLER_PATH, SERVICE_ENABLER_INTERFACE,
+ cmd_type, param, &cmd_ret);
+
+ g_variant_get(cmd_ret, "s", echo);
+
+ return ret;
+}
+
+typedef struct {
+ bye_cb _cb;
+ void* _data;
+} bye_wrapper_t;
+
+ // proxy_cb type
+void _bye_wrapper_cb(int error, GVariant* ret, void* user_data)
+{
+ bye_wrapper_t *_wrapper = (bye_wrapper_t *) user_data;
+ char *echo = NULL;
+
+ if (error == 0) {
+ g_variant_get(ret, "s", &echo);
+ }
+ _wrapper->_cb(error, echo, _wrapper->_data);
+}
+
+
+int
+bye(char *str, bye_cb user_cb, void* user_data)
+{
+ DEBUG_LOG("bye called");
+ int ret = 0;
+
+ int cmd_type = 30;
+ GVariant *param = g_variant_new("s", str);
+
+ bye_wrapper_t *_wrapper = (bye_wrapper_t *) malloc(sizeof(bye_wrapper_t));
+ if (!_wrapper) {
+ DEBUG_LOG("malloc error");
+ return -1; // error code required
+ }
+ _wrapper->_cb = user_cb;
+ _wrapper->_data = user_data;
+
+ ret = proxy_send_command_async(SERVICE_ENABLER_NAME, SERVICE_ENABLER_PATH, SERVICE_ENABLER_INTERFACE,
+ cmd_type, param, _bye_wrapper_cb, (void*) _wrapper);
+
+ 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;
+}
+#endif
+++ /dev/null
-#include <dlog.h>
-#include <glib.h>
-#include <gio/gio.h>
-#include <stdlib.h>
-#include "static_internal.h"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "FMW_LIB"
-#define DEBUG_LOG(fmt, ...) do { \
- 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)
-
-
-
-#define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
-#define DBUS_PATH_DBUS "/org/freedesktop/DBus"
-#define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
-
-#if 0
-static GDBusConnection *__gdbus_conn = NULL;
-
-
-int default_handler(int cmd_type, GVariant *input, GVariant **cmd_ret)
-{
- char *hi;
- int err = 0;
-
- if (!cmd_ret) {
- return -1; // error code required
- }
-
- g_variant_get(input, "s", &hi);
- DEBUG_LOG("cmd_type[%d], param[%s]", cmd_type, hi);
-
- char *tmp = g_strdup_printf("you said [%s]", hi);
- *cmd_ret = g_variant_new("s", tmp);
-
- return err;
-}
-
-GVariant* stub_send_command(GVariant *parameters)
-{
- DEBUG_LOG("called");
- if (!parameters) {
- ERROR_LOG("NULL param");
- return NULL;
- }
-
- gint cmd_type;
- GVariant *val;
- GVariant *ret = NULL;
- GVariant *cmd_ret = NULL;
- int cmd_error = 0;
-
- DEBUG_LOG("1");
- g_variant_get(parameters, "(iv)", &cmd_type, &val);
- DEBUG_LOG("2");
-
- switch (cmd_type) {
- case 20: {
- cmd_error = default_handler(cmd_type, val, &cmd_ret);
- break;
- }
- case 30: {
- cmd_error = default_handler(cmd_type, val, &cmd_ret);
- break;
- }
- }
-
- if (cmd_error != 0) {
- cmd_ret = g_variant_new("s", " ");
- }
- ret = g_variant_new("(iv)", cmd_error, cmd_ret );
-
- return ret;
-}
-
-
-int proxy_send_command(const char *bus_name, const char *bus_obj, const char *bus_if,
- int cmd_type, GVariant *cmd_param, GVariant **cmd_ret)
-{
- DEBUG_LOG("cmd[%d]", cmd_type);
- if(!__gdbus_conn)
- dbus_init();
-
- int ret = 0;
-
- GError *gerror = NULL;
- GCancellable *proxy_cancel = g_cancellable_new();
- DEBUG_LOG("cmd[%d]", cmd_type);
- GVariant *params = g_variant_new("(iv)", cmd_type, cmd_param);
-
-
- GVariant *result = g_dbus_connection_call_sync(
- __gdbus_conn,
- bus_name,
- bus_obj,
- bus_if,
- "send_command",
- params,
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- proxy_cancel,
- &gerror);
-
- if (!result) {
- DEBUG_LOG("g_dbus_proxy_call_sync 'send_command' error [%s]",
- (gerror ? gerror->message : "null"));
- ret = -1; // error code required
- goto EXIT;
- }
-
- g_variant_get(result, "(iv)", &ret, cmd_ret);
- DEBUG_LOG("error[%d]", ret);
-
-EXIT:
- return ret;
-}
-
-
-typedef struct {
- proxy_cb _cb;
- void* _data;
-} proxy_data_t;
-
-
-void _proxy_wrapper_cb (GObject *gobj, GAsyncResult *res, gpointer user_data)
-{
- DEBUG_LOG ("");
-
- GError *gerror;
- GVariant *result, *val;
- int error = 0; // error enum required
-
- gerror = NULL;
- result = g_dbus_connection_call_finish (__gdbus_conn, res, &gerror);
- if (!result) {
- error = -1; // error enum required
- val = g_variant_new("()");
- DEBUG_LOG("g_dbus_connection_call_finish error [%s]",
- (gerror ? gerror->message : "null"));
- }
- else {
- g_variant_get (result, "(iv)", &error, &val); // error type passing required
- }
- proxy_data_t *_wrapper = (proxy_data_t*) user_data;
- _wrapper->_cb(error, val, _wrapper->_data);
-}
-
-
-int proxy_send_command_async(const char *bus_name, const char *bus_obj, const char *bus_if,
- int cmd_type, GVariant *data, proxy_cb user_cb, void* user_data)
-{
- DEBUG_LOG("async begin");
- if(!__gdbus_conn)
- dbus_init();
-
- int ret = 0;
-
- GCancellable *proxy_cancel = g_cancellable_new();
- DEBUG_LOG("cmd[%d]", cmd_type);
- GVariant *params = g_variant_new("(iv)", cmd_type, data);
-
- proxy_data_t *_wrapper = (void*) malloc(sizeof(proxy_data_t));
- if (!_wrapper) {
- DEBUG_LOG("malloc error");
- return -1; // error enum required
- }
- _wrapper->_cb = user_cb;
- _wrapper->_data = user_data;
-
-
- g_dbus_connection_call(
- __gdbus_conn,
- bus_name,
- bus_obj,
- bus_if,
- "send_command",
- params,
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- proxy_cancel,
- _proxy_wrapper_cb,
- _wrapper);
-
-
- return ret;
-}
-
-
-static void __dbus_method_call_handler(GDBusConnection *conn,
- const gchar *sender, const gchar *object_path,
- const gchar *iface_name, const gchar *method_name,
- GVariant *parameters, GDBusMethodInvocation *invocation,
- gpointer user_data)
-{
- DEBUG_LOG("method_name: %s", method_name);
-/* gpointer sender_pid = g_hash_table_lookup(__sender_appid_hash, sender);
- if (sender_pid == NULL) {
- if (!__check_sender_validation(parameters, sender, conn))
- goto out;
- }
-*/
- GVariant *ret = NULL;
- if (g_strcmp0(method_name, "send_command") == 0)
- ret = stub_send_command(parameters);
-
- g_dbus_method_invocation_return_value(invocation, ret);
-}
-
-
-static const GDBusInterfaceVTable interface_vtable = {
- __dbus_method_call_handler,
- NULL,
- NULL
-};
-
-
-int dbus_init()
-{
- if (__gdbus_conn) return 0;
- DEBUG_LOG("");
- int ret = -1;
- GError *error = NULL;
-
- __gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
- if (__gdbus_conn == NULL) {
- if (error != NULL) {
- DEBUG_LOG("g_bus_get_sync error [%s]", error->message);
- g_error_free(error);
- }
- goto out;
- }
-
- ret = 0;
-
-out:
- if (!__gdbus_conn)
- g_object_unref(__gdbus_conn);
-
- return ret;
-
-}
-
-
-int register_dbus_interface(const char *bus_name, const char *bus_obj, const char *bus_if)
-{
- /* check param */
- DEBUG_LOG("%s %s %s", bus_name, bus_obj, bus_if);
- GDBusNodeInfo *introspection_data = NULL;
- int registration_id = 0;
-
-
- static gchar introspection_prefix[] =
- "<node>"
- " <interface name='";
-
- static gchar introspection_postfix[] =
- "'>"
- " <method name='send_command'>"
- " <arg type='i' name='cmd' direction='in'/>"
- " <arg type='v' name='data' direction='in'/>"
- " <arg type='i' name='error' direction='out'/>"
- " <arg type='v' name='ret' direction='out'/>"
- " </method>"
- " </interface>"
- "</node>";
-
- char *introspection_xml = g_strdup_printf("%s%s%s",
- introspection_prefix, bus_if, introspection_postfix);
- int owner_id = 0;
- GError *error = NULL;
- GVariant *result = NULL;
-
- DEBUG_LOG("xml[%s]", introspection_xml);
-
-
- result = g_dbus_connection_call_sync(
- __gdbus_conn,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS,
- "RequestName",
- g_variant_new("(su)", bus_name, G_BUS_NAME_OWNER_FLAGS_NONE),
- G_VARIANT_TYPE("(u)"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
- if (error) {
- DEBUG_LOG("RequestName fail : %s", error->message);
- goto out;
- }
- if (result == NULL) {
- DEBUG_LOG("fail to get name NULL");
- goto out;
- }
- g_variant_get(result, "(u)", &owner_id);
- if (owner_id == 0) {
- DEBUG_LOG("Acquiring the own name is failed");
- goto out;
- }
-
- DEBUG_LOG("Acquiring the own name : %d", owner_id);
-
- introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
- if (!introspection_data) {
- DEBUG_LOG("g_dbus_node_info_new_for_xml() is failed.");
- goto out;
- }
-
- registration_id = g_dbus_connection_register_object(__gdbus_conn,
- bus_obj, introspection_data->interfaces[0],
- &interface_vtable, NULL, NULL, NULL);
-
- DEBUG_LOG("registration_id %d", registration_id);
-
- if (registration_id == 0) {
- DEBUG_LOG("Failed to g_dbus_connection_register_object");
- goto out;
- }
-
-out:
- if (introspection_data)
- g_dbus_node_info_unref(introspection_data);
- if (result)
- g_variant_unref(result);
-
- return registration_id;
-}
-#endif
-
+++ /dev/null
-/**
- * This file contains the exported symbol.
- */
-#include "staticlibrary.h"
-#include <app_control.h>
-
-#include <dlog.h>
-#include <stdlib.h>
-#include <strings.h>
-#include <glib.h>
-#include <sqlite3.h>
-
-#include "static_internal.h"
-
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "FMW_LIB"
-#define DEBUG_LOG(fmt, ...) do { \
- 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;
-} result_t;
-
-
-// This is an example of an exported method.
-int
-test_sum(int a, int b)
-{
- return a+b;
-}
-
-int
-hello(char *hi, char **echo)
-{
- DEBUG_LOG("hello called");
- int ret = 0;
-
- int cmd_type = 20;
- GVariant *param = g_variant_new("s", hi);
- GVariant *cmd_ret = NULL;
- ret = proxy_send_command(SERVICE_ENABLER_NAME, SERVICE_ENABLER_PATH, SERVICE_ENABLER_INTERFACE,
- cmd_type, param, &cmd_ret);
-
- g_variant_get(cmd_ret, "s", echo);
-
- return ret;
-}
-
-typedef struct {
- bye_cb _cb;
- void* _data;
-} bye_wrapper_t;
-
- // proxy_cb type
-void _bye_wrapper_cb(int error, GVariant* ret, void* user_data)
-{
- bye_wrapper_t *_wrapper = (bye_wrapper_t *) user_data;
- char *echo = NULL;
-
- if (error == 0) {
- g_variant_get(ret, "s", &echo);
- }
- _wrapper->_cb(error, echo, _wrapper->_data);
-}
-
-
-int
-bye(char *str, bye_cb user_cb, void* user_data)
-{
- DEBUG_LOG("bye called");
- int ret = 0;
-
- int cmd_type = 30;
- GVariant *param = g_variant_new("s", str);
-
- bye_wrapper_t *_wrapper = (bye_wrapper_t *) malloc(sizeof(bye_wrapper_t));
- if (!_wrapper) {
- DEBUG_LOG("malloc error");
- return -1; // error code required
- }
- _wrapper->_cb = user_cb;
- _wrapper->_data = user_data;
-
- ret = proxy_send_command_async(SERVICE_ENABLER_NAME, SERVICE_ENABLER_PATH, SERVICE_ENABLER_INTERFACE,
- cmd_type, param, _bye_wrapper_cb, (void*) _wrapper);
-
- 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;
-}
-#endif