[Release] wrt-installer_0.1.85
[platform/framework/web/wrt-installer.git] / src / jobs / widget_install / manifest.h
1 /*
2  * Copyright (c) 2012 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  * @file    manifest.h
18  * @author  Mariusz Domanski (m.domanski@samsung.com)
19  */
20
21 #ifndef INSTALLER_JOBS_MANIFEST_H
22 #define INSTALLER_JOBS_MANIFEST_H
23
24 #include <list>
25
26 #include <libxml/encoding.h>
27 #include <libxml/xmlwriter.h>
28
29 #include <dpl/string.h>
30 #include <dpl/optional_typedefs.h>
31 #include <dpl/foreach.h>
32 #include <dpl/wrt-dao-ro/config_parser_data.h>
33
34 namespace Jobs {
35 namespace WidgetInstall {
36 /**
37  * @brief string with optional language attribute
38  */
39 class StringWithLang
40 {
41   public:
42     StringWithLang() { }
43     StringWithLang(DPL::String s) : string(s) { }
44     StringWithLang(DPL::String s, DPL::String l) : string(s), lang(l) { }
45     DPL::String getString()
46     {
47         return this->string;
48     }
49     DPL::String getLang()
50     {
51         return this->lang;
52     }
53     bool hasLang()
54     {
55         return !this->lang.empty();
56     }
57     int operator==(const StringWithLang &other)
58     {
59         return (DPL::ToUTF8String(other.string) == DPL::ToUTF8String(string)) &&
60                (DPL::ToUTF8String(other.lang) == DPL::ToUTF8String(lang));
61     }
62
63   private:
64     DPL::String string;
65     DPL::String lang;
66 };
67
68 typedef StringWithLang LabelType, IconType, DescriptionType;
69
70 /**
71  * These types are basicaly strings but they should allow usage of different
72  * range of characters or words (details in XML spec.).
73  * For simplicity DPL::Strings are used, although this can lead to XML
74  * validation
75  * errors (related to usage of not allowed characters in given places).
76  */
77 typedef DPL::String NcnameType, NmtokenType, AnySimpleType, LangType;
78 typedef DPL::String OperationType, MimeType, UriType, TypeType, PackageType;
79 typedef DPL::OptionalString InstallLocationType, CategoriesType;
80 typedef DPL::String AppCategoryType;
81 typedef DPL::OptionalString KeyType, ValueType;
82
83 /**
84  * xmllib2 wrappers
85  */
86 void writeElement(xmlTextWriterPtr writer, const char * name, DPL::String body);
87 void writeText(xmlTextWriterPtr writer, DPL::String text);
88 void writeElement(xmlTextWriterPtr writer, const char * name, const char * body);
89 void writeElementWithOneAttribute(xmlTextWriterPtr writer,
90                                   const char * name,
91                                   const char * body,
92                                   const char * nameAttr,
93                                   DPL::String bodyAttr,
94                                   bool condition = true);
95 void startElement(xmlTextWriterPtr writer, const char * name);
96 void endElement(xmlTextWriterPtr writer);
97 void writeAttribute(xmlTextWriterPtr writer, const char * name,
98                     DPL::String body, bool condition);
99 void writeAttribute(xmlTextWriterPtr writer, const char * name,
100                     const char * body, bool condition);
101
102 /**
103  * @brief author element
104  */
105 class Author
106 {
107   public:
108     Author() {}
109     Author(AnySimpleType e,
110            NcnameType h,
111            LangType l,
112            DPL::String b) :
113         email(e), href(h), lang(l), body(b) {}
114     void serialize(xmlTextWriterPtr writer);
115
116   private:
117     AnySimpleType email;
118     NcnameType href;
119     LangType lang;
120     DPL::String body;
121 };
122
123 typedef Author AuthorType;
124
125 /**
126  * @brief application-service element
127  */
128 class AppControl
129 {
130   public:
131     AppControl() {}
132     void addOperation(const OperationType &x)
133     {
134         this->operation.push_back(x);
135     }
136     void addUri(const UriType &x)
137     {
138         this->uri.push_back(x);
139     }
140     void addMime(const MimeType &x)
141     {
142         this->mime.push_back(x);
143     }
144     void serialize(xmlTextWriterPtr writer);
145
146   private:
147     std::list<OperationType> operation; //attr name AnySimpleType
148     std::list<UriType> uri; //attr name AnySimpleType
149     std::list<MimeType> mime; //attr name AnySimpleType
150 };
151
152 typedef AppControl AppControlType;
153
154 /**
155  * @brief account element
156  */
157 typedef std::list<std::pair<DPL::String, DPL::String>> IconListType;
158 typedef std::list<LabelType> DisplayNameListType;
159 typedef std::list<DPL::String> AccountCapabilityType;
160
161 struct AccountProvider
162 {
163     NcnameType appid;
164     NcnameType multiAccount;
165     IconListType icon;
166     DisplayNameListType name;
167     AccountCapabilityType capability;
168 };
169
170 typedef AccountProvider AccountProviderType;
171
172 class Account
173 {
174   public:
175     Account() {}
176     void addAccountProvider(const AccountProvider &x)
177     {
178         this->provider = x;
179     }
180     void serialize(xmlTextWriterPtr writer);
181
182   private:
183     AccountProviderType provider;
184 };
185
186 class Privilege
187 {
188   public:
189     Privilege() {}
190     void addPrivilegeName(const DPL::String &x)
191     {
192         this->name.push_back(x);
193     }
194     bool isEmpty()
195     {
196         return this->name.empty();
197     }
198
199     void serialize(xmlTextWriterPtr writer);
200
201   private:
202     std::list<DPL::String> name;
203 };
204
205 typedef Privilege PrivilegeType;
206
207 class Metadata
208 {
209   public:
210     Metadata(KeyType k, ValueType v) :
211         key(k),
212         value(v)
213     {}
214     void serialize(xmlTextWriterPtr writer);
215
216   private:
217     KeyType key;
218     ValueType value;
219 };
220
221 typedef Metadata MetadataType;
222
223
224 /**
225  * @brief ime-application element
226  */
227 class ImeApplication
228 {
229   public:
230     ImeApplication() {}
231     void setAppid(const NcnameType &x)
232     {
233         this->appid = x;
234     }
235     void setExec(const NcnameType &x)
236     {
237         this->exec = x;
238     }
239     void setMultiple(bool x)
240     {
241         this->multiple = x;
242     }
243     void setNodisplay(bool x)
244     {
245         this->nodisplay = x;
246     }
247     void setType(const TypeType &x)
248     {
249         this->type = x;
250     }
251     void addLabel(const LabelType &x)
252     {
253         this->label.push_back(x);
254     }
255     void addIcon(const IconType &x)
256     {
257         this->icon.push_back(x);
258     }
259     void serialize(xmlTextWriterPtr writer);
260
261   private:
262     NcnameType appid;
263     NcnameType exec;
264     DPL::OptionalBool multiple;
265     DPL::OptionalBool nodisplay;
266     TypeType type;
267     std::list<LabelType> label;
268     std::list<IconType> icon;
269 };
270
271 typedef ImeApplication ImeApplicationType;
272
273 /**
274  * @brief service-application element
275  */
276 class ServiceApplication
277 {
278   public:
279     ServiceApplication() {}
280     void setAppid(const NcnameType &x)
281     {
282         this->appid = x;
283     }
284     void setAutoRestart(bool x)
285     {
286         this->autoRestart = x;
287     }
288     void setExec(const AnySimpleType &x)
289     {
290         this->exec = x;
291     }
292     void setOnBoot(bool x)
293     {
294         this->onBoot = x;
295     }
296     void setType(const TypeType &x)
297     {
298         this->type = x;
299     }
300     void addLabel(const LabelType &x)
301     {
302         this->label.push_back(x);
303     }
304     void addIcon(const IconType &x)
305     {
306         this->icon.push_back(x);
307     }
308     void addAppControl(const AppControlType &x)
309     {
310         this->appControl.push_back(x);
311     }
312     void serialize(xmlTextWriterPtr writer);
313
314   private:
315     NcnameType appid;
316     DPL::OptionalBool autoRestart;
317     AnySimpleType exec;
318     DPL::OptionalBool onBoot;
319     TypeType type;
320     std::list<LabelType> label; //attr name AnySimpleType
321     std::list<IconType> icon; //attr name AnySimpleType
322     std::list<AppControlType> appControl; //attr name AnySimpleType
323 };
324
325 typedef ServiceApplication ServiceApplicationType;
326
327 /**
328  * @brief ui-application element
329  */
330 class UiApplication
331 {
332   public:
333     UiApplication() {}
334     void setAppid(const NcnameType &x)
335     {
336         this->appid = x;
337     }
338     void setExtraid(const NcnameType &x)
339     {
340         this->extraid = x;
341     }
342     void setExec(const AnySimpleType &x)
343     {
344         this->exec = x;
345     }
346     void setMultiple(bool x)
347     {
348         this->multiple = x;
349     }
350     void setNodisplay(bool x)
351     {
352         this->nodisplay = x;
353     }
354     void setTaskmanage(bool x)
355     {
356         this->taskmanage = x;
357     }
358     void setType(const TypeType &x)
359     {
360         this->type = x;
361     }
362     void setCategories(const NcnameType &x)
363     {
364         this->categories = x;
365     }
366     void addLabel(const LabelType &x)
367     {
368         this->label.push_back(x);
369     }
370     void addIcon(const IconType &x)
371     {
372         this->icon.push_back(x);
373     }
374     void addAppControl(const AppControlType &x)
375     {
376         this->appControl.push_back(x);
377     }
378     void addAppCategory(const AppCategoryType &x)
379     {
380         this->appCategory.push_back(x);
381     }
382     void addMetadata(const MetadataType &m)
383     {
384         this->metadata.push_back(m);
385     }
386     void serialize(xmlTextWriterPtr writer);
387
388   private:
389     NcnameType appid;
390     NcnameType extraid;
391     AnySimpleType exec;
392     DPL::OptionalBool multiple;
393     DPL::OptionalBool nodisplay;
394     DPL::OptionalBool taskmanage;
395     TypeType type;
396     CategoriesType categories;
397     std::list<LabelType> label;
398     std::list<IconType> icon;
399     std::list<AppControlType> appControl;
400     std::list<AppCategoryType> appCategory;
401     std::list<MetadataType> metadata;
402 };
403
404 typedef UiApplication UiApplicationType;
405
406 /**
407  * @brief LiveBox element
408  */
409 typedef WrtDB::ConfigParserData::LiveboxInfo::BoxSizeList BoxSizeType;
410 typedef WrtDB::ConfigParserData::LiveboxInfo::BoxLabelList BoxLabelType;
411
412 struct BoxInfo
413 {
414     NcnameType boxSrc;
415     NcnameType boxMouseEvent;
416     NcnameType boxTouchEffect;
417     BoxSizeType boxSize;
418     NcnameType pdSrc;
419     NcnameType pdWidth;
420     NcnameType pdHeight;
421 };
422 typedef BoxInfo BoxInfoType;
423
424 class LiveBox
425 {
426   public:
427     LiveBox() { }
428     void setLiveboxId(const NcnameType &x)
429     {
430         this->liveboxId = x;
431     }
432     void setPrimary(const NcnameType &x)
433     {
434         this->primary = x;
435     }
436     void setUpdatePeriod(const NcnameType &x)
437     {
438         this->updatePeriod = x;
439     }
440     void setLabel(const BoxLabelType &x)
441     {
442         this->label = x;
443     }
444     void setIcon(const NcnameType &x)
445     {
446         this->icon = x;
447     }
448     void setBox(const BoxInfoType &x)
449     {
450         this->box = x;
451     }
452
453     void serialize(xmlTextWriterPtr writer);
454
455   private:
456     NcnameType liveboxId;
457     NcnameType primary;
458     NcnameType autoLaunch;
459     NcnameType updatePeriod;
460     NcnameType timeout;
461     BoxLabelType label;
462     NcnameType icon;
463     NcnameType lang;
464     BoxInfoType box;
465 };
466
467 typedef LiveBox LiveBoxInfo;
468
469 /**
470  * @brief manifest element
471  *
472  * Manifest xml file representation.
473  */
474 class Manifest
475 {
476   public:
477     Manifest() {}
478     void serialize(xmlTextWriterPtr writer);
479     void generate(DPL::String filename);
480
481     void addLabel(const LabelType &x)
482     {
483 #ifdef MULTIPROCESS_SERVICE_SUPPORT
484         auto pos = std::find(label.begin(), label.end(), x);
485         if (pos == label.end()) {
486             this->label.push_back(x);
487         }
488 #else
489         this->label.push_back(x);
490 #endif
491     }
492     void addIcon(const IconType &x)
493     {
494         this->icon.push_back(x);
495     }
496     void addAuthor(const AuthorType &x)
497     {
498         this->author.push_back(x);
499     }
500     void addDescription(const DescriptionType &x)
501     {
502         this->description.push_back(x);
503     }
504     //    void addCompatibility(const CompatibilityType &x)
505     //    {
506     //        this->compatibility.push_back(x);
507     //    }
508     //    void addDeviceProfile(const DeviceProfileType &x)
509     //    {
510     //        this->deviceProfile.push_back(x);
511     //    }
512     void addServiceApplication(const ServiceApplicationType &x)
513     {
514         this->serviceApplication.push_back(x);
515     }
516     void addUiApplication(const UiApplicationType &x)
517     {
518         this->uiApplication.push_back(x);
519     }
520     void addImeApplication(const ImeApplicationType &x)
521     {
522         this->imeApplication.push_back(x);
523     }
524     //    void addFont(const FontType &x) { this->font.push_back(x); }
525
526     void addLivebox(const LiveBoxInfo &x)
527     {
528         this->livebox.push_back(x);
529     }
530
531     void addAccount(const Account &x)
532     {
533         this->account.push_back(x);
534     }
535
536     void addPrivileges(const PrivilegeType &x)
537     {
538         this->privileges = x;
539     }
540
541     void setInstallLocation(const InstallLocationType &x)
542     {
543         this->installLocation = x;
544     }
545     void setPackage(const NcnameType &x)
546     {
547         this->package = x;
548     }
549     void setType(const PackageType &x)
550     {
551         this->type = x;
552     }
553     void setVersion(const NmtokenType &x)
554     {
555         this->version = x;
556     }
557
558   private:
559     std::list<LabelType> label;
560     std::list<IconType> icon;
561     std::list<AuthorType> author;
562     std::list<DescriptionType> description;
563     //    std::list<CompatibilityType> compatibility;
564     //    std::list<DeviceProfileType> deviceProfile;
565     std::list<ServiceApplicationType> serviceApplication;
566     std::list<UiApplicationType> uiApplication;
567     std::list<ImeApplicationType> imeApplication;
568     //    std::list<FontType> font;
569     std::list<LiveBoxInfo> livebox;
570     InstallLocationType installLocation;
571     NcnameType package;
572     PackageType type;
573     NmtokenType version;
574     std::list<Account> account;
575     PrivilegeType privileges;
576
577 };
578 } //namespace Jobs
579 } //namespace WidgetInstall
580
581 #endif //INSTALLER_JOBS_MANIFEST_H