Salome HOME
Adding a new method to initialize YACS services if
authorribes <ribes>
Thu, 7 Jun 2012 09:22:35 +0000 (09:22 +0000)
committerribes <ribes>
Thu, 7 Jun 2012 09:22:35 +0000 (09:22 +0000)
the multi property on the service is used.

idl/DSC_Engines.idl
src/DSC/DSC_User/Datastream/Calcium/Calcium.cxx
src/DSC/DSC_User/Datastream/Calcium/Calcium.hxx
src/DSC/DSC_User/Superv_Component_i.hxx

index fb04a3a876079f314ab12214990c8e4cab8bd580..3335c8d6c49fb3585d6b0c4c9f3986f2e27ad861 100644 (file)
@@ -348,14 +348,32 @@ module Engines {
   interface Superv_Component : Engines::DSC {
     
     //! Operation to create the service ports before it is executed
-    /*! 
-      The SUPERV module call this method before starting the service. Thus the service 
+    /*!
+      YACS module call this method before starting the service. Thus the service 
       can add its dynamics ports before it is started.
 
       \param service_name service's name.
       \return true if the service is correctly initialised.
      */
     boolean init_service(in string service_name);
+
+    struct multiple_param {
+      string name;
+      long number;
+    };
+
+    typedef sequence<multiple_param> seq_multiple_param;
+
+    /*!
+      YACS module call this method before starting the service. Thus the service 
+      can add its dynamics ports before it is started.
+      This method is also used by YACS to specify for each datastream port (name in multiple_param)
+      how many the service should create a datastream port.
+
+      For a defined port named: in_data_port, the service should create ports with the names:
+      in_data_port_0, in_data_port_1, ...
+    */
+    boolean init_service_with_multiple(in string service_name, in seq_multiple_param params);
   };
 };
 
index 5f52641174f1f0420e33c7aa0a6f791ecae26114..17278634b4e12d36518c126ea03df0044016736c 100644 (file)
@@ -24,6 +24,7 @@
 #include <sstream>
 #include <string>
 #include <exception>
+#include <cstring>
 
 PySupervCompo::PySupervCompo( CORBA::ORB_ptr orb,
                               PortableServer::POA_ptr poa,
@@ -148,6 +149,33 @@ extern "C"
       }
   }
 
+  char** create_multiple_calcium_port(Superv_Component_i* compo,char* name,char* type,char *mode,char* depend, int number)
+  {
+    if (number <= 0)
+    {
+      std::cerr << "Cannot create a multiple calcium port with number <= 0, value is " << number << std::endl;
+      return NULL;
+    }
+    char** names = new char*[number];
+    for (int i = 0; i < number; i++)
+    {
+      std::ostringstream new_name;
+      new_name << name << "_" << i;
+      std::string cpp_name = new_name.str();
+      char * c_name = new char [cpp_name.size()+1];
+      strcpy(c_name, cpp_name.c_str());
+      names[i] = c_name;
+    }
+
+    // Create ports
+    for (int i = 0; i < number; i++)
+    {
+      create_calcium_port(compo, (char*)std::string(names[i]).c_str(), type, mode, depend);
+    }
+
+    return names;
+  }
+
 }
 
 
index 4da3f0fad5b970e01291767ef6d0b38883d85237..c9f1d4752f8450ed0454a7d9c23cb39c01bf12d9 100644 (file)
@@ -30,7 +30,15 @@ class PySupervCompo:public Superv_Component_i
          bool notif = false);
     virtual ~PySupervCompo();
     CORBA::Boolean init_service(const char * service_name){return true;};
+    CORBA::Boolean init_service_with_multiple(const char* service_name,
+                                              const Engines::Superv_Component::seq_multiple_param & params)
+    {
+      return true;
+    }
 };
 
 
 extern "C" void create_calcium_port(Superv_Component_i* compo,char* name,char* type,char *mode,char* depend);
+
+// This method permits to help a service developer to create multiple calcium ports
+extern "C" char** create_multiple_calcium_port(Superv_Component_i* compo,char* name,char* type,char *mode,char* depend, int number);
index 4fe3e94001ce8a033488f2452de93451933512e3..2d0e227c604b366bef5974be2fb875763bd7fdbf 100644 (file)
@@ -263,7 +263,16 @@ public:
   static void setTimeOut();
   void beginService(const char *serviceName);
 
-private:   
+
+  // This method is implemented by default since it is a very specific usage.
+  // It also permits to not break compatibility with older components.
+  virtual CORBA::Boolean init_service_with_multiple(const char* service_name,
+                                                    const Engines::Superv_Component::seq_multiple_param & params)
+  {
+    return true;
+  }
+
+private:
   // Factory map
   typedef std::map<std::string, port_factory*> factory_map_t;
   static factory_map_t _factory_map;