Rename invalid WRT_SMACK_LABEL macro to WRT_SMACK_ENABLED
[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 #ifdef LIVEBOX
407
408 /**
409  * @brief LiveBox element
410  */
411 typedef WrtDB::ConfigParserData::LiveboxInfo::BoxSizeList BoxSizeType;
412 typedef WrtDB::ConfigParserData::LiveboxInfo::BoxLabelList BoxLabelType;
413
414 struct BoxInfo
415 {
416     NcnameType boxSrc;
417     NcnameType boxMouseEvent;
418     NcnameType boxTouchEffect;
419     BoxSizeType boxSize;
420     NcnameType pdSrc;
421     NcnameType pdWidth;
422     NcnameType pdHeight;
423 };
424 typedef BoxInfo BoxInfoType;
425
426 class LiveBox
427 {
428   public:
429     LiveBox() { }
430     void setLiveboxId(const NcnameType &x)
431     {
432         this->liveboxId = x;
433     }
434     void setPrimary(const NcnameType &x)
435     {
436         this->primary = x;
437     }
438     void setUpdatePeriod(const NcnameType &x)
439     {
440         this->updatePeriod = x;
441     }
442     void setLabel(const BoxLabelType &x)
443     {
444         this->label = x;
445     }
446     void setIcon(const NcnameType &x)
447     {
448         this->icon = x;
449     }
450     void setBox(const BoxInfoType &x)
451     {
452         this->box = x;
453     }
454
455     void serialize(xmlTextWriterPtr writer);
456
457   private:
458     NcnameType liveboxId;
459     NcnameType primary;
460     NcnameType autoLaunch;
461     NcnameType updatePeriod;
462     NcnameType timeout;
463     BoxLabelType label;
464     NcnameType icon;
465     NcnameType lang;
466     BoxInfoType box;
467 };
468
469 typedef LiveBox LiveBoxInfo;
470 #endif //LIVEBOX
471
472 /**
473  * @brief manifest element
474  *
475  * Manifest xml file representation.
476  */
477 class Manifest
478 {
479   public:
480     Manifest() {}
481     void serialize(xmlTextWriterPtr writer);
482     void generate(DPL::String filename);
483
484     void addLabel(const LabelType &x)
485     {
486 #ifdef MULTIPROCESS_SERVICE_SUPPORT
487         auto pos = std::find(label.begin(), label.end(), x);
488         if (pos == label.end()) {
489             this->label.push_back(x);
490         }
491 #else
492         this->label.push_back(x);
493 #endif
494     }
495     void addIcon(const IconType &x)
496     {
497         this->icon.push_back(x);
498     }
499     void addAuthor(const AuthorType &x)
500     {
501         this->author.push_back(x);
502     }
503     void addDescription(const DescriptionType &x)
504     {
505         this->description.push_back(x);
506     }
507     //    void addCompatibility(const CompatibilityType &x)
508     //    {
509     //        this->compatibility.push_back(x);
510     //    }
511     //    void addDeviceProfile(const DeviceProfileType &x)
512     //    {
513     //        this->deviceProfile.push_back(x);
514     //    }
515     void addServiceApplication(const ServiceApplicationType &x)
516     {
517         this->serviceApplication.push_back(x);
518     }
519     void addUiApplication(const UiApplicationType &x)
520     {
521         this->uiApplication.push_back(x);
522     }
523     void addImeApplication(const ImeApplicationType &x)
524     {
525         this->imeApplication.push_back(x);
526     }
527     //    void addFont(const FontType &x) { this->font.push_back(x); }
528 #ifdef LIVEBOX
529     void addLivebox(const LiveBoxInfo &x)
530     {
531         this->livebox.push_back(x);
532     }
533 #endif //LIVEBOX
534     void addAccount(const Account &x)
535     {
536         this->account.push_back(x);
537     }
538
539     void addPrivileges(const PrivilegeType &x)
540     {
541         this->privileges = x;
542     }
543
544     void setInstallLocation(const InstallLocationType &x)
545     {
546         this->installLocation = x;
547     }
548     void setPackage(const NcnameType &x)
549     {
550         this->package = x;
551     }
552     void setType(const PackageType &x)
553     {
554         this->type = x;
555     }
556     void setVersion(const NmtokenType &x)
557     {
558         this->version = x;
559     }
560     void setStoreClientId(const NcnameType &x)
561     {
562         this->storeClientId= x;
563     }
564
565   private:
566     std::list<LabelType> label;
567     std::list<IconType> icon;
568     std::list<AuthorType> author;
569     std::list<DescriptionType> description;
570     //    std::list<CompatibilityType> compatibility;
571     //    std::list<DeviceProfileType> deviceProfile;
572     std::list<ServiceApplicationType> serviceApplication;
573     std::list<UiApplicationType> uiApplication;
574     std::list<ImeApplicationType> imeApplication;
575     //    std::list<FontType> font;
576 #ifdef LIVEBOX
577     std::list<LiveBoxInfo> livebox;
578 #endif
579     InstallLocationType installLocation;
580     NcnameType package;
581     PackageType type;
582     NmtokenType version;
583     std::list<Account> account;
584     PrivilegeType privileges;
585     NcnameType storeClientId;
586
587 };
588 } //namespace Jobs
589 } //namespace WidgetInstall
590
591 #endif //INSTALLER_JOBS_MANIFEST_H