Salome HOME
Transaction management in operations modifed.
[modules/gui.git] / src / SUIT / SUIT_Operation.h
1 /**
2 *  SALOME SalomeApp
3 *
4 *  Copyright (C) 2005  CEA/DEN, EDF R&D
5 *
6 *
7 *
8 *  File   : SUIT_Operation.h
9 *  Author : Unknown
10 *  Module : SALOME
11 */
12
13 #ifndef SUIT_OPERATION_H
14 #define SUIT_OPERATION_H
15
16 #include <qobject.h>
17
18 #include "SUIT.h"
19
20 class SUIT_Study;
21 class SUIT_Application;
22
23 /*!
24  * \brief Base class for all operations
25  *
26  *  Base class for all operations. If you perform an action it is reasonable to create
27  *  operation intended for this. This is a base class for all operations which provides
28  *  mechanism for correct starting operations, starting operations above already started
29  *  ones, committing operations and so on. To create own operation it is reasonable to
30  *  inherit it from this class and redefines virtual methods to provide own behavior
31  *  Main virtual methods are
32  *  - virtual bool      isReadyToStart();
33  *  - virtual void      startOperation();
34  *  - virtual void      abortOperation();
35  *  - virtual void      commitOperation();
36  *  - virtual void      resumeOperation();
37  *  - virtual void      suspendOperation();
38 */
39 class SUIT_EXPORT SUIT_Operation : public QObject
40 {
41   Q_OBJECT
42
43 public:
44   /*! Enum describes state of operation */
45   enum OperationState
46   {
47     Waiting,  //!< Operation is not used (it is not run or suspended)
48     Running,  //!< Operation is started
49     Suspended //!< Operation is started but suspended (other operation is performed above it)
50   };
51
52   /*!
53   * Enum describes execution status of operation. Execution status often used after
54   * ending work of operation which was started from this one. In this case this
55   * operation can ask previously started operation whether it finished successfully.
56   */
57   enum ExecStatus
58   {
59     Rejected, //!< Operation has not performed any action (modification of data model for example)
60     Accepted  //!< Operation has performed an actions and must be stopped
61   };
62
63   /*!
64   * Enum describes setting of the operation.
65   */
66   enum Flags
67   {
68     None        = 0x00, //!< None options
69     Transaction = 0x01  //!< Automatically open (commit/abort) transaction during start (commit/abort).
70   };
71
72 public:
73   SUIT_Operation( SUIT_Application* );
74   virtual ~SUIT_Operation();
75
76   OperationState    state() const;
77   bool              isActive() const;
78   bool              isRunning() const;
79
80   SUIT_Study*       study() const;
81   virtual void      setStudy( SUIT_Study* theStudy );
82   
83   SUIT_Application* application() const;
84   virtual void      setApplication( SUIT_Application* theApp );
85
86   virtual bool      isValid( SUIT_Operation* theOtherOp ) const;
87   virtual bool      isGranted() const;
88
89   bool              setSlot( const QObject* theReceiver, const char* theSlot );
90
91   void              setFlags( const int );
92   void              clearFlags( const int );
93   bool              testFlags( const int ) const;
94
95   virtual QString   operationName() const;
96
97 signals:
98   void              started( SUIT_Operation* );
99   void              aborted( SUIT_Operation* );
100   void              committed( SUIT_Operation* );
101
102   void              stopped( SUIT_Operation* );
103   void              resumed( SUIT_Operation* );
104   void              suspended( SUIT_Operation* );
105
106   void              callSlot();
107
108 public slots:
109   void              start();
110   void              abort();
111   void              commit();
112   void              resume();
113   void              suspend();
114
115 protected:
116   virtual bool      isReadyToStart() const;
117
118   virtual void      stopOperation();
119   virtual void      startOperation();
120   virtual void      abortOperation();
121   virtual void      commitOperation();
122   virtual void      resumeOperation();
123   virtual void      suspendOperation();
124
125   virtual bool      openTransaction();
126   virtual bool      abortTransaction();
127   virtual bool      hasTransaction() const;
128   virtual bool      commitTransaction( const QString& = QString::null );
129
130   int               execStatus() const;
131   void              setExecStatus( const int );
132
133   void              setState( const OperationState );
134
135   void              start( SUIT_Operation*, const bool = false );
136
137 private:
138   SUIT_Application* myApp;        //!< application for this operation
139   int               myFlags;      //!< operation flags
140   SUIT_Study*       myStudy;      //!< study for this operation
141   OperationState    myState;      //!< Operation state
142   ExecStatus        myExecStatus; //!< Execution status
143
144   friend class SUIT_Study;
145 };
146
147 #endif