tizen 2.4 release
[framework/web/wrt-commons.git] / modules / widget_dao / include / dpl / wrt-dao-ro / common_dao_types.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  *
18  * @file    common_dao_types.h
19  * @author  Michal Ciepielski (m.ciepielski@samsung.com)
20  * @version 1.0
21  * @brief   This file contains the declaration of common data types for wrtdb
22  */
23
24 #ifndef WRT_WIDGET_DAO_COMMON_DAO_TYPES_H_
25 #define WRT_WIDGET_DAO_COMMON_DAO_TYPES_H_
26
27 #include <set>
28 #include <string>
29 #include <map>
30 #include <vector>
31 #include <list>
32 #include <memory>
33 #include <dpl/optional_typedefs.h>
34 #include <sqlite3.h>
35 #include <dpl/platform.h>
36
37 namespace WrtDB {
38 class PluginMetafileData
39 {
40   public:
41     struct Feature
42     {
43         std::string m_name;
44         std::set<std::string> m_deviceCapabilities;
45
46         bool operator< (const Feature& obj) const
47         {
48             return m_name < obj.m_name;
49         }
50     };
51     typedef std::set<Feature> FeatureContainer;
52
53   public:
54
55     PluginMetafileData()
56     {}
57
58     std::string m_libraryName;
59     FeatureContainer m_featureContainer;
60 };
61
62 class PluginObjectsDAO
63 {
64   public:
65     typedef std::set<std::string> Objects;
66     typedef std::shared_ptr<Objects> ObjectsPtr;
67
68   public:
69     explicit PluginObjectsDAO() {}
70
71   protected:
72     ObjectsPtr m_implemented;
73     ObjectsPtr m_dependent;
74 };
75
76 /**
77  * @brief Widget id describes web-runtime global widget identifier.
78  *
79  * Notice that only up to one widget can exist at the same time.
80  * DbWidgetHandle can be translated into corresponding WidgetModel by invoking
81  * FindWidgetModel routine.
82  */
83 typedef int DbWidgetHandle;
84 typedef DPL::String TizenPkgId;
85 typedef DPL::String TizenAppId;
86
87 /**
88  * Value of invalid widget handle
89  */
90 enum {
91     INVALID_WIDGET_HANDLE = -1
92 };
93
94 /**
95  * @brief Structure to hold the information of widget's size
96  */
97 struct DbWidgetSize
98 {
99     DPL::OptionalInt width;
100     DPL::OptionalInt height;
101
102     DbWidgetSize(DPL::OptionalInt w = DPL::OptionalInt(),
103                  DPL::OptionalInt h = DPL::OptionalInt()) :
104         width(w),
105         height(h)
106     {}
107 };
108
109 inline bool operator ==(const DbWidgetSize &objA, const DbWidgetSize &objB)
110 {
111     if (!objA.height || !objA.width || !objB.width || !objB.height) {
112         return false;
113     } else {
114         return *objA.height == *objB.height && *objA.width == *objB.width;
115     }
116 }
117
118 /**
119  * Widget [G]lobal [U]nique [ID]entifier
120  * Orginated from appstore ID
121  */
122 typedef DPL::OptionalString WidgetGUID;
123
124 struct WidgetAccessInfo
125 {
126     DPL::String strIRI;                /* origin iri */
127     bool bSubDomains;                  /* do we want access to subdomains ? */
128
129     bool operator ==(const WidgetAccessInfo& info) const
130     {
131         return info.strIRI == strIRI &&
132                info.bSubDomains == bSubDomains;
133     }
134 };
135 typedef std::list<WidgetAccessInfo> WidgetAccessInfoList;
136
137 struct WidgetAllowNavigationInfo
138 {
139     DPL::String scheme;
140     DPL::String host;
141 };
142 typedef std::list<WidgetAllowNavigationInfo> WidgetAllowNavigationInfoList;
143
144 struct EncryptedFileInfo
145 {
146     DPL::String fileName;
147     int fileSize;
148
149     bool operator==(const EncryptedFileInfo& info) const
150     {
151         return fileName == info.fileName;
152     }
153
154     bool operator==(const DPL::String& file) const
155     {
156         return fileName == file;
157     }
158
159     bool operator< (const EncryptedFileInfo& info) const
160     {
161         return fileName < info.fileName;
162     }
163 };
164
165 typedef std::list<DPL::String> WindowModeList;
166
167 typedef std::list<DPL::String> PrivilegeList;
168
169 typedef std::set<EncryptedFileInfo> EncryptedFileList;
170
171 /**
172  * @brief Widget feature host information about possible javascript extensions
173  *        that widget may use
174  *
175  * Widget features are declared in configuration file in widget installation
176  * package. Each declared special feature is contained in some wrt-plugin that
177  * declares to implement it. After widget launch wrt searches for proper plugin
178  * libraries and load needed features.
179  *
180  * Widget features can be required or optional. It is possible to start widget
181  * without missing feature. When required feature cannot be loaded widget will
182  * not start.
183  */
184
185 enum {
186     INVALID_PLUGIN_HANDLE = -1
187 };
188 typedef int DbPluginHandle;
189
190 struct DbWidgetFeature
191 {
192     DPL::String name;        /// Feature name
193     bool rejected;           /// Api feature was rejected by ace
194     DbPluginHandle pluginId; /// Plugin id that implement this feature
195
196     DbWidgetFeature() :
197         pluginId(INVALID_PLUGIN_HANDLE)
198     {}
199 };
200
201 inline bool operator < (const DbWidgetFeature &objA,
202                         const DbWidgetFeature &objB)
203 {
204     return objA.name.compare(objB.name) < 0;
205 }
206
207 inline bool operator==(const DbWidgetFeature &featureA,
208                        const DbWidgetFeature &featureB)
209 {
210     return featureA.name == featureB.name &&
211            featureA.pluginId == featureB.pluginId;
212 }
213
214 /**
215  * @brief Default container for features list
216  */
217 typedef std::multiset<DbWidgetFeature> DbWidgetFeatureSet;
218
219 /**
220  * @brief Default container with DbWidgetHandle's
221  */
222 typedef std::list<DbWidgetHandle> DbWidgetHandleList;
223 typedef std::list<TizenAppId> TizenAppIdList;
224 typedef std::list<TizenPkgId> TizenPkgIdList;
225
226 class WidgetDAOReadOnly; //forward declaration
227 typedef std::shared_ptr<WidgetDAOReadOnly> WidgetDAOReadOnlyPtr;
228 /**
229  * @brief Default container with WidgetDAOReadOnly
230  */
231 typedef std::list<WidgetDAOReadOnlyPtr> DbWidgetDAOReadOnlyList;
232
233 /**
234  * @brief Widget specific type
235  *
236  * Widget type describes belowed in WAC, TIZEN WebApp
237  */
238 enum AppType
239 {
240     APP_TYPE_UNKNOWN = 0, // unknown
241     APP_TYPE_TIZENWEBAPP, // Tizen webapp
242     APP_TYPE_TIZENWEBSERVICE // Tizen web service
243 };
244
245 class WidgetType
246 {
247   public:
248     WidgetType() :
249         appType(APP_TYPE_UNKNOWN)
250     {}
251     WidgetType(const AppType type) :
252         appType(type)
253     {}
254     bool operator== (const AppType& other) const
255     {
256         return appType == other;
257     }
258     bool operator!= (const AppType& other) const
259     {
260         return appType != other;
261     }
262     std::string getApptypeToString()
263     {
264         switch (appType) {
265 #define X(x) case x: return #x;
266             X(APP_TYPE_UNKNOWN)
267             X(APP_TYPE_TIZENWEBAPP)
268             X(APP_TYPE_TIZENWEBSERVICE)
269
270 #undef X
271         default:
272             return "UNKNOWN";
273         }
274     }
275
276     AppType appType;
277 };
278
279 /**
280  * @brief Package specific type
281  *
282  * Package type describes belowed in Tizen webapp, C++ service App
283  */
284 enum PkgType
285 {
286     PKG_TYPE_UNKNOWN = 0, // unknown
287     PKG_TYPE_NOMAL_WEB_APP,
288     PKG_TYPE_DIRECTORY_WEB_APP,
289     PKG_TYPE_HOSTED_WEB_APP,    // request from browser
290     PKG_TYPE_HYBRID_WEB_APP // Tizen webapp with C++ service app
291 };
292
293 class PackagingType
294 {
295   public:
296     PackagingType() :
297         pkgType(PKG_TYPE_UNKNOWN)
298     {}
299     PackagingType(const PkgType type) :
300         pkgType(type)
301     {}
302     bool operator== (const PkgType& other) const
303     {
304         return pkgType == other;
305     }
306     bool operator!= (const PkgType& other) const
307     {
308         return pkgType != other;
309     }
310     std::string getPkgtypeToString()
311     {
312         switch (pkgType) {
313 #define X(x) case x: return #x;
314             X(PKG_TYPE_UNKNOWN)
315             X(PKG_TYPE_NOMAL_WEB_APP)
316             X(PKG_TYPE_DIRECTORY_WEB_APP)
317             X(PKG_TYPE_HOSTED_WEB_APP)
318             X(PKG_TYPE_HYBRID_WEB_APP)
319 #undef X
320         default:
321             return "UNKNOWN";
322         }
323     }
324
325     PkgType pkgType;
326 };
327
328 struct WidgetSetting
329 {
330     DPL::String settingName;
331     DPL::String settingValue;
332
333     bool operator ==(const WidgetSetting& info) const
334     {
335         return (info.settingName == settingName &&
336                 info.settingValue == settingValue);
337     }
338     bool operator !=(const WidgetSetting& info) const
339     {
340         return (info.settingName != settingName ||
341                 info.settingValue != settingValue);
342     }
343 };
344
345 typedef std::list<WidgetSetting> WidgetSettings;
346
347 /**
348  * @brief Widget AppControl
349  *
350  * Application control describes details of behaviour
351  * when widget receives aul bundle data.
352  */
353 namespace AppControlPrefix {
354     const char* const PROCESS_PREFIX = "-__CONTROL_PROCESS__";
355 }
356 struct WidgetAppControl
357 {
358     DPL::String src;       /* start uri */
359     DPL::String operation; /* service name */
360     DPL::String uri;       /* scheme type*/
361     DPL::String mime;      /* mime type */
362     bool reset;            /* src reset */
363
364     bool operator== (const WidgetAppControl& other) const
365     {
366         return src == other.src &&
367                operation == other.operation &&
368                uri == other.uri &&
369                mime == other.mime &&
370                reset == other.reset;
371     }
372 };
373
374 typedef std::list<WidgetAppControl> WidgetAppControlList;
375
376 enum class WidgetSecurityModelVersion
377 {
378     WIDGET_SECURITY_MODEL_V1 = 0, // WARP
379     WIDGET_SECURITY_MODEL_V2      // CSP, allow-navigation
380 };
381
382 class SQLiteDAOBase
383 {
384 private:
385 #if ENABLE(WIDGET_INTERFACE_DAO_PERFORMANCE)
386     void clearStatementsMap();
387     std::map<const char* const, sqlite3_stmt*> m_statements;
388 #endif //ENABLE(WIDGET_INTERFACE_DAO_PERFORMANCE)
389 protected:
390     class Exception
391     {
392     public:
393         DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
394         DECLARE_EXCEPTION_TYPE(Base, DatabaseError)
395     };
396
397     SQLiteDAOBase();
398     virtual ~SQLiteDAOBase();
399
400     inline DPL::String sqlite3_column_string(sqlite3_stmt* stmt, int iCol)
401     {
402         const char* str = reinterpret_cast<const char*>(sqlite3_column_text(stmt, iCol));
403         if (str == NULL) {
404             str = "";
405         }
406         return DPL::FromUTF8String(std::string(str));
407     }
408
409     void sqlBind(sqlite3_stmt* stmt, int index, const char* value) const;
410     void sqlBind(sqlite3_stmt* stmt, int index, const std::string& value) const;
411     void sqlBind(sqlite3_stmt* stmt, int index, const DPL::String& value) const;
412     void sqlBind(sqlite3_stmt* stmt, int index, int value) const;
413
414     sqlite3* m_databaseInterface;
415     sqlite3_stmt* sqlPrepare(const char* const query);
416 #if ENABLE(WIDGET_INTERFACE_DAO_PERFORMANCE)
417     inline void releaseStatement(sqlite3_stmt *)
418     { }
419 #else
420     inline void releaseStatement(sqlite3_stmt *statement)
421     {
422         sqlite3_finalize(statement);
423     }
424 #endif //ENABLE(WIDGET_INTERFACE_DAO_PERFORMANCE)
425 };
426
427 } // namespace WrtDB
428 #endif /* WRT_WIDGET_DAO_COMMON_DAO_TYPES_H_ */