Initialize Tizen 2.3
[framework/web/wrt-commons.git] / modules / utils / include / dpl / utils / 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_typedefs.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
36  * the following conditions:
37  *
38  *  - the Widget Id matches the Widget Id of an installed widget
39  *  - the Widget version number is greater (as a compared string) than that of
40  * the installed widget, or no version
41  *    information was provided for the installed widget
42  *
43  * To ensure that a string comparison of widget versions can reliably determine
44  * which version is an updated widget,
45  * WAC will mandate a specific version string format for WAC widgets. All
46  * widgets coming through the WAC channel
47  * will be required to have version strings in this format. Side-loaded widgets
48  * may have any format and, in this
49  * case, there is no requirement that the WRT support version detection for
50  * update of these widgets.
51  *
52  * The widget version format is the rec-version-tag grammar as described in
53  * [Widget Packaging]:
54  *
55  *  rec-version-tag = 1*DIGIT "." 1*DIGIT [ "." 1*DIGIT] *[ 1*ALPHA / SP /
56  * 1*DIGIT ]
57  *
58  * Examples of rec-version-tag:
59  *
60  *    1.0
61  *    1.10.1 beta1
62  *    1.02.12 RC1
63  *
64  * WL-3371 The WRT MUST use the following widget version comparison algorithm to
65  * compare WAC widget version strings:
66  *
67  *  - prepare the version strings for comparison:
68  *     - all leading zeros are discarded
69  *     - the optional *[ 1*ALPHA / SP / 1*DIGIT ] part, if present, is discarded
70  *     - the resulting numbers are then in the format major.minor[.micro]
71  *  - Version A = Amajor.Aminor[.Amicro] is equal to Version B =
72  * Bmajor.Bminor[.Bmicro] if and only if:
73  *     - Amajor Bmajor
74  *     - Aminor Bminor
75  *     - both Amicro and Bmicro are present and Amicro == Bmicro; or both Amicro
76  * and Bmicro are absent.
77  *  - Version A = Amajor.Aminor[.Amicro] is greater than Version B =
78  * Bmajor.Bminor[.Bmicro] if and only if:
79  *     - Amajor > Bmajor; or
80  *     - Amajor Bmajor && Aminor > Bminor; or
81  *     - Amajor Bmajor && Aminor == Bminor && both Amicro and Bmicro are present
82  * and Amicro > Bmicro; or Bmicro is absent.
83  */
84 class WidgetVersion
85 {
86   private:
87     bool m_isWac;
88     DPL::String m_raw;
89
90     DPL::String m_major;
91     DPL::String m_minor;
92     DPL::OptionalString m_micro;
93     DPL::OptionalString m_optional;
94
95     void WacCertify(const DPL::String &major,
96                     const DPL::String &minor,
97                     const DPL::OptionalString &micro,
98                     const DPL::OptionalString &optional);
99
100   public:
101     explicit WidgetVersion(const DPL::String &str = DPL::String());
102     WidgetVersion(const DPL::String &major,
103                   const DPL::String &minor,
104                   const DPL::OptionalString &micro,
105                   const DPL::OptionalString &optional);
106
107     bool IsWac() const;
108     const DPL::String &Raw() const;
109
110     const DPL::String &Major() const;
111     const DPL::String &Minor() const;
112     const DPL::OptionalString &Micro() const;
113     const DPL::OptionalString &Optional() const;
114 };
115
116 bool operator<(const WidgetVersion &left,
117                const WidgetVersion &right);
118 bool operator<=(const WidgetVersion &left,
119                 const WidgetVersion &right);
120 bool operator>(const WidgetVersion &left,
121                const WidgetVersion &right);
122 bool operator>=(const WidgetVersion &left,
123                 const WidgetVersion &right);
124 bool operator==(const WidgetVersion &left,
125                 const WidgetVersion &right);
126 bool operator!=(const WidgetVersion &left,
127                 const WidgetVersion &right);
128 std::ostream & operator<<(std::ostream& stream,
129                           const WidgetVersion& version);
130
131 #endif // WIDGET_VERSION_H