[Release] wrt-installer_0.1.4 for sdk branch
[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     boxSizeType boxSize;
334     NcnameType pdSrc;
335     NcnameType pdWidth;
336     NcnameType pdHeight;
337 };
338 typedef BoxInfo BoxInfoType;
339
340 class LiveBox
341 {
342   public:
343     LiveBox() { }
344     void setLiveboxId(const NcnameType &x)
345     {
346         this->liveboxId = x;
347     }
348     void setPrimary(const NcnameType &x)
349     {
350         this->primary = x;
351     }
352     void setAutoLaunch(const NcnameType &x)
353     {
354         this->autoLaunch = x;
355     }
356     void setUpdatePeriod(const NcnameType &x)
357     {
358         this->updatePeriod = x;
359     }
360     void setLabel(const NcnameType &x)
361     {
362         this->label = x;
363     }
364     void setIcon(const NcnameType &x)
365     {
366         this->icon = x;
367     }
368     void setBox(const BoxInfoType &x)
369     {
370         this->box = x;
371     }
372
373     void serialize(xmlTextWriterPtr writer);
374
375   private:
376     NcnameType liveboxId;
377     NcnameType primary;
378     NcnameType autoLaunch;
379     NcnameType updatePeriod;
380     NcnameType timeout;
381     NcnameType label;
382     NcnameType icon;
383     BoxInfoType box;
384 };
385
386 typedef LiveBox LiveBoxInfo;
387
388 /**
389  * @brief manifest element
390  *
391  * Manifest xml file representation.
392  */
393 class Manifest
394 {
395   public:
396     Manifest() {}
397     void serialize(xmlTextWriterPtr writer);
398     void generate(DPL::String filename);
399
400     void addLabel(const LabelType &x)
401     {
402         this->label.push_back(x);
403     }
404     void addIcon(const IconType &x)
405     {
406         this->icon.push_back(x);
407     }
408     void addAuthor(const AuthorType &x)
409     {
410         this->author.push_back(x);
411     }
412     void addDescription(const DescriptionType &x)
413     {
414         this->description.push_back(x);
415     }
416     //    void addCompatibility(const CompatibilityType &x)
417     //    {
418     //        this->compatibility.push_back(x);
419     //    }
420     //    void addDeviceProfile(const DeviceProfileType &x)
421     //    {
422     //        this->deviceProfile.push_back(x);
423     //    }
424     void addServiceApplication(const ServiceApplicationType &x)
425     {
426         this->serviceApplication.push_back(x);
427     }
428     void addUiApplication(const UiApplicationType &x)
429     {
430         this->uiApplication.push_back(x);
431     }
432     void addImeApplication(const ImeApplicationType &x)
433     {
434         this->imeApplication.push_back(x);
435     }
436     //    void addFont(const FontType &x) { this->font.push_back(x); }
437
438     void addLivebox(const LiveBoxInfo &x)
439     {
440         this->livebox.push_back(x);
441     }
442
443     void setInstallLocation(const InstallLocationType &x)
444     {
445         this->installLocation = x;
446     }
447     void setPackage(const NcnameType &x)
448     {
449         this->package = x;
450     }
451     void setType(const PackageType &x)
452     {
453         this->type = x;
454     }
455     void setVersion(const NmtokenType &x)
456     {
457         this->version = x;
458     }
459
460   private:
461     std::list<LabelType> label;
462     std::list<IconType> icon;
463     std::list<AuthorType> author;
464     std::list<DescriptionType> description;
465     //    std::list<CompatibilityType> compatibility;
466     //    std::list<DeviceProfileType> deviceProfile;
467     std::list<ServiceApplicationType> serviceApplication;
468     std::list<UiApplicationType> uiApplication;
469     std::list<ImeApplicationType> imeApplication;
470     //    std::list<FontType> font;
471     std::list<LiveBoxInfo> livebox;
472     InstallLocationType installLocation;
473     NcnameType package;
474     PackageType type;
475     NmtokenType version;
476 };
477 } //namespace Jobs
478 } //namespace WidgetInstall
479
480 #endif //INSTALLER_JOBS_MANIFEST_H