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

210 lines
5.1 KiB
C
Raw Normal View History

2025-11-18 10:07:08 +08:00
/** @file script.h
* @brief SCRIPT模块的交互
*/
#ifndef AUBO_SDK_SCRIPT_H
#define AUBO_SDK_SCRIPT_H
#include <string>
#include <memory>
#include <functional>
#include <aubo/global_config.h>
namespace arcs {
namespace aubo_sdk {
class ScriptWriter
{
public:
virtual ~ScriptWriter() = default;
virtual ScriptWriter &append(const std::string &line) = 0;
virtual ScriptWriter &append(const char *buf, size_t len) = 0;
virtual ScriptWriter &moveJoint() = 0;
virtual ScriptWriter &moveLine() = 0;
virtual ScriptWriter &ifCondition() = 0;
virtual ScriptWriter &elseCondition() = 0;
virtual ScriptWriter &elseIfCondition() = 0;
virtual ScriptWriter &whileCondition() = 0;
virtual ScriptWriter &end() = 0;
};
/// SCRIPT客户端
class ARCS_ABI ScriptClient
{
public:
enum Event
{
Connected,
Disconnected,
};
ScriptClient(int mode = 0);
~ScriptClient();
/**
*
*
* \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);
/**
*
*
* @param ip IP地址
* @param port SCRIPT端口号为30004
* @retval 0
* @retval 1
* @retval -1
*/
int connect(const std::string &ip = "", int port = 0);
/**
*
*
* @retval true
* @retval false
*/
bool hasConnected() const;
/**
*
*
* @param usrname
* @param passwd
* @retval 0
* @retval -1
*/
int login(const std::string &usrname, const std::string &passwd);
/**
*
*
* @retval true
* @retval false
*/
bool hasLogined();
/**
*
*
* @return 0
*/
int logout();
/**
*
*
* @retval 0
* @retval -1
*/
int disconnect();
/**
*
*
*
*
* @param path
* @retval 0
* @retval -1
*/
int sendFile(const std::string &path);
/**
*
*
*
*
* @param script
* @retval 0
* @retval -1
*/
int sendString(const std::string &script);
/**
* 使ScriptWriter构建服务器脚本
*
* @param chunck_name
* @param cb
* @retval 0
* @retval -1
*/
int send(const std::string &chunck_name,
std::function<int(ScriptWriter &)> cb);
/**
*
*
* @param cb
* @return 0
*/
int subscribeVariableUpdate(
std::function<void(const std::string &, const std::string &)> cb);
/**
*
*
* @param cb
* @return 0
*/
ARCS_DEPRECATED int subscribeScriptError(
std::function<void(const std::string &)> cb);
int subscribeScriptError2(
std::function<void(const std::string &, const std::string &)> cb);
/**
*
*
* @param cb
* @return
*/
int setEventHandler(std::function<void(int /*event*/)> cb);
private:
class Impl;
Impl *impl;
};
using ScriptClientPtr = std::shared_ptr<ScriptClient>;
} // namespace aubo_sdk
} // namespace arcs
#ifdef __cplusplus
extern "C" {
#endif
ARCS_ABI arcs::aubo_sdk::ScriptClient *createScriptClient(int mode = 0);
ARCS_ABI void destroyScriptClient(arcs::aubo_sdk::ScriptClient *cli);
#ifdef __cplusplus
}
#endif
#endif