upload tizen1.0 source
[framework/web/wrt-commons.git] / modules / utils / include / widget_version.h
1 /*
2  * Copyright (c) 2011 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    widget_version.h
18  * @author  Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19  * @version 1.0
20  * @brief   Header file for widget version
21  */
22 #ifndef WIDGET_VERSION_H
23 #define WIDGET_VERSION_H
24
25 #include <dpl/string.h>
26 #include <dpl/optional.h>
27 #include <ostream>
28
29 /*
30  * Note: This class also support non-WAC compliant version numbers
31  *
32  * WAC Waikiki Beta Release Core Specification: Widget Runtime
33  * 10 Dec 2010
34  *
35  * WL-3370 The WRT MUST process widget packages as an update when received under the following conditions:
36  *
37  *  - the Widget Id matches the Widget Id of an installed widget
38  *  - the Widget version number is greater (as a compared string) than that of the installed widget, or no version
39  *    information was provided for the installed widget
40  *
41  * To ensure that a string comparison of widget versions can reliably determine which version is an updated widget,
42  * WAC will mandate a specific version string format for WAC widgets. All widgets coming through the WAC channel
43  * will be required to have version strings in this format. Side-loaded widgets may have any format and, in this
44  * case, there is no requirement that the WRT support version detection for update of these widgets.
45  *
46  * The widget version format is the rec-version-tag grammar as described in [Widget Packaging]:
47  *
48  *  rec-version-tag = 1*DIGIT "." 1*DIGIT [ "." 1*DIGIT] *[ 1*ALPHA / SP / 1*DIGIT ]
49  *
50  * Examples of rec-version-tag:
51  *
52  *    1.0
53  *    1.10.1 beta1
54  *    1.02.12 RC1
55  *
56  * WL-3371 The WRT MUST use the following widget version comparison algorithm to compare WAC widget version strings:
57  *
58  *  - prepare the version strings for comparison:
59  *     - all leading zeros are discarded
60  *     - the optional *[ 1*ALPHA / SP / 1*DIGIT ] part, if present, is discarded
61  *     - the resulting numbers are then in the format major.minor[.micro]
62  *  - Version A = Amajor.Aminor[.Amicro] is equal to Version B = Bmajor.Bminor[.Bmicro] if and only if:
63  *     - Amajor Bmajor
64  *     - Aminor Bminor
65  *     - both Amicro and Bmicro are present and Amicro == Bmicro; or both Amicro and Bmicro are absent.
66  *  - Version A = Amajor.Aminor[.Amicro] is greater than Version B = Bmajor.Bminor[.Bmicro] if and only if:
67  *     - Amajor > Bmajor; or
68  *     - Amajor Bmajor && Aminor > Bminor; or
69  *     - Amajor Bmajor && Aminor == Bminor && both Amicro and Bmicro are present and Amicro > Bmicro; or Bmicro is absent.
70  */
71 class WidgetVersion
72 {
73   private:
74     bool m_isWac;
75     DPL::String m_raw;
76
77     DPL::String m_major;
78     DPL::String m_minor;
79     DPL::Optional<DPL::String> m_micro;
80     DPL::Optional<DPL::String> m_optional;
81
82     void WacCertify(const DPL::String &major,
83             const DPL::String &minor,
84             const DPL::Optional<DPL::String> &micro,
85             const DPL::Optional<DPL::String> &optional);
86
87   public:
88     explicit WidgetVersion(const DPL::String &str = DPL::String());
89     WidgetVersion(const DPL::String &major,
90             const DPL::String &minor,
91             const DPL::Optional<DPL::String> &micro,
92             const DPL::Optional<DPL::String> &optional);
93
94     bool IsWac() const;
95     const DPL::String &Raw() const;
96
97     const DPL::String &Major() const;
98     const DPL::String &Minor() const;
99     const DPL::Optional<DPL::String> &Micro() const;
100     const DPL::Optional<DPL::String> &Optional() const;
101 };
102
103 bool operator<(const WidgetVersion &left,
104         const WidgetVersion &right);
105 bool operator<=(const WidgetVersion &left,
106         const WidgetVersion &right);
107 bool operator>(const WidgetVersion &left,
108         const WidgetVersion &right);
109 bool operator>=(const WidgetVersion &left,
110         const WidgetVersion &right);
111 bool operator==(const WidgetVersion &left,
112         const WidgetVersion &right);
113 bool operator!=(const WidgetVersion &left,
114         const WidgetVersion &right);
115 std::ostream & operator<<(std::ostream& stream,
116         const WidgetVersion& version);
117
118 #endif // WIDGET_VERSION_H