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