]> SALOME platform Git repositories - modules/yacs.git/commitdiff
Salome HOME
Observer using plugins through python
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 5 Sep 2018 14:53:06 +0000 (16:53 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 5 Sep 2018 14:53:06 +0000 (16:53 +0200)
src/engine/CMakeLists.txt
src/engine/ObserverAsPlugin.cxx [new file with mode: 0644]
src/engine/ObserverAsPlugin.hxx [new file with mode: 0644]
src/engine_swig/pilot.i
src/yacsloader/driver.cxx

index 3e8442219f01d40121d2dbcff687cb2408940214..388bfea5f8a75b8d1fc42410966f66406f1cb1ac 100644 (file)
@@ -108,6 +108,7 @@ SET(YACSlibEngine_HEADERS
   ElementaryPoint.hxx
   SetOfPoints.hxx
   PlayGround.hxx
+  ObserverAsPlugin.hxx
   )
 
 # --- sources ---
@@ -183,6 +184,7 @@ SET(YACSlibEngine_SOURCES
   SetOfPoints.cxx
   PlayGround.cxx
   ComplexWeight.cxx
+  ObserverAsPlugin.cxx
   )
 SET(YACSlibEngine_HEADERS ${YACSlibEngine_HEADERS} PARENT_SCOPE)  # Make it visible to src/engine_swig to handle dependencies
 
diff --git a/src/engine/ObserverAsPlugin.cxx b/src/engine/ObserverAsPlugin.cxx
new file mode 100644 (file)
index 0000000..eb9dccf
--- /dev/null
@@ -0,0 +1,79 @@
+// Copyright (C) 2018  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "ObserverAsPlugin.hxx"
+#include "Dispatcher.hxx"
+#include "Exception.hxx"
+
+#include <sstream>
+
+#ifndef WIN32
+#include <dlfcn.h>
+#include <stdlib.h>
+#endif
+
+void *HandleOnLoadedPlugin=nullptr;
+void (*DefineCustomObservers)(YACS::ENGINE::Dispatcher *, YACS::ENGINE::ComposedNode *, YACS::ENGINE::Executor *)=nullptr;
+void (*CleanUpObservers) ()=nullptr;
+
+void YACS::ENGINE::LoadObserversPluginIfAny(ComposedNode *rootNode, Executor *executor)
+{
+  static const char SYMBOLE_NAME_1[]="DefineCustomObservers";
+  static const char SYMBOLE_NAME_2[]="CleanUpObservers";
+#ifndef WIN32
+  Dispatcher *disp(Dispatcher::getDispatcher());
+  if(!disp)
+    throw YACS::Exception("Internal error ! No dispatcher !");
+  char *yacsDriverPluginPath(getenv("YACS_DRIVER_PLUGIN_PATH"));
+  if(!yacsDriverPluginPath)
+    return ;
+  void *handle(dlopen(yacsDriverPluginPath, RTLD_LAZY | RTLD_GLOBAL));
+  if(!handle)
+    {
+      std::string message(dlerror());
+      std::ostringstream oss; oss << "Error during load of \"" << yacsDriverPluginPath << "\" defined by the YACS_DRIVER_PLUGIN_PATH env var : " << message;
+      throw YACS::Exception(oss.str());
+    }
+  DefineCustomObservers=(void (*)(YACS::ENGINE::Dispatcher *, YACS::ENGINE::ComposedNode *, YACS::ENGINE::Executor *))(dlsym(handle,SYMBOLE_NAME_1));
+  if(!DefineCustomObservers)
+    {
+      std::ostringstream oss; oss << "Error during load of \"" << yacsDriverPluginPath << "\" ! Library has been correctly loaded but symbol " << SYMBOLE_NAME_1 << " does not exists !";
+      throw YACS::Exception(oss.str());
+    }
+  CleanUpObservers=(void (*)())(dlsym(handle,SYMBOLE_NAME_2));
+  if(!CleanUpObservers)
+    {
+      std::ostringstream oss; oss << "Error during load of \"" << yacsDriverPluginPath << "\" ! Library has been correctly loaded but symbol " << SYMBOLE_NAME_2 << " does not exists !";
+      throw YACS::Exception(oss.str());
+    }
+  HandleOnLoadedPlugin=handle;
+  DefineCustomObservers(disp,rootNode,executor);
+#endif
+}
+
+void YACS::ENGINE::UnLoadObserversPluginIfAny()
+{
+#ifndef WIN32
+  if(HandleOnLoadedPlugin)
+    {
+      CleanUpObservers();
+      dlclose(HandleOnLoadedPlugin);
+    }
+#endif
+}
diff --git a/src/engine/ObserverAsPlugin.hxx b/src/engine/ObserverAsPlugin.hxx
new file mode 100644 (file)
index 0000000..1e65d1b
--- /dev/null
@@ -0,0 +1,32 @@
+// Copyright (C) 2018  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#pragma once
+
+namespace YACS
+{
+  namespace ENGINE
+  {
+    class ComposedNode;
+    class Executor;
+    
+    void LoadObserversPluginIfAny(ComposedNode *rootNode, Executor *executor);
+    void UnLoadObserversPluginIfAny();
+  }
+}
index 642fb3518fc696bd23e95a5ee67d8fb415e65f6e..c2c324fe75990c4da8490ddef48441bfab84cf0b 100644 (file)
@@ -64,6 +64,7 @@
 #include "ForkBlocPoint.hxx"
 #include "LinkedBlocPoint.hxx"
 #include "ElementaryPoint.hxx"
+#include "ObserverAsPlugin.hxx"
   
 using namespace YACS::ENGINE;
 
@@ -645,3 +646,17 @@ namespace YACS
   }
 }
 
+%rename(LoadObserversPluginIfAny) LoadObserversPluginIfAnySwig;
+%rename(UnLoadObserversPluginIfAny) UnLoadObserversPluginIfAnySwig;
+                                  
+%inline{
+  void LoadObserversPluginIfAnySwig(YACS::ENGINE::ComposedNode *rootNode, YACS::ENGINE::ExecutorSwig *executor)
+  {
+    YACS::ENGINE::LoadObserversPluginIfAny(rootNode,executor);
+  }
+
+  void UnLoadObserversPluginIfAnySwig()
+  {
+    YACS::ENGINE::UnLoadObserversPluginIfAny();
+  }
+}
index a26298375d163a22c8f8bbff4740039a76b4f146..2671ddd3b2114a60bec308839234e3ab91e3149e 100644 (file)
@@ -29,6 +29,7 @@
 #include "LoadState.hxx"
 #include "Dispatcher.hxx"
 #include "LinkInfo.hxx"
+#include "ObserverAsPlugin.hxx"
 
 #ifdef SALOME_KERNEL
 #include "SALOME_NamingService.hxx"
@@ -101,62 +102,6 @@ typedef struct {
   string lockFile;
 } thread_st;
 
-#ifndef WIN32
-#include <dlfcn.h>
-#include <stdlib.h>
-#endif
-
-std::string LoadedDriverPluginLibrary;
-void *HandleOnLoadedPlugin=0;
-void (*DefineCustomObservers)(YACS::ENGINE::Dispatcher *, YACS::ENGINE::ComposedNode *, YACS::ENGINE::Executor *)=0;
-void (*CleanUpObservers) ()=0;
-
-void LoadObserversPluginIfAny(YACS::ENGINE::ComposedNode *rootNode, YACS::ENGINE::Executor *executor)
-{
-  static const char SYMBOLE_NAME_1[]="DefineCustomObservers";
-  static const char SYMBOLE_NAME_2[]="CleanUpObservers";
-#ifndef WIN32
-  Dispatcher *disp(Dispatcher::getDispatcher());
-  if(!disp)
-    throw YACS::Exception("Internal error ! No dispatcher !");
-  char *yacsDriverPluginPath(getenv("YACS_DRIVER_PLUGIN_PATH"));
-  if(!yacsDriverPluginPath)
-    return ;
-  void *handle(dlopen(yacsDriverPluginPath, RTLD_LAZY | RTLD_GLOBAL));
-  if(!handle)
-    {
-      std::string message(dlerror());
-      std::ostringstream oss; oss << "Error during load of \"" << yacsDriverPluginPath << "\" defined by the YACS_DRIVER_PLUGIN_PATH env var : " << message;
-      throw YACS::Exception(oss.str());
-    }
-  DefineCustomObservers=(void (*)(YACS::ENGINE::Dispatcher *, YACS::ENGINE::ComposedNode *, YACS::ENGINE::Executor *))(dlsym(handle,SYMBOLE_NAME_1));
-  if(!DefineCustomObservers)
-    {
-      std::ostringstream oss; oss << "Error during load of \"" << yacsDriverPluginPath << "\" ! Library has been correctly loaded but symbol " << SYMBOLE_NAME_1 << " does not exists !";
-      throw YACS::Exception(oss.str());
-    }
-  CleanUpObservers=(void (*)())(dlsym(handle,SYMBOLE_NAME_2));
-  if(!CleanUpObservers)
-    {
-      std::ostringstream oss; oss << "Error during load of \"" << yacsDriverPluginPath << "\" ! Library has been correctly loaded but symbol " << SYMBOLE_NAME_2 << " does not exists !";
-      throw YACS::Exception(oss.str());
-    }
-  HandleOnLoadedPlugin=handle;
-  DefineCustomObservers(disp,rootNode,executor);
-#endif
-}
-
-void UnLoadObserversPluginIfAny()
-{
-#ifndef WIN32
-  if(HandleOnLoadedPlugin)
-    {
-      CleanUpObservers();
-      dlclose(HandleOnLoadedPlugin);
-    }
-#endif
-}
-
 #if defined WIN32 || defined __APPLE__
 static int
 #else
@@ -565,7 +510,7 @@ int main (int argc, char* argv[])
           st->lockFile = rootFile + ".lock";
           pthread_create(&th,NULL,&dumpState,(void*)st);
         }
-      LoadObserversPluginIfAny(p,&executor);
+      YACS::ENGINE::LoadObserversPluginIfAny(p,&executor);
       cerr << "+++++++++++++++++++ start calculation +++++++++++++++++++" << endl;
       executor.RunW(p,myArgs.display, fromScratch);
       cerr << "+++++++++++++++++++  end calculation  +++++++++++++++++++" << endl;
@@ -615,7 +560,7 @@ int main (int argc, char* argv[])
       r->fini();
       delete r;
       delete disp;
-      UnLoadObserversPluginIfAny();
+      YACS::ENGINE::UnLoadObserversPluginIfAny();
       return return_value;
     }
   catch (YACS::Exception& e)