362065875a55602a95b64ae69a9ab826123de414
[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
36 namespace WrtDB {
37 class PluginMetafileData
38 {
39   public:
40     struct Feature
41     {
42         std::string m_name;
43         std::set<std::string> m_deviceCapabilities;
44
45         bool operator< (const Feature& obj) const
46         {
47             return m_name < obj.m_name;
48         }
49     };
50     typedef std::set<Feature> FeatureContainer;
51
52   public:
53
54     PluginMetafileData()
55     {
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 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
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
136 struct EncryptedFileInfo
137 {
138     DPL::String fileName;
139     int fileSize;
140
141     bool operator==(const EncryptedFileInfo& info) const
142     {
143         return fileName == info.fileName;
144     }
145
146     bool operator==(const DPL::String& file) const
147     {
148         return fileName == file;
149     }
150
151     bool operator< (const EncryptedFileInfo& info) const
152     {
153         return fileName < info.fileName;
154     }
155 };
156
157 typedef std::list<WidgetAccessInfo> WidgetAccessInfoList;
158
159 typedef std::list<DPL::String> WindowModeList;
160
161 typedef std::set<EncryptedFileInfo> EncryptedFileList;
162
163 /**
164  * @brief Widget configuration parameter key
165  */
166 typedef DPL::String WidgetParamKey;
167
168 /**
169  * @brief Widget configuration parameter value
170  */
171 typedef DPL::String WidgetParamValue;
172
173 /**
174  * @brief A map of widget configuration parameters.
175  *
176  * Widget configuration parameters are read from database and are stored
177  * along with feature that they describe.
178  */
179 typedef std::multimap<WidgetParamKey, WidgetParamValue> WidgetParamMap;
180
181 /**
182  * @brief Widget feature host information about possible javascript extensions
183  *        that widget may use
184  *
185  * Widget features are declared in configuration file in widget installation
186  * package. Each declared special feature is contained in some wrt-plugin that
187  * declares to implement it. After widget launch wrt searches for proper plugin
188  * libraries and load needed features.
189  *
190  * Widget features can be required or optional. It is possible to start widget
191  * without missing feature. When required feature cannot be loaded widget will
192  * not start.
193  */
194
195 enum {
196     INVALID_PLUGIN_HANDLE = -1
197 };
198 typedef int DbPluginHandle;
199
200 struct DbWidgetFeature
201 {
202     DPL::String name;        /// Feature name
203     bool required;           /// Whether feature is required
204     bool rejected;           /// Api feature was rejected by ace
205     DbPluginHandle pluginId; /// Plugin id that implement this feature
206     WidgetParamMap params;   /// Widget's params
207
208     DbWidgetFeature() :
209         required(false),
210         pluginId(INVALID_PLUGIN_HANDLE)
211     {
212     }
213 };
214
215 inline bool operator < (const DbWidgetFeature &objA,
216         const DbWidgetFeature &objB)
217 {
218     return objA.name.compare(objB.name) < 0;
219 }
220
221 inline bool operator==(const DbWidgetFeature &featureA,
222         const DbWidgetFeature &featureB)
223 {
224     return featureA.name == featureB.name &&
225            featureA.required == featureB.required &&
226            featureA.pluginId == featureB.pluginId;
227 }
228
229 /**
230  * @brief Default container for features list
231  */
232 typedef std::multiset<DbWidgetFeature> DbWidgetFeatureSet;
233
234 /**
235  * @brief Default container with DbWidgetHandle's
236  */
237 typedef std::list<DbWidgetHandle> DbWidgetHandleList;
238
239 typedef std::list<WidgetPkgName> WidgetPkgNameList; //TODO: this cannot be null -> appropriate changes in db schema needed
240
241 class WidgetDAOReadOnly; //forward declaration
242 typedef std::shared_ptr<WidgetDAOReadOnly> WidgetDAOReadOnlyPtr;
243 /**
244  * @brief Default container with WidgetDAOReadOnly
245  */
246 typedef std::list<WidgetDAOReadOnlyPtr> DbWidgetDAOReadOnlyList;
247
248 /**
249  * @brief Widget specific type
250  *
251  * Widget type describes belowed in WAC, TIZEN WebApp
252  */
253 enum AppType
254 {
255     APP_TYPE_UNKNOWN = 0, // unknown
256     APP_TYPE_WAC20, // WAC 2.0
257     APP_TYPE_TIZENWEBAPP // Tizen webapp
258 };
259
260 class WidgetType
261 {
262   public:
263     WidgetType()
264     :appType(APP_TYPE_UNKNOWN)
265     {
266     }
267     WidgetType(const AppType type)
268     :appType(type)
269     {
270     }
271     bool operator== (const AppType& other) const
272     {
273         return appType == other;
274     }
275     bool operator!= (const AppType& other) const
276     {
277         return appType != other;
278     }
279     std::string getApptypeToString()
280     {
281         switch (appType) {
282 #define X(x) case x: return #x;
283         X(APP_TYPE_UNKNOWN)
284         X(APP_TYPE_WAC20)
285         X(APP_TYPE_TIZENWEBAPP)
286 #undef X
287         default:
288             return "UNKNOWN";
289         }
290     }
291
292     AppType appType;
293 };
294
295 /**
296  * @brief Package specific type
297  *
298  * Package type describes belowed in Tizen webapp, C++ service App
299  */
300 enum PkgType
301 {
302     PKG_TYPE_UNKNOWN = 0, // unknown
303     PKG_TYPE_NOMAL_WEB_APP,
304     PKG_TYPE_DIRECTORY_WEB_APP,
305     PKG_TYPE_HOSTED_WEB_APP,    // request from browser
306     PKG_TYPE_HYBRID_WEB_APP // Tizen webapp with C++ service app
307 };
308
309 class PackagingType
310 {
311   public:
312     PackagingType()
313     :pkgType(PKG_TYPE_UNKNOWN)
314     {
315     }
316     PackagingType(const PkgType type)
317     :pkgType(type)
318     {
319     }
320     bool operator== (const PkgType& other) const
321     {
322         return pkgType == other;
323     }
324     bool operator!= (const PkgType& other) const
325     {
326         return pkgType != other;
327     }
328     std::string getPkgtypeToString()
329     {
330         switch (pkgType) {
331 #define X(x) case x: return #x;
332         X(PKG_TYPE_UNKNOWN)
333         X(PKG_TYPE_NOMAL_WEB_APP)
334         X(PKG_TYPE_DIRECTORY_WEB_APP)
335         X(PKG_TYPE_HOSTED_WEB_APP)
336         X(PKG_TYPE_HYBRID_WEB_APP)
337 #undef X
338         default:
339             return "UNKNOWN";
340         }
341     }
342
343     PkgType pkgType;
344 };
345
346 enum SettingsType
347 {
348     SETTINGS_TYPE_UNKNOWN = 0,
349     SETTINGS_TYPE_ON,
350     SETTINGS_TYPE_ALWAYS_ASK,
351     SETTINGS_TYPE_OFF
352 };
353 } // namespace WrtDB
354
355 struct WidgetSetting
356 {
357     DPL::String settingName;
358     DPL::String settingValue;
359
360     bool operator ==(const WidgetSetting& info) const
361     {
362         return (info.settingName == settingName &&
363                info.settingValue == settingValue);
364     }
365     bool operator !=(const WidgetSetting& info) const
366     {
367         return (info.settingName != settingName ||
368                info.settingValue != settingValue);
369     }
370 };
371
372 typedef std::list<WidgetSetting> WidgetSettings;
373
374 /**
375  * @brief Widget Application Service
376  *
377  * Application sercvice describes details of behaviour
378  * when widget receives aul bundle data.
379  */
380 struct WidgetApplicationService
381 {
382   public:
383     DPL::String src;       /* start uri */
384     DPL::String operation; /* service name */
385     DPL::String scheme;    /* scheme type*/
386     DPL::String mime;      /* mime type */
387
388     bool operator== (const WidgetApplicationService& other) const
389     {
390         return src == other.src &&
391         operation == other.operation &&
392         scheme == other.scheme &&
393         mime == other.mime;
394     }
395 };
396
397 typedef std::list<WidgetApplicationService> WidgetApplicationServiceList;
398
399 #endif /* WRT_WIDGET_DAO_COMMON_DAO_TYPES_H_ */