Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / nsframework / framework_unified / client / NS_UtilityCenter / src / frameworkunified_version.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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 //////////////////////////////////////////////////////////////////////////////////////////////////
18 /// \ingroup  tag_NativeServices
19 /// \brief    Implementation of CFrameworkunifiedVersion class
20 ///
21 ///
22 //////////////////////////////////////////////////////////////////////////////////////////////////
23
24 #include <native_service/ns_version_if.h>
25 #include <stdio.h>
26 #include <unistd.h>
27 #include <time.h>
28 #include <string>
29
30
31 // defaults - top level makefile for entire system will provide an override
32 #ifndef FRAMEWORKUNIFIED_SIGNATURE
33 #define FRAMEWORKUNIFIED_SIGNATURE   0xE0344333
34 #endif
35
36 #ifndef FRAMEWORKUNIFIED_STRUC_VER
37 #define FRAMEWORKUNIFIED_STRUC_VER   0x02
38 #endif
39
40 #ifndef FRAMEWORKUNIFIED_PRODUCT_VER
41 #define FRAMEWORKUNIFIED_PRODUCT_VER   0x01
42 #endif
43
44 #ifndef PRODUCT_LABEL
45 #define PRODUCT_LABEL  "undefined"
46 #endif
47
48 #ifndef FRAMEWORKUNIFIED_BUILD_VER
49 #define FRAMEWORKUNIFIED_BUILD_VER  "undefined"
50 #endif
51
52 /* For future use */
53 #define YEAR ((((__DATE__[7] - '0') * 10 + (__DATE__[8] - '0')) * 10 \
54 + (__DATE__[9] - '0')) * 10 + (__DATE__[10] - '0'))
55
56 #define MONTH (__DATE__[2] == 'n' ? 0 \
57 : __DATE__[2] == 'b' ? 1 \
58 : __DATE__[2] == 'r' ? (__DATE__[0] == 'M' ? 2 : 3) \
59 : __DATE__[2] == 'y' ? 4 \
60 : __DATE__[2] == 'n' ? 5 \
61 : __DATE__[2] == 'l' ? 6 \
62 : __DATE__[2] == 'g' ? 7 \
63 : __DATE__[2] == 'p' ? 8 \
64 : __DATE__[2] == 't' ? 9 \
65 : __DATE__[2] == 'v' ? 10 : 11)
66
67 #define DAY ((__DATE__[4] == ' ' ? 0 : __DATE__[4] - '0') * 10 \
68 + (__DATE__[5] - '0'))
69
70 #define DATE_AS_INT (((YEAR - 2000) * 12 + MONTH) * 31 + DAY)
71
72 #define HOUR (((__TIME__[0] - '0') * 10 + (__TIME__[1] - '0')))
73
74 #define MIN (((__TIME__[3] - '0') * 10 + (__TIME__[4] - '0')))
75
76
77 ////////////////////////////////////////////////////////////////////////////////////////////
78 /// Function: Default Constructor
79 ////////////////////////////////////////////////////////////////////////////////////////////
80 CFrameworkunifiedVersion::CFrameworkunifiedVersion():
81   m_tVersionInfo(const_cast<PSTR>(PRODUCT_LABEL),
82                  FRAMEWORKUNIFIED_SIGNATURE,
83                  FRAMEWORKUNIFIED_STRUC_VER,
84                  FRAMEWORKUNIFIED_PRODUCT_VER,
85                  DATE_AS_INT,
86                  0,
87                  0,
88                  const_cast<PSTR>(FRAMEWORKUNIFIED_BUILD_VER),
89                  0),
90   m_u32Month(MONTH + 1),
91   m_u32Year(YEAR),
92   m_u32Day(DAY) {
93 }
94
95 ////////////////////////////////////////////////////////////////////////////////////////////
96 /// Function: Parametrized constructor
97 ////////////////////////////////////////////////////////////////////////////////////////////
98 CFrameworkunifiedVersion::CFrameworkunifiedVersion(UI_16 major, UI_16 minor, UI_16 revision) :
99   m_tVersionInfo(const_cast<PSTR>(PRODUCT_LABEL),
100                  FRAMEWORKUNIFIED_SIGNATURE,
101                  FRAMEWORKUNIFIED_STRUC_VER,
102                  FRAMEWORKUNIFIED_PRODUCT_VER,
103                  DATE_AS_INT,
104                  major,
105                  minor,
106                  const_cast<PSTR>(FRAMEWORKUNIFIED_BUILD_VER),
107                  revision),
108   m_u32Month(MONTH + 1),
109   m_u32Year(YEAR),
110   m_u32Day(DAY) {
111 }
112
113 ////////////////////////////////////////////////////////////////////////////////////////////
114 /// Function: Destructor
115 ////////////////////////////////////////////////////////////////////////////////////////////
116 CFrameworkunifiedVersion::~CFrameworkunifiedVersion() {
117 }
118
119 ////////////////////////////////////////////////////////////////////////////////////////////
120 /// Function: Compares two version instances
121 ////////////////////////////////////////////////////////////////////////////////////////////
122 BOOL operator == (CFrameworkunifiedVersion &a, CFrameworkunifiedVersion &b) {  // NOLINT (readability/nolint)
123   return a.operator == (b);
124 }
125
126 ////////////////////////////////////////////////////////////////////////////////////////////
127 /// Function: Compares two version instances
128 ////////////////////////////////////////////////////////////////////////////////////////////
129 BOOL CFrameworkunifiedVersion::operator == (const CFrameworkunifiedVersion &f_test_i) {
130   if (!strcmp(m_tVersionInfo.p_str_product, f_test_i.m_tVersionInfo.p_str_product)     &&
131       !strcmp(m_tVersionInfo.p_str_build, f_test_i.m_tVersionInfo.p_str_build)       &&
132       (m_tVersionInfo.u16_major == f_test_i.m_tVersionInfo.u16_major)         &&
133       (m_tVersionInfo.u16_minor == f_test_i.m_tVersionInfo.u16_minor)         &&
134       (m_tVersionInfo.u16_revision == f_test_i.m_tVersionInfo.u16_revision)       &&
135       (m_tVersionInfo.u32_date == f_test_i.m_tVersionInfo.u32_date)           &&
136       (m_tVersionInfo.u32_product_version == f_test_i.m_tVersionInfo.u32_product_version) &&
137       (m_tVersionInfo.u32_signature == f_test_i.m_tVersionInfo.u32_signature)     &&
138       (m_tVersionInfo.u32_struc_version == f_test_i.m_tVersionInfo.u32_struc_version)) {
139     return TRUE;
140   }
141
142   return FALSE;
143 }
144
145 ////////////////////////////////////////////////////////////////////////////////////////////
146 /// Function: Returns the version string
147 ////////////////////////////////////////////////////////////////////////////////////////////
148 PCSTR CFrameworkunifiedVersion::VersionStr() {
149   static char version[30] = {};
150
151   snprintf(version, sizeof(version) - 1, "%s_%s_%02d.%02d.%02d",
152            m_tVersionInfo.p_str_product,
153            m_tVersionInfo.p_str_build,
154            m_tVersionInfo.u16_major,
155            m_tVersionInfo.u16_minor,
156            m_tVersionInfo.u16_revision);
157
158   return version;
159 }
160
161 ////////////////////////////////////////////////////////////////////////////////////////////
162 /// Function: Returns the date when the new version of the app was created
163 ////////////////////////////////////////////////////////////////////////////////////////////
164 PCSTR CFrameworkunifiedVersion::DateStr() {
165   static char date[30] = {};
166
167   snprintf(date, sizeof(date) - 1, "%d-%02d-%02d",
168            m_u32Year,
169            m_u32Month,
170            m_u32Day);
171
172   return date;
173 }
174
175 ////////////////////////////////////////////////////////////////////////////////////////////
176 /// Function: Returns the Signature
177 ////////////////////////////////////////////////////////////////////////////////////////////
178 UI_32 CFrameworkunifiedVersion::Signature() const {
179   return m_tVersionInfo.u32_signature;
180 }
181
182 ////////////////////////////////////////////////////////////////////////////////////////////
183 /// Function: Returns a new structure version
184 ////////////////////////////////////////////////////////////////////////////////////////////
185 UI_32 CFrameworkunifiedVersion::StrucVersion() const {
186   return m_tVersionInfo.u32_struc_version;
187 }
188
189 ////////////////////////////////////////////////////////////////////////////////////////////
190 /// Function: Returns the product version
191 ////////////////////////////////////////////////////////////////////////////////////////////
192 UI_32 CFrameworkunifiedVersion::ProductVersion() const {
193   return m_tVersionInfo.u32_product_version;
194 }
195
196 ////////////////////////////////////////////////////////////////////////////////////////////
197 /// Function: Returns the date
198 ////////////////////////////////////////////////////////////////////////////////////////////
199 UI_32 CFrameworkunifiedVersion::Date() const {
200   return m_tVersionInfo.u32_date;
201 }
202
203 ////////////////////////////////////////////////////////////////////////////////////////////
204 /// Function: Returns the major number
205 ////////////////////////////////////////////////////////////////////////////////////////////
206 UI_16 CFrameworkunifiedVersion::Major() const {
207   return m_tVersionInfo.u16_major;
208 }
209
210 ////////////////////////////////////////////////////////////////////////////////////////////
211 /// Function: Returns the minor number
212 ////////////////////////////////////////////////////////////////////////////////////////////
213 UI_16 CFrameworkunifiedVersion::Minor() const {
214   return m_tVersionInfo.u16_minor;
215 }
216
217 ////////////////////////////////////////////////////////////////////////////////////////////
218 /// Function: Returns the unique product identifier
219 ////////////////////////////////////////////////////////////////////////////////////////////
220 PCSTR CFrameworkunifiedVersion::Product() const {
221   return m_tVersionInfo.p_str_product;
222 }
223
224 ////////////////////////////////////////////////////////////////////////////////////////////
225 /// Function: Returns the unique build identifier number
226 ////////////////////////////////////////////////////////////////////////////////////////////
227 PCSTR CFrameworkunifiedVersion::Build() const {
228   return m_tVersionInfo.p_str_build;
229 }
230
231 ////////////////////////////////////////////////////////////////////////////////////////////
232 /// Function: Returns the revision number
233 ////////////////////////////////////////////////////////////////////////////////////////////
234 UI_16 CFrameworkunifiedVersion::Revision() const {
235   return m_tVersionInfo.u16_revision;
236 }