Re-organized sub-directory by category
[staging/basesystem.git] / service / native / framework_unified / client / include / native_service / ns_buildversioncheck.hpp
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  * @file ns_buildversioncheck.hpp
19  * @brief \~english Provide the APIs to check/get version
20  */
21
22 #ifndef FRAMEWORK_UNIFIED_CLIENT_NS_UTILITY_BUILDVERSIONCHECK_LIBRARY_INCLUDE_NATIVE_SERVICE_NS_BUILDVERSIONCHECK_HPP_  // NOLINT  (build/header_guard)
23 #define FRAMEWORK_UNIFIED_CLIENT_NS_UTILITY_BUILDVERSIONCHECK_LIBRARY_INCLUDE_NATIVE_SERVICE_NS_BUILDVERSIONCHECK_HPP_
24
25 #include <native_service/frameworkunified_types.h>
26
27 /** @addtogroup BaseSystem
28  *  @{
29  */
30 /** @addtogroup native_service
31  *  @ingroup BaseSystem
32  *  @{
33  */
34 /** @addtogroup framework_unified
35  *  @ingroup native_service
36  *  @{
37  */
38
39 /**
40  * \~english the namespace frameworkunified
41  */
42 namespace frameworkunified {
43 /**
44  * \~english the namespace ns
45  */
46 namespace ns {
47 /**
48  * \~english the namespace utility
49  */
50 namespace utility {
51
52 ////////////////////////////////////////////////////////////////////////////////////////////////
53 /// \ingroup NS_BuildVersionCheck
54 /// \~english @par Brief
55 ///       Check whether the input param build_version is matched or not.
56 /// \~english @param [in] build_version
57 ///       PCSTR - The version to be checked
58 /// \~english @retval TRUE: match; FALSE: does not match
59 ///
60 /// \~english @par Prerequisite
61 ///       - NULL
62 /// \~english @par Change of internal state
63 ///       - NULL
64 /// \~english @par Conditions of processing failure
65 ///       - NULL
66 /// \~english @par Classification
67 ///       Public
68 /// \~english @par Type
69 ///       Sync Only
70 /// \~english @par Detail
71 ///       If the input param version string build_version is empty, the function returns FALSE.      \n
72 ///       If the input param version string build_version is equal to the environment build version \n
73 ///       and library build version, the function returns TRUE.
74 /// \~english @see getEnvironmentBuildVersion getLibraryBuildVersion
75 ////////////////////////////////////////////////////////////////////////////////////////////////
76 BOOL buildVersionsMatch(PCSTR build_version);  // NOLINT (readability/nolint)
77
78 ////////////////////////////////////////////////////////////////////////////////////////////////
79 /// \ingroup NS_BuildVersionCheck
80 /// \~english @par Brief
81 ///       Get the build version from environment variable.
82 /// \~english @retval the build version string
83 ///
84 /// \~english @par Prerequisite
85 ///       - NULL
86 /// \~english @par Change of internal state
87 ///       - NULL
88 /// \~english @par Conditions of processing failure
89 ///       - NULL
90 /// \~english @par Classification
91 ///       Public
92 /// \~english @par Type
93 ///       Sync Only
94 /// \~english @par Detail
95 ///       The funcion returns the value of the system environment variable "BUILD_VERSION". If \n
96 ///       the environment variable does not exist, the function returns "".
97 /// \~english @see
98 ////////////////////////////////////////////////////////////////////////////////////////////////
99 PCSTR getEnvironmentBuildVersion();  // NOLINT (readability/nolint)
100
101 ////////////////////////////////////////////////////////////////////////////////////////////////
102 /// \ingroup NS_BuildVersionCheck
103 /// \~english @par Brief
104 ///       Get the library build version string
105 /// \~english @retval the library buidling version string
106 ///
107 /// \~english @par Prerequisite
108 ///       - NULL
109 /// \~english @par Change of internal state
110 ///       - NULL
111 /// \~english @par Conditions of processing failure
112 ///       - NULL
113 /// \~english @par Classification
114 ///       Public
115 /// \~english @par Type
116 ///       Sync Only
117 /// \~english @par Detail
118 ///       The function returns the string as macro _BUILD_VERSION.
119 /// \~english @see _BUILD_VERSION
120 ////////////////////////////////////////////////////////////////////////////////////////////////
121 PCSTR getLibraryBuildVersion();  // NOLINT (readability/nolint)
122
123 /**
124  * \~english the namespace utility_private
125  */
126 namespace utility_private {
127
128 ////////////////////////////////////////////////////////////////////////////////////////////////
129 /// \ingroup NS_BuildVersionCheck
130 /// \~english @par Brief
131 ///       Check whether the input param is empty or not.
132 /// \~english @param [in] build_version
133 ///       PCSTR - the build version
134 /// \~english @retval the input param build_version or "<Not defined>"
135 ///
136 /// \~english @par Prerequisite
137 ///       - NULL
138 /// \~english @par Change of internal state
139 ///       - NULL
140 /// \~english @par Conditions of processing failure
141 ///       - NULL
142 /// \~english @par Classification
143 ///       Public
144 /// \~english @par Type
145 ///       Sync Only
146 /// \~english @par Detail
147 ///       If the input param build_version is not empty, the function returns build_version, \n
148 ///       or the function returns "<Not defined>".
149 /// \~english @see
150 ////////////////////////////////////////////////////////////////////////////////////////////////
151 PCSTR niceBuildVersion(PCSTR build_version);  // NOLINT (readability/nolint)
152
153 /**
154  * \~english the end of namespace utility_private
155  */
156 }
157 /**
158  * \~english the end of namespace utility
159  */
160 }
161 /**
162  * \~english the end of namespace ns
163  */
164 }
165 /**
166  * \~english the end of namespace frameworkunified
167  */
168 }
169
170 /**
171  * \~english define the macro _BUILD_VERSION
172  */
173 #ifndef BUILD_VERSION
174 #define _BUILD_VERSION ""
175 #else
176 #define QUOTE( ___str___ ) #___str___
177 #define EXPAND_AND_QUOTE( ___str___ ) QUOTE( ___str___ )
178 #define _BUILD_VERSION EXPAND_AND_QUOTE( BUILD_VERSION )
179 #endif
180
181 /**
182  * \~english define the macro WARNING_STRING to print the warning
183  */
184 #define WARNING_STRING "\n\
185 !!! WARNING - Build Versions do not match !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\
186 project build:     %s\n\
187 library build:     %s\n\
188 environment build: %s\n\
189 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
190
191 /**
192  * \~english define the macro _BUILD_VERSION
193  */
194 #if defined STDOUT_LOGGING
195 #include <cstdio>
196 #define BUILDVERSIONLOG( ___log_string___, ...) std::printf( ___log_string___ "\n", __VA_ARGS__)
197 #define BUILDVERSION_NULL_STATEMENT (0)
198 #elif defined NO_LOGGING
199 #define BUILDVERSIONLOG(...) ((void)0)
200 #define BUILDVERSION_NULL_STATEMENT ((void)0)
201 #else
202 #include <native_service/ns_logger_if.h>
203 #define BUILDVERSIONLOG( ___log_string___, ...) TEXT( __PRETTY_FUNCTION__, ___log_string___, __VA_ARGS__)
204 /**
205  * \~english define the macro BUILDVERSION_NULL_STATEMENT
206  */
207 #define BUILDVERSION_NULL_STATEMENT ((void)0)
208 #endif
209
210 /**
211  * \~english define the macro CHECK_BUILD_VERSION to check the version
212  */
213 #define CHECK_BUILD_VERSION() \
214     (!framework_unified::ns::utility::buildVersionsMatch( _BUILD_VERSION )) ? \
215             BUILDVERSIONLOG( WARNING_STRING, \
216                              framework_unified::ns::utility::utility_private::niceBuildVersion( _BUILD_VERSION ), \
217                              framework_unified::ns::utility::utility_private::niceBuildVersion( framework_unified::ns::utility::getLibraryBuildVersion() ), \
218                              framework_unified::ns::utility::utility_private::niceBuildVersion( framework_unified::ns::utility::getEnvironmentBuildVersion() ) ) :\
219             BUILDVERSION_NULL_STATEMENT
220
221 /** @}*/  // end of framework_unified
222
223 /** @}*/  // end of native_service
224
225 /** @}*/  // end of BaseSystem
226
227 #endif  // FRAMEWORK_UNIFIED_CLIENT_NS_UTILITY_BUILDVERSIONCHECK_LIBRARY_INCLUDE_NATIVE_SERVICE_NS_BUILDVERSIONCHECK_HPP_  // NOLINT  (build/header_guard)