Update wrt-commons_0.2.54
[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
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
57     std::string m_libraryName;
58     FeatureContainer m_featureContainer;
59 };
60
61 class PluginObjectsDAO
62 {
63   public:
64     typedef std::set<std::string> Objects;
65     typedef DPL::SharedPtr<Objects> ObjectsPtr;
66
67   public:
68     explicit PluginObjectsDAO() {}
69
70   protected:
71     ObjectsPtr m_implemented;
72     ObjectsPtr m_dependent;
73 };
74
75 /**
76  * @brief Widget id describes web-runtime global widget identifier.
77  *
78  * Notice that only up to one widget can exist at the same time.
79  * DbWidgetHandle can be translated into corresponding WidgetModel by invoking
80  * FindWidgetModel routine.
81  */
82 typedef int DbWidgetHandle;
83
84 /**
85  * Value of invalid widget handle
86  */
87 enum {
88     INVALID_WIDGET_HANDLE = -1
89 };
90
91 /**
92  * @brief Structure to hold the information of widget's size
93  */
94 struct DbWidgetSize
95 {
96     DPL::OptionalInt width;
97     DPL::OptionalInt height;
98
99     DbWidgetSize(DPL::OptionalInt w = DPL::OptionalInt::Null,
100             DPL::OptionalInt h = DPL::OptionalInt::Null) :
101         width(w),
102         height(h)
103     {
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::set<EncryptedFileInfo> EncryptedFileList;
160
161 /**
162  * @brief Widget configuration parameter key
163  */
164 typedef DPL::String WidgetParamKey;
165
166 /**
167  * @brief Widget configuration parameter value
168  */
169 typedef DPL::String WidgetParamValue;
170
171 /**
172  * @brief A map of widget configuration parameters.
173  *
174  * Widget configuration parameters are read from database and are stored
175  * along with feature that they describe.
176  */
177 typedef std::multimap<WidgetParamKey, WidgetParamValue> WidgetParamMap;
178
179 /**
180  * @brief Widget feature host information about possible javascript extensions
181  *        that widget may use
182  *
183  * Widget features are declared in configuration file in widget installation
184  * package. Each declared special feature is contained in some wrt-plugin that
185  * declares to implement it. After widget launch wrt searches for proper plugin
186  * libraries and load needed features.
187  *
188  * Widget features can be required or optional. It is possible to start widget
189  * without missing feature. When required feature cannot be loaded widget will
190  * not start.
191  */
192
193 enum {
194     INVALID_PLUGIN_HANDLE = -1
195 };
196 typedef int DbPluginHandle;
197
198 struct DbWidgetFeature
199 {
200     DPL::String name;        /// Feature name
201     bool required;           /// Whether feature is required
202     bool rejected;           /// Api feature was rejected by ace
203     DbPluginHandle pluginId; /// Plugin id that implement this feature
204     WidgetParamMap params;   /// Widget's params
205
206     DbWidgetFeature() :
207         required(false),
208         pluginId(INVALID_PLUGIN_HANDLE)
209     {
210     }
211 };
212
213 inline bool operator < (const DbWidgetFeature &objA,
214         const DbWidgetFeature &objB)
215 {
216     return objA.name.compare(objB.name) < 0;
217 }
218
219 inline bool operator==(const DbWidgetFeature &featureA,
220         const DbWidgetFeature &featureB)
221 {
222     return featureA.name == featureB.name &&
223            featureA.required == featureB.required &&
224            featureA.pluginId == featureB.pluginId;
225 }
226
227 /**
228  * @brief Default container for features list
229  */
230 typedef std::multiset<DbWidgetFeature> DbWidgetFeatureSet;
231
232 /**
233  * @brief Default container with DbWidgetHandle's
234  */
235 typedef std::list<DbWidgetHandle> DbWidgetHandleList;
236
237 /**
238  * @brief Widget specific type
239  *
240  * Widget type describes belowed in WAC, TIZEN WebApp
241  */
242 enum AppType
243 {
244     APP_TYPE_UNKNOWN = 0, // unknown
245     APP_TYPE_WAC20, // WAC 2.0
246     APP_TYPE_TIZENWEBAPP, // Tizen webapp
247 };
248
249 class WidgetType
250 {
251   public:
252     WidgetType()
253     :appType(APP_TYPE_UNKNOWN)
254     {
255     }
256     WidgetType(const AppType type)
257     :appType(type)
258     {
259     }
260     bool operator== (const AppType& other) const
261     {
262         return appType == other;
263     }
264     std::string getApptypeToString()
265     {
266         switch (appType) {
267 #define X(x) case x: return #x;
268         X(APP_TYPE_UNKNOWN)
269         X(APP_TYPE_WAC20)
270         X(APP_TYPE_TIZENWEBAPP)
271 #undef X
272         default:
273             return "UNKNOWN";
274         }
275     }
276
277     AppType appType;
278 };
279
280 /**
281  * @brief Package specific type
282  *
283  * Package type describes belowed in Tizen webapp, C++ service App
284  */
285 enum PackagingType
286 {
287     PKG_TYPE_UNKNOWN = 0, // unknown
288     PKG_TYPE_TIZEN_WEBAPP, // Tizen webapp
289     PKG_TYPE_TIZEN_WITHSVCAPP, // Tizen webapp with C++ service app
290 };
291
292 class PkgType
293 {
294   public:
295     PkgType()
296     :pkgType(PKG_TYPE_UNKNOWN)
297     {
298     }
299     PkgType(const PackagingType type)
300     :pkgType(type)
301     {
302     }
303     bool operator== (const PackagingType& 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_TIZEN_WEBAPP)
313         X(PKG_TYPE_TIZEN_WITHSVCAPP)
314 #undef X
315         default:
316             return "UNKNOWN";
317         }
318     }
319
320     PackagingType pkgType;
321 };
322
323 } // namespace WrtDB
324
325 struct WidgetSetting
326 {
327     DPL::String settingName;
328     DPL::String settingValue;
329
330     bool operator ==(const WidgetSetting& info) const
331     {
332         return (info.settingName == settingName &&
333                info.settingValue == settingValue);
334     }
335     bool operator !=(const WidgetSetting& info) const
336     {
337         return (info.settingName != settingName ||
338                info.settingValue != settingValue);
339     }
340 };
341
342 typedef std::list<WidgetSetting> WidgetSettings;
343
344 /**
345  * @brief Widget Application Service
346  *
347  * Application sercvice describes details of behaviour
348  * when widget receives aul bundle data.
349  */
350 struct WidgetApplicationService
351 {
352   public:
353     DPL::String src;       /* start uri */
354     DPL::String operation; /* service name */
355     DPL::String scheme;    /* scheme type*/
356     DPL::String mime;      /* mime type */
357
358     bool operator== (const WidgetApplicationService& other) const
359     {
360         return src == other.src &&
361         operation == other.operation &&
362         scheme == other.scheme &&
363         mime == other.mime;
364     }
365 };
366
367 typedef std::list<WidgetApplicationService> WidgetApplicationServiceList;
368
369 #endif /* WRT_WIDGET_DAO_COMMON_DAO_TYPES_H_ */