--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <meta http-equiv="X-UA-Compatible" content="IE=9" />
+ <link rel="stylesheet" type="text/css" href="../../css/styles.css" />
+ <link rel="stylesheet" type="text/css" href="../../css/snippet.css" />
+ <script type="text/javascript" src="../../scripts/snippet.js"></script>
+ <script type="text/javascript" src="../../scripts/jquery.util.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/common.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/core.js" charset="utf-8"></script>
+ <script type="text/javascript" src="../../scripts/search.js" charset="utf-8"></script>
+
+ <title>Service Adaptor Client: Working with Plugins</title>
+</head>
+
+<body onload="prettyPrint()" style="overflow: auto;">
+
+<div id="toc-navigation">
+ <div id="profile">
+ <p><img alt="Mobile Web" src="../../images/mw_icon.png"/> <img alt="Wearable Web" src="../../images/ww_icon.png"/></p>
+ </div>
+ <div id="toc_border"><div id="toc">
+ <p class="toc-title">Content</p>
+ <ul class="toc">
+ <li><a href="#Starting_up">Starting up</a>
+ </li>
+ <li><a href="#Files_listing">Files listing</a>
+ </li>
+ <li><a href="#File_upload">File upload</a>
+ </li>
+ <li><a href="#File_download">File download</a>
+ </li>
+ <li><a href="#File_remove">File remove</a>
+ </li>
+ </ul>
+ </div></div>
+</div>
+
+<div id="container"><div id="contents"><div class="content">
+<h1>Service Adaptor Client: Working with Plugins</h1>
+ <p>This tutorial demonstrates how you can use Service Adaptor Client API to work with plugins.</p>
+ <h2>Warm-up</h2>
+ <p>Become familiar with the Service Adaptor Client API basics:</p>
+ <ul>
+ <li><a href="#Starting_up">Starting up</a>
+ <p>Obtaining Service Adaptor handle and plugins initialization.</p></li>
+ <li><a href="#Files_listing">Files listing</a>
+ <p>Obtaining list of files in the storage.</p></li>
+ <li><a href="#File_upload">File upload</a>
+ <p>Uploading file to the storage.</p></li>
+ <li><a href="#File_download">File download</a>
+ <p>Downloading file from the storage</p></li>
+ <li><a href="#File_remove">File remove</a>
+ <p>Removing file from the storage</p></li>
+ </ul>
+
+<h2 id="Starting_up" name="Starting_up">Starting up</h2>
+<p>To use Service Adaptor Plugins in your application, you must learn to obtain Service Adaptor handle and list of available plugins:</p>
+<ol>
+<li><p>Obtain Service Adaptor handle:</p>
+<pre class="prettyprint">
+static service_adaptor_h service_adaptor;
+
+void service_adaptor_init()
+{
+ int ret = service_adaptor_create(&service_adaptor);
+
+ if (SERVICE_ADAPTOR_ERROR_NONE != ret)
+ {
+ /* Handle error */
+ }
+}
+</pre>
+</li>
+<li><p>Use some data structure to store obtained plugin handles:</p>
+<pre class="prettyprint">
+struct plugin_list_item_s
+{
+ service_plugin_h plugin;
+ struct plugin_list_item_s *next;
+};
+
+typedef struct plugin_list_item_s plugin_list_item_t;
+typedef plugin_list_item_t plugin_list_t;
+typedef plugin_list_item_t* plugin_list_item_h;
+typedef plugin_list_t* plugin_list_h;
+
+/* Implementation details of this function are not in scope of this tutorial */
+extern void plugin_list_item_add(plugin_list_h plugins, plugin_list_item_h plugin_item);
+</pre>
+</li>
+<li><p>Obtain list of available Service Adaptor plugins:</p>
+<pre class="prettyprint">
+static plugin_list_t plugins;
+
+static bool _plugin_iterator_cb(char *plugin_uri, int service_mask, void *user_data)
+{
+ plugin_list_item_h plugin_item = (plugin_list_item_h)calloc(1, sizeof(plugin_list_item_t));
+
+ /* Add plugin to the list */
+ plugin_list_item_add(&plugins, plugin_item);
+
+ /* Create plugin handle */
+ service_adaptor_create_plugin(service_adaptor, plugin_uri, &plugin_item->plugin);
+
+ /* Set plugin properties */
+ service_plugin_add_property(plugin_item->plugin, SERVICE_PLUGIN_PROPERTY_APP_KEY, "app_key");
+ service_plugin_add_property(plugin_item->plugin, SERVICE_PLUGIN_PROPERTY_APP_SECRET, "app_secret");
+
+ /* Initialize plugin */
+ service_plugin_start(plugin_item->plugin, service_mask);
+
+ return true;
+}
+
+void plugin_lookup()
+{
+ /* Iterate over plugins' list */
+ int ret = service_adaptor_foreach_plugin(service_adaptor, _plugin_iterator_cb, &plugins);
+
+ if (SERVICE_ADAPTOR_ERROR_NO_DATA == ret)
+ {
+ /* Handle no plugins */
+ }
+ else if (SERVICE_ADAPTOR_ERROR_NONE != ret)
+ {
+ /* Handle error */
+ }
+}
+</pre>
+</ol>
+
+<h2 id="Files_listing" name="Files_listing">Files listing</h2>
+<p>Use obtained plugin handle to list files in the storage:</p>
+<ol>
+<pre class="prettyprint">
+static bool _file_iterator_cb(service_storage_file_h file, void *user_data)
+{
+ char *name = NULL;
+ unsigned long long size = 0;
+ bool is_dir = false;
+
+ /* Fetch basic file info */
+ service_storage_file_is_dir(file, &is_dir);
+ service_storage_file_get_size(file, &size);
+ service_storage_file_get_logical_path(file, &name);
+
+ return true;
+}
+
+static void _service_storage_result_cb(int result, service_storage_file_list_h list, void *user_data)
+{
+ /* Iterate over files' list */
+ service_storage_file_list_foreach_file(list, _file_iterator_cb, NULL);
+}
+
+void plugin_get_file_list(service_plugin_h plugin)
+{
+ service_storage_get_file_list(plugin, "/", _service_storage_result_cb, NULL);
+}
+</pre>
+</ol>
+
+<h2 id="File_upload" name="File_upload">File upload</h2>
+<p>Uploading file to the storage requires creation of upload task in the first place:</p>
+<ol>
+<li><p>Obtain Service Adaptor handle:</p>
+<pre class="prettyprint">
+static void task_progress_cb(unsigned long long progress, unsigned long long total, void *user_data)
+{
+ /* Handle task progress */
+}
+
+static void task_state_cb(service_storage_task_state_e state, void *user_data)
+{
+ /* Handle task states */
+ switch (state)
+ {
+ case SERVICE_STORAGE_TASK_IN_PROGRESS:
+ break;
+ case SERVICE_STORAGE_TASK_COMPLETED:
+ break;
+ case SERVICE_STORAGE_TASK_CANCELED:
+ break;
+ case SERVICE_STORAGE_TASK_FAILED:
+ break;
+ }
+}
+
+static int create_upload_task(service_plugin_h plugin, const char *local_path, const char *storage_path, service_storage_task_h *task)
+{
+ return service_storage_create_upload_task(plugin, local_path, storage_path, task);
+}
+
+void plugin_upload_file(service_plugin_h plugin, const char *local_path, const char *storage_path)
+{
+ service_storage_task_h task;
+
+ /* Upload local file to the storage */
+ if (SERVICE_ADAPTOR_ERROR_NONE != create_upload_task(plugin, storage_path, local_path, &task))
+ {
+ /* Handle create upload task error */
+
+ return;
+ }
+
+ /* Set task progress change callback to have ability to monitor progress */
+ if (SERVICE_ADAPTOR_ERROR_NONE != service_storage_set_task_progress_cb(task, task_progress_cb, NULL))
+ {
+ /* Handle error */
+
+ return;
+ }
+
+ /* Set task state change callback to have ability to monitor state */
+ if (SERVICE_ADAPTOR_ERROR_NONE != service_storage_set_task_state_changed_cb(task, task_state_cb, NULL))
+ {
+ /* Handle error */
+
+ return;
+ }
+
+ /* Start task */
+ if (SERVICE_ADAPTOR_ERROR_NONE != service_storage_start_task(task))
+ {
+ /* Handle error */
+
+ return;
+ }
+}
+</pre>
+</ol>
+
+<h2 id="File_download" name="File_download">File download</h2>
+<p>Downloading file from the storage requires creation of download task in the first place:</p>
+<ol>
+<pre class="prettyprint">
+static int create_download_task(service_plugin_h plugin, const char *storage_path, const char *local_path, service_storage_task_h *task)
+{
+ return service_storage_create_download_task(plugin, storage_path, local_path, task);
+}
+
+void plugin_download_file(service_plugin_h plugin, const char *storage_path, const char *local_path)
+{
+ service_storage_task_h task;
+
+ /* Download file from storage to local directory */
+ if (SERVICE_ADAPTOR_ERROR_NONE != create_download_task(plugin, storage_path, local_path, &task))
+ {
+ /* Handle create download task error */
+
+ return;
+ }
+
+ /* Set task progress change callback to have ability to monitor progress */
+ if (SERVICE_ADAPTOR_ERROR_NONE != service_storage_set_task_progress_cb(task, task_progress_cb, NULL))
+ {
+ /* Handle error */
+
+ return;
+ }
+
+ /* Set task state change callback to have ability to monitor state */
+ if (SERVICE_ADAPTOR_ERROR_NONE != service_storage_set_task_state_changed_cb(task, task_state_cb, NULL))
+ {
+ /* Handle error */
+
+ return;
+ }
+
+ /* Start task */
+ if (SERVICE_ADAPTOR_ERROR_NONE != service_storage_start_task(task))
+ {
+ /* Handle error */
+
+ return;
+ }
+}
+</pre>
+</ol>
+
+<h2 id="File_remove" name="File_remove">File remove</h2>
+<p>Removing file from storage is done by calling single function:</p>
+<ol>
+<pre class="prettyprint">
+static void file_remove_cb(int result, void *user_data)
+{
+ if (SERVICE_ADAPTOR_ERROR_NONE != result)
+ {
+ /* Handle remove error */
+ }
+}
+
+void plugin_remove_file(service_plugin_h plugin, const char *file)
+{
+ const int ret = service_storage_remove(plugin, file, file_remove_cb, NULL);
+
+ if (SERVICE_ADAPTOR_ERROR_NONE == ret)
+ {
+ /* Handle error */
+ }
+}
+</pre>
+</ol>
+
+<script type="text/javascript" src="../../scripts/jquery.zclip.min.js"></script>
+<script type="text/javascript" src="../../scripts/showhide.js"></script>
+
+</div></div></div>
+
+<a class="top sms" href="#"><img src="../../images/btn_top.gif" alt="Go to top" /></a>
+
+<div id="footer">
+<p class="footer">Except as noted, this content - excluding the Code Examples - is licensed under <a href="http://creativecommons.org/licenses/by/3.0/legalcode" target="_blank">Creative Commons Attribution 3.0</a> and all of the Code Examples contained herein are licensed under <a href="https://www.tizen.org/bsd-3-clause-license" target="_blank">BSD-3-Clause</a>.<br/>For details, see the <a href="https://www.tizen.org/content-license" target="_blank">Content License</a>.</p>
+</div>
+
+ <script type="text/javascript">
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-25976949-1']);
+_gaq.push(['_trackPageview']);
+(function() {
+var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();
+</script>
+
+ </body>
+</html>