c++_api/inc/opals/IControlObject.hpp
1 #ifndef OPALS_CONTROL_OBJECT_HPP_INCLUDED
2 #define OPALS_CONTROL_OBJECT_HPP_INCLUDED
3 
4 #pragma once
5 
6 #include "opals/fwd.hpp"
7 #include "opals/String.hpp"
8 #include "opals/Vector.hpp"
9 #include "opals/LogLevel.hpp"
10 
11 namespace opals {
12 
13  /**
14  \class IControlObject
15  \brief Interface for retrieving status and progress information from a module run
16  \author jo
17  \date 06.09.2012
18 
19  \internal
20  An object that is derived from that interface can be applied to an opals module allows
21  retrieving status and progress information while executing the run function. Status information
22  is set synchronous by the modules. Attention: complex code within that the member functions (especially \see setSteps)
23  will slow down the processing performance. If the object is also accessed from a second thread, its the objects
24  responsibility to secure thread safety.
25 
26  A control object can be passed (by reference) to a OPALS module either while creating a new instance or using the
27  opals::IModuleBase::set_controlObject. It's the programmers responsibility to secure proper lifetime of the control
28  object (or use opals::IModuleBase::unset_controlObject to remove the internal link).
29 
30  To interrupt processing throw the opals::Exceptions::UserInterrupt within the overloaded member function (mainly relevant in setSteps).
31  */
32 
33  class OPALS_API IControlObject {
34  public:
35  virtual ~IControlObject() {}
36 
37  /// sets the descriptions of the stages (implicitly sets the number of stages. it will be set within the module's run function)
38  virtual void setStages(const Vector<String> &stageDescriptions) = 0;
39 
40  /// \brief sets the current stage (zero based index)
41  /// In rare situations no step information will be available for a certain stage. Usually those stages are processed quite quickly
42  virtual void setCurrStage(unsigned currentStage) = 0;
43 
44  /// \brief sets the number of steps for the current stage (will be called after the stage was set)
45  /// This function is always called before the first corresponding setCurrStep call.
46  virtual void setSteps(long long stepCount) = 0;
47 
48  /// \brief sets the current step
49  /// It is internally secured that for the last setCurrStep call currStep >= stepCount for the corresponding stage.
50  virtual void setCurrStep(long long currStep) = 0;
51 
52  /// retrieve log message
53  virtual void log(LogLevel::Type level, unsigned threadId, const char* message) = 0;
54  };
55 
56 }
57 
58 #endif //OPALS_CONTROL_OBJECT_HPP_INCLUDED