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