mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
Implement remote procedure calls.
This commit is contained in:
@@ -137,6 +137,14 @@ struct NT_RpcDefinition {
|
||||
NT_RpcResultDef *results;
|
||||
};
|
||||
|
||||
/** NetworkTables RPC Call Data */
|
||||
struct NT_RpcCallInfo {
|
||||
unsigned int rpc_id;
|
||||
unsigned int call_uid;
|
||||
struct NT_String name;
|
||||
struct NT_String params;
|
||||
};
|
||||
|
||||
/*
|
||||
* Table Functions
|
||||
*/
|
||||
@@ -268,18 +276,31 @@ void NT_RemoveConnectionListener(unsigned int conn_listener_uid);
|
||||
* Remote Procedure Call Functions
|
||||
*/
|
||||
|
||||
typedef NT_Value **(*NT_RpcCallback)(unsigned int uid, void *data,
|
||||
const char *name, size_t name_len,
|
||||
const struct NT_Value **params,
|
||||
size_t params_len, size_t *results_len);
|
||||
typedef char *(*NT_RpcCallback)(void *data, const char *name, size_t name_len,
|
||||
const char *params, size_t params_len,
|
||||
size_t *results_len);
|
||||
|
||||
unsigned int NT_CreateRpc(const char *name, size_t name_len,
|
||||
const struct NT_RpcDefinition *def, void *data,
|
||||
NT_RpcCallback callback);
|
||||
void NT_DeleteRpc(unsigned int rpc_uid);
|
||||
unsigned int NT_CallRpc(const char *name, size_t name_len,
|
||||
const struct NT_Value **params, size_t params_len);
|
||||
struct NT_Value **NT_GetRpcResult(unsigned int result_uid, size_t *results_len);
|
||||
void NT_CreateRpc(const char *name, size_t name_len, const char *def,
|
||||
size_t def_len, void *data, NT_RpcCallback callback);
|
||||
void NT_CreatePolledRpc(const char *name, size_t name_len, const char *def,
|
||||
size_t def_len);
|
||||
|
||||
int NT_PollRpc(int blocking, struct NT_RpcCallInfo* call_info);
|
||||
void NT_PostRpcResponse(unsigned int rpc_id, unsigned int call_uid,
|
||||
const char *result, size_t result_len);
|
||||
|
||||
unsigned int NT_CallRpc(const char *name, size_t name_len, const char *params,
|
||||
size_t params_len);
|
||||
char *NT_GetRpcResult(int blocking, unsigned int call_uid, size_t *result_len);
|
||||
|
||||
char *NT_PackRpcDefinition(const struct NT_RpcDefinition *def,
|
||||
size_t *packed_len);
|
||||
int NT_UnpackRpcDefinition(const char *packed, size_t packed_len,
|
||||
struct NT_RpcDefinition *def);
|
||||
char *NT_PackRpcValues(const struct NT_Value **values, size_t values_len,
|
||||
size_t *packed_len);
|
||||
struct NT_Value **NT_UnpackRpcValues(const char *packed, size_t packed_len,
|
||||
const NT_Type *types, size_t types_len);
|
||||
|
||||
/*
|
||||
* Client/Server Functions
|
||||
@@ -319,6 +340,10 @@ void NT_InitString(struct NT_String *str);
|
||||
|
||||
void NT_DisposeConnectionInfoArray(struct NT_ConnectionInfo *arr, size_t count);
|
||||
|
||||
void NT_DisposeRpcDefinition(struct NT_RpcDefinition *def);
|
||||
|
||||
void NT_DisposeRpcCallInfo(struct NT_RpcCallInfo *call_info);
|
||||
|
||||
/* timestamp */
|
||||
unsigned long long NT_Now(void);
|
||||
|
||||
|
||||
@@ -50,12 +50,19 @@ struct ConnectionInfo {
|
||||
|
||||
/** NetworkTables RPC Parameter Definition */
|
||||
struct RpcParamDef {
|
||||
RpcParamDef() = default;
|
||||
RpcParamDef(StringRef name_, std::shared_ptr<Value> def_value_)
|
||||
: name(name_), def_value(def_value_) {}
|
||||
|
||||
std::string name;
|
||||
std::shared_ptr<Value> def_value;
|
||||
};
|
||||
|
||||
/** NetworkTables RPC Result Definition */
|
||||
struct RpcResultDef {
|
||||
RpcResultDef() = default;
|
||||
RpcResultDef(StringRef name_, NT_Type type_) : name(name_), type(type_) {}
|
||||
|
||||
std::string name;
|
||||
NT_Type type;
|
||||
};
|
||||
@@ -68,6 +75,14 @@ struct RpcDefinition {
|
||||
std::vector<RpcResultDef> results;
|
||||
};
|
||||
|
||||
/** NetworkTables RPC Call Data */
|
||||
struct RpcCallInfo {
|
||||
unsigned int rpc_id;
|
||||
unsigned int call_uid;
|
||||
std::string name;
|
||||
std::string params;
|
||||
};
|
||||
|
||||
/*
|
||||
* Table Functions
|
||||
*/
|
||||
@@ -183,15 +198,24 @@ void RemoveConnectionListener(unsigned int conn_listener_uid);
|
||||
* Remote Procedure Call Functions
|
||||
*/
|
||||
|
||||
typedef std::function<std::vector<std::shared_ptr<Value>>(
|
||||
unsigned int uid, StringRef name, ArrayRef<std::shared_ptr<Value>> params)>
|
||||
typedef std::function<std::string(StringRef name, StringRef params)>
|
||||
RpcCallback;
|
||||
|
||||
unsigned int CreateRpc(StringRef name, const RpcDefinition& def,
|
||||
RpcCallback callback);
|
||||
void DeleteRpc(unsigned int rpc_uid);
|
||||
unsigned int CallRpc(StringRef name, ArrayRef<std::shared_ptr<Value>> params);
|
||||
std::vector<std::shared_ptr<Value>> GetRpcResult(unsigned int result_uid);
|
||||
void CreateRpc(StringRef name, StringRef def, RpcCallback callback);
|
||||
void CreatePolledRpc(StringRef name, StringRef def);
|
||||
|
||||
bool PollRpc(bool blocking, RpcCallInfo* call_info);
|
||||
void PostRpcResponse(unsigned int rpc_id, unsigned int call_uid,
|
||||
StringRef result);
|
||||
|
||||
unsigned int CallRpc(StringRef name, StringRef params);
|
||||
bool GetRpcResult(bool blocking, unsigned int call_uid, std::string* result);
|
||||
|
||||
std::string PackRpcDefinition(const RpcDefinition& def);
|
||||
bool UnpackRpcDefinition(StringRef packed, RpcDefinition *def);
|
||||
std::string PackRpcValues(ArrayRef<std::shared_ptr<Value>> values);
|
||||
std::vector<std::shared_ptr<Value>> UnpackRpcValues(StringRef packed,
|
||||
ArrayRef<NT_Type> types);
|
||||
|
||||
/*
|
||||
* Client/Server Functions
|
||||
|
||||
Reference in New Issue
Block a user