*/
module Engines
{
+/*!
+ General Key Value Structure to set or get properties, for component
+*/
+ struct KeyValuePair
+ {
+ string key;
+ any value;
+ };
+
+ typedef sequence<KeyValuePair> FieldsDict;
+
interface Component ;
/*! \brief Interface of the %Container
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
interface TestComponent : Component
{
string Coucou(in long L);
+ void Setenv();
};
};
return _id ;
}
+void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
+{
+ _fieldsDict.clear();
+ for (CORBA::ULong i=0; i<dico.length(); i++)
+ {
+ std::string cle(dico[i].key);
+ _fieldsDict[cle] = dico[i].value;
+ }
+}
+
+Engines::FieldsDict* Engines_Component_i::getProperties()
+{
+ Engines::FieldsDict_var copie = new Engines::FieldsDict;
+ copie->length(_fieldsDict.size());
+ map<std::string,CORBA::Any>::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
class SALOME_ComponentPy_i (Engines__POA.Component):
_orb = None
_poa = None
+ _fieldsDict = []
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
+ 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)
#include <unistd.h>
#include <sys/types.h>
#include <string>
+#include <map>
#include <SALOMEconfig.h>
#include CORBA_SERVER_HEADER(SALOME_Component)
#include "NOTIFICATION.hxx"
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);
Engines_Component_i * _thisObj ;
RegistryConnexion *_myConnexionToRegistry;
NOTIFICATION_Supplier* _notifSupplier;
+ map<std::string,CORBA::Any>_fieldsDict;
private:
pthread_t _ThreadId ;
#include "utilities.h"
#include "SALOME_TestComponent_i.hxx"
#include <stdio.h>
+#include <cstdlib>
+#include <map>
Engines_TestComponent_i::Engines_TestComponent_i(CORBA::ORB_ptr orb,
PortableServer::POA_ptr poa,
return CORBA::string_dup(s);
}
+void Engines_TestComponent_i::Setenv()
+{
+ bool overwrite = true;
+ map<std::string,CORBA::Any>::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: "<<cle<<" = "<< value);
+ }
+ }
+ MESSAGE("read environment associated with keys in map _fieldsDict");
+ for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
+ {
+ std::string cle((*it).first);
+ char* valenv= getenv(cle.c_str());
+ MESSAGE("--- getenv: "<<cle<<" = "<< valenv);
+ }
+}
+
extern "C"
{
PortableServer::ObjectId * SalomeTestComponentEngine_factory(
virtual ~Engines_TestComponent_i();
char* Coucou(CORBA::Long L);
+ void Setenv();
private:
m1 = Engines::TestComponent::_narrow(obj);
MESSAGE("recup m1");
SCRUTE(m1->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; i<dico2->length(); i++)
+ {
+ MESSAGE("dico2["<<i<<"].key="<<dico2[i].key);
+ MESSAGE("dico2["<<i<<"].value type ="<<dico2[i].value.type()->kind());
+ if (dico2[i].value.type()->kind() == CORBA::tk_string)
+ {
+ const char* value;
+ dico2[i].value >>= value;
+ MESSAGE("dico2["<<i<<"].value="<<value);
+ }
+ }
+
iGenFact->remove_impl(m1) ;
//iGenFact->finalize_removal() ; // unpredictable results ...
sleep(5);