92adaa63ff4e49fdae123fa47790cdb8ff15d537
[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     std::string m_featuresInstallURI;
59     std::string m_featuresKeyCN;
60     std::string m_featuresRootCN;
61     std::string m_featuresRootFingerprint;
62
63     FeatureContainer m_featureContainer;
64 };
65
66 class PluginObjectsDAO
67 {
68   public:
69     typedef std::set<std::string> Objects;
70     typedef DPL::SharedPtr<Objects> ObjectsPtr;
71
72   public:
73     explicit PluginObjectsDAO() {}
74
75   protected:
76     ObjectsPtr m_implemented;
77     ObjectsPtr m_dependent;
78 };
79
80 /**
81  * @brief Widget id describes web-runtime global widget identifier.
82  *
83  * Notice that only up to one widget can exist at the same time.
84  * DbWidgetHandle can be translated into corresponding WidgetModel by invoking
85  * FindWidgetModel routine.
86  */
87 typedef int DbWidgetHandle;
88
89 /**
90  * @brief Structure to hold the information of widget's size
91  */
92 struct DbWidgetSize
93 {
94     DPL::OptionalInt width;
95     DPL::OptionalInt height;
96
97     DbWidgetSize(DPL::OptionalInt w = DPL::OptionalInt::Null,
98             DPL::OptionalInt h = DPL::OptionalInt::Null) :
99         width(w),
100         height(h)
101     {
102     }
103 };
104
105 inline bool operator ==(const DbWidgetSize &objA, const DbWidgetSize &objB)
106 {
107     if (!objA.height || !objA.width || !objB.width || !objB.height) {
108         return false;
109     } else {
110         return *objA.height == *objB.height && *objA.width == *objB.width;
111     }
112 }
113
114 /**
115  * Widget [G]lobal [U]nique [ID]entifier
116  * Orginated from appstore ID
117  */
118 typedef DPL::OptionalString WidgetGUID;
119
120 struct WidgetAccessInfo
121 {
122     DPL::String strIRI;                /* origin iri */
123     bool bSubDomains;                  /* do we want access to subdomains ? */
124
125     bool operator ==(const WidgetAccessInfo& info) const
126     {
127         return info.strIRI == strIRI &&
128                info.bSubDomains == bSubDomains;
129     }
130 };
131
132 typedef std::list<WidgetAccessInfo> WidgetAccessInfoList;
133
134 typedef std::list<DPL::String> WindowModeList;
135
136 /**
137  * @brief Widget configuration parameter key
138  */
139 typedef DPL::String WidgetParamKey;
140
141 /**
142  * @brief Widget configuration parameter value
143  */
144 typedef DPL::String WidgetParamValue;
145
146 /**
147  * @brief A map of widget configuration parameters.
148  *
149  * Widget configuration parameters are read from database and are stored
150  * along with feature that they describe.
151  */
152 typedef std::multimap<WidgetParamKey, WidgetParamValue> WidgetParamMap;
153
154 /**
155  * @brief Widget feature host information about possible javascript extensions
156  *        that widget may use
157  *
158  * Widget features are declared in configuration file in widget installation
159  * package. Each declared special feature is contained in some wrt-plugin that
160  * declares to implement it. After widget launch wrt searches for proper plugin
161  * libraries and load needed features.
162  *
163  * Widget features can be required or optional. It is possible to start widget
164  * without missing feature. When required feature cannot be loaded widget will
165  * not start.
166  */
167
168 enum {
169     INVALID_PLUGIN_HANDLE = -1
170 };
171 typedef int DbPluginHandle;
172
173 struct DbWidgetFeature
174 {
175     DPL::String name;        /// Feature name
176     bool required;           /// Whether feature is required
177     bool rejected;           /// Api feature was rejected by ace
178     DbPluginHandle pluginId; /// Plugin id that implement this feature
179     WidgetParamMap params;   /// Widget's params
180
181     DbWidgetFeature() :
182         required(false),
183         pluginId(INVALID_PLUGIN_HANDLE)
184     {
185     }
186 };
187
188 inline bool operator < (const DbWidgetFeature &objA,
189         const DbWidgetFeature &objB)
190 {
191     return objA.name.compare(objB.name) < 0;
192 }
193
194 inline bool operator==(const DbWidgetFeature &featureA,
195         const DbWidgetFeature &featureB)
196 {
197     return featureA.name == featureB.name &&
198            featureA.required == featureB.required &&
199            featureA.pluginId == featureB.pluginId;
200 }
201
202 /**
203  * @brief Default container for features list
204  */
205 typedef std::multiset<DbWidgetFeature> DbWidgetFeatureSet;
206
207 /**
208  * @brief Default container with DbWidgetHandle's
209  */
210 typedef std::list<DbWidgetHandle> DbWidgetHandleList;
211
212 /**
213  * @brief Widget specific type
214  *
215  * Widget type describes belowed in WAC, TIZEN WebApp
216  */
217 enum AppType
218 {
219     APP_TYPE_UNKNOWN = 0, // unknown
220     APP_TYPE_WAC10, // WAC 1.0
221     APP_TYPE_WAC20, // WAC 2.0
222     APP_TYPE_TIZENWEBAPP, // Tizen webapp
223 };
224
225 class WidgetType
226 {
227   public:
228     WidgetType()
229     :appType(APP_TYPE_UNKNOWN)
230     {
231     }
232     WidgetType(const AppType type)
233     :appType(type)
234     {
235     }
236     bool operator== (const AppType& other) const
237     {
238         return appType == other;
239     }
240     std::string getApptypeToString()
241     {
242         switch (appType) {
243 #define X(x) case x: return #x;
244         X(APP_TYPE_UNKNOWN)
245         X(APP_TYPE_WAC10)
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 } // namespace WrtDB
258
259 struct WidgetSetting
260 {
261     DPL::String settingName;
262     DPL::String settingValue;
263
264     bool operator ==(const WidgetSetting& info) const
265     {
266         return (info.settingName == settingName &&
267                info.settingValue == settingValue);
268     }
269     bool operator !=(const WidgetSetting& info) const
270     {
271         return (info.settingName != settingName ||
272                info.settingValue != settingValue);
273     }
274 };
275
276 typedef std::list<WidgetSetting> WidgetSettings;
277
278 /**
279  * @brief Widget Application Service
280  *
281  * Application sercvice describes details of behaviour
282  * when widget receives aul bundle data.
283  */
284 struct WidgetApplicationService
285 {
286   public:
287     DPL::String src;       /* start uri */
288     DPL::String operation; /* service name */
289     DPL::String scheme;    /* scheme type*/
290     DPL::String mime;      /* mime type */
291
292     bool operator== (const WidgetApplicationService& other) const
293     {
294         return src == other.src &&
295         operation == other.operation &&
296         scheme == other.scheme &&
297         mime == other.mime;
298     }
299 };
300
301 typedef std::list<WidgetApplicationService> WidgetApplicationServiceList;
302
303 #endif /* WRT_WIDGET_DAO_COMMON_DAO_TYPES_H_ */