hooks Module
Specific controller operations can trigger corresponding callbacks, allowing plugins to implement custom logic.
When the control system runs these callbacks, plugin logic is executed automatically. Examples include pp2main and similar events.
Usage example:
/**
* @brief Event list
*/
enum HookEventAPI{
INVALID_EVENT,
POINT_CHANGE, ///< Point add/delete/modify event callback
PP_TO_MAIN, ///< pp2main callback
PP_TO_LINE, ///< pp2line event callback
B_START_RUN, ///< Start-run event callback
B_PAUSE_RUN, ///< Pause-run event callback
E_STOP_RUN ///< Emergency-stop event callback
};
/**
* @brief Run mode for a hook callback
*/
enum RunTypeAPI:short{
SYNC_RUN, ///< Synchronous run; blocks the corresponding controller event
ASYNC_RUN_IN_THREAD_POOL, ///< Runs in the general thread pool
ASYNC_RUN_IN_RT_THREAD ///< Runs in the RT thread
};
/**
* @brief Test pp2line hook with parameters
*/
void TestPP2LineHooks(){
namespace xhooks = xcore_api::hooks;
xhooks::HookDataAPI data;
data.SetEvent(xhooks::PP_TO_LINE);
auto func = [](const std::shared_ptr<const xhooks::HookArgsBaseAPI> p){
LOG_INFO<<"this is pp2line callback:";
const auto ptr = std::dynamic_pointer_cast<const xhooks::HookPPToLineArgsAPI>(p);
if(ptr == nullptr){
LOG_INFO<<"pp2line callback: nullptr";
} else {
LOG_INFO<<ptr->GetTaskName()<<" : "<<ptr->GetFileName()<<" : "<<ptr->GetFileLine();
}
};
data.SetHook(func);
int id = xhooks::RegisterHooksAPI(data);
LOG_INFO<<"register pp2line hook id:"<<id;
}
When printq is used in the HMI, reaching that command prints the quaternion in the log. Users can inject the command through the client plugin in auxiliary programming for convenient use of newly registered commands.

