|
Urbi SDK Remote for C++
2.7.5
|
00001 /* 00002 * Copyright (C) 2010, 2011, Gostai S.A.S. 00003 * 00004 * This software is provided "as is" without warranty of any kind, 00005 * either expressed or implied, including but not limited to the 00006 * implied warranties of fitness for a particular purpose. 00007 * 00008 * See the LICENSE file for more information. 00009 */ 00010 00011 #ifndef URBI_VERSION_CHECK_HH 00012 # define URBI_VERSION_CHECK_HH 00013 00014 # include <libport/debug.hh> 00015 # include <urbi/revision.hh> 00016 00017 # ifndef URBI_INHIBIT_REVISION_CHECK 00018 # include <libport/package-info.hh> 00019 # include <urbi/package-info.hh> 00020 # endif 00021 00022 namespace urbi 00023 { 00028 inline int check_sdk_version(std::string where = "", 00029 std::string version_exp = URBI_SDK_VERSION, 00030 std::string revision_exp = URBI_SDK_REVISION) 00031 { 00032 LIBPORT_USE(where, version_exp, revision_exp); 00033 # ifndef URBI_INHIBIT_REVISION_CHECK 00034 GD_CATEGORY(Urbi.Version); 00035 const libport::PackageInfo& info = urbi::package_info(); 00036 if (!where.empty()) 00037 where += ": "; 00038 std::string revision_eff = info.get("revision"); 00039 GD_FINFO_TRACE("%sCompiled with Urbi SDK %s, loaded in Urbi SDK %s", 00040 where, revision_exp, revision_eff); 00041 if (revision_eff != revision_exp) 00042 { 00043 std::string expected = version_exp; 00044 std::string effective = info.get("version"); 00045 if (expected == effective) 00046 { 00047 expected += " " + revision_exp; 00048 effective += " " + revision_eff; 00049 } 00050 std::string msg(libport::format 00051 ("%sCompiled with Urbi SDK version %s," 00052 " but is loaded in version %s", 00053 where, expected, effective)); 00054 00055 const char* varname = "URBI_ACCEPT_BINARY_MISMATCH"; 00056 const bool fatal = !libport::getenv(varname); 00057 if (fatal) 00058 { 00059 GD_ERROR(msg); 00060 GD_FERROR("define %s to bypass this error", varname); 00061 throw std::runtime_error(msg); 00062 } 00063 else 00064 GD_WARN(msg); 00065 } 00066 #endif 00067 return 0; 00068 } 00069 00071 inline void 00072 check_sdk_version_once(const std::string& where = "", 00073 std::string version_exp = URBI_SDK_VERSION, 00074 std::string revision_exp = URBI_SDK_REVISION) 00075 { 00076 static int i = check_sdk_version(where, version_exp, revision_exp); 00077 LIBPORT_USE(i); 00078 } 00079 00080 class VersionChecker 00081 { 00082 public: 00083 VersionChecker(const std::string& where = "", 00084 std::string version_exp = URBI_SDK_VERSION, 00085 std::string revision_exp = URBI_SDK_REVISION) 00086 { 00087 GD_CATEGORY(Urbi); 00088 GD_SINFO_DUMP("VersionChecker instantiating..."); 00089 check_sdk_version(where, version_exp, revision_exp); 00090 } 00091 }; 00092 } 00093 00094 #define URBI_CHECK_SDK_VERSION(Where) \ 00095 ::urbi::check_sdk_version(Where, URBI_SDK_VERSION, URBI_SDK_REVISION) 00096 00098 #define URBI_CHECK_SDK_VERSION_BARE(Where) \ 00099 static ::urbi::VersionChecker LIBPORT_CAT(urbicheck, __LINE__) \ 00100 = ::urbi::VersionChecker(Where, URBI_SDK_VERSION, URBI_SDK_REVISION) 00101 00102 #endif