Update wrt-installer_0.0.54
[framework/web/wrt-installer.git] / src / wrt-installer / wrt_installer_api.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file        wrt_installer_api.h
18  * @author      Chung Jihoon (jihoon.chung@samsung.com)
19  * @version     1.0
20  * @brief       This file contains declarations of wrt_installer_api
21  */
22
23 /*
24  * @defgroup wrt_engine_group WebRunTime engine Library
25  * @ingroup internet_FW
26  * Functions to APIs to access wrt-engine
27  */
28
29 #ifndef WRT_INSTALLER_API_H_
30 #define WRT_INSTALLER_API_H_
31
32 #include <string>
33 #include <stdbool.h>
34 #include <stddef.h>
35 #include <wrt_type.h>
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 /**
42  * Callback function type invoked after async init function
43  */
44 typedef void (*WrtInstallerInitCallback)(WrtErrStatus status,
45                                 void *data);
46
47 /**
48  * Callback function type invoked after async functions
49  */
50 typedef void (*WrtPluginInstallerStatusCallback)(WrtErrStatus status,
51                                                  void *data);
52
53 /**
54  * Callback function type invoked after async functions
55  */
56 typedef void (*WrtInstallerStatusCallback)(int widget_handle,
57                                   WrtErrStatus status,
58                                   void *data);
59
60 /**
61  * Callback function type invoked after async functions
62  */
63 typedef void (*WrtProgressCallback)(float percent,
64                                     const char *description,
65                                     void *data);
66
67 /**
68  * Callback function type invoked when all plugin installations are finished
69  */
70 typedef void (*WrtAllPluginInstalledCallback)(void *userdata);
71
72 typedef struct
73 {
74     WrtAllPluginInstalledCallback plugin_installed_cb;
75     char *plugin_path;
76     void *user_data;
77 } wrt_plugin_data;
78
79 /**
80  * @fn int wrt_installer_init(void *userdata, WrtInstallerInitCallback callback)
81  * @brief Initializes WRT
82  *
83  * This method is used to initialize wrt-engine.
84  * It connects to database, initializes webkit, widget and plugin logic.
85  *
86  * @param [in]  userdata - User parameters to be passed to the callback
87  * @param [in]  callback - The callback function that is launched, after
88  *                         wrt initialization.
89  *                         The callback is called in the context of the
90  *                         application's main loop.
91  *
92  * @return 0 on success, -1 on failure
93  *
94  * Sample code:
95  * @code
96  * int main (int argc, char *argv[])
97  * {
98  *     init_loop(argc, argv);
99  *     printf("Initializing WRT");
100  *     wrt_init(NULL, &init_cb);
101  *
102  *     wait_for_wrt_init();
103  *     printf("Starting tests");
104  *
105  *     int status = DPL_TestRunnerSingleton_Instance().ExecTestRunner(argc,
106  *                                                                    argv);
107  *
108  *     wrt_installer_shutdown();
109  *     quit_loop();
110  *     return status;
111  * }
112  * @endcode
113  *
114  * @see wrt_installer_shutdown
115  */
116 typedef enum wrt_widget_install_mode_e
117 {
118     /**
119      * Raw install bit flags
120      */
121     WRT_WIM_NOT_INSTALLED = (1 << 0),
122     WRT_WIM_INCOMING_VERSION_NOT_STD = (1 << 1),
123     WRT_WIM_EXISTING_VERSION_NOT_STD = (1 << 2),
124     WRT_WIM_BOTH_VERSIONS_NOT_STD = (1 << 3),
125     WRT_WIM_EXISTING_VERSION_OLDER = (1 << 4),
126     WRT_WIM_EXISTING_VERSION_EQUAL = (1 << 5),
127     WRT_WIM_EXISTING_VERSION_NEWER = (1 << 6),
128
129     /**
130      * Update default policies
131      */
132
133     /* Never update policy
134      */
135     WRT_WIM_POLICY_NEVER_UPDATE = WRT_WIM_NOT_INSTALLED,
136
137     /* WAC update policy
138      */
139     WRT_WIM_POLICY_WAC = WRT_WIM_NOT_INSTALLED |
140         WRT_WIM_EXISTING_VERSION_OLDER,
141
142     /* Always update policy
143      */
144     WRT_WIM_POLICY_ALWAYS_INSTALL = WRT_WIM_NOT_INSTALLED |
145         WRT_WIM_INCOMING_VERSION_NOT_STD |
146         WRT_WIM_EXISTING_VERSION_NOT_STD |
147         WRT_WIM_BOTH_VERSIONS_NOT_STD |
148         WRT_WIM_EXISTING_VERSION_OLDER |
149         WRT_WIM_EXISTING_VERSION_EQUAL |
150         WRT_WIM_EXISTING_VERSION_NEWER,
151
152     /* Force install policy
153      */
154     WRT_WIM_POLICY_FORCE_INSTALL = WRT_WIM_POLICY_ALWAYS_INSTALL
155 } wrt_widget_update_mode_t;
156
157 int wrt_installer_init(void *userdata,
158         WrtInstallerInitCallback callback);
159
160 /**
161  * @fn void wrt_installer_shutdown(void)
162  * @brief Deinitializes WRT
163  *
164  * This method is used to deinitialize wrt-engine.
165  * It deinitializes widget logic, plugin logic, shuts down connection to
166  * database, switchs back to single thread and does deinit checks.
167  *
168  * @return      nothing
169  *
170  * Sample code:
171  * @code
172  * int main (int argc, char *argv[])
173  * {
174  *     init_loop(argc, argv);
175  *     printf("Initializing WRT");
176  *     wrt_init(NULL, &init_cb);
177  *
178  *     wait_for_wrt_init();
179  *     printf("Starting tests");
180  *
181  *     int status = DPL_TestRunnerSingleton_Instance().ExecTestRunner(argc,
182  *                                                                    argv);
183  *
184  *     wrt_installer_shutdown();
185  *     quit_loop();
186  *     return status;
187  * }
188  * @endcode
189  *
190  * @see wrt_init
191  */
192 void wrt_installer_shutdown(void);
193
194 /**
195  * @fn void wrt_install_widget(const char *widget_package_path,
196  *                      void *user_parameter,
197  *                      WrtInstallerStatusCallback status_callback,
198  *                      WrtProgressCallback progress_callback,
199  *                      wrt_widget_update_mode_t update_mode);
200  *
201  * @brief Installs widget from given path
202  *
203  * This method is used to install widget from a given path.
204  *
205  * @param [in]  widget_package_path Path of the widget package.
206  * @param [in]  user_parameter      User parameters to be passed to the callback
207  * @param [in]  status_cb           Call to this one will be done at the end of
208  *                                  operation
209  *                                  The callback is called in the context of the
210  *                                  application's
211  * @param [in]  progress_cb         Callback function to get data of install
212  *                                  progress
213  *                                  If you don't want to get progress data, this
214  *                                  should be NULL
215  * @param [in]  install_mode        Installation mode
216  * @return                          Nothing (status returned in callback).
217  *
218  * Sample code:
219  * @code
220  *   wrt_install_widget(path.c_str(),
221  *                      NULL,
222  *                      install_cb,
223  *                      progress_cb,
224  *                      WRT_WIM_POLICY_WAC);
225  * @endcode
226  *
227  * @see wrt_installer_uninstall_widget
228  */
229 void wrt_install_widget(const char *path,
230         void *user_parameter,
231         WrtInstallerStatusCallback status_callback,
232         WrtProgressCallback progress_callback,
233         wrt_widget_update_mode_t update_mode,
234         bool quiet);
235
236 /**
237  * @fn void wrt_installer_uninstall_widget (int widget_handle,
238  *                                void* userdata,
239  *                                WrtInstallerStatusCallback cb)
240  * @brief Uninstalls widget using its id
241  *
242  * This method is used to uninstall the widget specified by its handle.
243  * The callback function is called when the uninstall operation is done.
244  *
245  * @param [in]  widget_handle - widget id
246  * @param [in]  userdata    - user parameters to be passed to the callback
247  * @param [in]  status_cb   - Call to this one will be done at the end of
248  *                            operation
249  *                            The callback is called in the context of the
250                               application's
251  * @param [in]  progress_cb - Callback function to get data of install progress
252  *                            If you don't want to get progress data, this
253  *                            should be NULL
254  *
255  * @return      nothing (status returned in callback).
256  *
257  * Sample code:
258  * @code //TODO SAMPLE
259  *  wrt_installer_uninstall_widget( appId, NULL, uninstall_cb, progress_cb);
260  * @endcode
261  *
262  * @see wrt_installer_install_widget
263  */
264 void wrt_uninstall_widget (int widget_handle,
265         void* userdata,
266         WrtInstallerStatusCallback status_cb,
267         WrtProgressCallback progress_cb);
268
269 /**
270  *  @fn void wrt_install_plugin(const char *pluginDirectory,
271  *                              void *userData,
272  *                              WrtInstallerStatusCallback statusCallback,
273  *                              WrtProgressCallback progressCallback)
274  *
275  *  @brief Installs plugin from given path
276  *
277  *  This method installs new plugin from specified location and calls a callback
278  *  function when the operation is done.
279  *
280  *  @param [in] pluginDirectory - plugin directory
281  *  @param [in] userData    - user parameters to be passed to the callback
282  *  @param [in] statusCallback   - user callback to call after installation
283  *  @param [in] progressCallback - user callback to call when plugin
284  *                                 installation progress has changed
285  *
286  *  @return nothing (status returned in callback).
287  *
288  * Sample code:
289  * @code
290  *  wrt_install_plugin("/usr/lib/wrt-plugins/",NULL,NULL,NULL);
291  * @endcode
292  *
293  * @see wrt_install_plugin
294  */
295 void wrt_install_plugin(const char *pluginDirectory,
296         void *userData,
297         WrtPluginInstallerStatusCallback statusCallback,
298         WrtProgressCallback progressCallback);
299
300 /**
301  * @brief To install plugins for first excution
302  *
303  * This method install plugins
304  *
305  * @return nothing
306  */
307 void wrt_install_all_plugins(WrtAllPluginInstalledCallback installed_cb,
308         void *user_param);
309
310 /**
311  * @brief To initialize for tests
312  *
313  * This method is wrt init for tests
314  *
315  * @return int
316  */
317 int wrt_installer_init_for_tests(void *userdata,
318         WrtInstallerInitCallback callback);
319
320 /**
321  * @brief To shutdown for tests
322  *
323  * This method is wrt shutdown for tests
324  *
325  * @return int
326  */
327 void wrt_installer_shutdown_for_tests();
328
329 WrtErrStatus wrt_get_widget_by_pkgname(const std::string pkgname,
330         int *widget_handle);
331
332 WrtErrStatus wrt_get_widget_by_guid(const std::string guid,
333         int *widget_handle);
334 #ifdef __cplusplus
335 }
336 #endif
337
338 #endif /* WRT_INSTALLER_API_H_ */