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