Merge "Fixed widget install fail when using partner privilege"
[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
57   private:
58     DPL::String string;
59     DPL::String lang;
60 };
61
62 typedef StringWithLang LabelType, IconType, DescriptionType;
63
64 /**
65  * These types are basicaly strings but they should allow usage of different
66  * range of characters or words (details in XML spec.).
67  * For simplicity DPL::Strings are used, although this can lead to XML
68  * validation
69  * errors (related to usage of not allowed characters in given places).
70  */
71 typedef DPL::String NcnameType, NmtokenType, AnySimpleType, LangType;
72 typedef DPL::String OperationType, MimeType, UriType, TypeType, PackageType;
73 typedef DPL::OptionalString InstallLocationType, CategoriesType;
74 typedef DPL::String AppCategoryType;
75
76 /**
77  * xmllib2 wrappers
78  */
79 void writeElement(xmlTextWriterPtr writer, const char * name, DPL::String body);
80 void writeText(xmlTextWriterPtr writer, DPL::String text);
81 void writeElement(xmlTextWriterPtr writer, const char * name, const char * body);
82 void writeElementWithOneAttribute(xmlTextWriterPtr writer,
83                                   const char * name,
84                                   const char * body,
85                                   const char * nameAttr,
86                                   DPL::String bodyAttr,
87                                   bool condition = true);
88 void startElement(xmlTextWriterPtr writer, const char * name);
89 void endElement(xmlTextWriterPtr writer);
90 void writeAttribute(xmlTextWriterPtr writer, const char * name,
91                     DPL::String body, bool condition);
92 void writeAttribute(xmlTextWriterPtr writer, const char * name,
93                     const char * body, bool condition);
94
95 /**
96  * @brief author element
97  */
98 class Author
99 {
100   public:
101     Author() {}
102     Author(AnySimpleType e,
103            NcnameType h,
104            LangType l,
105            DPL::String b) :
106         email(e), href(h), lang(l), body(b) {}
107     void serialize(xmlTextWriterPtr writer);
108
109   private:
110     AnySimpleType email;
111     NcnameType href;
112     LangType lang;
113     DPL::String body;
114 };
115
116 typedef Author AuthorType;
117
118 /**
119  * @brief application-service element
120  */
121 class AppControl
122 {
123   public:
124     AppControl() {}
125     void addOperation(const OperationType &x)
126     {
127         this->operation.push_back(x);
128     }
129     void addUri(const UriType &x)
130     {
131         this->uri.push_back(x);
132     }
133     void addMime(const MimeType &x)
134     {
135         this->mime.push_back(x);
136     }
137     void serialize(xmlTextWriterPtr writer);
138
139   private:
140     std::list<OperationType> operation; //attr name AnySimpleType
141     std::list<UriType> uri; //attr name AnySimpleType
142     std::list<MimeType> mime; //attr name AnySimpleType
143 };
144
145 typedef AppControl AppControlType;
146
147 /**
148  * @brief ime-application element
149  */
150 class ImeApplication
151 {
152   public:
153     ImeApplication() {}
154     void setAppid(const NcnameType &x)
155     {
156         this->appid = x;
157     }
158     void setExec(const NcnameType &x)
159     {
160         this->exec = x;
161     }
162     void setMultiple(bool x)
163     {
164         this->multiple = x;
165     }
166     void setNodisplay(bool x)
167     {
168         this->nodisplay = x;
169     }
170     void setType(const TypeType &x)
171     {
172         this->type = x;
173     }
174     void addLabel(const LabelType &x)
175     {
176         this->label.push_back(x);
177     }
178     void addIcon(const IconType &x)
179     {
180         this->icon.push_back(x);
181     }
182     void serialize(xmlTextWriterPtr writer);
183
184   private:
185     NcnameType appid;
186     NcnameType exec;
187     DPL::OptionalBool multiple;
188     DPL::OptionalBool nodisplay;
189     TypeType type;
190     std::list<LabelType> label;
191     std::list<IconType> icon;
192 };
193
194 typedef ImeApplication ImeApplicationType;
195
196 /**
197  * @brief service-application element
198  */
199 class ServiceApplication
200 {
201   public:
202     ServiceApplication() {}
203     void setAppid(const NcnameType &x)
204     {
205         this->appid = x;
206     }
207     void setAutoRestart(bool x)
208     {
209         this->autoRestart = x;
210     }
211     void setExec(const AnySimpleType &x)
212     {
213         this->exec = x;
214     }
215     void setOnBoot(bool x)
216     {
217         this->onBoot = x;
218     }
219     void setType(const TypeType &x)
220     {
221         this->type = x;
222     }
223     void addLabel(const LabelType &x)
224     {
225         this->label.push_back(x);
226     }
227     void addIcon(const IconType &x)
228     {
229         this->icon.push_back(x);
230     }
231     void addAppControl(const AppControlType &x)
232     {
233         this->appControl.push_back(x);
234     }
235     void serialize(xmlTextWriterPtr writer);
236
237   private:
238     NcnameType appid;
239     DPL::OptionalBool autoRestart;
240     AnySimpleType exec;
241     DPL::OptionalBool onBoot;
242     TypeType type;
243     std::list<LabelType> label; //attr name AnySimpleType
244     std::list<IconType> icon; //attr name AnySimpleType
245     std::list<AppControlType> appControl; //attr name AnySimpleType
246 };
247
248 typedef ServiceApplication ServiceApplicationType;
249
250 /**
251  * @brief ui-application element
252  */
253 class UiApplication
254 {
255   public:
256     UiApplication() {}
257     void setAppid(const NcnameType &x)
258     {
259         this->appid = x;
260     }
261     void setExtraid(const NcnameType &x)
262     {
263         this->extraid = x;
264     }
265     void setExec(const AnySimpleType &x)
266     {
267         this->exec = x;
268     }
269     void setMultiple(bool x)
270     {
271         this->multiple = x;
272     }
273     void setNodisplay(bool x)
274     {
275         this->nodisplay = x;
276     }
277     void setTaskmanage(bool x)
278     {
279         this->taskmanage = x;
280     }
281     void setType(const TypeType &x)
282     {
283         this->type = x;
284     }
285     void setCategories(const NcnameType &x)
286     {
287         this->categories = x;
288     }
289     void addLabel(const LabelType &x)
290     {
291         this->label.push_back(x);
292     }
293     void addIcon(const IconType &x)
294     {
295         this->icon.push_back(x);
296     }
297     void addAppControl(const AppControlType &x)
298     {
299         this->appControl.push_back(x);
300     }
301     void addAppCategory(const AppCategoryType &x)
302     {
303         this->appCategory.push_back(x);
304     }
305     void serialize(xmlTextWriterPtr writer);
306
307   private:
308     NcnameType appid;
309     NcnameType extraid;
310     AnySimpleType exec;
311     DPL::OptionalBool multiple;
312     DPL::OptionalBool nodisplay;
313     DPL::OptionalBool taskmanage;
314     TypeType type;
315     CategoriesType categories;
316     std::list<LabelType> label;
317     std::list<IconType> icon;
318     std::list<AppControlType> appControl;
319     std::list<AppCategoryType> appCategory;
320 };
321
322 typedef UiApplication UiApplicationType;
323
324 /**
325  * @brief LiveBox element
326  */
327 typedef std::list<std::pair<DPL::String, DPL::String> > boxSizeType;
328
329 struct BoxInfo
330 {
331     NcnameType boxSrc;
332     NcnameType boxMouseEvent;
333     NcnameType boxTouchEffect;
334     boxSizeType boxSize;
335     NcnameType pdSrc;
336     NcnameType pdWidth;
337     NcnameType pdHeight;
338 };
339 typedef BoxInfo BoxInfoType;
340
341 class LiveBox
342 {
343   public:
344     LiveBox() { }
345     void setLiveboxId(const NcnameType &x)
346     {
347         this->liveboxId = x;
348     }
349     void setPrimary(const NcnameType &x)
350     {
351         this->primary = x;
352     }
353     void setAutoLaunch(const NcnameType &x)
354     {
355         this->autoLaunch = x;
356     }
357     void setUpdatePeriod(const NcnameType &x)
358     {
359         this->updatePeriod = x;
360     }
361     void setLabel(const NcnameType &x)
362     {
363         this->label = x;
364     }
365     void setIcon(const NcnameType &x)
366     {
367         this->icon = x;
368     }
369     void setBox(const BoxInfoType &x)
370     {
371         this->box = x;
372     }
373
374     void serialize(xmlTextWriterPtr writer);
375
376   private:
377     NcnameType liveboxId;
378     NcnameType primary;
379     NcnameType autoLaunch;
380     NcnameType updatePeriod;
381     NcnameType timeout;
382     NcnameType label;
383     NcnameType icon;
384     BoxInfoType box;
385 };
386
387 typedef LiveBox LiveBoxInfo;
388
389 /**
390  * @brief manifest element
391  *
392  * Manifest xml file representation.
393  */
394 class Manifest
395 {
396   public:
397     Manifest() {}
398     void serialize(xmlTextWriterPtr writer);
399     void generate(DPL::String filename);
400
401     void addLabel(const LabelType &x)
402     {
403         this->label.push_back(x);
404     }
405     void addIcon(const IconType &x)
406     {
407         this->icon.push_back(x);
408     }
409     void addAuthor(const AuthorType &x)
410     {
411         this->author.push_back(x);
412     }
413     void addDescription(const DescriptionType &x)
414     {
415         this->description.push_back(x);
416     }
417     //    void addCompatibility(const CompatibilityType &x)
418     //    {
419     //        this->compatibility.push_back(x);
420     //    }
421     //    void addDeviceProfile(const DeviceProfileType &x)
422     //    {
423     //        this->deviceProfile.push_back(x);
424     //    }
425     void addServiceApplication(const ServiceApplicationType &x)
426     {
427         this->serviceApplication.push_back(x);
428     }
429     void addUiApplication(const UiApplicationType &x)
430     {
431         this->uiApplication.push_back(x);
432     }
433     void addImeApplication(const ImeApplicationType &x)
434     {
435         this->imeApplication.push_back(x);
436     }
437     //    void addFont(const FontType &x) { this->font.push_back(x); }
438
439     void addLivebox(const LiveBoxInfo &x)
440     {
441         this->livebox.push_back(x);
442     }
443
444     void setInstallLocation(const InstallLocationType &x)
445     {
446         this->installLocation = x;
447     }
448     void setPackage(const NcnameType &x)
449     {
450         this->package = x;
451     }
452     void setType(const PackageType &x)
453     {
454         this->type = x;
455     }
456     void setVersion(const NmtokenType &x)
457     {
458         this->version = x;
459     }
460
461   private:
462     std::list<LabelType> label;
463     std::list<IconType> icon;
464     std::list<AuthorType> author;
465     std::list<DescriptionType> description;
466     //    std::list<CompatibilityType> compatibility;
467     //    std::list<DeviceProfileType> deviceProfile;
468     std::list<ServiceApplicationType> serviceApplication;
469     std::list<UiApplicationType> uiApplication;
470     std::list<ImeApplicationType> imeApplication;
471     //    std::list<FontType> font;
472     std::list<LiveBoxInfo> livebox;
473     InstallLocationType installLocation;
474     NcnameType package;
475     PackageType type;
476     NmtokenType version;
477 };
478 } //namespace Jobs
479 } //namespace WidgetInstall
480
481 #endif //INSTALLER_JOBS_MANIFEST_H