5 #ifndef CCF_COMMON_RECIPE_BASE_HPP_H_
6 #define CCF_COMMON_RECIPE_BASE_HPP_H_
21 template <
class SRC_IM_TYPE,
class TRG_IM_TYPE>
24 TRG_IM_TYPE** target_buf,
25 uint32_t* target_buf_size) {
26 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
27 *target_buf_size = (pixels *
sizeof(TRG_IM_TYPE));
28 *target_buf = (TRG_IM_TYPE*)malloc(*target_buf_size);
30 SRC_IM_TYPE* im_ptr = image_buffer;
31 TRG_IM_TYPE* target_buf_ptr = *target_buf;
32 for (uint32_t n = 0; n < pixels; n++) {
33 *target_buf_ptr++ =
static_cast<TRG_IM_TYPE
>(*im_ptr++);
43 uint32_t* target_buffer_size);
51 static const std::string&
GenId(
const std::string& proc_thread_name,
52 const std::string& recipe_name);
57 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
59 if (recipe_factory_obj.GetClassName() ==
"") {
60 CCFTHROW(
"Must define a classname for a Processing Recipe Plug-In");
63 BEGIN_CRIT_SEC(
"ccf::common::RecipeBase") {
64 if (s_recipe_factory_objects.find(recipe_factory_obj.GetClassName()) !=
65 s_recipe_factory_objects.end()) {
66 CCFTHROW(fmt::format(
"Factory object with classname: {} already exists",
67 recipe_factory_obj.GetClassName()));
69 LOG4CPLUS_INFO(
Logger(),
"Registering Processing Recipe factory object. Classname: " <<
70 recipe_factory_obj.GetClassName());
71 s_recipe_factory_objects[recipe_factory_obj.GetClassName()] = std::make_shared<TYPE>();
85 const std::string& proc_thread_name,
86 const std::string& recipe_name,
87 std::shared_ptr<RecipeBase>& new_obj);
94 const std::string& proc_thread_name,
95 std::shared_ptr<RecipeBase>& recipe_obj,
96 const bool initialise =
true);
99 static const std::map<std::string, std::shared_ptr<RecipeBase>>&
GetRecipeObjs();
103 const std::string& proc_thread_name,
104 std::shared_ptr<RecipeBase>& recipe_obj);
116 RecipeBase(
const std::string& proc_thread_name,
117 const std::string& recipe_name);
170 const std::string& recipe_name,
171 std::shared_ptr<RecipeBase>& new_object);
199 static std::map<std::string, std::shared_ptr<RecipeBase>> s_recipe_factory_objects;
200 static std::map<std::string, std::shared_ptr<RecipeBase>> s_recipe_objects;
201 static bool s_cpl_initialised;
207 std::string m_recipe_id;
208 std::string m_recipe_name;
209 std::string m_proc_thread_name;
213 std::string m_db_base_name;
#define CCFLOC
Macro generating a location identifier: "<file>:<line>:<function>:<thread>".
Definition: base.hpp:441
#define CCFTHROW(msg)
Guard for TRACE logs. Ensures log text is only generated when the given log level is enabled.
Definition: base.hpp:489
Class to be used as parent all CCF classes.
Definition: base.hpp:151
Frame class used to store the data and metadata for one frames received from the camera.
Definition: dataFrame.hpp:17
Processing Recipe base class. All recipes shall be derived from this class.
Definition: recipeBase.hpp:47
virtual void DisableUser()
Definition: recipeBase.cpp:257
const std::string & GetDbPath() const
Generate DB path for this recipe.
Definition: recipeBase.cpp:165
RecipeBase()
Definition: recipeBase.cpp:118
static void AddRecipeFactoryObj(TYPE &recipe_factory_obj)
Static method to register a Data Publisher factory object in the internal registry.
Definition: recipeBase.hpp:56
static const std::map< std::string, std::shared_ptr< RecipeBase > > & GetRecipeObjs()
Get reference to all Processing Recipe objects registered.
Definition: recipeBase.cpp:94
void SetEnabled(const bool enabled)
Set the enabled status flag of the recipe object.
Definition: recipeBase.cpp:182
virtual ~RecipeBase()
Definition: recipeBase.cpp:131
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:31
void DisableRecipe()
Disable the recipe so that it will not be invoked.
Definition: recipeBase.cpp:188
bool GetInitialised() const
Return flag indicating if the recipe object has been initialised.
Definition: recipeBase.cpp:170
virtual void EnableUser()
Definition: recipeBase.cpp:243
bool GetEnabled() const
Return the enabled status of the recipe.
Definition: recipeBase.cpp:194
const std::string & GetProcThreadName() const
Get the name of the Processing Thread, hosting the Recipe instance.
Definition: recipeBase.cpp:219
const std::string & GetRecipeName() const
Get the name of the recipe.
Definition: recipeBase.cpp:140
virtual void InitialiseUser()
Initialise the recipe object. See "Initialise()".
Definition: recipeBase.cpp:175
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:14
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:50
void Enable()
Enable the recipe so that it will be invoked by the Processing Thread to which it belongs.
Definition: recipeBase.cpp:231
ProcStatus GetStatus() const
Get status of the recipe object.
Definition: recipeBase.cpp:275
void Initialise()
Initalise the object. Invoked after creating a new object from the factory object.
Definition: recipeBase.cpp:145
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:224
void Disable()
Definition: recipeBase.cpp:248
void Process(DataFrame &frame)
Execute the processing of the given frame.
Definition: recipeBase.cpp:199
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:74
virtual void ProcessUser(DataFrame &frame)
User specific processing.
Definition: recipeBase.cpp:213
const std::string & GetRecipeId() const
Get the ID of the recipe.
Definition: recipeBase.cpp:135
static const std::map< std::string, std::shared_ptr< RecipeBase > > & GetRecipeFactoryObjs()
Statis method to retrieve references to the Recipe Factory Objects.
Definition: recipeBase.cpp:26
void SetStatus(const ProcStatus status)
Update status for a given Publisher Thread in the OLDB.
Definition: recipeBase.cpp:262
Definition: appBase.cpp:8
void PrepCplImage(const ccf::common::DataFrame &frame, cpl_image **image, ccf::DataTypes *target_data_type, uint32_t *target_buffer_size)
Definition: recipeBase.cpp:280
void ConvertImage(SRC_IM_TYPE *image_buffer, uint32_t pixels, TRG_IM_TYPE **target_buf, uint32_t *target_buf_size)
Definition: recipeBase.hpp:22
ProcStatus
Possible states for a Processing Recipe defined.
Definition: base.hpp:289
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:53
log4cplus::Logger & Logger()
Definition: base.cpp:9
DataTypes
Definition: dataType.hpp:46