2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 //////////////////////////////////////////////////////////////////////////////////////////////////
18 /// \ingroup tag_NativeServices
19 /// \brief Implementation of CFrameworkunifiedVersion class
22 //////////////////////////////////////////////////////////////////////////////////////////////////
24 #include <native_service/ns_version_if.h>
31 // defaults - top level makefile for entire system will provide an override
32 #ifndef FRAMEWORKUNIFIED_SIGNATURE
33 #define FRAMEWORKUNIFIED_SIGNATURE 0xE0344333
36 #ifndef FRAMEWORKUNIFIED_STRUC_VER
37 #define FRAMEWORKUNIFIED_STRUC_VER 0x02
40 #ifndef FRAMEWORKUNIFIED_PRODUCT_VER
41 #define FRAMEWORKUNIFIED_PRODUCT_VER 0x01
45 #define PRODUCT_LABEL "undefined"
48 #ifndef FRAMEWORKUNIFIED_BUILD_VER
49 #define FRAMEWORKUNIFIED_BUILD_VER "undefined"
53 #define YEAR ((((__DATE__[7] - '0') * 10 + (__DATE__[8] - '0')) * 10 \
54 + (__DATE__[9] - '0')) * 10 + (__DATE__[10] - '0'))
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)
67 #define DAY ((__DATE__[4] == ' ' ? 0 : __DATE__[4] - '0') * 10 \
68 + (__DATE__[5] - '0'))
70 #define DATE_AS_INT (((YEAR - 2000) * 12 + MONTH) * 31 + DAY)
72 #define HOUR (((__TIME__[0] - '0') * 10 + (__TIME__[1] - '0')))
74 #define MIN (((__TIME__[3] - '0') * 10 + (__TIME__[4] - '0')))
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,
88 const_cast<PSTR>(FRAMEWORKUNIFIED_BUILD_VER),
90 m_u32Month(MONTH + 1),
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,
106 const_cast<PSTR>(FRAMEWORKUNIFIED_BUILD_VER),
108 m_u32Month(MONTH + 1),
113 ////////////////////////////////////////////////////////////////////////////////////////////
114 /// Function: Destructor
115 ////////////////////////////////////////////////////////////////////////////////////////////
116 CFrameworkunifiedVersion::~CFrameworkunifiedVersion() {
119 ////////////////////////////////////////////////////////////////////////////////////////////
120 /// Function: Compares two version instances
121 ////////////////////////////////////////////////////////////////////////////////////////////
122 BOOL operator == (CFrameworkunifiedVersion &a, CFrameworkunifiedVersion &b) { // NOLINT (readability/nolint)
123 return a.operator == (b);
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)) {
145 ////////////////////////////////////////////////////////////////////////////////////////////
146 /// Function: Returns the version string
147 ////////////////////////////////////////////////////////////////////////////////////////////
148 PCSTR CFrameworkunifiedVersion::VersionStr() {
149 static char version[30] = {};
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);
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] = {};
167 snprintf(date, sizeof(date) - 1, "%d-%02d-%02d",
175 ////////////////////////////////////////////////////////////////////////////////////////////
176 /// Function: Returns the Signature
177 ////////////////////////////////////////////////////////////////////////////////////////////
178 UI_32 CFrameworkunifiedVersion::Signature() const {
179 return m_tVersionInfo.u32_signature;
182 ////////////////////////////////////////////////////////////////////////////////////////////
183 /// Function: Returns a new structure version
184 ////////////////////////////////////////////////////////////////////////////////////////////
185 UI_32 CFrameworkunifiedVersion::StrucVersion() const {
186 return m_tVersionInfo.u32_struc_version;
189 ////////////////////////////////////////////////////////////////////////////////////////////
190 /// Function: Returns the product version
191 ////////////////////////////////////////////////////////////////////////////////////////////
192 UI_32 CFrameworkunifiedVersion::ProductVersion() const {
193 return m_tVersionInfo.u32_product_version;
196 ////////////////////////////////////////////////////////////////////////////////////////////
197 /// Function: Returns the date
198 ////////////////////////////////////////////////////////////////////////////////////////////
199 UI_32 CFrameworkunifiedVersion::Date() const {
200 return m_tVersionInfo.u32_date;
203 ////////////////////////////////////////////////////////////////////////////////////////////
204 /// Function: Returns the major number
205 ////////////////////////////////////////////////////////////////////////////////////////////
206 UI_16 CFrameworkunifiedVersion::Major() const {
207 return m_tVersionInfo.u16_major;
210 ////////////////////////////////////////////////////////////////////////////////////////////
211 /// Function: Returns the minor number
212 ////////////////////////////////////////////////////////////////////////////////////////////
213 UI_16 CFrameworkunifiedVersion::Minor() const {
214 return m_tVersionInfo.u16_minor;
217 ////////////////////////////////////////////////////////////////////////////////////////////
218 /// Function: Returns the unique product identifier
219 ////////////////////////////////////////////////////////////////////////////////////////////
220 PCSTR CFrameworkunifiedVersion::Product() const {
221 return m_tVersionInfo.p_str_product;
224 ////////////////////////////////////////////////////////////////////////////////////////////
225 /// Function: Returns the unique build identifier number
226 ////////////////////////////////////////////////////////////////////////////////////////////
227 PCSTR CFrameworkunifiedVersion::Build() const {
228 return m_tVersionInfo.p_str_build;
231 ////////////////////////////////////////////////////////////////////////////////////////////
232 /// Function: Returns the revision number
233 ////////////////////////////////////////////////////////////////////////////////////////////
234 UI_16 CFrameworkunifiedVersion::Revision() const {
235 return m_tVersionInfo.u16_revision;