Skip to main content

Hooks Module

Specific operations in the control system can trigger corresponding callbacks, and the corresponding logic can be implemented in the Plugin. When the control system executes these logics, it will automatically execute the Plugin's logic. For example, pp2main and other 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 Specify hook callback run mode
*/
enum RunTypeAPI:short{
SYNC_RUN, ///< Synchronous run, will block Controller corresponding events
ASYNC_RUN_IN_THREAD_POOL, ///< Run in normal thread pool
ASYNC_RUN_IN_RT_THREAD ///< Run in 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 using the printq command in HMI, executing this command will print the quaternion in the log. Users can use the Client Plugin to inject this command into the auxiliary programming, making it convenient to use the newly registered command.

hooks result 1

hooks result 2