]> SALOME platform Git repositories - modules/yacs.git/blob - src/SALOMESDS/SALOMESDS_Transaction.hxx
Salome HOME
Implementation of producer/consumer mechanism and transaction mechanism for global...
[modules/yacs.git] / src / SALOMESDS / SALOMESDS_Transaction.hxx
1 // Copyright (C) 2007-2015  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
38   class SALOMESDS_EXPORT Transaction : public virtual POA_SALOME::Transaction, public POAHolder
39   {
40   public:
41     Transaction(DataScopeServerTransaction *dsct, const std::string& varName):_dsct(dsct),_var_name(varName) { if(!_dsct) throw Exception("Transaction constructor error !"); }
42     std::string getVarName() const { return _var_name; }
43     void checkVarExisting() { _dsct->checkExistingVar(_var_name); }
44     void checkNotAlreadyExisting() { _dsct->checkNotAlreadyExistingVar(_var_name); }
45     PortableServer::POA_var getPOA() const { return _dsct->getPOA(); }
46     virtual void prepareRollBackInCaseOfFailure() = 0;
47     virtual void perform() = 0;
48     virtual void rollBack() = 0;
49     virtual void notify() = 0;
50     virtual ~Transaction();
51   public:
52     static void FromByteSeqToVB(const SALOME::ByteVec& bsToBeConv, std::vector<unsigned char>& ret);
53     static void FromVBToByteSeq(const std::vector<unsigned char>& bsToBeConv, SALOME::ByteVec& ret);
54   protected:
55     DataScopeServerTransaction *_dsct;
56     std::string _var_name;
57   };
58
59   class TransactionVarCreate : public Transaction
60   {
61   public:
62     TransactionVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue);
63     void prepareRollBackInCaseOfFailure();
64     void rollBack();
65     void notify();
66   protected:
67     std::vector<unsigned char> _data;
68   };
69
70   class TransactionRdOnlyVarCreate : public TransactionVarCreate
71   {
72   public:
73     TransactionRdOnlyVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(dsct,varName,constValue) { }
74     void perform();
75   };
76
77   class TransactionRdExtVarCreate : public TransactionVarCreate
78   {
79   public:
80     TransactionRdExtVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(dsct,varName,constValue) { }
81     void perform();
82   };
83
84   class TransactionRdWrVarCreate : public TransactionVarCreate
85   {
86   public:
87     TransactionRdWrVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(dsct,varName,constValue) { }
88     void perform();
89   };
90
91   class PickelizedPyObjServer;
92
93   class TransactionDictModify : public Transaction
94   {
95   public:
96     TransactionDictModify(DataScopeServerTransaction *dsct, const std::string& varName);
97     PickelizedPyObjServer *checkVarExistingAndDict() { return _dsct->checkVarExistingAndDict(_var_name); }
98     void prepareRollBackInCaseOfFailure();
99     void rollBack();
100   protected:
101     std::string _zeDataBefore;
102     PickelizedPyObjServer *_varc;
103   };
104
105   class TransactionAddKeyValue : public TransactionDictModify
106   {
107   public:
108     TransactionAddKeyValue(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
109     void prepareRollBackInCaseOfFailure();
110     void notify();
111     ~TransactionAddKeyValue();
112   protected:
113     PyObject *_key;
114     PyObject *_value;
115   };
116
117   class TransactionAddKeyValueHard : public TransactionAddKeyValue
118   {
119   public:
120     TransactionAddKeyValueHard(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
121     void perform();
122   };
123
124   class TransactionAddKeyValueErrorIfAlreadyExisting : public TransactionAddKeyValue
125   {
126   public:
127     TransactionAddKeyValueErrorIfAlreadyExisting(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
128     void perform();
129   };
130
131   class TransactionRemoveKeyInVarErrorIfNotAlreadyExisting : public TransactionDictModify
132   {
133   public:
134     TransactionRemoveKeyInVarErrorIfNotAlreadyExisting(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key);
135     void perform();
136     void notify();
137     ~TransactionRemoveKeyInVarErrorIfNotAlreadyExisting();
138   private:
139     PyObject *_key;
140   };
141 }
142
143 #endif