From: prascle Date: Wed, 28 Apr 2004 19:32:11 +0000 (+0000) Subject: PR: setProperties ans getProperties methods on SALOMRE_component X-Git-Tag: Ecole_Ete_a2~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3ab154df9bf3f75c180f0e9bd62be2290b6e6bc2;p=modules%2Fkernel.git PR: setProperties ans getProperties methods on SALOMRE_component --- diff --git a/idl/SALOME_Component.idl b/idl/SALOME_Component.idl index a18580fe7..ecad1fa41 100644 --- a/idl/SALOME_Component.idl +++ b/idl/SALOME_Component.idl @@ -32,6 +32,17 @@ for management of %MED component in %SALOME application. */ module Engines { +/*! + General Key Value Structure to set or get properties, for component +*/ + struct KeyValuePair + { + string key; + any value; + }; + + typedef sequence FieldsDict; + interface Component ; /*! \brief Interface of the %Container @@ -119,6 +130,18 @@ module Engines Returns the container that the %Component refers to. */ Container GetContainerRef() ; +/*! + Gives a sequence of (key=string,value=any) to the component. + Base class component stores the sequence in a map. + The map is cleared before. + This map is for use by derived classes. +*/ + void setProperties(in FieldsDict dico); +/*! + returns a previously stored map (key=string,value=any) as a sequence. + See setProperties(in FieldsDict dico). +*/ + FieldsDict getProperties(); /*! This method is used by the %SUPERVISOR component. It sets the names of the graph and of the node. \param aGraphName Name of graph diff --git a/idl/SALOME_TestComponent.idl b/idl/SALOME_TestComponent.idl index 96de5a0d6..c580d65b0 100644 --- a/idl/SALOME_TestComponent.idl +++ b/idl/SALOME_TestComponent.idl @@ -31,6 +31,7 @@ module Engines interface TestComponent : Component { string Coucou(in long L); + void Setenv(); }; }; diff --git a/src/Container/Component_i.cxx b/src/Container/Component_i.cxx index 09d463416..309f7ef4a 100644 --- a/src/Container/Component_i.cxx +++ b/src/Container/Component_i.cxx @@ -134,6 +134,31 @@ PortableServer::ObjectId * Engines_Component_i::getId() return _id ; } +void Engines_Component_i::setProperties(const Engines::FieldsDict& dico) +{ + _fieldsDict.clear(); + for (CORBA::ULong i=0; ilength(_fieldsDict.size()); + map::iterator it; + CORBA::ULong i = 0; + for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++) + { + std::string cle((*it).first); + copie[i].key = CORBA::string_dup(cle.c_str()); + copie[i].value = _fieldsDict[cle]; + } + return copie._retn(); +} + void Engines_Component_i::beginService(const char *serviceName) { MESSAGE(pthread_self() << "Send BeginService notification for " << serviceName << endl diff --git a/src/Container/SALOME_ComponentPy.py b/src/Container/SALOME_ComponentPy.py index 004d6eded..2c2a5d0f1 100755 --- a/src/Container/SALOME_ComponentPy.py +++ b/src/Container/SALOME_ComponentPy.py @@ -49,6 +49,7 @@ from thread import * class SALOME_ComponentPy_i (Engines__POA.Component): _orb = None _poa = None + _fieldsDict = [] #------------------------------------------------------------------------- @@ -118,6 +119,16 @@ class SALOME_ComponentPy_i (Engines__POA.Component): #------------------------------------------------------------------------- + def setProperties(self, dico): + self._fieldsDict = dico + + #------------------------------------------------------------------------- + + def getProperties(self): + return self._fieldsDict + + #------------------------------------------------------------------------- + def destroy(self): MESSAGE( "SALOME_ComponentPy_i::destroy" ) poa.deactivate_object(self) diff --git a/src/Container/SALOME_Component_i.hxx b/src/Container/SALOME_Component_i.hxx index fc537d1c8..4b93ef5b5 100644 --- a/src/Container/SALOME_Component_i.hxx +++ b/src/Container/SALOME_Component_i.hxx @@ -35,6 +35,7 @@ #include #include #include +#include #include #include CORBA_SERVER_HEADER(SALOME_Component) #include "NOTIFICATION.hxx" @@ -72,6 +73,9 @@ public: Engines::Container_ptr GetContainerRef(); PortableServer::ObjectId * getId(); + void setProperties(const Engines::FieldsDict& dico); + Engines::FieldsDict* getProperties(); + void beginService(const char *serviceName); void endService(const char *serviceName); void sendMessage(const char *event_type, const char *message); @@ -101,6 +105,7 @@ protected: Engines_Component_i * _thisObj ; RegistryConnexion *_myConnexionToRegistry; NOTIFICATION_Supplier* _notifSupplier; + map_fieldsDict; private: pthread_t _ThreadId ; diff --git a/src/TestContainer/SALOME_TestComponent_i.cxx b/src/TestContainer/SALOME_TestComponent_i.cxx index 85f49d22b..66f55c70e 100644 --- a/src/TestContainer/SALOME_TestComponent_i.cxx +++ b/src/TestContainer/SALOME_TestComponent_i.cxx @@ -30,6 +30,8 @@ using namespace std; #include "utilities.h" #include "SALOME_TestComponent_i.hxx" #include +#include +#include Engines_TestComponent_i::Engines_TestComponent_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, @@ -60,6 +62,31 @@ char* Engines_TestComponent_i::Coucou(CORBA::Long L) return CORBA::string_dup(s); } +void Engines_TestComponent_i::Setenv() +{ + bool overwrite = true; + map::iterator it; + MESSAGE("set environment associated with keys in map _fieldsDict"); + for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++) + { + std::string cle((*it).first); + if ((*it).second.type()->kind() == CORBA::tk_string) + { + const char* value; + (*it).second >>= value; + int ret = setenv(cle.c_str(), value, overwrite); + MESSAGE("--- setenv: "<instanceName()); + + Engines::FieldsDict_var dico = new Engines::FieldsDict; + dico->length(3); + dico[0].key=CORBA::string_dup("key_0"); + dico[0].value <<="value_0"; + dico[1].key=CORBA::string_dup("key_1"); + dico[1].value <<=(CORBA::UShort)72; + dico[2].key=CORBA::string_dup("key_2"); + dico[2].value <<="value_2"; + m1->setProperties(dico); + MESSAGE("Coucou " << m1->Coucou(1L)); + + m1->Setenv(); + + Engines::FieldsDict_var dico2 = m1->getProperties(); + for (CORBA::ULong i=0; ilength(); i++) + { + MESSAGE("dico2["<