1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony GEAY (EDF R&D)
21 #ifndef __SALOMESDS_DATASCOPEERVER_HXX__
22 #define __SALOMESDS_DATASCOPEERVER_HXX__
24 #include "SALOMEconfig.h"
25 #include CORBA_SERVER_HEADER(SALOME_SDS)
27 #include "SALOMESDS_RequestSwitcher.hxx"
28 #include "SALOMESDS_RefCountServ.hxx"
29 #include "SALOMESDS_AutoRefCountPtr.hxx"
30 #include "SALOMESDS_BasicDataServer.hxx"
31 #include "SALOMESDS_Auto.hxx"
32 #include "SALOMESDS_Defines.hxx"
33 #include "SALOME_CPythonHelper.hxx"
43 class SALOMESDS_EXPORT DataScopeKiller : public POA_SALOME::DataScopeKiller
46 DataScopeKiller(CORBA::ORB_ptr orb):_orb(CORBA::ORB::_duplicate(orb)) { }
52 class DataScopeServerTransaction;
55 * Servant activated by a specific POA (single thread) having itself its specific POA_manager.
56 * This class is able to hold/active the default POA_manager shared by other POA than this.
58 class SALOMESDS_EXPORT RequestSwitcher : public RequestSwitcherBase, public virtual POA_SALOME::RequestSwitcher
61 RequestSwitcher(CORBA::ORB_ptr orb, DataScopeServerTransaction *ds);
62 SALOME::StringVec *listVars();
63 SALOME::ByteVec *fetchSerializedContent(const char *varName);
64 void fetchAndGetAccessOfVar(const char *varName, CORBA::String_out access, SALOME::ByteVec_out data);
66 //! handle on its creator to give access to services when _poa_manager_under_control is in hold mode.
67 DataScopeServerTransaction *_ds;
71 class PickelizedPyObjServer;
73 class SALOMESDS_EXPORT DataScopeServerBase : public virtual POA_SALOME::DataScopeServerBase, public POAHolder
76 DataScopeServerBase(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName);
77 DataScopeServerBase(const DataScopeServerBase& other);
78 public: // remote access methods
81 SALOME::StringVec *listVars();
82 CORBA::Boolean existVar(const char *varName);
83 SALOME::BasicDataServer_ptr retrieveVarInternal(const char *varName);
84 void deleteVar(const char *varName);
85 CORBA::Boolean shutdownIfNotHostedByDSM(SALOME::DataScopeKiller_out killer);
86 SALOME::ByteVec *fetchSerializedContent(const char *varName);
87 SALOME::SeqOfByteVec *getAllKeysOfVarWithTypeDict(const char *varName);
88 void takeANap(CORBA::Double napDurationInSec);
90 ~DataScopeServerBase();
91 BasicDataServer *retrieveVarInternal2(const std::string& varName);
92 void registerToSalomePiDict() const;
93 void setPOA(PortableServer::POA_var poa);
94 void registerInNS(SALOME::DataScopeServerBase_ptr ptr);
95 PyObject *getGlobals() const { return _pyHelper->getGlobals(); }
96 PyObject *getLocals() const { return _pyHelper->getLocals(); }
97 PyObject *getPickler() const { return _pyHelper->getPickler(); }
98 PortableServer::POA_var getPOA() const { return _poa; }
99 CORBA::ORB_var getORB() { return _orb; }
100 std::string getScopeNameCpp() const { return _name; }
101 static std::string BuildTmpVarNameFrom(const std::string& varName);
103 std::vector< std::string> getAllVarNames() const;
104 bool isExistingVar(const std::string& varName) const;
105 void checkNotAlreadyExistingVar(const std::string& varName) const;
106 void checkExistingVar(const std::string& varName) const;
107 PickelizedPyObjServer *checkVarExistingAndDict(const std::string& varName);
109 void moveStatusOfVarFromRdWrToRdOnly(const std::string& varName);
110 void moveStatusOfVarFromRdOnlyToRdWr(const std::string& varName);
111 void moveStatusOfVarFromRdExtOrRdExtInitToRdExtInit(const std::string& varName);
112 void moveStatusOfVarFromRdExtOrRdExtInitToRdExt(const std::string& varName);
114 std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::const_iterator retrieveVarInternal3(const std::string& varName) const;
115 std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator retrieveVarInternal4(const std::string& varName);
117 const SALOME_CPythonHelper *_pyHelper = nullptr;
118 PortableServer::POA_var _poa;
121 std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > > _vars;
122 SALOME::DataScopeKiller_var _killer;
123 static std::size_t COUNTER;
126 class SALOMESDS_EXPORT DataScopeServer : public DataScopeServerBase, public virtual POA_SALOME::DataScopeServer
129 DataScopeServer(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName);
130 DataScopeServer(const DataScopeServer& other);
131 SALOME::BasicDataServer_ptr retrieveVar(const char *varName) { return retrieveVarInternal(varName); }
132 SALOME::PickelizedPyObjRdOnlyServer_ptr createRdOnlyVar(const char *varName, const SALOME::ByteVec& constValue);
133 SALOME::PickelizedPyObjRdExtServer_ptr createRdExtVar(const char *varName, const SALOME::ByteVec& constValue);
134 SALOME::PickelizedPyObjRdWrServer_ptr createRdWrVar(const char *typeName, const char *varName);
138 class SALOMESDS_EXPORT DataScopeServerTransaction : public DataScopeServerBase, public virtual POA_SALOME::DataScopeServerTransaction
140 public://not remotely callable
141 DataScopeServerTransaction(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName);
142 DataScopeServerTransaction(const DataScopeServerTransaction& other);
143 ~DataScopeServerTransaction();
144 void createRdOnlyVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
145 void createRdExtVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
146 void createRdExtVarFreeStyleInternal(const std::string& varName, const SALOME::ByteVec& constValue, std::string&& compareFuncContent, SALOME::AutoPyRef&& compareFunc);
147 void createRdExtInitVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
148 void createRdWrVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
149 PortableServer::POA_var getPOA4KeyWaiter() const { return _poa_for_key_waiter; }
150 void addWaitKey(KeyWaiter *kw);
151 void pingKey(PyObject *keyObj);
152 void notifyKey(const std::string& varName, PyObject *keyObj, PyObject *valueObj);
153 SALOME::ByteVec *waitForMonoThrRev(SALOME::KeyWaiter_ptr kw);
154 SALOME::ByteVec *waitForAndKill(SALOME::KeyWaiter_ptr kw);
155 public://remotely callable
156 char *getAccessOfVar(const char *varName);
157 void fetchAndGetAccessOfVar(const char *varName, CORBA::String_out access, SALOME::ByteVec_out data);
158 SALOME::Transaction_ptr createRdOnlyVarTransac(const char *varName, const SALOME::ByteVec& constValue);
159 SALOME::Transaction_ptr createRdExtVarTransac(const char *varName, const SALOME::ByteVec& constValue);
160 SALOME::Transaction_ptr createRdExtVarFreeStyleTransac(const char *varName, const SALOME::ByteVec& constValue, const char *compareFuncContent);
161 SALOME::Transaction_ptr createRdExtInitVarTransac(const char *varName, const SALOME::ByteVec& constValue);
162 SALOME::Transaction_ptr createRdWrVarTransac(const char *varName, const SALOME::ByteVec& constValue);
163 SALOME::Transaction_ptr addKeyValueInVarHard(const char *varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
164 SALOME::Transaction_ptr addKeyValueInVarErrorIfAlreadyExisting(const char *varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
165 SALOME::TransactionMultiKeyAddSession_ptr addMultiKeyValueSession(const char *varName);
166 SALOME::Transaction_ptr removeKeyInVarErrorIfNotAlreadyExisting(const char *varName, const SALOME::ByteVec& key);
167 SALOME::TransactionRdWrAccess_ptr createWorkingVarTransac(const char *varName, const SALOME::ByteVec& constValue);
168 SALOME::Transaction_ptr killVarTransac(const char *varName);
169 SALOME::KeyWaiter_ptr waitForKeyInVar(const char *varName, const SALOME::ByteVec& keyVal);
170 SALOME::KeyWaiter_ptr waitForKeyInVarAndKillIt(const char *varName, const SALOME::ByteVec& keyVal, SALOME::Transaction_out transac);
171 void atomicApply(const SALOME::ListOfTransaction& transactions);
172 SALOME::RequestSwitcher_ptr getRequestSwitcher();
174 PortableServer::POA_var _poa_for_key_waiter;
175 std::list< KeyWaiter * > _waiting_keys;
176 AutoServantPtr<RequestSwitcher> _rs;