CfgMgr::Monitor
Description
Monitors a specified parameter. When the Set operation is performed on this parameter, a callback function is called.
Prototype
uint32_t CfgMgr::Monitor(const std::string &kParam, std::function<void(T)> monitorFunc, const bool changeNeeded = false, const std::string &srv = "")
Function Security Level
ASIL-D
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
kParam |
Input |
Key, which is a parameter name or namespace, for example, /ros/use_sim_time or /ros. Starting with a slash (/) is not mandatory. |
monitorFunc |
Input |
Callback function. For details about the types supported by function input parameters, see "Usage". |
changeNeeded |
Input |
|
srv |
Input |
Parameter group, which corresponds to a resource file. If it is not specified, parameters are obtained from the parameter groups on which you have the permission by default, which reduces the efficiency. |
Returns
The return value is of the uint32_t type. If the operation is successful, CFGMGR_SUCCESS is returned. If the operation fails, an error code is returned.
Usage
Non-template functions can overload for various types. The callback function parameters support the following types:
std::string, double, float, int, bool, std::vector<std::string>, std::vector<double>, std::vector<float>, std::vector<int>, std::vector<bool>, std::map<std::string, std::string>, std::map<std::string, double>, std::map<std::string, float>, std::map<std::string, int>, and std::map<std::string, bool>.
Precautions
- The key must be less than 128 bytes, and a single value must be less than 256 bytes.
- This interface needs to be called for multiple times when multiple parameters are monitored.
- Calling a monitoring function starts an independent thread. Multiple monitoring functions within the same group share a common thread, while those in different groups run on different threads.
- The Set operation can be monitored only when the key of the Set operation is the same as that of the Monitor operation.
- When a complete key is used for monitoring, the Load and Revert operations also trigger monitoring.
- When a process calls Monitor for the same key for multiple times, all registered callback functions take effect. That is, when the Set operation is performed on this key, all callback functions are called in sequence.
- If Monitor is called, CfgMgr::CancelMonitor must be called to destroy threads when processes exit. Otherwise, a core dump may occur. If OpenHiva::Shutdown is called, CancelMonitor does not need to be called because OpenHiva::Shutdown calls CancelMonitor by default.
- If parameter monitoring fails, determine whether to report the fault or perform other operations.
- The interface may return a failure message for several reasons, including the absence of permissions and parameters, parameter loading failure, and data transmission failure (management plane).