4 #include <glib-object.h>
7 #include "service_adaptor.h"
9 service_plugin_h service_plugin = NULL;
11 void _service_auth_oauth1_cb(int result, service_auth_oauth1_h oauth1, void *user_data)
13 char *access_token = NULL;
14 service_auth_oauth1_get_access_token(oauth1, &access_token);
16 printf("access_token = %s (%s)\n", access_token, (char *) user_data);
19 bool _service_storage_cloud_file_cb(int result, service_storage_cloud_file_h file, void *user_data)
21 char *cloud_path = NULL;
22 service_storage_cloud_file_get_cloud_path(file, &cloud_path);
24 printf("cloud_path = %s (%s)\n", cloud_path, (char *) user_data);
29 void _service_plugin_login_callback(int result, void *user_data)
31 int ret = SERVICE_ADAPTOR_ERROR_NONE;
33 ret = service_plugin_start(service_plugin);
35 if (SERVICE_ADAPTOR_ERROR_NONE != ret)
37 printf("service_plugin_start Failed(%d)\n", ret);
42 service_auth_oauth1_h oauth1 = NULL;
43 ret = service_auth_oauth1_create(service_plugin, &oauth1);
44 ret = service_auth_oauth1_set_callback(oauth1, _service_auth_oauth1_cb, NULL);
45 ret = service_auth_oauth1_set_operation(oauth1, SERVICE_AUTH_OAUTH1_0_GET_ACCESS_TOKEN_URI);
47 service_task_h auth_task = NULL;
48 ret = service_auth_oauth1_create_task(oauth1, &auth_task);
49 ret = service_task_start(auth_task);
50 if (SERVICE_ADAPTOR_ERROR_NONE == ret)
52 printf("service_auth_oauth1_get_access_token() Request Successed\n");
55 char *cloud_path = "/root/cloud";
56 service_storage_cloud_file_h file = NULL;
57 ret = service_storage_cloud_file_create(service_plugin, &file);
58 ret = service_storage_cloud_file_set_callback(file, _service_storage_cloud_file_cb, NULL);
59 ret = service_storage_cloud_file_set_cloud_path(file, cloud_path);
60 ret = service_storage_cloud_file_set_operation(file, SERVICE_STORAGE_CLOUD_REMOVE_FILE_URI);
62 service_task_h task = NULL;
63 ret = service_storage_cloud_file_create_task(file, &task);
64 ret = service_task_start(task);
65 if (SERVICE_ADAPTOR_ERROR_NONE == ret)
67 printf("service_storage_cloud_remove_file() Request Successed: %s\n", cloud_path);
71 bool _service_adaptor_plugin_callback(const char *uri, int service_mask, void *user_data)
73 if (0 != strcmp(uri, "org.tizen.service-plugin-sample"))
78 int ret = SERVICE_ADAPTOR_ERROR_NONE;
80 ret = service_plugin_create(uri, &service_plugin);
82 if (SERVICE_ADAPTOR_ERROR_NONE != ret)
84 printf("service_plugin_create(%s) Failed(%d)\n", uri, ret);
88 ret = service_plugin_login(service_plugin, _service_plugin_login_callback, NULL);
90 if (SERVICE_ADAPTOR_ERROR_NONE != ret)
92 printf("service_plugin_login(%s) Failed(%d)\n", uri, ret);
99 static gint _sigterm_callback(void *data)
101 g_main_loop_quit((GMainLoop*)data);
108 GMainLoop *loop = NULL;
110 #if !GLIB_CHECK_VERSION(2,32,0)
113 #if !GLIB_CHECK_VERSION(2,35,0)
118 int ret = SERVICE_ADAPTOR_ERROR_NONE;
120 ret = service_adaptor_connect();
121 ret = service_adaptor_foreach_plugin(_service_adaptor_plugin_callback, NULL);
123 loop = g_main_loop_new(NULL, FALSE);
125 g_unix_signal_add_full(G_PRIORITY_HIGH, SIGINT,
126 _sigterm_callback, loop, NULL );
127 g_unix_signal_add_full(G_PRIORITY_HIGH, SIGTERM,
128 _sigterm_callback, loop, NULL );
130 g_main_loop_run(loop);
132 g_main_loop_unref(loop);
135 ret = service_plugin_stop(service_plugin);
136 ret = service_plugin_destroy(service_plugin);
137 ret = service_adaptor_disconnect();