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