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