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