Salome HOME
Shutdown data servers scopes in driver command.
[modules/yacs.git] / src / runtime / CppComponent.cxx
index 26b94773f7bec7ce68d4d7def62fbdb78cc401f0..e612052a87577675dd03ca0c3d2f7ee7485f9d12 100644 (file)
@@ -1,9 +1,27 @@
+// Copyright (C) 2006-2021  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 "RuntimeSALOME.hxx"
 #include "CppComponent.hxx"
 #include "CppContainer.hxx"
 #include "TypeCode.hxx"
 #include "CppNode.hxx"
-#include "DynLibLoader.hxx"
 
 using namespace YACS::ENGINE;
  
@@ -39,16 +57,16 @@ static std::ostream & operator<<(std::ostream & f, const Any & A)
             f << "(type Bool) " << A.getBoolValue();
             break;
          case Objref :
-           f << "(type Objref)";
+            f << "(type Objref)";
             break;
          case Sequence :
-           f << "(type Sequence) ";
-           {
+            f << "(type Sequence) ";
+            {
               int i;
-             const SequenceAny * sA = dynamic_cast<const SequenceAny *>(&A);
-             for (i=0; i<sA->size(); i++)
-                     f << " " << *((*sA)[i]);
-           }
+              const SequenceAny * sA = dynamic_cast<const SequenceAny *>(&A);
+              for (i=0; i<sA->size(); i++)
+                f << " " << *((*sA)[i]);
+            }
             break;
        }
     return f;
@@ -56,49 +74,53 @@ static std::ostream & operator<<(std::ostream & f, const Any & A)
 
 std::string CppComponent::getKind() const
 {
-   return CppComponent::KIND;
+  return CppComponent::KIND;
+}
+
+std::string CppComponent::getKindForNode() const
+{
+  return CppComponent::KIND;
 }
 
 //! CppComponent constructor
-CppComponent::CppComponent(const std::string &name) : ComponentInstance(name)
+CppComponent::CppComponent(const std::string &name) : ComponentInstance(name), __obj(0), __run(0),__terminate(0)
 {
   _container = getRuntime()->createContainer(CppNode::KIND);
-  if (!_container->isAlreadyStarted())
-         _container->start();
-  
+  /* This part of code has been commented because the load part is supposed to do that !
+  if (!_container->isAlreadyStarted(0))
+    _container->start(0);
   CppContainer * _containerC = dynamic_cast<CppContainer *> (_container);
-  _containerC->createInternalInstance(name, __obj, __run, __terminate);
+  _containerC->createInternalInstance(name, __obj, __run, __terminate);*/
 }
 
 //! CppComponent copy constructor
-CppComponent::CppComponent(const CppComponent& other) : ComponentInstance(other._compoName), __run(other.__run),
-                                                        __terminate(other.__terminate), __obj(0)
+CppComponent::CppComponent(const CppComponent& other) : ComponentInstance(other._compoName), __obj(0), __run(0),__terminate(0)
 {
   _container = getRuntime()->createContainer(CppNode::KIND);
-  if (!_container->isAlreadyStarted())
-    _container->start();
-
+  /* This part of code has been commented because the load part is supposed to do that !
+  if (!_container->isAlreadyStarted(0))
+    _container->start(0);
   CppContainer * _containerC = dynamic_cast<CppContainer *> (_container);  
-   _containerC->createInternalInstance(_compoName, __obj, __run, __terminate);
+   _containerC->createInternalInstance(_compoName, __obj, __run, __terminate);*/
 }
 
 CppComponent::~CppComponent()
 {
-    DEBTRACE("CppComponent::~CppComponent()");
-    if (__terminate) __terminate(&__obj);
-    if (_container)
-       ((CppContainer *) _container)->unregisterComponentInstance(this);
+  DEBTRACE("CppComponent::~CppComponent()");
+  if (__terminate) __terminate(&__obj);
+  if (_container)
+    ((CppContainer *) _container)->unregisterComponentInstance(this);
 }
 
 void CppComponent::run (const char * service, int nbIn, int nbOut,
-                                                Any ** argIn, Any ** argOut) throw (YACS::Exception)
+                        Any ** argIn, Any ** argOut)
 {
   int i;
   returnInfo return_code;
     
 #ifdef _DEVDEBUG_
   std::ostringstream sDebug;
-  sDebug << _name << "::" << service << "(";
+  sDebug << getInstanceName() << "::" << service << "(";
   for (i=0; i<nbIn; i++) {
      sDebug << *(argIn[i]);
      if (i<nbIn-1)
@@ -128,50 +150,50 @@ void CppComponent::run (const char * service, int nbIn, int nbOut,
 }
 
 //! Unload the component 
-void CppComponent::unload()
+void CppComponent::unload(Task *askingNode)
 {
   //Not implemented
   DEBTRACE("CppComponent::unload : not implemented ");
 }
 
 //! Is the component instance already loaded ?
-bool CppComponent::isLoaded()
+bool CppComponent::isLoaded(Task *askingNode) const
 {
   return NULL != __obj;
 }
  
-void CppComponent::load()
+void CppComponent::load(Task *askingNode)
 {
-   if (!_container) {
-          _container = getRuntime()->createContainer(CppNode::KIND);
-   }
-   
-   if(_container) {
-               
-      CppContainer * containerC= dynamic_cast< CppContainer *> (_container);
-      
+  if (!_container)
+    {
+      _container = getRuntime()->createContainer(CppNode::KIND);
+    }
+
+  if(_container)
+    {
+      CppContainer *containerC(dynamic_cast< CppContainer *> (_container));
+      if(!containerC)
+        throw Exception("The type of container should be CPP for component CPP !");
       containerC->lock();//To be sure
-      if(!_container->isAlreadyStarted())
+      if(!_container->isAlreadyStarted(askingNode))
         {
           try
-            {
-              _container->start();
-            }
+          {
+              _container->start(askingNode);
+          }
           catch(Exception& e)
-            {
+          {
               containerC->unLock();
               throw e;
-            }
+          }
         }
       containerC->unLock();
       containerC->lock();//To be sure
-      
-      YACS::BASES::DynLibLoader D(_compoName + "Local");
-      
-      bool isLoadable = containerC->loadComponentLibrary(_compoName);
+
+      bool isLoadable(containerC->loadComponentLibrary(_compoName));
       if (isLoadable) 
         containerC->createInternalInstance(_compoName, __obj, __run, __terminate);
-        
+
       if(NULL == __obj)
         {
           containerC->unLock();
@@ -180,7 +202,6 @@ void CppComponent::load()
       containerC->unLock();
       return;
     }
-       
 }
 
 ServiceNode* CppComponent::createNode(const std::string& name)
@@ -202,3 +223,7 @@ ComponentInstance* CppComponent::clone() const
     return new CppComponent(*this);
 }
 
+YACS::ENGINE::ComponentInstance *CppComponent::cloneAlways() const
+{
+  return new CppComponent(*this);
+}