]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMESDS/SALOMESDS_Transaction.hxx
Salome HOME
Merge branch 'V8_5_BR'
[modules/kernel.git] / src / SALOMESDS / SALOMESDS_Transaction.hxx
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_TRANSACTION_HXX__
22 #define __SALOMESDS_TRANSACTION_HXX__
23
24 #include "SALOMEconfig.h"
25 #include CORBA_SERVER_HEADER(SALOME_SDS)
26
27 #include "SALOMESDS_Defines.hxx"
28 #include "SALOMESDS_Exception.hxx"
29 #include "SALOMESDS_DataServerManager.hxx"
30
31 #include <string>
32 #include <vector>
33
34 namespace SALOMESDS
35 {
36   class PickelizedPyObjServer;
37   class PickelizedPyObjRdWrServer;
38   class PickelizedPyObjRdExtServer;
39
40   class SALOMESDS_EXPORT Transaction : public virtual POA_SALOME::Transaction, public POAHolder
41   {
42   public:
43     Transaction(DataScopeServerTransaction *dsct, const std::string& varName):_dsct(dsct),_var_name(varName) { if(!_dsct) throw Exception("Transaction constructor error !"); }
44     std::string getVarName() const { return _var_name; }
45     void checkVarExisting() { _dsct->checkExistingVar(_var_name); }
46     void checkNotAlreadyExisting() { _dsct->checkNotAlreadyExistingVar(_var_name); }
47     PortableServer::POA_var getPOA() const { return _dsct->getPOA(); }
48     virtual void prepareRollBackInCaseOfFailure() = 0;
49     virtual void perform() = 0;
50     virtual void rollBack() = 0;
51     virtual void notify() = 0;
52     virtual ~Transaction();
53   public:
54     static void FromByteSeqToVB(const SALOME::ByteVec& bsToBeConv, std::vector<unsigned char>& ret);
55     static void FromVBToByteSeq(const std::vector<unsigned char>& bsToBeConv, SALOME::ByteVec& ret);
56   protected:
57     DataScopeServerTransaction *_dsct;
58     std::string _var_name;
59   };
60
61   class TransactionVarCreate : public Transaction
62   {
63   public:
64     TransactionVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue);
65     void prepareRollBackInCaseOfFailure();
66     void rollBack();
67     void notify();
68   protected:
69     std::vector<unsigned char> _data;
70   };
71
72   class TransactionRdOnlyVarCreate : public TransactionVarCreate
73   {
74   public:
75     TransactionRdOnlyVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(dsct,varName,constValue) { }
76     void perform();
77   };
78
79   class TransactionRdExtVarCreate : public TransactionVarCreate
80   {
81   public:
82     TransactionRdExtVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(dsct,varName,constValue) { }
83     void perform();
84   };
85
86   class TransactionRdExtVarFreeStyleCreate : public TransactionRdExtVarCreate
87   {
88   public:
89     TransactionRdExtVarFreeStyleCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue, const SALOME::ByteVec& sha1);
90     void prepareRollBackInCaseOfFailure();
91     void perform();
92   protected:
93     std::vector<unsigned char> _sha1;
94   };
95
96   class TransactionRdExtInitVarCreate : public TransactionVarCreate
97   {
98   public:
99     TransactionRdExtInitVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(dsct,varName,constValue) { }
100     void perform();
101   };
102
103   class TransactionRdWrVarCreate : public TransactionVarCreate
104   {
105   public:
106     TransactionRdWrVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(dsct,varName,constValue) { }
107     void perform();
108   };
109
110   class TransactionKillVar : public Transaction
111   {
112   public:
113     TransactionKillVar(DataScopeServerTransaction *dsct, const std::string& varName);
114     void prepareRollBackInCaseOfFailure();
115     void perform();
116     void rollBack();
117     void notify();
118   };
119
120   class PickelizedPyObjServer;
121
122   class TransactionDictModify : public Transaction
123   {
124   public:
125     TransactionDictModify(DataScopeServerTransaction *dsct, const std::string& varName);
126     PickelizedPyObjServer *checkVarExistingAndDict() { return _dsct->checkVarExistingAndDict(_var_name); }
127     void prepareRollBackInCaseOfFailure();
128     void rollBack();
129   protected:
130     std::string _zeDataBefore;
131     PickelizedPyObjServer *_varc;
132   };
133
134   class TransactionAddKeyValue : public TransactionDictModify
135   {
136   public:
137     TransactionAddKeyValue(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
138     void prepareRollBackInCaseOfFailure();
139     void notify();
140     ~TransactionAddKeyValue();
141   protected:
142     PyObject *_key;
143     PyObject *_value;
144   };
145
146   class TransactionAddKeyValueHard : public TransactionAddKeyValue
147   {
148   public:
149     TransactionAddKeyValueHard(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
150     void perform();
151   };
152
153   class TransactionAddKeyValueErrorIfAlreadyExisting : public TransactionAddKeyValue
154   {
155   public:
156     TransactionAddKeyValueErrorIfAlreadyExisting(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
157     void perform();
158   };
159
160   class TransactionRemoveKeyInVarErrorIfNotAlreadyExisting : public TransactionDictModify
161   {
162   public:
163     TransactionRemoveKeyInVarErrorIfNotAlreadyExisting(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key);
164     void perform();
165     void notify();
166     ~TransactionRemoveKeyInVarErrorIfNotAlreadyExisting();
167   private:
168     PyObject *_key;
169   };
170
171   class TransactionMorphRdWrIntoRdOnly : public Transaction, public virtual POA_SALOME::TransactionRdWrAccess
172   {
173   public:
174     TransactionMorphRdWrIntoRdOnly(DataScopeServerTransaction *dsct, const std::string& varName);
175   public:
176     SALOME::PickelizedPyObjRdWrServer_ptr getVar();
177   public:
178     void prepareRollBackInCaseOfFailure();
179     void perform();
180     void rollBack();
181     void notify();
182   };
183
184   /*!
185    * This transaction switch from RdExt to RdExtInit in constructor and when perform called RdExtInit to RdExt.
186    */
187   class TransactionMultiKeyAddSession : public Transaction, public virtual POA_SALOME::TransactionMultiKeyAddSession
188   {
189   public:
190     TransactionMultiKeyAddSession(DataScopeServerTransaction *dsct, const std::string& varName);
191   public://remotely callable
192     void addKeyValueInVarErrorIfAlreadyExistingNow(const SALOME::ByteVec& key, const SALOME::ByteVec& value);
193   public:
194     void prepareRollBackInCaseOfFailure();
195     void perform();
196     void rollBack();
197     void notify();
198   };
199 }
200
201 #endif