module SALOME
{
typedef sequence<string> StringVec;
+ typedef sequence<octet> ByteVec;
interface BasicDataServer
{
interface StringDataServer : BasicDataServer
{
- void setValueOf(in string newValue);
- string getValueOf();
- string invokePythonMethodOn(in string method, in string args);
+ void setValueOf(in ByteVec newValue);
+ ByteVec getValueOf();
+ ByteVec invokePythonMethodOn(in string method, in ByteVec args);
};
interface AnyDataServer : BasicDataServer
interface DataScopeServer
{
+ void ping();
string getScopeName();
StringVec listVars();
BasicDataServer retrieveVar(in string varName);
interface DataServerManager
{
StringVec listScopes();
+ StringVec listAliveAndKickingScopes();
DataScopeServer getDefaultScope();
+ boolean isAliveAndKicking(in string scopeName);
DataScopeServer createDataScope(in string scopeName);
DataScopeServer retriveDataScope(in string scopeName);
+ DataScopeServer giveADataScopeCalled(in string scopeName);
void removeDataScope(in string scopeName);
+ void cleanScopesInNS();
void shutdownScopes();
};
};
Py_XDECREF(_pickler);
}
+/*!
+ * Called remotely -> to protect against throw
+ */
+void DataScopeServer::ping()
+{
+}
+
/*!
* Called remotely -> to protect against throw
*/
public:
DataScopeServer(CORBA::ORB_ptr orb, const std::string& scopeName);
DataScopeServer(const DataScopeServer& other);
+ void ping();
char *getScopeName();
SALOME::StringVec *listVars();
SALOME::BasicDataServer_ptr retrieveVar(const char *varName);
return ret;
}
+SALOME::StringVec *DataServerManager::listAliveAndKickingScopes()
+{
+ std::vector<std::string> scopes(listOfScopesCpp());
+ std::size_t sz(scopes.size());
+ std::vector<std::string> retCpp; retCpp.reserve(sz);
+ for(std::size_t i=0;i<sz;i++)
+ {
+ if(isAliveAndKicking(scopes[i].c_str()))
+ retCpp.push_back(scopes[i]);
+ }
+ //
+ SALOME::StringVec *ret(new SALOME::StringVec);
+ sz=retCpp.size();
+ ret->length(sz);
+ for(std::size_t i=0;i<sz;i++)
+ (*ret)[i]=CORBA::string_dup(retCpp[i].c_str());
+ return ret;
+}
+
SALOME::DataScopeServer_ptr DataServerManager::getDefaultScope()
{
return retriveDataScope(DFT_SCOPE_NAME_IN_NS);
}
+CORBA::Boolean DataServerManager::isAliveAndKicking(const char *scopeName)
+{
+ SALOME::DataScopeServer_var scopePtr(getScopePtrGivenName(scopeName));
+ CORBA::Boolean ret(true);
+ try
+ {
+ scopePtr->ping();
+ }
+ catch(...)
+ { ret=false; }
+ return ret;
+}
+
SALOME::DataScopeServer_ptr DataServerManager::createDataScope(const char *scopeName)
{
std::string scopeNameCpp(scopeName);
//
SALOME_NamingService ns(_orb);
std::string fullScopeName(CreateAbsNameInNSFromScopeName(scopeName));
- std::ostringstream oss; oss << "valgrind SALOME_DataScopeServer" << " " << scopeName << " ";
+ std::ostringstream oss; oss << "SALOME_DataScopeServer" << " " << scopeName << " ";
SALOME_ContainerManager::AddOmninamesParams(oss,&ns);
std::string command(oss.str());
SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(command);
return SALOME::DataScopeServer::_duplicate(ret);
}
+SALOME::DataScopeServer_ptr DataServerManager::giveADataScopeCalled(const char *scopeName)
+{
+ std::string scopeNameCpp(scopeName);
+ std::vector<std::string> scopes(listOfScopesCpp());
+ if(std::find(scopes.begin(),scopes.end(),scopeNameCpp)==scopes.end())
+ {
+ return createDataScope(scopeName);
+ }
+ else
+ {
+ if(isAliveAndKicking(scopeName))
+ return retriveDataScope(scopeName);
+ else
+ {
+ SALOME_NamingService ns(_orb);
+ std::string fullScopeName(SALOMESDS::DataServerManager::CreateAbsNameInNSFromScopeName(scopeNameCpp));
+ ns.Destroy_Name(fullScopeName.c_str());
+ return createDataScope(scopeName);
+ }
+ }
+}
+
SALOME::DataScopeServer_ptr DataServerManager::retriveDataScope(const char *scopeName)
{
SALOME::DataScopeServer_var ret(getScopePtrGivenName(scopeName));
scs->shutdownIfNotHostedByDSM();
}
+void DataServerManager::cleanScopesInNS()
+{
+ SALOME_NamingService ns(_orb);
+ std::vector<std::string> scopes(listOfScopesCpp());
+ for(std::vector<std::string>::const_iterator it=scopes.begin();it!=scopes.end();it++)
+ {
+ if(!isAliveAndKicking((*it).c_str()))
+ {
+ std::string fullScopeName(SALOMESDS::DataServerManager::CreateAbsNameInNSFromScopeName(*it));
+ ns.Destroy_Name(fullScopeName.c_str());
+ }
+ }
+}
+
void DataServerManager::shutdownScopes()
{
std::vector<std::string> scopeNames(listOfScopesCpp());
public:
DataServerManager(int argc, char *argv[], CORBA::ORB_ptr orb, PortableServer::POA_ptr poa);
SALOME::StringVec *listScopes();
+ SALOME::StringVec *listAliveAndKickingScopes();
SALOME::DataScopeServer_ptr getDefaultScope();
+ CORBA::Boolean isAliveAndKicking(const char *scopeName);
SALOME::DataScopeServer_ptr createDataScope(const char *scopeName);
SALOME::DataScopeServer_ptr retriveDataScope(const char *scopeName);
+ SALOME::DataScopeServer_ptr giveADataScopeCalled(const char *scopeName);
void removeDataScope(const char *scopeName);
+ void cleanScopesInNS();
void shutdownScopes();
static std::string CreateAbsNameInNSFromScopeName(const std::string& scopeName);
public:
/*!
* Called remotely -> to protect against throw
*/
-void StringDataServer::setValueOf(const char *newValue)
+void StringDataServer::setValueOf(const SALOME::ByteVec& newValue)
{
checkReadOnlyStatusRegardingConstness("StringDataServer::setValueOf : read only var !");
- _data=newValue;
+ FromByteSeqToCpp(newValue,_data);
}
/*!
* Called remotely -> to protect against throw
*/
-char *StringDataServer::getValueOf()
+SALOME::ByteVec *StringDataServer::getValueOf()
{
- return CORBA::string_dup(_data.c_str());
+ return FromCppToByteSeq(_data);
}
/*!
* Called remotely -> to protect against throw
*/
-char *StringDataServer::invokePythonMethodOn(const char *method, const char *args)
+SALOME::ByteVec *StringDataServer::invokePythonMethodOn(const char *method, const SALOME::ByteVec& args)
{
PyObject *self(getPyObjFromPickled(_data));
- PyObject *argsPy(getPyObjFromPickled(args));
+ std::string argsCpp;
+ FromByteSeqToCpp(args,argsCpp);
+ PyObject *argsPy(getPyObjFromPickled(argsCpp));
//
PyObject *selfMeth(PyObject_GetAttrString(self,method));
if(!selfMeth)
}
PyObject *res(PyObject_CallObject(selfMeth,argsPy));
_data=pickelize(self);// if it is a non const method !
- std::string ret(pickelize(res));
+ std::string retCpp(pickelize(res));
// to test : res and self
Py_XDECREF(selfMeth);
//
Py_XDECREF(argsPy);
- return CORBA::string_dup(ret.c_str());
+ return FromCppToByteSeq(retCpp);
+}
+
+void StringDataServer::FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret)
+{
+ std::size_t sz(bsToBeConv.length());
+ ret.resize(sz,' ');
+ char *buf(const_cast<char *>(ret.c_str()));
+ for(std::size_t i=0;i<sz;i++)
+ buf[i]=bsToBeConv[i];
+}
+
+SALOME::ByteVec *StringDataServer::FromCppToByteSeq(const std::string& strToBeConv)
+{
+ SALOME::ByteVec *ret(new SALOME::ByteVec);
+ const char *buf(strToBeConv.c_str());
+ std::size_t sz(strToBeConv.size());
+ ret->length(sz);
+ for(std::size_t i=0;i<sz;i++)
+ (*ret)[i]=buf[i];
+ return ret;
}
//! New reference returned
PyObject *StringDataServer::getPyObjFromPickled(const std::string& pickledData)
{
- PyObject *pickledDataPy(PyString_FromString(pickledData.c_str()));
+ std::size_t sz(pickledData.size());
+ PyObject *pickledDataPy(PyString_FromStringAndSize(NULL,sz));// agy : do not use PyString_FromString because std::string hides a vector of byte.
+ char *buf(PyString_AsString(pickledDataPy));// this buf can be used thanks to python documentation.
+ const char *inBuf(pickledData.c_str());
+ std::copy(inBuf,inBuf+sz,buf);
PyObject *selfMeth(PyObject_GetAttrString(_father->getPickler(),"loads"));
PyObject *args(PyTuple_New(1)); PyTuple_SetItem(args,0,pickledDataPy);
PyObject *ret(PyObject_CallObject(selfMeth,args));
PyObject *retPy(PyObject_CallObject(selfMeth,args));
Py_XDECREF(selfMeth);
Py_XDECREF(args);
- std::string ret(PyString_AsString(retPy));
+ std::size_t sz(PyString_Size(retPy));
+ std::string ret(sz,'\0');
+ const char *buf(PyString_AsString(retPy));
+ char *inBuf(const_cast<char *>(ret.c_str()));
+ for(std::size_t i=0;i<sz;i++)
+ inBuf[i]=buf[i];
Py_XDECREF(retPy);
return ret;
}
public:
StringDataServer(DataScopeServer *father, const std::string& varName);
~StringDataServer();
- void setValueOf(const char *newValue);
- char *getValueOf();
- char *invokePythonMethodOn(const char *method, const char *args);
+ void setValueOf(const SALOME::ByteVec& newValue);
+ SALOME::ByteVec *getValueOf();
+ SALOME::ByteVec *invokePythonMethodOn(const char *method, const SALOME::ByteVec& args);
private:
+ static void FromByteSeqToCpp(const SALOME::ByteVec& bsToBeConv, std::string& ret);
+ static SALOME::ByteVec *FromCppToByteSeq(const std::string& strToBeConv);
PyObject *getPyObjFromPickled(const std::string& pickledData);
std::string pickelize(PyObject *obj);
private: