Ensure backward compatibility using either functions from .so/dll or environment variables MESHGEMS_VERSION_MAJOR/MINOR/PATCH defined in SAT

This commit is contained in:
Nabil Ghodbane 2023-05-05 12:31:20 +02:00
parent dc881f9d8c
commit 08f1a99b8b
2 changed files with 59 additions and 51 deletions

View File

@ -636,6 +636,44 @@ namespace SMESHUtils_MGLicenseKeyGen // API implementation
return key; return key;
} }
//================================================================================
/*!
* \brief Get MeshGems version major/minor/patch from the environment variables
* \param [out] error - return error description
* \return int - the version
*/
//================================================================================
int GetMGVersionFromEnv(const char* env_variable){
MESSAGE("Entering GetMGVersionFromEnv and calling " << env_variable);
int version = -1;
if (getenv(env_variable) == nullptr ){
MESSAGE("Could not find " << env_variable << " from environment");
}
else{
version = std::stoi(std::string(getenv(env_variable)));
}
return version;
}
//================================================================================
/*!
* \brief Get MeshGems version major/minor/patch from the keygen library and meshgems built-in functions
* \param [out] error - return error description
* \return int - the function implemented in the library
*/
//================================================================================
int GetMGVersionFromFct(const char* function_name){
MESSAGE("Entering GetMGVersionFromFct and calling " << function_name);
int version = -1;
typedef int (*GetKeyFun)();
GetKeyFun keyFun = (GetKeyFun) GetProc( theLibraryHandle, function_name);
if ( !keyFun ){
MESSAGE("Could not find " << function_name << " from library");
}
else{
version = keyFun( );
}
return version;
}
//================================================================================ //================================================================================
/*! /*!
@ -651,63 +689,32 @@ namespace SMESHUtils_MGLicenseKeyGen // API implementation
LibraryFile libraryFile; LibraryFile libraryFile;
if ( !loadLibrary( error, libraryFile )) if ( !loadLibrary( error, libraryFile ))
return v_min; return v_min;
MESSAGE("Extracting MeshGems version");
typedef int (*GetKeyFun)(); v_min = GetMGVersionFromFct("meshgems_core_get_version_minor");
GetKeyFun keyFun = (GetKeyFun) GetProc( theLibraryHandle, "GetVersionMinor" ); if (v_min == -1) v_min = GetMGVersionFromFct("GetVersionMinor");
if ( !keyFun ) if (v_min == -1) v_min = GetMGVersionFromEnv("MESHGEMS_VERSION_MINOR");
{ if (v_min == -1)
if ( ! getLastError( error )) error = "could not retrieve minor version (located in '" + libraryFile._name + "')";
error = SMESH_Comment( "Can't find symbol 'GetVersionMinor' in '") << getenv( theEnvVar ) << "'"; MESSAGE("MeshGems minor version = " << v_min);
}
else
{
v_min = keyFun( );
}
if ( v_min==-1 )
error = "GetVersionMinor() failed (located in '" + libraryFile._name + "')";
MESSAGE("GetVersionMinor: " << v_min);
// get major version // get major version
int v_maj = -1; int v_maj = GetMGVersionFromFct("meshgems_core_get_version_major");
if (v_maj == -1) v_maj = GetMGVersionFromFct("GetVersionMajor");
typedef int (*GetKeyFun)(); if (v_maj == -1) v_maj = GetMGVersionFromEnv("MESHGEMS_VERSION_MAJOR");
keyFun = (GetKeyFun) GetProc( theLibraryHandle, "GetVersionMajor" ); if (v_maj == -1)
if ( !keyFun ) error = "could not retrieve major version (located in '" + libraryFile._name + "')";
{ MESSAGE("MeshGems major version = " << v_maj);
if ( ! getLastError( error ))
error = SMESH_Comment( "Can't find symbol 'GetVersionMajor' in '") << getenv( theEnvVar ) << "'";
}
else
{
v_maj = keyFun( );
}
if ( v_maj==-1 )
error = "GetVersionMajor() failed (located in '" + libraryFile._name + "')";
MESSAGE("GetVersionMajor: " << v_maj);
// get patch version // get patch version
int v_patch = -1; int v_patch = GetMGVersionFromFct("meshgems_core_get_version_patch ");
if (v_patch == -1) v_patch = GetMGVersionFromFct("GetVersionPatch");
typedef int (*GetKeyFun)(); if (v_patch == -1) v_patch = GetMGVersionFromEnv("MESHGEMS_VERSION_PATCH");
keyFun = (GetKeyFun) GetProc( theLibraryHandle, "GetVersionPatch" ); if (v_patch == -1)
if ( !keyFun ) error = "could not retrieve patch version (located in '" + libraryFile._name + "')";
{ MESSAGE("MeshGems patch version = " << v_patch);
if ( ! getLastError( error ))
error = SMESH_Comment( "Can't find symbol 'GetVersionPatch' in '") << getenv( theEnvVar ) << "'";
}
else
{
v_patch = keyFun( );
}
if ( v_patch==-1 )
error = "GetVersionPatch() failed (located in '" + libraryFile._name + "')";
MESSAGE("GetVersionPatch: " << v_patch );
int v_hex = (v_maj << 16 | v_min << 8 | v_patch); int v_hex = (v_maj << 16 | v_min << 8 | v_patch);
MESSAGE("v_hex: " << v_hex); MESSAGE("v_hex: " << v_hex);
return v_hex; return v_hex;

View File

@ -58,7 +58,8 @@ namespace SMESHUtils_MGLicenseKeyGen
SMESHUtils_EXPORT bool CheckKeyGenLibrary( std::string& error ); SMESHUtils_EXPORT bool CheckKeyGenLibrary( std::string& error );
SMESHUtils_EXPORT std::string GetLibraryName(); SMESHUtils_EXPORT std::string GetLibraryName();
SMESHUtils_EXPORT int GetMGVersionFromFct(const char* function_name);
SMESHUtils_EXPORT int GetMGVersionFromEnv(const char* env_variable);
SMESHUtils_EXPORT int GetMGVersionHex(std::string& error); SMESHUtils_EXPORT int GetMGVersionHex(std::string& error);
SMESHUtils_EXPORT bool NeedsMGSpatialEnvLicense(std::string& error); SMESHUtils_EXPORT bool NeedsMGSpatialEnvLicense(std::string& error);
SMESHUtils_EXPORT bool SetMGSpatialEnvLicense(std::string& error); SMESHUtils_EXPORT bool SetMGSpatialEnvLicense(std::string& error);