2163cfedc6a8a6413c61724871bc793ad55e3d26
[framework/web/wrt-installer.git] / src / wrt-installer / wrt_type.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_type.h
18  * @author      jihoon Chung (jihoon.Chung@samsung.com)
19  * @version     1.0
20  * @brief       This file contains declarations of wrt 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_TYPE_H_
30 #define WRT_TYPE_H_
31
32 #include <stdbool.h>
33 #include <stddef.h>
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 #define WRT_DEPRECATED __attribute__((deprecated))
40
41 typedef enum
42 {
43     /* Generic success */
44     WRT_SUCCESS = 0,                /*< Success*/
45     WRT_ALREADY_INIT,               /*< Wrt already initialized*/
46     WRT_UPDATE_NEED,                /*< Widget data has been updated*/
47     WRT_SHUTDOWN,                   /*<WRT daemon has been closed*/
48
49     /* Version result */
50     WRT_VERSION_OLD = 128,          /*< widget's version is older*/
51     WRT_VERSION_NEW,                /*< widget's version is latest*/
52     WRT_VERSION_EXACT,              /*< widget's version the same as in arg*/
53     WRT_VERSION_NOT_COMPARABLE,     /*< widget's version are not comparable */
54
55     /* Error result */
56     WRT_ERROR_INTERNAL = -128,      /*< Internal library error.
57                                      * Should never occur */
58     WRT_ERROR_INVALID_PARAMETER,    /*< Invalid parameter value was given
59                                      * (eg. NULL) */
60     WRT_ERROR_HANDLE_NOT_FOUND,     /*< Widget handle was not found */
61     WRT_ERROR_ID_NOT_FOUND,         /*< Widget id was not found */
62     WRT_ERROR_PKGNAME_NOT_FOUND,    /*< package name was not found */
63     WRT_ERROR_ALREADY_RUNNING,      /*< Widget is already running */
64     WRT_ERROR_ALREADY_STOPPED,      /*< Widget is already stopped */
65     WRT_ERROR_STILL_AUTHORIZING,    /*< Widget is still autorizing and has not
66                                      * yet finished it */
67     WRT_ERROR_EARLY_KILLED,         /*< Widget was early killed during launch */
68     WRT_ERROR_ACCESS_DENIED,        /*< Access denied from ACE */
69     WRT_ERROR_NOT_INITIALIZED,      /*<Occur if wrt initialization fails*/
70     WRT_ERROR_INIT,                 /*<Occur if wrt initialization fails*/
71     WRT_ERROR_CONNECTION,           /*<Connectiond error occured*/
72     WRT_ERROR_NO_PATH,              /*<One of specific directory does not
73                                      * exist*/
74
75     /* Installer Errors*/
76     WRT_INSTALLER_ERROR_INVALID_WIDGET_PACKAGE, /*<  */
77     WRT_INSTALLER_ERROR_WIDGET_DOES_NOT_EXIST,  /*<  */
78
79     WRT_INSTALLER_ERROR_ALREADY_UNINSTALLING,   /*< Widget is already being
80                                                  * uninstalled */
81     WRT_INSTALLER_ERROR_OUT_OUT_DISK_SPACE,     /*<  */
82     WRT_INSTALLER_ERROR_INVALID_CERTIFICATE,    /*<  */
83     WRT_INSTALLER_ERROR_ALREADY_INSTALLED,      /*< Widget is already installed
84                                                  */
85     WRT_INSTALLER_ERROR_INTERNAL,               /*<  */
86     WRT_INSTALLER_ERROR_NOT_ALLOWED,            /*< Widget installation or
87                                                  * update not allowed */
88                                                 /*< because violation of policy
89                                                  * ocurred */
90     WRT_INSTALLER_ERROR_DEFERRED,               /*< Widget installation deferred
91                                                  */
92     WRT_INSTALLER_ERROR_DATABASE_FAILURE,       /*< Failure in database */
93     WRT_INSTALLER_ERROR_UNKNOWN,                /*< Temporary error. Try to not
94                                                  * use this. */
95     WRT_INSTALLER_ERROR_OSPSVC,                 /*< */
96     WRT_ERROR_INVALID_LANGUAGE,                 /*< Widget is not valid in
97                                                  *  current locales*/
98
99     /* Plugin Installer Errors */
100     WRT_PLUGIN_INSTALLER_ERROR_WRONG_PATH,       /*< Wrong Path to plugin Dir */
101     WRT_PLUGIN_INSTALLER_ERROR_METAFILE,         /*< Plugin metafile error */
102     WRT_PLUGIN_INSTALLER_ERROR_ALREADY_INSTALLED, /*< Plugin already installed*/
103     WRT_PLUGIN_INSTALLER_ERROR_LIBRARY_ERROR,    /*< Shared library error*/
104     WRT_PLUGIN_INSTALLER_ERROR_WAITING,          /*< Missing dependencies*/
105     WRT_PLUGIN_INSTALLER_ERROR_LOCK,             /*< Another installation
106                                                   *  in progress or lock file
107                                                   *  error*/
108     WRT_PLUGIN_INSTALLER_ERROR_UNKNOWN           /*< Unknown error*/
109 } WrtErrStatus;
110
111 typedef struct
112 {
113     char* id;           /**< the widget's id
114                          * (read from its config.xml during installation)*/
115     char* name;         /**< the widget's name
116                          * (read from its config.xml during installation)*/
117     char* version;      /**< the widget's varsion
118                          * (read from its config.xml during installation)*/
119     char* icon_path;    /**< the widget's icon_path
120                          * (read from its config.xml during installation)*/
121     char* pkg_name;     /**< the widget's pkg name */
122
123     /**< the widget's application storage size */
124     size_t application_size;
125     /**< the widget's data storage size */
126     size_t data_size;
127 } wrt_widget_info;
128
129 typedef struct
130 {
131     char *src; /**< valid path to widget's icon*/
132     int width;  /**< the width of the icon in pixels*/
133     int height;  /**< the height of the icon in pixels*/
134 } wrt_widget_icon;
135
136 typedef struct
137 {
138     int width;      /**< the width of the widget in pixels*/
139     int height;     /**< the height of the widget in pixels*/
140 } wrt_widget_size;
141
142 typedef struct
143 {
144     char *widget_name;              /**< the widget's name*/
145     wrt_widget_icon *widget_icon;   /**< the widget's icon data*/
146     wrt_widget_size widget_size;    /**< the widget's size data*/
147     wrt_widget_info *widget_info;   /**< the widget's info data*/
148 } wrt_widget_info_data;
149
150 /**
151  * @fn inline bool wrt_has_succeded(WrtErrStatus err)
152  * @brief Checks whether call succeded
153  *
154  * This function checks whether call succeded.
155  * If call succeded it returns TRUE.
156  *
157  * @param [in] err WrtErrStatus to check
158  *
159  * @return Result of the test
160  * @retval TRUE     - the call was successful
161  * @retval FALSE    - the call failed
162  *
163  * Sample code:
164  * @code
165  *      static void InitCallback(WrtErrStatus status, void *data)
166  *      {
167  *          MyApplication *This = (MyApplication *)(data);
168  *
169  *          printf("[LAUNCH-WIDGET] init callback");
170  *
171  *          if (wrt_has_succeded(status) && status!=WRT_UPDATE_NEED)
172  *          {
173  *             This->InstallAllPlugins();
174  *
175  *             if (This->m_argc == 2)
176  *                 wrt_install_widget(This->m_argv[1], This, InstallCallback);
177  *          }
178  *          else if(wrt_has_failed(status))
179  *              printf("[LAUNCH-WIDGET] INITIALIZATION HAS FAILED");
180  *      }
181  * @endcode
182  *
183  * @see wrt_has_failed
184  */
185 inline bool wrt_has_succeded(WrtErrStatus err)
186 {
187     return (err >= 0);
188 }
189
190 /**
191  * @fn inline bool wrt_has_failed(WrtErrStatus err)
192  * @brief Checks whether call failed
193  *
194  * This function checks whether call failed.
195  * If call failed it returns TRUE.
196  *
197  * @param [in] err WrtErrStatus to check
198  *
199  * @return Result of the test
200  * @retval TRUE     - the call failed
201  * @retval FALSE    - the call was successful
202  *
203  * Sample code:
204  * @code
205  *      static void InitCallback(WrtErrStatus status, void *data)
206  *      {
207  *          MyApplication *This = (MyApplication *)(data);
208  *
209  *          printf("[LAUNCH-WIDGET] init callback");
210  *
211  *          if (wrt_has_succeded(status) && status!=WRT_UPDATE_NEED)
212  *          {
213  *             This->InstallAllPlugins();
214  *
215  *             if (This->m_argc == 2)
216  *                 wrt_install_widget(This->m_argv[1], This, InstallCallback);
217  *          }
218  *          else if(wrt_has_failed(status))
219  *              printf("[LAUNCH-WIDGET] INITIALIZATION HAS FAILED");
220  *      }
221  * @endcode
222  *
223  * @see wrt_has_succeded
224  */
225 inline bool wrt_has_failed(WrtErrStatus err)
226 {
227     return (err < 0);
228 }
229
230 namespace CommonError {
231 enum Type
232 {
233     WrtSuccess,                ///< Success
234
235     HandleNotFound,         ///< Widget handle was not found
236     AlreadyRunning,         ///< Widget is already running
237     AlreadyStopped,         ///< Widget is already stopped
238     InvalidLanguage,        ///< Widget is invalid in current locales
239     StillAuthorizing,       ///< Widget is still autorizing and has not yet
240                             // finished it
241     EarlyKilled,            ///< Widget was early killed during launch
242     AccessDenied,           ///< Access denied from ACE
243     CertificateRevoked,     ///< Some certificate was revoked.
244                             ///  Widget is not allowed to run.
245
246     Unknown                 ///< Temporary error. Try to not use this.
247 };
248 }
249
250 #ifdef __cplusplus
251 }
252 #endif
253
254 #endif /* WRT_TYPE_H_ */