tizen beta release
[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     WRT_INSTALLER_ERROR_FACTORY_WIDGET,         /*< Widget is factory installed,
79                                                    and cannot be uninstalled */
80     WRT_INSTALLER_ERROR_ALREADY_UNINSTALLING,   /*< Widget is already being
81                                                    uninstalled */
82     WRT_INSTALLER_ERROR_OUT_OUT_DISK_SPACE,     /*<  */
83     WRT_INSTALLER_ERROR_INVALID_CERTIFICATE,    /*<  */
84     WRT_INSTALLER_ERROR_ALREADY_INSTALLED,      /*< Widget is already installed
85                                                  */
86     WRT_INSTALLER_ERROR_INTERNAL,               /*<  */
87     WRT_INSTALLER_ERROR_NOT_ALLOWED,            /*< Widget installation or
88                                                    update not allowed */
89                                                 /*< because violation of policy
90                                                    ocurred */
91     WRT_INSTALLER_ERROR_DEFERRED,               /*< Widget installation deferred
92                                                  */
93     WRT_INSTALLER_ERROR_DATABASE_FAILURE,       /*< Failure in database */
94     WRT_INSTALLER_ERROR_UNKNOWN,                /*< Temporary error. Try to not
95                                                    use this. */
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 /**
152  * @fn inline bool wrt_has_succeded(WrtErrStatus err)
153  * @brief Checks whether call succeded
154  *
155  * This function checks whether call succeded.
156  * If call succeded it returns TRUE.
157  *
158  * @param [in] err WrtErrStatus to check
159  *
160  * @return Result of the test
161  * @retval TRUE     - the call was successful
162  * @retval FALSE    - the call failed
163  *
164  * Sample code:
165  * @code
166  *      static void InitCallback(WrtErrStatus status, void *data)
167  *      {
168  *          MyApplication *This = (MyApplication *)(data);
169  *
170  *          printf("[LAUNCH-WIDGET] init callback");
171  *
172  *          if (wrt_has_succeded(status) && status!=WRT_UPDATE_NEED)
173  *          {
174  *             This->InstallAllPlugins();
175  *
176  *             if (This->m_argc == 2)
177  *                 wrt_install_widget(This->m_argv[1], This, InstallCallback);
178  *          }
179  *          else if(wrt_has_failed(status))
180  *              printf("[LAUNCH-WIDGET] INITIALIZATION HAS FAILED");
181  *      }
182  * @endcode
183  *
184  * @see wrt_has_failed
185  */
186 inline bool wrt_has_succeded(WrtErrStatus err)
187 {
188     return (err >= 0);
189 }
190
191 /**
192  * @fn inline bool wrt_has_failed(WrtErrStatus err)
193  * @brief Checks whether call failed
194  *
195  * This function checks whether call failed.
196  * If call failed it returns TRUE.
197  *
198  * @param [in] err WrtErrStatus to check
199  *
200  * @return Result of the test
201  * @retval TRUE     - the call failed
202  * @retval FALSE    - the call was successful
203  *
204  * Sample code:
205  * @code
206  *      static void InitCallback(WrtErrStatus status, void *data)
207  *      {
208  *          MyApplication *This = (MyApplication *)(data);
209  *
210  *          printf("[LAUNCH-WIDGET] init callback");
211  *
212  *          if (wrt_has_succeded(status) && status!=WRT_UPDATE_NEED)
213  *          {
214  *             This->InstallAllPlugins();
215  *
216  *             if (This->m_argc == 2)
217  *                 wrt_install_widget(This->m_argv[1], This, InstallCallback);
218  *          }
219  *          else if(wrt_has_failed(status))
220  *              printf("[LAUNCH-WIDGET] INITIALIZATION HAS FAILED");
221  *      }
222  * @endcode
223  *
224  * @see wrt_has_succeded
225  */
226 inline bool wrt_has_failed(WrtErrStatus err)
227 {
228     return (err < 0);
229 }
230
231 namespace CommonError {
232 enum Type
233 {
234     WrtSuccess,                ///< Success
235
236     HandleNotFound,         ///< Widget handle was not found
237     AlreadyRunning,         ///< Widget is already running
238     AlreadyStopped,         ///< Widget is already stopped
239     InvalidLanguage,        ///< Widget is invalid in current locales
240     StillAuthorizing,       ///< Widget is still autorizing and has not yet 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_ */