CSupplierCompBase.h
Go to the documentation of this file.
1 #ifndef iinsp_CSupplierCompBase_included
2 #define iinsp_CSupplierCompBase_included
3 
4 
5 // ACF includes
7 #include <imod/IModel.h>
8 #include <imod/TModelWrap.h>
10 #include <icomp/CComponentBase.h>
11 #include <ilog/TLoggerCompWrap.h>
12 #include <ilog/CMessageContainer.h>
13 
14 // ACF-Solutions includes
15 #include <iinsp/ISupplier.h>
16 
17 
18 namespace iinsp
19 {
20 
21 
27  virtual public ISupplier
28 {
29 public:
31 
36  enum MessageId
37  {
41  MI_DURATION_TIME = 0x077a1b,
42 
47 
53 
58  };
59 
60  I_BEGIN_BASE_COMPONENT(CSupplierCompBase);
61  I_REGISTER_INTERFACE(ISupplier);
62  I_REGISTER_SUBELEMENT(TaskLog);
63  I_REGISTER_SUBELEMENT_INTERFACE(TaskLog, ilog::IMessageConsumer, ExtractTaskLog);
64  I_REGISTER_SUBELEMENT_INTERFACE(TaskLog, istd::IPolymorphic, ExtractTaskLog);
65  I_REGISTER_SUBELEMENT(TempMessages);
66  I_REGISTER_SUBELEMENT_INTERFACE(TempMessages, ilog::IMessageConsumer, ExtractTempMessages);
67  I_REGISTER_SUBELEMENT_INTERFACE(TempMessages, istd::IPolymorphic, ExtractTempMessages);
68  I_ASSIGN(m_diagnosticNameAttrPtr, "DiagnosticName", "Name of this supplier for diagnostic, if it is not set, no diagnostic log message will be send", false, "");
69  I_ASSIGN(m_paramsSetCompPtr, "ParamsSet", "Parameters set describing model parameter used to produce results", false, "ParamsSet");
70  I_ASSIGN_TO(m_paramsSetModelCompPtr, m_paramsSetCompPtr, false);
71  I_ASSIGN_MULTI_0(m_additionalTriggerInputsCompPtr, "AdditionalTriggerInputs", "Additional observed trigger inputs, the supplier will be invalidated if some input signal the change", false);
72  I_END_COMPONENT;
73 
75 
76  // reimplemented (iinsp::ISupplier)
77  virtual int GetWorkStatus() const;
78  virtual imod::IModel* GetWorkStatusModel() const;
79  virtual void InvalidateSupplier();
80  virtual void EnsureWorkInitialized();
81  virtual void EnsureWorkFinished();
82  virtual void ClearWorkResults();
83  virtual const ilog::IMessageContainer* GetWorkMessages(int containerType) const;
84  virtual iprm::IParamsSet* GetModelParametersSet() const;
85 
86 protected:
87  class Timer
88  {
89  public:
90  Timer(const CSupplierCompBase* parentPtr, const QString& measuredFeatureName);
91  ~Timer();
92 
93  private:
95  const CSupplierCompBase* m_parentPtr;
96  QString m_measuredFeatureName;
97  };
98 
99  class Status: virtual public istd::IChangeable
100  {
101  public:
102  Status();
103 
104  int GetSupplierState() const;
105  void SetSupplierState(int state);
106 
107  private:
108  int m_state;
109  };
110 
112 
117  virtual bool InitializeWork();
118 
123  virtual void OnParametersChanged();
124 
134  virtual void RegisterSupplierInput(imod::IModel* modelPtr, ISupplier* supplierPtr = NULL);
139  virtual void UnregisterSupplierInput(imod::IModel* modelPtr);
140 
144  virtual QString GetDiagnosticName() const;
145 
150  virtual bool IsMessageContainerSupported(int containerType) const;
158  virtual void AddMessage(const istd::IInformationProvider* messagePtr, int containerType = MCT_RESULTS) const;
159 
160  // reimplemented (icomp::CComponentBase)
161  virtual void OnComponentCreated();
162  virtual void OnComponentDestroyed();
163 
164  // abstract methods
165  virtual int ProcessWorkOutput() = 0;
166 
169 
170 private:
171  class InputsObserver: public imod::CMultiModelObserverBase
172  {
173  public:
174  InputsObserver(CSupplierCompBase* parentPtr);
175 
177 
178  protected:
179  // reimplemented (imod::CMultiModelObserverBase)
180  virtual void BeforeUpdate(imod::IModel* modelPtr);
181 
182  CSupplierCompBase& m_parent;
183  };
184 
185  class ParamsObserver: public imod::CMultiModelObserverBase
186  {
187  public:
188  ParamsObserver(CSupplierCompBase* parentPtr);
189 
191 
192  protected:
193  // reimplemented (imod::CMultiModelObserverBase)
194  virtual void BeforeUpdate(imod::IModel* modelPtr);
195  virtual void AfterUpdate(imod::IModel* modelPtr, const istd::IChangeable::ChangeSet& changeSet);
196 
197  CSupplierCompBase& m_parent;
198  };
199 
200  // static template methods for subelement access
201  template <class InterfaceType>
202  static InterfaceType* ExtractTaskLog(CSupplierCompBase& component)
203  {
204  return &component.m_messageContainers[MCT_RESULTS];
205  }
206 
207  template <class InterfaceType>
208  static InterfaceType* ExtractTempMessages(CSupplierCompBase& component)
209  {
210  return &component.m_messageContainers[MCT_TEMP];
211  }
212 
213  I_ATTR(QString, m_diagnosticNameAttrPtr);
214  I_REF(iprm::IParamsSet, m_paramsSetCompPtr);
215  I_REF(imod::IModel, m_paramsSetModelCompPtr);
216  I_MULTIREF(imod::IModel, m_additionalTriggerInputsCompPtr);
217 
218  InputsObserver m_inputsObserver;
219  ParamsObserver m_paramsObserver;
220 
221  typedef QMap<imod::IModel*, ISupplier*> InputSuppliersMap;
222  InputSuppliersMap m_inputSuppliersMap;
223 
224  iprm::IParamsSet* m_paramsSetPtr;
225 
226  StatusModel m_workStatus;
227  int m_lastWorkState;
228  bool m_isInputValid;
229 
230  bool m_areParametersValid;
231 
232  istd::TDelPtr<istd::CChangeNotifier> m_productChangeNotifierPtr;
233 };
234 
235 
236 } // namespace iinsp
237 
238 
239 #endif // !iinsp_CSupplierCompBase_included
240 
241 
imod::TModelWrap< Status > StatusModel
The message describes status of the supplier results.
virtual void OnComponentDestroyed()
virtual void InvalidateSupplier()
Called to signalize that this supplier is invalid.
virtual void EnsureWorkFinished()
Ensure that all objects are produced.
virtual bool IsMessageContainerSupported(int containerType) const
Check if message container is supported.
Base implementation of interface iinsp::ISupplier for iinsp::TSupplierCompWrap.
ilog::CLoggerComponentBase BaseClass
The message describes main geometrical result.
virtual void OnParametersChanged()
Called if the supplier parameters was changed.
virtual void OnComponentCreated()
virtual void ClearWorkResults()
Remove all stored work results.
imod::TModelWrap< ilog::CMessageContainer > MessageContainer
virtual int ProcessWorkOutput()=0
virtual imod::IModel * GetWorkStatusModel() const
Get access to the status model of the supplier.
Timer(const CSupplierCompBase *parentPtr, const QString &measuredFeatureName)
virtual QString GetDiagnosticName() const
Get supplier name used for diagnostic reasons.
virtual bool InitializeWork()
Called if the new work should be initialized.
MessageContainer m_messageContainers[MTC_LAST+1]
virtual const ilog::IMessageContainer * GetWorkMessages(int containerType) const
Get messages outputted by this work.
Base interface for suppliers providing calculating of objects on demand ("pull data" model)...
Definition: ISupplier.h:22
The message contains product calculation time.
virtual iprm::IParamsSet * GetModelParametersSet() const
Get parameter set using by this supplier.
virtual void UnregisterSupplierInput(imod::IModel *modelPtr)
Unregister supplier input.
virtual void EnsureWorkInitialized()
Force the supplier to initialize its work.
virtual void AddMessage(const istd::IInformationProvider *messagePtr, int containerType=MCT_RESULTS) const
Add ilog::CMessage to the internal message container (also from const functions). ...
virtual void RegisterSupplierInput(imod::IModel *modelPtr, ISupplier *supplierPtr=NULL)
Register supplier input.
virtual int GetWorkStatus() const
Get status of last work.

© 2007-2017 Witold Gantzke and Kirill Lepskiy