36ee03731ef94fd96ad9e6eb6d955746937ba140
[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 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<DPL::Optional<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_HOSTED_WEB_APP,    // request from browser
305     PKG_TYPE_HYBRID_WEB_APP, // Tizen webapp with C++ service app
306 };
307
308 class PackagingType
309 {
310   public:
311     PackagingType()
312     :pkgType(PKG_TYPE_UNKNOWN)
313     {
314     }
315     PackagingType(const PkgType type)
316     :pkgType(type)
317     {
318     }
319     bool operator== (const PkgType& other) const
320     {
321         return pkgType == other;
322     }
323     bool operator!= (const PkgType& other) const
324     {
325         return pkgType != other;
326     }
327     std::string getPkgtypeToString()
328     {
329         switch (pkgType) {
330 #define X(x) case x: return #x;
331         X(PKG_TYPE_UNKNOWN)
332         X(PKG_TYPE_NOMAL_WEB_APP)
333         X(PKG_TYPE_HOSTED_WEB_APP)
334         X(PKG_TYPE_HYBRID_WEB_APP)
335 #undef X
336         default:
337             return "UNKNOWN";
338         }
339     }
340
341     PkgType pkgType;
342 };
343
344 } // namespace WrtDB
345
346 struct WidgetSetting
347 {
348     DPL::String settingName;
349     DPL::String settingValue;
350
351     bool operator ==(const WidgetSetting& info) const
352     {
353         return (info.settingName == settingName &&
354                info.settingValue == settingValue);
355     }
356     bool operator !=(const WidgetSetting& info) const
357     {
358         return (info.settingName != settingName ||
359                info.settingValue != settingValue);
360     }
361 };
362
363 typedef std::list<WidgetSetting> WidgetSettings;
364
365 /**
366  * @brief Widget Application Service
367  *
368  * Application sercvice describes details of behaviour
369  * when widget receives aul bundle data.
370  */
371 struct WidgetApplicationService
372 {
373   public:
374     DPL::String src;       /* start uri */
375     DPL::String operation; /* service name */
376     DPL::String scheme;    /* scheme type*/
377     DPL::String mime;      /* mime type */
378
379     bool operator== (const WidgetApplicationService& other) const
380     {
381         return src == other.src &&
382         operation == other.operation &&
383         scheme == other.scheme &&
384         mime == other.mime;
385     }
386 };
387
388 typedef std::list<WidgetApplicationService> WidgetApplicationServiceList;
389
390 #endif /* WRT_WIDGET_DAO_COMMON_DAO_TYPES_H_ */