Version: 8.3.0
SALOMESDS_DataScopeServer.hxx
Go to the documentation of this file.
1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony GEAY (EDF R&D)
20 
21 #ifndef __SALOMESDS_DATASCOPEERVER_HXX__
22 #define __SALOMESDS_DATASCOPEERVER_HXX__
23 
24 #include "SALOMEconfig.h"
25 #include CORBA_SERVER_HEADER(SALOME_SDS)
26 
30 #include "SALOMESDS_Defines.hxx"
31 
32 #include <Python.h>
33 
34 #include <string>
35 #include <vector>
36 #include <list>
37 
38 namespace SALOMESDS
39 {
40  class SALOMESDS_EXPORT DataScopeKiller : public POA_SALOME::DataScopeKiller
41  {
42  public:
43  DataScopeKiller(CORBA::ORB_ptr orb):_orb(CORBA::ORB::_duplicate(orb)) { }
44  void shutdown();
45  private:
46  CORBA::ORB_var _orb;
47  };
48 
49  class KeyWaiter;
51 
52  class SALOMESDS_EXPORT DataScopeServerBase : public virtual POA_SALOME::DataScopeServerBase, public POAHolder
53  {
54  public:
55  DataScopeServerBase(CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName);
57  void ping();
58  char *getScopeName();
59  SALOME::StringVec *listVars();
60  CORBA::Boolean existVar(const char *varName);
61  SALOME::BasicDataServer_ptr retrieveVarInternal(const char *varName);
62  void deleteVar(const char *varName);
63  CORBA::Boolean shutdownIfNotHostedByDSM(SALOME::DataScopeKiller_out killer);
64  SALOME::ByteVec *fetchSerializedContent(const char *varName);
65  SALOME::SeqOfByteVec *getAllKeysOfVarWithTypeDict(const char *varName);
67  public:
68  BasicDataServer *retrieveVarInternal2(const std::string& varName);
69  void initializePython(int argc, char *argv[]);
70  void registerToSalomePiDict() const;
71  void setPOA(PortableServer::POA_var poa);
72  void registerInNS(SALOME::DataScopeServerBase_ptr ptr);
73  PyObject *getGlobals() const { return _globals; }
74  PyObject *getLocals() const { return _locals; }
75  PyObject *getPickler() const { return _pickler; }
76  PortableServer::POA_var getPOA() const { return _poa; }
77  CORBA::ORB_var getORB() { return _orb; }
78  std::string getScopeNameCpp() const { return _name; }
79  static std::string BuildTmpVarNameFrom(const std::string& varName);
80  public:
81  std::vector< std::string> getAllVarNames() const;
82  void checkNotAlreadyExistingVar(const std::string& varName) const;
83  void checkExistingVar(const std::string& varName) const;
84  PickelizedPyObjServer *checkVarExistingAndDict(const std::string& varName);
85  public:
86  void moveStatusOfVarFromRdWrToRdOnly(const std::string& varName);
87  void moveStatusOfVarFromRdOnlyToRdWr(const std::string& varName);
88  void moveStatusOfVarFromRdExtOrRdExtInitToRdExtInit(const std::string& varName);
89  void moveStatusOfVarFromRdExtOrRdExtInitToRdExt(const std::string& varName);
90  protected:
91  std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::const_iterator retrieveVarInternal3(const std::string& varName) const;
92  std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator retrieveVarInternal4(const std::string& varName);
93  protected:
94  PyObject *_globals;
95  PyObject *_locals;
96  PyObject *_pickler;
97  PortableServer::POA_var _poa;
98  CORBA::ORB_var _orb;
99  std::string _name;
100  std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > > _vars;
101  SALOME::DataScopeKiller_var _killer;
102  static std::size_t COUNTER;
103  };
104 
105  class SALOMESDS_EXPORT DataScopeServer : public DataScopeServerBase, public virtual POA_SALOME::DataScopeServer
106  {
107  public:
108  DataScopeServer(CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName);
109  DataScopeServer(const DataScopeServer& other);
110  SALOME::BasicDataServer_ptr retrieveVar(const char *varName) { return retrieveVarInternal(varName); }
111  SALOME::PickelizedPyObjRdOnlyServer_ptr createRdOnlyVar(const char *varName, const SALOME::ByteVec& constValue);
112  SALOME::PickelizedPyObjRdExtServer_ptr createRdExtVar(const char *varName, const SALOME::ByteVec& constValue);
113  SALOME::PickelizedPyObjRdWrServer_ptr createRdWrVar(const char *typeName, const char *varName);
114  ~DataScopeServer();
115  };
116 
117  class SALOMESDS_EXPORT DataScopeServerTransaction : public DataScopeServerBase, public virtual POA_SALOME::DataScopeServerTransaction
118  {
119  public://not remotely callable
120  DataScopeServerTransaction(CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName);
123  void createRdOnlyVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
124  void createRdExtVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
125  void createRdExtInitVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
126  void createRdWrVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
127  PortableServer::POA_var getPOA4KeyWaiter() const { return _poa_for_key_waiter; }
128  void addWaitKey(KeyWaiter *kw);
129  void pingKey(PyObject *keyObj);
130  void notifyKey(const std::string& varName, PyObject *keyObj, PyObject *valueObj);
131  SALOME::ByteVec *waitForMonoThrRev(SALOME::KeyWaiter_ptr kw);
132  SALOME::ByteVec *waitForAndKill(SALOME::KeyWaiter_ptr kw);
133  public://remotely callable
134  char *getAccessOfVar(const char *varName);
135  void fetchAndGetAccessOfVar(const char *varName, CORBA::String_out access, SALOME::ByteVec_out data);
136  SALOME::Transaction_ptr createRdOnlyVarTransac(const char *varName, const SALOME::ByteVec& constValue);
137  SALOME::Transaction_ptr createRdExtVarTransac(const char *varName, const SALOME::ByteVec& constValue);
138  SALOME::Transaction_ptr createRdExtInitVarTransac(const char *varName, const SALOME::ByteVec& constValue);
139  SALOME::Transaction_ptr createRdWrVarTransac(const char *varName, const SALOME::ByteVec& constValue);
140  SALOME::Transaction_ptr addKeyValueInVarHard(const char *varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
141  SALOME::Transaction_ptr addKeyValueInVarErrorIfAlreadyExisting(const char *varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
142  SALOME::TransactionMultiKeyAddSession_ptr addMultiKeyValueSession(const char *varName);
143  SALOME::Transaction_ptr removeKeyInVarErrorIfNotAlreadyExisting(const char *varName, const SALOME::ByteVec& key);
144  SALOME::TransactionRdWrAccess_ptr createWorkingVarTransac(const char *varName, const SALOME::ByteVec& constValue);
145  SALOME::Transaction_ptr killVarTransac(const char *varName);
146  SALOME::KeyWaiter_ptr waitForKeyInVar(const char *varName, const SALOME::ByteVec& keyVal);
147  SALOME::KeyWaiter_ptr waitForKeyInVarAndKillIt(const char *varName, const SALOME::ByteVec& keyVal, SALOME::Transaction_out transac);
148  void atomicApply(const SALOME::ListOfTransaction& transactions);
149  private:
150  PyObject *getPyCmpFunc();
151  private:
152  PortableServer::POA_var _poa_for_key_waiter;
153  std::list< KeyWaiter * > _waiting_keys;
154  };
155 }
156 
157 #endif