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