CSupplierCompBase.h
Go to the documentation of this file.
1 #ifndef iproc_CSupplierCompBase_included
2 #define iproc_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 "iproc/ISupplier.h"
16 
17 
18 namespace iproc
19 {
20 
21 
27  virtual public ISupplier,
28  virtual protected ilog::IMessageConsumer
29 {
30 public:
32 
33  enum MessageId
34  {
38  MI_DURATION_TIME = 0x077a1b,
39 
45  };
46 
47  I_BEGIN_BASE_COMPONENT(CSupplierCompBase);
48  I_REGISTER_INTERFACE(ISupplier);
49  I_REGISTER_SUBELEMENT(TaskLog);
51  I_REGISTER_SUBELEMENT_INTERFACE(TaskLog, istd::IPolymorphic, ExtractTaskLog);
52  I_REGISTER_SUBELEMENT(TempMessages);
53  I_REGISTER_SUBELEMENT_INTERFACE(TempMessages, ilog::IMessageConsumer, ExtractTempMessages);
54  I_REGISTER_SUBELEMENT_INTERFACE(TempMessages, istd::IPolymorphic, ExtractTempMessages);
55  I_ASSIGN(m_diagnosticNameAttrPtr, "DiagnosticName", "Name of this supplier for diagnostic, if it is not set, no diagnostic log message will be send", false, "");
56  I_ASSIGN(m_paramsSetCompPtr, "ParamsSet", "Parameters set describing model parameter used to produce results", false, "ParamsSet");
57  I_ASSIGN_TO(m_paramsSetModelCompPtr, m_paramsSetCompPtr, false);
58  I_ASSIGN_MULTI_0(m_additionalTriggerInputsCompPtr, "AdditionalTriggerInputs", "Additional observed trigger inputs, the supplier will be invalidated if some input signal the change", false);
59  I_END_COMPONENT;
60 
62 
63  // reimplemented (iproc::ISupplier)
64  virtual int GetWorkStatus() const;
65  virtual void InvalidateSupplier();
66  virtual void EnsureWorkInitialized();
67  virtual void ClearWorkResults();
68  virtual const ilog::IMessageContainer* GetWorkMessages(int messageType) const;
69  virtual iprm::IParamsSet* GetModelParametersSet() const;
70 
71 protected:
72  class Timer
73  {
74  public:
75  Timer(const CSupplierCompBase* parentPtr, const QString& measuredFeatureName);
76  ~Timer();
77 
78  private:
80  const CSupplierCompBase* m_parentPtr;
81  QString m_measuredFeatureName;
82  };
83 
88  virtual bool InitializeWork();
89 
94  virtual void OnParametersChanged();
95 
101  virtual void RegisterSupplierInput(imod::IModel* modelPtr, ISupplier* supplierPtr = NULL);
106  virtual void UnregisterSupplierInput(imod::IModel* modelPtr);
107 
111  virtual QString GetDiagnosticName() const;
112 
116  virtual void AddMessage(const ilog::CMessage* messagePtr) const;
117 
118  // reimplemented (ilog::IMessageConsumer)
119  virtual bool IsMessageSupported(
120  int messageCategory = -1,
121  int messageId = -1,
122  const istd::IInformationProvider* messagePtr = NULL) const;
123  virtual void AddMessage(const MessagePtr& messagePtr);
124 
125  // reimplemented (icomp::CComponentBase)
126  virtual void OnComponentCreated();
127  virtual void OnComponentDestroyed();
128 
129 protected:
132 
133 private:
134  class InputsObserver: public imod::CMultiModelObserverBase
135  {
136  public:
137  InputsObserver(CSupplierCompBase* parentPtr);
138 
139  using imod::CMultiModelObserverBase::EnsureModelsDetached;
140 
141  protected:
142  // reimplemented (imod::CMultiModelObserverBase)
143  virtual void BeforeUpdate(imod::IModel* modelPtr, int updateFlags, istd::IPolymorphic* updateParamsPtr);
144 
145  CSupplierCompBase& m_parent;
146  };
147 
148  class ParamsObserver: public imod::CMultiModelObserverBase
149  {
150  public:
151  ParamsObserver(CSupplierCompBase* parentPtr);
152 
153  using imod::CMultiModelObserverBase::EnsureModelsDetached;
154 
155  protected:
156  // reimplemented (imod::CMultiModelObserverBase)
157  virtual void BeforeUpdate(imod::IModel* modelPtr, int updateFlags, istd::IPolymorphic* updateParamsPtr);
158  virtual void AfterUpdate(imod::IModel* modelPtr, int updateFlags, istd::IPolymorphic* updateParamsPtr);
159 
160  CSupplierCompBase& m_parent;
161  };
162 
163  // static template methods for subelement access
164  template <class InterfaceType>
165  static InterfaceType* ExtractTaskLog(CSupplierCompBase& component)
166  {
167  return &component;
168  }
169  template <class InterfaceType>
170 
171  static InterfaceType* ExtractTempMessages(CSupplierCompBase& component)
172  {
173  return &component.m_tempMessageContainer;
174  }
175 
176  I_ATTR(QString, m_diagnosticNameAttrPtr);
177  I_REF(iprm::IParamsSet, m_paramsSetCompPtr);
178  I_REF(imod::IModel, m_paramsSetModelCompPtr);
179  I_MULTIREF(imod::IModel, m_additionalTriggerInputsCompPtr);
180 
181  InputsObserver m_inputsObserver;
182  ParamsObserver m_paramsObserver;
183 
184  typedef QMap<imod::IModel*, ISupplier*> InputSuppliersMap;
185  InputSuppliersMap m_inputSuppliersMap;
186 
187  imod::TModelWrap<ilog::CMessageContainer> m_tempMessageContainer;
188  mutable imod::TModelWrap<ilog::CMessageContainer> m_messageContainer;
189 
190  bool m_areParametersValid;
191 };
192 
193 
194 } // namespace iproc
195 
196 
197 #endif // !iproc_CSupplierCompBase_included
198 
199 
virtual void OnParametersChanged()
Called if the supplier parameters was changed.
I_REGISTER_SUBELEMENT_INTERFACE(TaskLog, ilog::IMessageConsumer, ExtractTaskLog)
Base implementation of interface iproc::ISupplier for iproc::TSupplierCompWrap.
virtual void OnComponentDestroyed()
virtual int GetWorkStatus() const
Get status of last work.
Timer(const CSupplierCompBase *parentPtr, const QString &measuredFeatureName)
virtual QString GetDiagnosticName() const
Get supplier name used for diagnostic reasons.
The message contains product calculation time.
virtual bool IsMessageSupported(int messageCategory=-1, int messageId=-1, const istd::IInformationProvider *messagePtr=NULL) const
virtual void EnsureWorkInitialized()
Force the supplier to initialize its work.
virtual void RegisterSupplierInput(imod::IModel *modelPtr, ISupplier *supplierPtr=NULL)
Register supplier input.
Base interface for suppliers providing synchrone processing of single object with "pull data" model...
Definition: ISupplier.h:22
virtual void ClearWorkResults()
Remove all stored work results.
virtual iprm::IParamsSet * GetModelParametersSet() const
Get parameter set using by this supplier.
virtual const ilog::IMessageContainer * GetWorkMessages(int messageType) const
Get messages outputted by this work.
virtual void AddMessage(const ilog::CMessage *messagePtr) const
Add ilog::CMessage to the internal message container (also from const functions). ...
virtual void OnComponentCreated()
ilog::CLoggerComponentBase BaseClass
virtual void InvalidateSupplier()
Called to signalize that this supplier is invalid.
I_ASSIGN_TO(m_paramsSetModelCompPtr, m_paramsSetCompPtr, false)
virtual void UnregisterSupplierInput(imod::IModel *modelPtr)
Unregister supplier input.
The message describes status of the supplier results.
virtual bool InitializeWork()
Called if the new work should be initialized.
istd::CChangeNotifier m_productChangeNotifier

© 2007-2011 Witold Gantzke and Kirill Lepskiy