Salome HOME
Improve new MG license mechanism to be binary compatible 2.14/2.15 cbr/new_mg_license_215_v2
authorChristophe Bourcier <christophe.bourcier@cea.fr>
Wed, 19 Apr 2023 12:30:38 +0000 (14:30 +0200)
committerChristophe Bourcier <christophe.bourcier@cea.fr>
Thu, 20 Apr 2023 14:35:50 +0000 (16:35 +0200)
src/SMESHUtils/SMESH_MGLicenseKeyGen.cxx
src/SMESHUtils/SMESH_MGLicenseKeyGen.hxx

index 4d2a83cbb511de990c08e348d1fc62fa0e30ffba..412fb0b5d9dbf0dafddb85db66891b83a1926eab 100644 (file)
@@ -430,12 +430,75 @@ namespace SMESHUtils_MGLicenseKeyGen // API implementation
     }
     return ok;
   }
+
+  //================================================================================
+  /*!
+   * \brief Unlock a specific MeshGems product (for products called as a library)
+   *  \param [in] product - product of MeshGems to unlock
+   *  \param [out] error - return error description
+   *  \return bool - is a success
+   */
+  //================================================================================
+  bool UnlockProduct( const std::string& product, std::string& error )
+  {
+    MESSAGE("SMESH UnlockProduct: " << product);
+    LibraryFile libraryFile;
+    if ( !loadLibrary( error, libraryFile ))
+      return false;
+
+    bool ok = false;
+    // get the key from KeyGen
+    std::string key = SMESHUtils_MGLicenseKeyGen::GetKey(error);
+    typedef int (*SignFun)(const char* );
+
+    // specific function to unlock each product
+    std::string function = "meshgems_" + product + "_unlock_product";
+
+    SignFun signFun = (SignFun) GetProc( theLibraryHandle, function.c_str() );
+    if ( !signFun )
+    {
+      if ( ! getLastError( error ))
+        error = SMESH_Comment( "Can't find symbol '") << function << "' in '" << getenv( theEnvVar ) << "'";
+    }
+    else
+    {
+      SMESH_TRY;
+
+      int status = signFun( key.c_str() );
+      // MeshGems status: 0: OK, 1: warning, -1: error
+      ok = status >= 0;
+
+      SMESH_CATCH( SMESH::returnError );
+
+      if ( !error.empty() )
+       {
+         ok = false;
+       }
+      else if ( !ok )
+        error = "UnlockProduct() failed (located in '" + libraryFile._name + "')";
+    }
+    return ok;
+  }
   
+  //================================================================================
+  /*!
+   * \brief Sign a CAD (or don't do it if env MESHGEMS_OLD_STYLE is set)
+   *  \param [in] meshgems_cad - pointer to a MG CAD object (meshgems_cad_t)
+   *  \param [out] error - return error description
+   *  \return bool - is a success
+   */
+  //================================================================================
   bool SignCAD( void* meshgems_cad, std::string& error )
   {
     const char *meshGemsOldStyleEnvVar( getenv( MESHGEMS_OLD_STYLE ) );
     if ( !meshGemsOldStyleEnvVar || strlen(meshGemsOldStyleEnvVar) == 0 )
-      return SignCAD_After(meshgems_cad, error);
+      {
+       if (NeedsMGSpatialEnvLicense(error))
+         // SignCAD is only called by cadsurf. Other components call SignMesh
+         return UnlockProduct("cadsurf", error);
+       else
+         return SignCAD_After(meshgems_cad, error);
+      }
     else
       return true;
   }
@@ -479,12 +542,27 @@ namespace SMESHUtils_MGLicenseKeyGen // API implementation
     return ok;
   }
   
-  bool SignMesh( void* meshgems_mesh, std::string& error )
+  //================================================================================
+  /*!
+   * \brief Sign a mesh (or don't do it if env MESHGEMS_OLD_STYLE is set)
+   *  \param [in] meshgems_mesh - pointer to a MG mesh (meshgems_mesh_t)
+   *  \param [in] product - product of MeshGems to unlock
+   *  \param [out] error - return error description
+   *  \return bool - is a success
+   */
+  //================================================================================
+  bool SignMesh( void* meshgems_mesh, const std::string& product, std::string& error )
   {
     const char *meshGemsOldStyleEnvVar( getenv( MESHGEMS_OLD_STYLE ) );
     if ( !meshGemsOldStyleEnvVar || strlen(meshGemsOldStyleEnvVar) == 0 )
-      // sign the mesh (MG 2.13 and 2.14)
-      return SignMesh_After(meshgems_mesh, error);
+      {
+       if (NeedsMGSpatialEnvLicense(error))
+         // unlock product (MG 2.15)
+         return UnlockProduct(product, error);
+       else
+         // sign the mesh (MG 2.13 and 2.14)
+         return SignMesh_After(meshgems_mesh, error);
+      }
     else
       // use DLIM8 server (nothing to do here)
       return true;
index 6f05f5d047aaf16c852ca01dc6f9169c7c1eac03..e56777fa304035735c5d37b7ccbce17afd94229f 100644 (file)
@@ -38,8 +38,11 @@ namespace SMESHUtils_MGLicenseKeyGen
   // MeshGems 2.13, 2.14 (for CADSurf)
   SMESHUtils_EXPORT bool        SignCAD( void* meshgems_cad, std::string& error );
 
+  // MeshGems 2.15 (for products launched as library)
+  SMESHUtils_EXPORT bool        UnlockProduct( const std::string& product, std::string& error );
+
   // MeshGems 2.13, 2.14 (for products launched as library)
-  SMESHUtils_EXPORT bool        SignMesh( void* meshgems_mesh, std::string& error );
+  SMESHUtils_EXPORT bool        SignMesh( void* meshgems_mesh, const std::string& product, std::string& error );
 
   // MeshGems 2.13, 2.14 and 2.15 (for products launched as executables)
   SMESHUtils_EXPORT std::string GetKey(const std::string& gmfFile,