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