cmvr-es/third_party/AuboSdk/linux/include/aubo_sdk/rpc.h

172 lines
3.9 KiB
C
Raw Normal View History

2025-11-17 13:48:22 +08:00
/** @file rpc.h
* @brief RPC模块的交互
*/
#ifndef AUBO_SDK_RPC_H
#define AUBO_SDK_RPC_H
#include <memory>
#include <aubo/aubo_api.h>
#include <aubo/global_config.h>
namespace arcs {
namespace aubo_sdk {
using namespace arcs::common_interface;
/// RPC客户端
class ARCS_ABI RpcClient : public AuboApi
{
public:
enum Event
{
Connected = 0,
Disconnected = 1,
};
/**
* @brief RpcClient
* @param mode 0-TCP 1-UDS
*/
RpcClient(int mode = 0);
~RpcClient();
/**
*
*
* \n
* Aubo SDK
*
* Aubo SDK
*
* @note setLogHandler函数要放在即将触发的日志之前
*
*
* @param handler \n
* : \n
* void handler(int level, const char* filename, int line, const
* std::string& message) \n
* level \n
* &nbsp; 0: LOGLEVEL_FATAL \n
* &nbsp; 1: LOGLEVEL_ERROR \n
* &nbsp; 2: LOGLEVEL_WARNING \n
* &nbsp; 3: LOGLEVEL_INFO \n
* &nbsp; 4: LOGLEVEL_DEBUG \n
* &nbsp; 5: LOGLEVEL_BACKTRACE \n
* filename \n
* line \n
* message \n
* @return
*/
void setLogHandler(
std::function<void(int /*level*/, const char * /*filename*/,
int /*line*/, const std::string & /*message*/)>
handler);
/**
* RPC服务
*
* @param ip IP地址
* @param port RPC的端口号是30004
* @param ip和port为空时unix domain sockets通讯方式
* @retval 0 RPC连接成功
* @retval -8 RPC连接失败RPC连接被拒绝
* @retval -15 RPC连接失败SDK版本与Server版本不兼容
*/
int connect(const std::string &ip = "", int port = 0);
/**
* RPC连接
*
* @retval 0
* @retval -1
*/
int disconnect();
/**
* RPC
*
* @retval true RPC
* @retval false RPC
*/
bool hasConnected() const;
/**
*
*
* @param usrname
* @param passwd
* @return 0
*/
int login(const std::string &usrname, const std::string &passwd);
/**
*
*
* @return 0
*/
int logout();
/**
*
*
* @retval true
* @retval false
*/
bool hasLogined();
/**
* RPC请求超时时间
*
* @param timeout ms
* @return 0
*/
int setRequestTimeout(int timeout = 100);
/**
*
*
* @param cb
* @return
*/
int setEventHandler(std::function<void(int /*event*/)> cb);
/**
*
*
* @param enable
* @return
*/
int setExceptionFree(bool enable);
/**
*
*
* @return
*/
int errorCode() const;
/**
*
*
* @return
*/
int shutdown();
};
using RpcClientPtr = std::shared_ptr<RpcClient>;
} // namespace aubo_sdk
} // namespace arcs
#ifdef __cplusplus
extern "C" {
#endif
ARCS_ABI arcs::aubo_sdk::RpcClient *createRpcClient(int mode = 0);
ARCS_ABI void destroyRpcClient(arcs::aubo_sdk::RpcClient *cli);
#ifdef __cplusplus
}
#endif
#endif