IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
BaseActionRequest.h
1 // BaseActionRequest.h:
3 // --------------------
4 //
14 
15 #ifndef __IPSDKCORE_BASEACTIONREQUEST_H__
16 #define __IPSDKCORE_BASEACTIONREQUEST_H__
17 
18 // suppression warnings
19 // warning C4275: non dll-interface class 'boost::noncopyable_::noncopyable' used as base for dll-interface class 'ipsdk::core::BaseActionRequest'
20 // warning C4251: 'ipsdk::core::BaseActionRequest::_requestCompletionCB' : class 'boost::function1<R,T0>' needs to have dll-interface to be used by clients of class 'ipsdk::core::BaseActionRequest'
21 #pragma warning (push)
22 #pragma warning (disable : 4275 4251)
23 
27 #include <IPSDKUtil/Tools/ProcessingResult.h>
28 #include <IPSDKUtil/Tools/Guid.h>
29 #include <boost/enable_shared_from_this.hpp>
30 #include <boost/noncopyable.hpp>
31 #include <boost/thread/mutex.hpp>
32 #include <boost/thread/condition_variable.hpp>
33 
34 namespace ipsdk {
35 namespace core {
36 
39 
40 class IPSDKCORE_API BaseActionRequest : public boost::noncopyable,
41  public boost::enable_shared_from_this<BaseActionRequest>
42 {
43  // friend class for protected accesses
44  friend class AskForRemoteAction;
45  friend class BaseActionProvider;
46 
47 public:
51  virtual ~BaseActionRequest() = 0;
53 
54 // methods
55 public:
57  virtual eActionRequestType getActionRequestType() const = 0;
58 
60  bool isInit() const;
61 
64  const Guid& getGuid() const;
65 
68  eExecutionStatus getStatus() const;
69 
74  void addCompletionCB(const RequestCompletionCB& completionCB);
75 
80  ExecResult executeAction();
81 
84  void requestCancellation();
85 
88  bool isCancellationRequested() const;
89 
92  void waitForCompletion();
93 
97  ExecResult getActionResult() const;
98 
104  void clear();
105 
106 protected:
113  BoolResult initBase(const Guid& requestGuid = Guid());
114 
117  virtual ExecResult executeActionDerived() = 0;
118 
120  virtual void requestCancellationDerived() = 0;
121 
123  virtual void clearDerived() {}
124 
128  void setStatusToWaiting();
129 
134  void notifyCompletion(const ExecResult& bResult);
135 
136 private:
138  void internalClear();
139 
144  void addCompletionCB(const RequestCompletionCB& completionCB,
145  bool bPushBack);
146 
147 // attributes
148 private:
150  Guid _requestGuid;
151 
153  eExecutionStatus _requestStatus;
154 
156  ExecResult _bActionResult;
157 
159  RequestCompletionCBColl _completionCBColl;
160 
162  bool volatile _bCancellationRequested;
163 
165  mutable boost::mutex _mutex;
166 
168  boost::condition_variable _condition;
169 
171  bool _bInit;
172 };
173 
176 
177 inline bool
179 {
180  return _bInit;
181 }
182 
185 
186 } // end of namespace core
187 } // end of namespace ipsdk
188 
189 #pragma warning (pop)
190 
191 #endif // __IPSDKCORE_BASEACTIONREQUEST_H__
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
bool isInit() const
retrieve object initialization flag
Definition: BaseActionRequest.h:178
virtual void clearDerived()
clear of object data in derived class
Definition: BaseActionRequest.h:123
boost::function1< void, const ActionRequestPtr & > RequestCompletionCB
function callback used to notify of action request completion
Definition: ActionRequestTypes.h:58
Base class for action requests.
Definition: BaseActionRequest.h:40
Definition of import/export macro for library.
Base class for action providers.
Definition: BaseActionProvider.h:54
#define IPSDKCORE_API
Import/Export macro for library IPSDKCore.
Definition: IPSDKCoreExports.h:27
Class encapsulating an auto initialized uuid.
Definition: Guid.h:27
Predefined types for processing management.
eActionRequestType
Enumerate describing action request type.
Definition: ActionRequestTypes.h:38
Predefined types for action resquests management.
std::list< RequestCompletionCB > RequestCompletionCBColl
collection of functions callback used to notify of action request completion
Definition: ActionRequestTypes.h:61
eExecutionStatus
Enumerate describing an execution status.
Definition: ProcessingTypes.h:33
Action allowing to ask for a new action on a distant machine.
Definition: AskForRemoteAction.h:31