ifw-ccf  1.0.0
recipeBase.hpp
Go to the documentation of this file.
1 
5 #ifndef CCF_COMMON_RECIPE_BASE_HPP_H_
6 #define CCF_COMMON_RECIPE_BASE_HPP_H_
7 
8 #include <ccf/common/base.hpp>
10 #include <ccf/common/dataFrame.hpp>
11 
12 #include <cpl.h>
13 #include <clipm.h>
14 
15 namespace ccf::common {
16 
18  // @{
19  const std::string SETUP_KEY_RECIPE_ENABLED = "proc%d.recipe%d.enabled";
20  const std::string SETUP_KEY_RECIPE_BASE_DELAY = "proc%d.recipe%d.recipe_base.delay";
21  // @}
22 
24  template <class SRC_IM_TYPE, class TRG_IM_TYPE>
25  void ConvertImage(SRC_IM_TYPE* image_buffer,
26  uint32_t pixels,
27  TRG_IM_TYPE** target_buf,
28  uint32_t* target_buf_size) {
29  CCFTRACE;
30  *target_buf_size = (pixels * sizeof(TRG_IM_TYPE));
31  *target_buf = (TRG_IM_TYPE*)malloc(*target_buf_size);
32  ccf::common::AssertPtr(target_buf, "CPL Image Tmp Buffer", CCFLOC);
33  SRC_IM_TYPE* im_ptr = image_buffer;
34  TRG_IM_TYPE* target_buf_ptr = *target_buf;
35  for (uint32_t n = 0; n < pixels; n++) {
36  *target_buf_ptr++ = static_cast<TRG_IM_TYPE>(*im_ptr++);
37  }
38  }
39 
42  void PrepCplImage(const ccf::common::DataFrame& frame,
43  cpl_image** image,
44  ccf::common::ImageDataType* target_data_type,
45  uint32_t* target_buffer_size);
46 
47 
49  class RecipeBase: public Base {
50  public:
51 
53  static const std::string& GenId(const uint16_t proc_thread_nb,
54  const uint16_t recipe_nb);
55 
57  static void AddRecipeFactoryObj(RecipeBase& recipe_factory_obj);
58 
60  static void GetRecipeFactoryObjs(std::vector<RecipeBase*>& recipe_factory_objs);
61 
66  static void CreateRecipeObj(const std::string& class_name,
67  const uint16_t proc_thread_nb,
68  const uint16_t recipe_nb,
69  const std::string recipe_name,
70  RecipeBase** new_obj);
71 
76  static void GetRecipeObj(const uint16_t proc_thread_nb,
77  const uint16_t recipe_nb,
78  RecipeBase** recipe_obj,
79  const bool initialise = true);
80 
82  static void GetRecipeObjs(std::vector<RecipeBase*>& recipe_objs);
83 
85  static bool HasRecipeObj(const uint16_t proc_thread_nb,
86  const uint16_t recipe_nb,
87  RecipeBase** recipe_obj);
88 
91  static void FreeRecipeObjs();
92 
95  static void FreeRecipeFactoryObjs();
96 
98  RecipeBase(const uint16_t proc_thread_nb,
99  const uint16_t recipe_nb,
100  const std::string& recipe_name);
101 
102  RecipeBase();
103 
104  virtual ~RecipeBase();
105 
107  void Initialise();
108 
110  virtual void InitialiseUser();
111 
113  bool GetInitialised() const;
114 
116  const std::string& GetRecipeId() const;
117 
119  const std::string& GetRecipeName() const;
120 
122  uint16_t GetProcThreadNb() const;
123 
125  uint16_t GetRecipeNb() const;
126 
128  const std::string& GetDbPath() const;
129 
131  const std::string& GetKeyPrefix() const;
132 
134  const std::string GenKey(const std::string& name) const;
135 
137  void Process(DataFrame& frame);
138 
139  // /// Set the enabled status flag of the recipe object.
140  // void SetEnabled(const bool enabled);
141 
142  // /// Disable the recipe so that it will not be invoked.
143  // void DisableRecipe();
144 
146  void Enable();
147 
150  virtual void EnableUser();
151 
153  void Disable();
154 
157  virtual void DisableUser();
158 
160  bool GetEnabled() const;
161 
163  virtual void ProcessUser(DataFrame& frame);
164 
166  virtual void CreateObjectUser(const uint16_t proc_thread_nb,
167  const uint16_t recipe_nb,
168  const std::string& recipe_name,
169  RecipeBase** new_object);
170 
172  void SetStatus(const ProcStatus status);
173 
175  ProcStatus GetStatus() const;
176 
177  // TODO: Consider to add.
178  // RecipeBase& SetRecipePar(const ctd::param::Parameter& recipe_par);
179  // bool HasRecipePar(const std::string& par_name,
180  // ctd::param::Parameter** recipe_par);
181  // RecipeBase& ClearRecipePars();
182 
183  // TODO: Add:
184  // void ResetDbStatus() const;
185  // void UpdateDbStatus() const;
186  // std::string ToString() const;
187  // void Dismantle();
188  // virtual void DismantleUser();
189 
190  // TODO: Add + invoke when a setup command is received.
191  // void HandleSetup();
192  // void HandleSetupUser();
193 
194  protected:
195 
197  void SetEnabled(const bool enabled);
198 
200  void DisableRecipe();
201 
202  private:
203  static std::map<std::string, RecipeBase*> s_recipe_factory_objects;
204  static std::map<std::string, RecipeBase*> s_recipe_objects;
205  static bool s_cpl_initialised;
206 
207  bool m_initialised;
208  bool m_enabled;
209  double m_delay;
210 
211  std::string m_recipe_id;
212  std::string m_recipe_name;
213  uint16_t m_proc_thread_nb;
214  uint16_t m_recipe_nb;
215 
216  //std::map<std::string, ctd::param::Parameter> m_recipe_pars;
217 
218  // TODO: Check if m_recipe_properties needed.
219  //std::map<std::string, ctd::param::Parameter> m_recipe_properties;
220 
221  ProcStatus m_recipe_status;
222 
223  std::string m_db_base_name;
224  std::string m_key_prefix;
225  };
226 
227 }
228 
229 #endif // CCF_COMMON_RECIPE_BASE_HPP_H_
ccf::common::ImageDataType
ImageDataType
CCF image data types. Based on the values defined for BITPIX in the FITS standard.
Definition: base.hpp:153
ccf::common::RecipeBase::GetInitialised
bool GetInitialised() const
Return flag indicating if the recipe object has been initialised.
Definition: recipeBase.cpp:249
ccf::common::RecipeBase::FreeRecipeFactoryObjs
static void FreeRecipeFactoryObjs()
Definition: recipeBase.cpp:146
ccf::common::RecipeBase::SetStatus
void SetStatus(const ProcStatus status)
Update status for a given Publisher Thread in the OLDB.
Definition: recipeBase.cpp:374
ccf::common::RecipeBase::GetRecipeNb
uint16_t GetRecipeNb() const
Return the number of the Recipe to.
Definition: recipeBase.cpp:207
ccf::common::RecipeBase::Process
void Process(DataFrame &frame)
Execute the processing of the given frame.
Definition: recipeBase.cpp:278
ccf::common::SETUP_KEY_RECIPE_ENABLED
const std::string SETUP_KEY_RECIPE_ENABLED
Definition: recipeBase.hpp:19
ccf::common::RecipeBase::GetKeyPrefix
const std::string & GetKeyPrefix() const
Get the key prefix for this recipe, e.g. "proc1.recipe1".
Definition: recipeBase.cpp:239
ccf::common::RecipeBase::GetRecipeObj
static void GetRecipeObj(const uint16_t proc_thread_nb, const uint16_t recipe_nb, RecipeBase **recipe_obj, const bool initialise=true)
Definition: recipeBase.cpp:76
ccf::common::RecipeBase::GetRecipeName
const std::string & GetRecipeName() const
Get the name of the recipe.
Definition: recipeBase.cpp:202
ccf::common::Base
Class to be used as parent all CCF classes.
Definition: base.hpp:93
ccf::common::RecipeBase::Disable
void Disable()
Disable the recipe so that it will no longer be invoked by the Processing Thread to which it belongs.
Definition: recipeBase.cpp:325
ccf::common::RecipeBase::Initialise
void Initialise()
Initalise the object. Invoked after creating a new object from the factory object.
Definition: recipeBase.cpp:217
ccf::common::RecipeBase::GetRecipeFactoryObjs
static void GetRecipeFactoryObjs(std::vector< RecipeBase * > &recipe_factory_objs)
Statis method to retrieve references to the Recipe Factory Objects.
Definition: recipeBase.cpp:46
ccf::common::RecipeBase::RecipeBase
RecipeBase()
Definition: recipeBase.cpp:179
CCFLOC
#define CCFLOC
Macro generating a location identifier: "<file>:<line>:<function>:<thread>".
Definition: base.hpp:292
ccf::common::RecipeBase::DisableRecipe
void DisableRecipe()
Disable the recipe so that it will not be invoked.
Definition: recipeBase.cpp:267
ccf::common::PrepCplImage
void PrepCplImage(const ccf::common::DataFrame &frame, cpl_image **image, ccf::common::ImageDataType *target_data_type, uint32_t *target_buffer_size)
Definition: recipeBase.cpp:392
setupBase.hpp
ccf::common::RecipeBase::GenKey
const std::string GenKey(const std::string &name) const
Generate a fully qualified key name, e.g. "proc1.recipe1.par".
Definition: recipeBase.cpp:244
ccf::common::RecipeBase::FreeRecipeObjs
static void FreeRecipeObjs()
Definition: recipeBase.cpp:133
ccf::common::AssertPtr
void AssertPtr(const void *ptr, const std::string &object, const std::string &location)
Check that pointer is not NULL and raise rad::exception in case it is.
Definition: base.cpp:49
ccf::common::RecipeBase::EnableUser
virtual void EnableUser()
Definition: recipeBase.cpp:320
ccf::common::RecipeBase::GetDbPath
const std::string & GetDbPath() const
Get the reference to the DB base path for ths recipe.
Definition: recipeBase.cpp:234
ccf::common::RecipeBase::~RecipeBase
virtual ~RecipeBase()
Definition: recipeBase.cpp:193
ccf::common::RecipeBase::HasRecipeObj
static bool HasRecipeObj(const uint16_t proc_thread_nb, const uint16_t recipe_nb, RecipeBase **recipe_obj)
Check if a Proc Recipe object is defined.
Definition: recipeBase.cpp:100
dataFrame.hpp
ccf::common::RecipeBase::DisableUser
virtual void DisableUser()
Definition: recipeBase.cpp:333
ccf::common::ProcStatus
ProcStatus
Possible states for a Processing Recipe defined.
Definition: base.hpp:191
ccf::common::RecipeBase::CreateRecipeObj
static void CreateRecipeObj(const std::string &class_name, const uint16_t proc_thread_nb, const uint16_t recipe_nb, const std::string recipe_name, RecipeBase **new_obj)
Definition: recipeBase.cpp:57
ccf::common::RecipeBase::AddRecipeFactoryObj
static void AddRecipeFactoryObj(RecipeBase &recipe_factory_obj)
Static method to register a Data Publisher factory object in the internal registry.
Definition: recipeBase.cpp:26
base.hpp
ccf::common
Definition: appBase.cpp:8
ccf::common::RecipeBase::ProcessUser
virtual void ProcessUser(DataFrame &frame)
User specific processing.
Definition: recipeBase.cpp:292
ccf::common::ConvertImage
void ConvertImage(SRC_IM_TYPE *image_buffer, uint32_t pixels, TRG_IM_TYPE **target_buf, uint32_t *target_buf_size)
Convert the given image from one pixel type to another. A buffer is allocated internally,...
Definition: recipeBase.hpp:25
ccf::common::RecipeBase::GetRecipeObjs
static void GetRecipeObjs(std::vector< RecipeBase * > &recipe_objs)
Get reference to all Processing Recipe objects registered.
Definition: recipeBase.cpp:120
ccf::common::RecipeBase::GetRecipeId
const std::string & GetRecipeId() const
Get the ID of the recipe.
Definition: recipeBase.cpp:197
ccf::common::RecipeBase::GetProcThreadNb
uint16_t GetProcThreadNb() const
Return the number of the Processing Thread to which this recipe object belongs.
Definition: recipeBase.cpp:212
ccf::common::RecipeBase::GetStatus
ProcStatus GetStatus() const
Get status of the recipe object.
Definition: recipeBase.cpp:387
ccf::common::RecipeBase
Processing Recipe base class. All recipes shall be derived from this class.
Definition: recipeBase.hpp:49
ccf::common::RecipeBase::InitialiseUser
virtual void InitialiseUser()
Initialise the recipe object. See "Initialise()".
Definition: recipeBase.cpp:254
CCFTRACE
#define CCFTRACE
TRACE log macro. Includes the location ("CCFLOC") in the log message.
Definition: base.hpp:403
ccf::common::RecipeBase::GenId
static const std::string & GenId(const uint16_t proc_thread_nb, const uint16_t recipe_nb)
Generate the ID for this recipe from the Processing Thread and Recipe number.
Definition: recipeBase.cpp:14
ccf::common::RecipeBase::CreateObjectUser
virtual void CreateObjectUser(const uint16_t proc_thread_nb, const uint16_t recipe_nb, const std::string &recipe_name, RecipeBase **new_object)
Instantiate a specific instance of the object.
Definition: recipeBase.cpp:298
ccf::common::RecipeBase::GetEnabled
bool GetEnabled() const
Return the enabled status of the recipe.
Definition: recipeBase.cpp:273
ccf::common::DataFrame
Frame class used to store the data and metadata for one frames received from the camera.
Definition: dataFrame.hpp:15
ccf::common::SETUP_KEY_RECIPE_BASE_DELAY
const std::string SETUP_KEY_RECIPE_BASE_DELAY
Definition: recipeBase.hpp:20
ccf::common::RecipeBase::Enable
void Enable()
Enable the recipe so that it will be invoked by the Processing Thread to which it belongs.
Definition: recipeBase.cpp:308
ccf::common::RecipeBase::SetEnabled
void SetEnabled(const bool enabled)
Set the enabled status flag of the recipe object.
Definition: recipeBase.cpp:261