SALOME::StringVec *RequestSwitcherDSM::listScopes()
{
- return _dsm->listScopes();
+ return _dsm->listScopes_unsafe();
}
SALOME::DataScopeServerTransaction_ptr RequestSwitcherDSM::giveADataScopeTransactionCalled(const char *scopeName, CORBA::Boolean& isCreated)
{
- return _dsm->giveADataScopeTransactionCalled(scopeName,isCreated);
+ return _dsm->giveADataScopeTransactionCalled_unsafe(scopeName,isCreated);
}
+void RequestSwitcherDSM::holdRequests()
+{
+ _dsm->holdRequests();
+}
+
+void RequestSwitcherDSM::activeRequests()
+{
+ _dsm->activeRequests();
+}
+
+
DataServerManager::DataServerManager(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, SALOME_NamingService_Abstract *ns):_orb(CORBA::ORB::_duplicate(orb))
{
_ns = ns==nullptr?new SALOME_NamingService(_orb):ns;
policies.length(1);
PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL));
policies[0]=PortableServer::ThreadPolicy::_duplicate(threadPol);
- _poa=poa->create_POA("SingleThPOA4SDS",pman,policies);
+ PortableServer::POA_var safePoa = poa->create_POA("SingleThPOA4SDS",pman,policies);
+ _poa= poa;
threadPol->destroy();
// activate this to be ready to be usable from NS.
PortableServer::ObjectId_var id(_poa->activate_object(this));
// publish Data server manager in NS
_ns->Register(obj2,NAME_IN_NS);
// the default DataScopeServer object is the only one hosted by the current process
- dftScope->setPOA(_poa);
+ dftScope->setPOA(safePoa);
obj=dftScope->activate();
SALOME::DataScopeServer_var dftScopePtr(SALOME::DataScopeServer::_narrow(obj));
dftScope->registerInNS(dftScopePtr);// agy : Very important ! invoke this method BEFORE activation ! Because this method initializes Python !
delete _ns;
}
-SALOME::StringVec *DataServerManager::listScopes()
+SALOME::StringVec * DataServerManager::listScopes_unsafe()
{
std::vector<std::string> scopes(listOfScopesCpp());
SALOME::StringVec *ret(new SALOME::StringVec);
return ret;
}
+SALOME::StringVec *DataServerManager::listScopes()
+{
+ const std::lock_guard<std::mutex> lock(_mutex);
+ return listScopes_unsafe();
+}
+
SALOME::StringVec *DataServerManager::listAliveAndKickingScopes()
{
+ const std::lock_guard<std::mutex> lock(_mutex);
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()))
+ if(isAliveAndKicking_unsafe(scopes[i].c_str()))
retCpp.push_back(scopes[i]);
}
//
SALOME::DataScopeServer_ptr DataServerManager::getDefaultScope()
{
- SALOME::DataScopeServerBase_var ret(retriveDataScope(DFT_SCOPE_NAME_IN_NS));
+ const std::lock_guard<std::mutex> lock(_mutex);
+ SALOME::DataScopeServerBase_var ret(retriveDataScope_unsafe(DFT_SCOPE_NAME_IN_NS));
if(CORBA::is_nil(ret))
return SALOME::DataScopeServer::_narrow(ret);
SALOME::DataScopeServer_ptr ret2(SALOME::DataScopeServer::_narrow(ret));
}
CORBA::Boolean DataServerManager::isAliveAndKicking(const char *scopeName)
+{
+ const std::lock_guard<std::mutex> lock(_mutex);
+ return isAliveAndKicking_unsafe(scopeName);
+}
+
+CORBA::Boolean DataServerManager::isAliveAndKicking_unsafe(const char *scopeName)
{
SALOME::DataScopeServerBase_var scopePtr(getScopePtrGivenName(scopeName));
return IsAliveAndKicking(scopePtr);
SALOME::DataScopeServer_ptr DataServerManager::createDataScope(const char *scopeName)
{
+ const std::lock_guard<std::mutex> lock(_mutex);
return CreateDataScope<NormalFunctor>(_orb,scopeName,listOfScopesCpp(),*_ns);
}
SALOME::DataScopeServer_ptr DataServerManager::giveADataScopeCalled(const char *scopeName, CORBA::Boolean& isCreated)
{
+ const std::lock_guard<std::mutex> lock(_mutex);
return GiveADataScopeCalled<NormalFunctor>(_orb,scopeName,listOfScopesCpp(),*_ns,isCreated);
}
SALOME::DataScopeServerTransaction_ptr DataServerManager::createDataScopeTransaction(const char *scopeName)
{
+ const std::lock_guard<std::mutex> lock(_mutex);
return CreateDataScope<TransactionFunctor>(_orb,scopeName,listOfScopesCpp(),*_ns);
}
-SALOME::DataScopeServerTransaction_ptr DataServerManager::giveADataScopeTransactionCalled(const char *scopeName, CORBA::Boolean& isCreated)
+SALOME::DataScopeServerTransaction_ptr
+DataServerManager::giveADataScopeTransactionCalled_unsafe(
+ const char *scopeName, CORBA::Boolean& isCreated)
{
return GiveADataScopeCalled<TransactionFunctor>(_orb,scopeName,listOfScopesCpp(),*_ns,isCreated);
}
+
+SALOME::DataScopeServerTransaction_ptr DataServerManager::giveADataScopeTransactionCalled(const char *scopeName, CORBA::Boolean& isCreated)
+{
+ const std::lock_guard<std::mutex> lock(_mutex);
+ return giveADataScopeTransactionCalled_unsafe(scopeName, isCreated);
+}
+
SALOME::DataScopeServerBase_ptr DataServerManager::retriveDataScope(const char *scopeName)
+{
+ const std::lock_guard<std::mutex> lock(_mutex);
+ return retriveDataScope_unsafe(scopeName);
+}
+
+SALOME::DataScopeServerBase_ptr DataServerManager::retriveDataScope_unsafe(const char *scopeName)
{
SALOME::DataScopeServerBase_var ret(getScopePtrGivenName(scopeName));
return SALOME::DataScopeServerBase::_duplicate(ret);
void DataServerManager::removeDataScope(const char *scopeName)
{
+ const std::lock_guard<std::mutex> lock(_mutex);
SALOME::DataScopeServerBase_var scs(getScopePtrGivenName(scopeName));
SALOME::DataScopeKiller_ptr killer;
if(scs->shutdownIfNotHostedByDSM(killer))
void DataServerManager::cleanScopesInNS()
{
+ const std::lock_guard<std::mutex> lock(_mutex);
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()))
+ if(!isAliveAndKicking_unsafe((*it).c_str()))
{
std::string fullScopeName(SALOMESDS::DataServerManager::CreateAbsNameInNSFromScopeName(*it));
_ns->Destroy_Name(fullScopeName.c_str());
void DataServerManager::shutdownScopes()
{
+ const std::lock_guard<std::mutex> lock(_mutex);
std::vector<std::string> scopeNames(listOfScopesCpp());
for(std::vector<std::string>::const_iterator it=scopeNames.begin();it!=scopeNames.end();it++)
{
SALOME::RequestSwitcherDSM_ptr DataServerManager::getRequestSwitcher()
{
+ const std::lock_guard<std::mutex> lock(_mutex);
if(_rs.isNull())
{
_rs=new RequestSwitcherDSM(_orb,this);
CORBA::Object_var obj(_rs->activate());
return SALOME::RequestSwitcherDSM::_narrow(obj);
}
+
+void DataServerManager::holdRequests()
+{
+ _mutex.lock();
+}
+
+void DataServerManager::activeRequests()
+{
+ _mutex.unlock();
+}
#include "SALOMESDS_Defines.hxx"
#include <string>
+#include <mutex>
class SALOME_NamingService_Abstract;
RequestSwitcherDSM(CORBA::ORB_ptr orb, DataServerManager *dsm):RequestSwitcherBase(orb),_dsm(dsm) { }
SALOME::StringVec *listScopes();
SALOME::DataScopeServerTransaction_ptr giveADataScopeTransactionCalled(const char *scopeName, CORBA::Boolean& isCreated);
+ void holdRequests()override;
+ void activeRequests()override;
private:
DataServerManager *_dsm;
};
void cleanScopesInNS();
void shutdownScopes();
SALOME::RequestSwitcherDSM_ptr getRequestSwitcher();
+ void holdRequests();
+ void activeRequests();
+
public:
CORBA::ORB_var getORB() { return _orb; }
static std::string CreateAbsNameInNSFromScopeName(const std::string& scopeName);
static CORBA::Boolean IsAliveAndKicking(SALOME::DataScopeServerBase_ptr scopePtr);
static SALOME::DataScopeServerBase_var GetScopePtrGivenName(const std::string& scopeName, const std::vector<std::string>& scopes, SALOME_NamingService_Abstract *ns);
+ SALOME::StringVec *listScopes_unsafe();
+ SALOME::DataScopeServerTransaction_ptr giveADataScopeTransactionCalled_unsafe(
+ const char *scopeName, CORBA::Boolean& isCreated);
public:
static const char NAME_IN_NS[];
static const char DFT_SCOPE_NAME_IN_NS[];
private:
std::vector<std::string> listOfScopesCpp();
SALOME::DataScopeServerBase_var getScopePtrGivenName(const std::string& scopeName);
+ CORBA::Boolean isAliveAndKicking_unsafe(const char *scopeName);
+ SALOME::DataScopeServerBase_ptr retriveDataScope_unsafe(const char *scopeName);
private:
//! naming service object is owned
SALOME_NamingService_Abstract *_ns = nullptr;
//! single thread poa
PortableServer::POA_var _poa;
AutoServantPtr<RequestSwitcherDSM> _rs;
+ std::mutex _mutex;
};
}