444f176dd50ab9e9f649efd784524f5e8650242b
[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 typedef std::list<WidgetPkgName> WidgetPkgNameList_TEMPORARY_API; //TODO: this cannot be null -> appropriate changes in db schema needed
241
242 class WidgetDAOReadOnly; //forward declaration
243 typedef std::shared_ptr<WidgetDAOReadOnly> WidgetDAOReadOnlyPtr;
244 /**
245  * @brief Default container with WidgetDAOReadOnly
246  */
247 typedef std::list<WidgetDAOReadOnlyPtr> DbWidgetDAOReadOnlyList;
248
249 /**
250  * @brief Widget specific type
251  *
252  * Widget type describes belowed in WAC, TIZEN WebApp
253  */
254 enum AppType
255 {
256     APP_TYPE_UNKNOWN = 0, // unknown
257     APP_TYPE_WAC20, // WAC 2.0
258     APP_TYPE_TIZENWEBAPP // Tizen webapp
259 };
260
261 class WidgetType
262 {
263   public:
264     WidgetType()
265     :appType(APP_TYPE_UNKNOWN)
266     {
267     }
268     WidgetType(const AppType type)
269     :appType(type)
270     {
271     }
272     bool operator== (const AppType& other) const
273     {
274         return appType == other;
275     }
276     bool operator!= (const AppType& other) const
277     {
278         return appType != other;
279     }
280     std::string getApptypeToString()
281     {
282         switch (appType) {
283 #define X(x) case x: return #x;
284         X(APP_TYPE_UNKNOWN)
285         X(APP_TYPE_WAC20)
286         X(APP_TYPE_TIZENWEBAPP)
287 #undef X
288         default:
289             return "UNKNOWN";
290         }
291     }
292
293     AppType appType;
294 };
295
296 /**
297  * @brief Package specific type
298  *
299  * Package type describes belowed in Tizen webapp, C++ service App
300  */
301 enum PkgType
302 {
303     PKG_TYPE_UNKNOWN = 0, // unknown
304     PKG_TYPE_NOMAL_WEB_APP,
305     PKG_TYPE_DIRECTORY_WEB_APP,
306     PKG_TYPE_HOSTED_WEB_APP,    // request from browser
307     PKG_TYPE_HYBRID_WEB_APP // Tizen webapp with C++ service app
308 };
309
310 class PackagingType
311 {
312   public:
313     PackagingType()
314     :pkgType(PKG_TYPE_UNKNOWN)
315     {
316     }
317     PackagingType(const PkgType type)
318     :pkgType(type)
319     {
320     }
321     bool operator== (const PkgType& other) const
322     {
323         return pkgType == other;
324     }
325     bool operator!= (const PkgType& other) const
326     {
327         return pkgType != other;
328     }
329     std::string getPkgtypeToString()
330     {
331         switch (pkgType) {
332 #define X(x) case x: return #x;
333         X(PKG_TYPE_UNKNOWN)
334         X(PKG_TYPE_NOMAL_WEB_APP)
335         X(PKG_TYPE_DIRECTORY_WEB_APP)
336         X(PKG_TYPE_HOSTED_WEB_APP)
337         X(PKG_TYPE_HYBRID_WEB_APP)
338 #undef X
339         default:
340             return "UNKNOWN";
341         }
342     }
343
344     PkgType pkgType;
345 };
346
347 enum SettingsType
348 {
349     SETTINGS_TYPE_UNKNOWN = 0,
350     SETTINGS_TYPE_ON,
351     SETTINGS_TYPE_ALWAYS_ASK,
352     SETTINGS_TYPE_OFF
353 };
354 } // namespace WrtDB
355
356 struct WidgetSetting
357 {
358     DPL::String settingName;
359     DPL::String settingValue;
360
361     bool operator ==(const WidgetSetting& info) const
362     {
363         return (info.settingName == settingName &&
364                info.settingValue == settingValue);
365     }
366     bool operator !=(const WidgetSetting& info) const
367     {
368         return (info.settingName != settingName ||
369                info.settingValue != settingValue);
370     }
371 };
372
373 typedef std::list<WidgetSetting> WidgetSettings;
374
375 /**
376  * @brief Widget Application Service
377  *
378  * Application sercvice describes details of behaviour
379  * when widget receives aul bundle data.
380  */
381 struct WidgetApplicationService
382 {
383   public:
384     DPL::String src;       /* start uri */
385     DPL::String operation; /* service name */
386     DPL::String scheme;    /* scheme type*/
387     DPL::String mime;      /* mime type */
388
389     bool operator== (const WidgetApplicationService& other) const
390     {
391         return src == other.src &&
392         operation == other.operation &&
393         scheme == other.scheme &&
394         mime == other.mime;
395     }
396 };
397
398 typedef std::list<WidgetApplicationService> WidgetApplicationServiceList;
399
400 #endif /* WRT_WIDGET_DAO_COMMON_DAO_TYPES_H_ */