234ef6e0f51d9958d49c995bb03160b3beb14413
[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 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     std::string m_libraryName;
57     FeatureContainer m_featureContainer;
58 };
59
60 class PluginObjectsDAO
61 {
62   public:
63     typedef std::set<std::string> Objects;
64     typedef std::shared_ptr<Objects> ObjectsPtr;
65
66   public:
67     explicit PluginObjectsDAO() {}
68
69   protected:
70     ObjectsPtr m_implemented;
71     ObjectsPtr m_dependent;
72 };
73
74 /**
75  * @brief Widget id describes web-runtime global widget identifier.
76  *
77  * Notice that only up to one widget can exist at the same time.
78  * DbWidgetHandle can be translated into corresponding WidgetModel by invoking
79  * FindWidgetModel routine.
80  */
81 typedef int DbWidgetHandle;
82 typedef DPL::String TizenPkgId;
83 typedef DPL::String TizenAppId;
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 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 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 typedef std::list<WidgetPkgName> WidgetPkgNameList; //TODO: this cannot be null
238                                                     // -> appropriate changes in
239                                                     // db schema needed
240 typedef std::list<TizenAppId> TizenAppIdList; //TODO: this cannot be null ->
241                                               // appropriate changes in db
242                                               // 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     WidgetType(const AppType type) :
270         appType(type)
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     PackagingType(const PkgType type) :
317         pkgType(type)
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_DIRECTORY_WEB_APP)
334             X(PKG_TYPE_HOSTED_WEB_APP)
335             X(PKG_TYPE_HYBRID_WEB_APP)
336 #undef X
337         default:
338             return "UNKNOWN";
339         }
340     }
341
342     PkgType pkgType;
343 };
344
345 enum SettingsType
346 {
347     SETTINGS_TYPE_UNKNOWN = 0,
348     SETTINGS_TYPE_ON,
349     SETTINGS_TYPE_ALWAYS_ASK,
350     SETTINGS_TYPE_OFF
351 };
352 } // namespace WrtDB
353
354 struct WidgetSetting
355 {
356     DPL::String settingName;
357     DPL::String settingValue;
358
359     bool operator ==(const WidgetSetting& info) const
360     {
361         return (info.settingName == settingName &&
362                 info.settingValue == settingValue);
363     }
364     bool operator !=(const WidgetSetting& info) const
365     {
366         return (info.settingName != settingName ||
367                 info.settingValue != settingValue);
368     }
369 };
370
371 typedef std::list<WidgetSetting> WidgetSettings;
372
373 /**
374  * @brief Widget Application Service
375  *
376  * Application sercvice describes details of behaviour
377  * when widget receives aul bundle data.
378  */
379 struct WidgetApplicationService
380 {
381     enum class Disposition {
382         WINDOW = 0,
383         INLINE
384     };
385
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     Disposition disposition;
391
392     bool operator== (const WidgetApplicationService& other) const
393     {
394         return src == other.src &&
395                operation == other.operation &&
396                scheme == other.scheme &&
397                mime == other.mime &&
398                disposition == other.disposition;
399     }
400 };
401
402 typedef std::list<WidgetApplicationService> WidgetApplicationServiceList;
403
404 #endif /* WRT_WIDGET_DAO_COMMON_DAO_TYPES_H_ */