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.
18 * @file ns_buildversioncheck.hpp
19 * @brief \~english Provide the APIs to check/get version
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_
25 #include <native_service/frameworkunified_types.h>
27 /** @addtogroup BaseSystem
30 /** @addtogroup native_service
34 /** @addtogroup framework_unified
35 * @ingroup native_service
40 * \~english the namespace frameworkunified
42 namespace frameworkunified {
44 * \~english the namespace ns
48 * \~english the namespace utility
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
60 /// \~english @par Prerequisite
62 /// \~english @par Change of internal state
64 /// \~english @par Conditions of processing failure
66 /// \~english @par Classification
68 /// \~english @par Type
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)
78 ////////////////////////////////////////////////////////////////////////////////////////////////
79 /// \ingroup NS_BuildVersionCheck
80 /// \~english @par Brief
81 /// Get the build version from environment variable.
82 /// \~english @retval the build version string
84 /// \~english @par Prerequisite
86 /// \~english @par Change of internal state
88 /// \~english @par Conditions of processing failure
90 /// \~english @par Classification
92 /// \~english @par Type
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 "".
98 ////////////////////////////////////////////////////////////////////////////////////////////////
99 PCSTR getEnvironmentBuildVersion(); // NOLINT (readability/nolint)
101 ////////////////////////////////////////////////////////////////////////////////////////////////
102 /// \ingroup NS_BuildVersionCheck
103 /// \~english @par Brief
104 /// Get the library build version string
105 /// \~english @retval the library buidling version string
107 /// \~english @par Prerequisite
109 /// \~english @par Change of internal state
111 /// \~english @par Conditions of processing failure
113 /// \~english @par Classification
115 /// \~english @par Type
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)
124 * \~english the namespace utility_private
126 namespace utility_private {
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>"
136 /// \~english @par Prerequisite
138 /// \~english @par Change of internal state
140 /// \~english @par Conditions of processing failure
142 /// \~english @par Classification
144 /// \~english @par Type
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>".
150 ////////////////////////////////////////////////////////////////////////////////////////////////
151 PCSTR niceBuildVersion(PCSTR build_version); // NOLINT (readability/nolint)
154 * \~english the end of namespace utility_private
158 * \~english the end of namespace utility
162 * \~english the end of namespace ns
166 * \~english the end of namespace frameworkunified
171 * \~english define the macro _BUILD_VERSION
173 #ifndef BUILD_VERSION
174 #define _BUILD_VERSION ""
176 #define QUOTE( ___str___ ) #___str___
177 #define EXPAND_AND_QUOTE( ___str___ ) QUOTE( ___str___ )
178 #define _BUILD_VERSION EXPAND_AND_QUOTE( BUILD_VERSION )
182 * \~english define the macro WARNING_STRING to print the warning
184 #define WARNING_STRING "\n\
185 !!! WARNING - Build Versions do not match !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\
188 environment build: %s\n\
189 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
192 * \~english define the macro _BUILD_VERSION
194 #if defined STDOUT_LOGGING
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)
202 #include <native_service/ns_logger_if.h>
203 #define BUILDVERSIONLOG( ___log_string___, ...) TEXT( __PRETTY_FUNCTION__, ___log_string___, __VA_ARGS__)
205 * \~english define the macro BUILDVERSION_NULL_STATEMENT
207 #define BUILDVERSION_NULL_STATEMENT ((void)0)
211 * \~english define the macro CHECK_BUILD_VERSION to check the version
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
221 /** @}*/ // end of framework_unified
223 /** @}*/ // end of native_service
225 /** @}*/ // end of BaseSystem
227 #endif // FRAMEWORK_UNIFIED_CLIENT_NS_UTILITY_BUILDVERSIONCHECK_LIBRARY_INCLUDE_NATIVE_SERVICE_NS_BUILDVERSIONCHECK_HPP_ // NOLINT (build/header_guard)