From fab64bcf21aa315912f4b8b90ce5f1ac105c6ee8 Mon Sep 17 00:00:00 2001 From: ribes Date: Thu, 7 Jun 2012 09:22:35 +0000 Subject: [PATCH] Adding a new method to initialize YACS services if the multi property on the service is used. --- idl/DSC_Engines.idl | 22 +++++++++++++-- .../DSC_User/Datastream/Calcium/Calcium.cxx | 28 +++++++++++++++++++ .../DSC_User/Datastream/Calcium/Calcium.hxx | 8 ++++++ src/DSC/DSC_User/Superv_Component_i.hxx | 11 +++++++- 4 files changed, 66 insertions(+), 3 deletions(-) diff --git a/idl/DSC_Engines.idl b/idl/DSC_Engines.idl index fb04a3a87..3335c8d6c 100644 --- a/idl/DSC_Engines.idl +++ b/idl/DSC_Engines.idl @@ -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 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); }; }; diff --git a/src/DSC/DSC_User/Datastream/Calcium/Calcium.cxx b/src/DSC/DSC_User/Datastream/Calcium/Calcium.cxx index 5f5264117..17278634b 100644 --- a/src/DSC/DSC_User/Datastream/Calcium/Calcium.cxx +++ b/src/DSC/DSC_User/Datastream/Calcium/Calcium.cxx @@ -24,6 +24,7 @@ #include #include #include +#include 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; + } + } diff --git a/src/DSC/DSC_User/Datastream/Calcium/Calcium.hxx b/src/DSC/DSC_User/Datastream/Calcium/Calcium.hxx index 4da3f0fad..c9f1d4752 100644 --- a/src/DSC/DSC_User/Datastream/Calcium/Calcium.hxx +++ b/src/DSC/DSC_User/Datastream/Calcium/Calcium.hxx @@ -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); diff --git a/src/DSC/DSC_User/Superv_Component_i.hxx b/src/DSC/DSC_User/Superv_Component_i.hxx index 4fe3e9400..2d0e227c6 100644 --- a/src/DSC/DSC_User/Superv_Component_i.hxx +++ b/src/DSC/DSC_User/Superv_Component_i.hxx @@ -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 factory_map_t; static factory_map_t _factory_map; -- 2.39.2