Fixed buildrequires dukgenerator to dukgenerator-devel
[framework/web/wrt-commons.git] / tests / files_localization / mockup_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_SRC_CONFIGURATION_COMMON_DAO_TYPES_H_
25 #define WRT_SRC_CONFIGURATION_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 <memory>
34
35 namespace WrtDB {
36 namespace Powder {
37 typedef std::set<DPL::String> StringSet;
38 //! Widget description
39 struct Description
40 {
41     //!Content level
42     typedef enum
43     {
44         Level0 = 0,
45         Level1,
46         Level2,
47         Level3,
48         Level4,
49         Level5,
50         LevelUnknown
51     } LevelEnum;
52     struct LevelEntry
53     {
54         LevelEnum level; //!< content level
55
56         typedef StringSet Context;
57
58         //! POWDER context
59         //! xa    This material appears in an artistic context
60         //! xb    This material appears in an educational context
61         //! xc    This material appears in a medical context
62         //! xd    This material appears in a sports context
63         //! xe    This material appears in a violent context
64         Context context;
65         explicit LevelEntry(LevelEnum level = LevelUnknown);
66         //! Function checks if context is valid
67         //! \param[in] level POWDER content level
68         //! \param[in] context POWDER context
69         bool isContextValid(LevelEnum level,
70                             const DPL::OptionalString& context) const;
71     };
72
73     struct CategoryEntry
74     {
75         //! Levels entries for POWDER description
76         typedef std::vector <LevelEntry> LevelsContainer;
77         LevelsContainer levels;
78         //! Function checks if context is valid
79         //! \param[out] reason set if context invalid
80         //! \param[in] level POWDER content level
81         //! \param[in] context POWDER context
82         bool isCategoryValid(LevelEntry& reason,
83                              LevelEnum level,
84                              const DPL::OptionalString& context) const;
85     };
86
87     //! POWDER Category -> Category entry map for Widget
88     //!
89     //! nu    Nudity
90     //! se    Sex
91     //! vi    Violence
92     //! la    Potentially offensive language
93     //! dr    Drug use
94     //! ga    Gambling
95     //! ha    Hate or harmful activities
96     //! ug    Use of user-generated content
97     typedef std::map<DPL::String, CategoryEntry> CategoryEntries;
98
99     CategoryEntries categories;
100
101     //! Age rating for widget
102     //! If Null not set
103     DPL::OptionalInt ageRating;
104 };
105 } // namespace Powder
106
107 namespace ChildProtection {
108 //! Blacklist with forbidden URLs
109 //! It should be stored in WidgetDAO
110 typedef std::vector<DPL::String> BlackList;
111
112 //! Widget Child protection record
113 //! Record should be stored in WingetDAO
114 struct Record
115 {
116     //! Child protection enabled
117     bool enabled;
118     explicit Record(bool enabled) :
119         enabled(enabled)
120     {}
121 };
122
123 //! Powder processing
124 struct PowderRules
125 {
126     //! Rule set by parent about forbidden category
127     //! Powder category
128     //! nu    Nudity
129     //! se    Sex
130     //! vi    Violence
131     //! la    Potentially offensive language
132     //! dr    Drug use
133     //! ga    Gambling
134     //! ha    Hate or harmful activities
135     //! ug    Use of user-generated content
136     //! Powder context
137     //! xa    This material appears in an artistic conteaxt
138     //! xb    This material appears in an educational context
139     //! xc    This material appears in a medical context
140     //! xd    This material appears in a sports context
141     //! xe    This material appears in a violent context
142     struct CategoryRule
143     {
144         DPL::String category;
145         Powder::Description::LevelEnum level;
146         DPL::OptionalString context;
147         explicit CategoryRule(
148             const DPL::String& category = DPL::String(),
149             Powder::Description::LevelEnum level =
150                 Powder::Description::LevelUnknown,
151             const DPL::OptionalString& context =
152                 DPL::OptionalString());
153     };
154
155     struct PowderResult
156     {
157         //! Reasoning outcome: part of POWDER description used to invalidate
158         Powder::Description::LevelEntry invalidDescription;
159         //! Reasoning outcome: rule set by parent not full filed by description
160         CategoryRule invalidRule;
161
162         //! Reasoning outcome: type of invalidity
163         enum InvalidReason
164         {
165             InvalidRule, //!< One of rules was not fulfilled
166             InvalidAge, //!< Age is invalid
167             AgeRatingNotSet, //!< Age rating for widget is not set
168             Valid //!< Description valid
169         };
170         InvalidReason reason;
171         explicit PowderResult(
172             InvalidReason reason = Valid,
173             const Powder::Description::LevelEntry&
174             invalidDescription =
175                 Powder::Description::LevelEntry(),
176             const CategoryRule& invalidRule = CategoryRule());
177     };
178
179     typedef std::pair<bool, PowderResult> ResultPair;
180
181     //! Function checks if rule is fulfilled by description
182     //! \param[in] rule checked rule
183     //! \param[in] description
184     //! \retval true rule is valid
185     //! \retval false rule is invalid
186     ResultPair isRuleValidForDescription(const CategoryRule& rule,
187                                          const Powder::Description& description)
188     const;
189     //! Function checks if age limit is fulfilled by description
190     //! \param[in] description
191     //! \retval true age is valid
192     //! \retval false age is invalid
193     ResultPair isAgeValidForDescription(
194         const Powder::Description& description) const;
195
196     //! It is the maximum age rating valid for child
197     //! Uniform age is stored in WidgetDAO
198     DPL::OptionalInt ageLimit;
199
200     //! Set to true if age rating is required
201     //! If ageLimit is not set value is ignored
202     bool isAgeRatingRequired;
203
204     //! Set of rules configured by parent
205     //! Rules are stored in WidgetDAO and are uniform for all widgets
206     typedef std::vector<CategoryRule> RulesContainer;
207     RulesContainer rules;
208
209     //! Function check if Widget description is valid for ChildProtection
210     //! configuration
211     //! \param description widget description
212     //! \retval true widget is valid
213     //! \retval false widget is invalid
214     ResultPair isDescriptionValid(const Powder::Description& description)
215     const;
216
217     PowderRules() :
218         isAgeRatingRequired(false)
219     {}
220 };
221 } // namespace ChildProtection
222
223 class PluginMetafileData
224 {
225   public:
226     struct Feature
227     {
228         std::string m_name;
229         std::set<std::string> m_deviceCapabilities;
230
231         bool operator< (const Feature& obj) const
232         {
233             return m_name < obj.m_name;
234         }
235     };
236     typedef std::set<Feature> FeatureContainer;
237
238   public:
239
240     PluginMetafileData()
241     {}
242
243     std::string m_libraryName;
244     std::string m_featuresInstallURI;
245     std::string m_featuresKeyCN;
246     std::string m_featuresRootCN;
247     std::string m_featuresRootFingerprint;
248
249     FeatureContainer m_featureContainer;
250 };
251
252 class PluginObjectsDAO
253 {
254   public:
255     typedef std::set<std::string> Objects;
256     typedef std::shared_ptr<Objects> ObjectsPtr;
257
258   public:
259     explicit PluginObjectsDAO() {}
260
261   protected:
262     ObjectsPtr m_implemented;
263     ObjectsPtr m_dependent;
264 };
265
266 /**
267  * @brief Widget id describes web-runtime global widget identifier.
268  *
269  * Notice that only up to one widget can exist at the same time.
270  * DbWidgetHandle can be translated into corresponding WidgetModel by invoking
271  * FindWidgetModel routine.
272  */
273 typedef int DbWidgetHandle;
274
275 /**
276  * @brief Structure to hold the information of widget's size
277  */
278 struct DbWidgetSize
279 {
280     DPL::OptionalInt width;
281     DPL::OptionalInt height;
282
283     DbWidgetSize(DPL::OptionalInt w = DPL::OptionalInt::Null,
284                  DPL::OptionalInt h = DPL::OptionalInt::Null) :
285         width(w),
286         height(h)
287     {}
288 };
289
290 inline bool operator ==(const DbWidgetSize &objA, const DbWidgetSize &objB)
291 {
292     if (!objA.height || !objA.width || !objB.width || !objB.height) {
293         return false;
294     } else {
295         return *objA.height == *objB.height && *objA.width == *objB.width;
296     }
297 }
298
299 /**
300  * Widget [G]lobal [U]nique [ID]entifier
301  * Orginated from appstore ID
302  */
303 typedef DPL::OptionalString WidgetGUID;
304
305 struct WidgetAccessInfo
306 {
307     DPL::String strIRI;                /* origin iri */
308     bool bSubDomains;                  /* do we want access to subdomains ? */
309
310     bool operator ==(const WidgetAccessInfo& info) const
311     {
312         return info.strIRI == strIRI &&
313                info.bSubDomains == bSubDomains;
314     }
315 };
316
317 typedef std::list<WidgetAccessInfo> WidgetAccessInfoList;
318
319 typedef std::list<DPL::String> WindowModeList;
320
321 /**
322  * @brief Widget configuration parameter key
323  */
324 typedef DPL::String WidgetParamKey;
325
326 /**
327  * @brief Widget configuration parameter value
328  */
329 typedef DPL::String WidgetParamValue;
330
331 /**
332  * @brief A map of widget configuration parameters.
333  *
334  * Widget configuration parameters are read from database and are stored
335  * along with feature that they describe.
336  */
337 typedef std::multimap<WidgetParamKey, WidgetParamValue> WidgetParamMap;
338
339 /**
340  * @brief Widget feature host information about possible javascript extensions
341  *        that widget may use
342  *
343  * Widget features are declared in configuration file in widget installation
344  * package. Each declared special feature is contained in some wrt-plugin that
345  * declares to implement it. After widget launch wrt searches for proper plugin
346  * libraries and load needed features.
347  *
348  * Widget features can be required or optional. It is possible to start widget
349  * without missing feature. When required feature cannot be loaded widget will
350  * not start.
351  */
352
353 enum {
354     INVALID_PLUGIN_HANDLE = -1
355 };
356 typedef int DbPluginHandle;
357
358 struct DbWidgetFeature
359 {
360     DPL::String name;        /// Feature name
361     bool required;           /// Whether feature is required
362     DbPluginHandle pluginId;            /// Plugin id that implement this
363                                         // feature
364     WidgetParamMap params;   /// Widget's params
365
366     DbWidgetFeature() :
367         required(false),
368         pluginId(INVALID_PLUGIN_HANDLE)
369     {}
370 };
371
372 inline bool operator < (const DbWidgetFeature &objA,
373                         const DbWidgetFeature &objB)
374 {
375     return objA.name.compare(objB.name) < 0;
376 }
377
378 inline bool operator==(const DbWidgetFeature &featureA,
379                        const DbWidgetFeature &featureB)
380 {
381     return featureA.name == featureB.name &&
382            featureA.required == featureB.required &&
383            featureA.pluginId == featureB.pluginId;
384 }
385
386 /**
387  * @brief Default container for features list
388  */
389 typedef std::multiset<DbWidgetFeature> DbWidgetFeatureSet;
390
391 /**
392  * @brief Default container with DbWidgetHandle's
393  */
394 typedef std::list<DbWidgetHandle> DbWidgetHandleList;
395
396 /**
397  * @brief Widget specific type
398  *
399  * Widget type describes belowed in WAC, TIZEN WebApp
400  */
401 enum AppType
402 {
403     APP_TYPE_UNKNOWN = 0, // unknown
404     APP_TYPE_WAC20, // WAC 2.0
405     APP_TYPE_TIZENWEBAPP, // slp webapp
406 };
407
408 class WidgetType
409 {
410   public:
411     WidgetType() :
412         appType(APP_TYPE_UNKNOWN)
413     {}
414     WidgetType(const AppType type) :
415         appType(type)
416     {}
417     bool operator== (const AppType& other) const
418     {
419         return appType == other;
420     }
421     std::string getApptypeToString()
422     {
423         switch (appType) {
424 #define X(x) case x: return #x;
425             X(APP_TYPE_UNKNOWN)
426             X(APP_TYPE_WAC20)
427             X(APP_TYPE_TIZENWEBAPP)
428 #undef X
429         default:
430             return "UNKNOWN";
431         }
432     }
433
434     AppType appType;
435 };
436 } // namespace WrtDB
437
438 struct WidgetSetting
439 {
440     DPL::String settingName;
441     DPL::String settingValue;
442
443     bool operator ==(const WidgetSetting& info) const
444     {
445         return (info.settingName == settingName &&
446                 info.settingValue == settingValue);
447     }
448     bool operator !=(const WidgetSetting& info) const
449     {
450         return (info.settingName != settingName ||
451                 info.settingValue != settingValue);
452     }
453 };
454
455 typedef std::list<WidgetSetting> WidgetSettings;
456
457 /**
458  * @brief Widget Application Service
459  *
460  * Application sercvice describes details of behaviour
461  * when widget receives aul bundle data.
462  */
463 struct WidgetApplicationService
464 {
465   public:
466     DPL::String src;       /* start uri */
467     DPL::String operation; /* service name */
468     DPL::String scheme;    /* scheme type*/
469     DPL::String mime;      /* mime type */
470
471     bool operator== (const WidgetApplicationService& other) const
472     {
473         return src == other.src &&
474                operation == other.operation &&
475                scheme == other.scheme &&
476                mime == other.mime;
477     }
478 };
479
480 typedef std::list<WidgetApplicationService> WidgetApplicationServiceList;
481 #endif /* WRT_SRC_CONFIGURATION_COMMON_DAO_TYPES_H_ */