ifw-ccf 6.0.0
 
Loading...
Searching...
No Matches
recipeBase.hpp
Go to the documentation of this file.
1
6
7#ifndef CCF_COMMON_RECIPE_BASE_HPP_H_
8#define CCF_COMMON_RECIPE_BASE_HPP_H_
9
10#include <cpl.h>
11#include <ifw/odp/clipm/clipm.h>
12
14#include <ifw/ccf/common/db.hpp>
17
18
19namespace ifw::ccf::common {
20
23 template <class SRC_IM_TYPE, class TRG_IM_TYPE>
24 void ConvertImage(SRC_IM_TYPE* image_buffer,
25 uint32_t pixels,
26 TRG_IM_TYPE** target_buf,
27 uint32_t* target_buf_size) {
28 LOG4CPLUS_TRACE_METHOD(Logger(), __PRETTY_FUNCTION__);
29 *target_buf_size = (pixels * sizeof(TRG_IM_TYPE));
30 *target_buf = static_cast<TRG_IM_TYPE*>(malloc(*target_buf_size));
31 ifw::ccf::AssertPtr(target_buf, "CPL Image Tmp Buffer", IFWLOC);
32 SRC_IM_TYPE* im_ptr = image_buffer;
33 TRG_IM_TYPE* target_buf_ptr = *target_buf;
34 for (uint32_t n = 0; n < pixels; n++) {
35 *target_buf_ptr++ = static_cast<TRG_IM_TYPE>(*im_ptr++);
36 }
37 }
38
43 cpl_image** image,
44 ifw::fnd::datatype::DataType* 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 std::string& proc_thread_name,
54 const std::string& recipe_name);
55
57 template <class TYPE>
58 static void AddRecipeFactoryObj(TYPE& recipe_factory_obj) {
59 LOG4CPLUS_TRACE_METHOD(Logger(), __PRETTY_FUNCTION__);
60
61 if (recipe_factory_obj.GetClassName() == "") {
62 CCFTHROW("Must define a classname for a Processing Recipe Plug-In");
63 }
64
65 BEGIN_CRIT_SEC("ifw::ccf::common::RecipeBase") {
66 if (s_recipe_factory_objects.find(recipe_factory_obj.GetClassName()) !=
67 s_recipe_factory_objects.end()) {
68 CCFTHROW(fmt::format("Factory object with classname: {} already exists",
69 recipe_factory_obj.GetClassName()));
70 }
71 LOG4CPLUS_INFO(Logger(), "Registering Processing Recipe factory object. Classname: " <<
72 recipe_factory_obj.GetClassName());
73 s_recipe_factory_objects[recipe_factory_obj.GetClassName()] = std::make_shared<TYPE>();
74 } END_CRIT_SEC();
75
76 }
77
79 static const std::map<std::string, std::shared_ptr<RecipeBase>>& GetRecipeFactoryObjs();
80
86 static void CreateRecipeObj(const std::string& class_name,
87 const std::string& proc_thread_name,
88 const std::string& recipe_name,
89 std::shared_ptr<RecipeBase>& new_obj);
90
95 static void GetRecipeObj(const std::string& class_name,
96 const std::string& proc_thread_name,
97 std::shared_ptr<RecipeBase>& recipe_obj,
98 const bool initialise = true);
99
101 static const std::map<std::string, std::shared_ptr<RecipeBase>>& GetRecipeObjs();
102
104 static bool HasRecipeObj(const std::string& class_name,
105 const std::string& proc_thread_name,
106 std::shared_ptr<RecipeBase>& recipe_obj);
107
110 // static void FreeRecipeObjs();
111
114 // static void FreeRecipeFactoryObjs();
115
118 RecipeBase(const std::string& proc_thread_name,
119 const std::string& recipe_name);
120
121 RecipeBase();
122
123 virtual ~RecipeBase();
124
126 void Initialise();
127
129 virtual void InitialiseUser();
130
132 bool GetInitialised() const;
133
135 const std::string& GetRecipeId() const;
136
138 const std::string& GetProcThreadName() const;
139
141 const std::string& GetRecipeName() const;
142
144 const std::string& GetDbPath() const;
145
147 void Process(DataFrame& frame);
148
150 void Enable();
151
154 virtual void EnableUser();
155
158 void Disable();
159
162 virtual void DisableUser();
163
165 bool GetEnabled() const;
166
168 virtual void ProcessUser(DataFrame& frame);
169
171 virtual void CreateObjectUser(const std::string& proc_thread_name,
172 const std::string& recipe_name,
173 std::shared_ptr<RecipeBase>& new_object);
174
176 void SetStatus(const ProcStatus status);
177
179 ProcStatus GetStatus() const;
180
181 // TODO: Add:
182 // void ResetDbStatus() const;
183 // void UpdateDbStatus() const;
184 // std::string ToString() const;
185 // void Dismantle();
186 // virtual void DismantleUser();
187
190 void HandleSetup();
191
193 virtual void HandleSetupUser();
194
195 protected:
196
198 void SetEnabled(const bool enabled);
199
201 void DisableRecipe();
202
203 private:
204 static std::map<std::string, std::shared_ptr<RecipeBase>> s_recipe_factory_objects;
205 static std::map<std::string, std::shared_ptr<RecipeBase>> s_recipe_objects;
206 static bool s_cpl_initialised;
207
208 bool m_initialised;
209 bool m_enabled;
210 double m_delay;
211
212 std::string m_recipe_id;
213 std::string m_recipe_name;
214 std::string m_proc_thread_name;
215
216 ProcStatus m_recipe_status;
217
218 std::string m_db_base_name;
219 };
220
221}
222
223#endif // CCF_COMMON_RECIPE_BASE_HPP_H_
#define CCFTHROW(msg)
Definition base.hpp:399
Base()
Definition base.cpp:121
Frame class used to store the data and metadata for one frames received from the camera.
Definition dataFrame.hpp:20
const std::string & GetRecipeId() const
Get the ID of the recipe.
Definition recipeBase.cpp:137
static void GetRecipeObj(const std::string &class_name, const std::string &proc_thread_name, std::shared_ptr< RecipeBase > &recipe_obj, const bool initialise=true)
Definition recipeBase.cpp:52
virtual void CreateObjectUser(const std::string &proc_thread_name, const std::string &recipe_name, std::shared_ptr< RecipeBase > &new_object)
Instantiate a specific instance of the object.
Definition recipeBase.cpp:232
static const std::string & GenId(const std::string &proc_thread_name, const std::string &recipe_name)
Generate the ID for this recipe from the Processing Thread and Recipe number.
Definition recipeBase.cpp:16
void Process(DataFrame &frame)
Execute the processing of the given frame.
Definition recipeBase.cpp:207
void Initialise()
Initalise the object. Invoked after creating a new object from the factory object.
Definition recipeBase.cpp:147
void DisableRecipe()
Disable the recipe so that it will not be invoked.
Definition recipeBase.cpp:196
bool GetEnabled() const
Return the enabled status of the recipe.
Definition recipeBase.cpp:202
void Disable()
Definition recipeBase.cpp:256
static void AddRecipeFactoryObj(TYPE &recipe_factory_obj)
Static method to register a Data Publisher factory object in the internal registry.
Definition recipeBase.hpp:58
static bool HasRecipeObj(const std::string &class_name, const std::string &proc_thread_name, std::shared_ptr< RecipeBase > &recipe_obj)
Check if a Proc Recipe object is defined.
Definition recipeBase.cpp:76
static const std::map< std::string, std::shared_ptr< RecipeBase > > & GetRecipeObjs()
Get reference to all Processing Recipe objects registered.
Definition recipeBase.cpp:96
virtual void HandleSetupUser()
User-specific setup handling. Override in derived classes to perform custom reset logic.
Definition recipeBase.cpp:276
void SetEnabled(const bool enabled)
Set the enabled status flag of the recipe object.
Definition recipeBase.cpp:190
RecipeBase(const std::string &proc_thread_name, const std::string &recipe_name)
Definition recipeBase.cpp:101
void HandleSetup()
Definition recipeBase.cpp:270
void Enable()
Enable the recipe so that it will be invoked by the Processing Thread to which it belongs.
Definition recipeBase.cpp:239
static const std::map< std::string, std::shared_ptr< RecipeBase > > & GetRecipeFactoryObjs()
Statis method to retrieve references to the Recipe Factory Objects.
Definition recipeBase.cpp:28
const std::string & GetDbPath() const
Generate DB path for this recipe.
Definition recipeBase.cpp:173
bool GetInitialised() const
Return flag indicating if the recipe object has been initialised.
Definition recipeBase.cpp:178
const std::string & GetRecipeName() const
Get the name of the recipe.
Definition recipeBase.cpp:142
void SetStatus(const ProcStatus status)
Update status for a given Publisher Thread in the OLDB.
Definition recipeBase.cpp:281
virtual void InitialiseUser()
Initialise the recipe object. See "Initialise()".
Definition recipeBase.cpp:183
ProcStatus GetStatus() const
Get status of the recipe object.
Definition recipeBase.cpp:293
const std::string & GetProcThreadName() const
Get the name of the Processing Thread, hosting the Recipe instance.
Definition recipeBase.cpp:227
static void CreateRecipeObj(const std::string &class_name, const std::string &proc_thread_name, const std::string &recipe_name, std::shared_ptr< RecipeBase > &new_obj)
Definition recipeBase.cpp:33
virtual void DisableUser()
Definition recipeBase.cpp:265
virtual ~RecipeBase()
Definition recipeBase.cpp:133
virtual void EnableUser()
Definition recipeBase.cpp:251
RecipeBase()
Definition recipeBase.cpp:120
virtual void ProcessUser(DataFrame &frame)
User specific processing.
Definition recipeBase.cpp:221
Definition appBase.cpp:10
void ConvertImage(SRC_IM_TYPE *image_buffer, uint32_t pixels, TRG_IM_TYPE **target_buf, uint32_t *target_buf_size)
Definition recipeBase.hpp:24
void PrepCplImage(const ifw::ccf::common::DataFrame &frame, cpl_image **image, ifw::fnd::datatype::DataType *target_data_type, uint32_t *target_buffer_size)
Definition recipeBase.cpp:298
log4cplus::Logger & Logger()
Definition base.cpp:24
ProcStatus
Possible states for a Processing Recipe defined.
Definition base.hpp:198
void AssertPtr(const void *ptr, const std::string &object, const std::string &location)
Check that pointer is not nullptr and raise rad::exception in case it is.
Definition base.cpp:66