2015-06-27 10:22:59 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) FIRST 2015. All Rights Reserved. */
|
|
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "ntcore.h"
|
|
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
2015-07-17 07:21:07 -07:00
|
|
|
#include "Value_internal.h"
|
2015-06-27 10:22:59 -07:00
|
|
|
|
2015-07-17 07:21:07 -07:00
|
|
|
using namespace nt;
|
2015-06-27 10:22:59 -07:00
|
|
|
|
2015-07-17 08:47:25 -07:00
|
|
|
// Conversion helpers
|
|
|
|
|
|
|
|
|
|
static void ConvertToC(llvm::StringRef in, char** out) {
|
|
|
|
|
*out = static_cast<char*>(std::malloc(in.size() + 1));
|
|
|
|
|
std::memmove(*out, in.data(), in.size());
|
2015-07-17 10:16:46 -07:00
|
|
|
(*out)[in.size()] = '\0';
|
2015-07-17 08:47:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void ConvertToC(const EntryInfo& in, NT_EntryInfo* out) {
|
|
|
|
|
ConvertToC(in.name, &out->name);
|
|
|
|
|
out->type = in.type;
|
|
|
|
|
out->flags = in.flags;
|
|
|
|
|
out->last_change = in.last_change;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void ConvertToC(const ConnectionInfo& in, NT_ConnectionInfo* out) {
|
|
|
|
|
ConvertToC(in.remote_id, &out->remote_id);
|
|
|
|
|
ConvertToC(in.remote_name, &out->remote_name);
|
|
|
|
|
out->remote_port = in.remote_port;
|
|
|
|
|
out->last_update = in.last_update;
|
|
|
|
|
out->protocol_version = in.protocol_version;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-13 13:12:15 -07:00
|
|
|
static void ConvertToC(const RpcParamDef& in, NT_RpcParamDef* out) {
|
|
|
|
|
ConvertToC(in.name, &out->name);
|
|
|
|
|
ConvertToC(*in.def_value, &out->def_value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void ConvertToC(const RpcResultDef& in, NT_RpcResultDef* out) {
|
|
|
|
|
ConvertToC(in.name, &out->name);
|
|
|
|
|
out->type = in.type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void ConvertToC(const RpcDefinition& in, NT_RpcDefinition* out) {
|
|
|
|
|
out->version = in.version;
|
|
|
|
|
ConvertToC(in.name, &out->name);
|
|
|
|
|
|
|
|
|
|
out->num_params = in.params.size();
|
|
|
|
|
out->params = static_cast<NT_RpcParamDef*>(
|
|
|
|
|
std::malloc(in.params.size() * sizeof(NT_RpcParamDef)));
|
|
|
|
|
for (size_t i = 0; i < in.params.size(); ++i)
|
|
|
|
|
ConvertToC(in.params[i], &out->params[i]);
|
|
|
|
|
|
|
|
|
|
out->num_results = in.results.size();
|
|
|
|
|
out->results = static_cast<NT_RpcResultDef*>(
|
|
|
|
|
std::malloc(in.results.size() * sizeof(NT_RpcResultDef)));
|
|
|
|
|
for (size_t i = 0; i < in.results.size(); ++i)
|
|
|
|
|
ConvertToC(in.results[i], &out->results[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void ConvertToC(const RpcCallInfo& in, NT_RpcCallInfo* out) {
|
|
|
|
|
out->rpc_id = in.rpc_id;
|
|
|
|
|
out->call_uid = in.call_uid;
|
|
|
|
|
ConvertToC(in.name, &out->name);
|
|
|
|
|
ConvertToC(in.params, &out->params);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-17 08:47:25 -07:00
|
|
|
static void DisposeConnectionInfo(NT_ConnectionInfo *info) {
|
|
|
|
|
std::free(info->remote_id.str);
|
|
|
|
|
std::free(info->remote_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static RpcParamDef ConvertFromC(const NT_RpcParamDef& in) {
|
|
|
|
|
RpcParamDef out;
|
|
|
|
|
out.name = ConvertFromC(in.name);
|
|
|
|
|
out.def_value = ConvertFromC(in.def_value);
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static RpcResultDef ConvertFromC(const NT_RpcResultDef& in) {
|
|
|
|
|
RpcResultDef out;
|
|
|
|
|
out.name = ConvertFromC(in.name);
|
|
|
|
|
out.type = in.type;
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static RpcDefinition ConvertFromC(const NT_RpcDefinition& in) {
|
|
|
|
|
RpcDefinition out;
|
|
|
|
|
out.version = in.version;
|
|
|
|
|
out.name = ConvertFromC(in.name);
|
|
|
|
|
|
|
|
|
|
out.params.reserve(in.num_params);
|
|
|
|
|
for (size_t i = 0; i < in.num_params; ++i)
|
|
|
|
|
out.params.push_back(ConvertFromC(in.params[i]));
|
|
|
|
|
|
|
|
|
|
out.results.reserve(in.num_results);
|
|
|
|
|
for (size_t i = 0; i < in.num_results; ++i)
|
|
|
|
|
out.results.push_back(ConvertFromC(in.results[i]));
|
|
|
|
|
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-27 10:22:59 -07:00
|
|
|
/*
|
|
|
|
|
* Table Functions
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void NT_GetEntryValue(const char *name, unsigned int name_len,
|
2015-07-17 07:21:07 -07:00
|
|
|
struct NT_Value *value) {
|
|
|
|
|
NT_InitValue(value);
|
|
|
|
|
auto v = nt::GetEntryValue(StringRef(name, name_len));
|
|
|
|
|
if (!v) return;
|
|
|
|
|
ConvertToC(*v, value);
|
|
|
|
|
}
|
2015-06-27 10:22:59 -07:00
|
|
|
|
|
|
|
|
int NT_SetEntryValue(const char *name, unsigned int name_len,
|
|
|
|
|
const struct NT_Value *value) {
|
2015-07-17 07:21:07 -07:00
|
|
|
return nt::SetEntryValue(StringRef(name, name_len), ConvertFromC(*value));
|
2015-06-27 10:22:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NT_SetEntryTypeValue(const char *name, unsigned int name_len,
|
2015-07-17 07:21:07 -07:00
|
|
|
const struct NT_Value *value) {
|
|
|
|
|
nt::SetEntryTypeValue(StringRef(name, name_len), ConvertFromC(*value));
|
|
|
|
|
}
|
2015-06-27 10:22:59 -07:00
|
|
|
|
2015-07-17 07:21:07 -07:00
|
|
|
void NT_SetEntryFlags(const char *name, size_t name_len, unsigned int flags) {
|
|
|
|
|
nt::SetEntryFlags(StringRef(name, name_len), flags);
|
|
|
|
|
}
|
2015-06-27 10:22:59 -07:00
|
|
|
|
|
|
|
|
unsigned int NT_GetEntryFlags(const char *name, size_t name_len) {
|
2015-07-17 07:21:07 -07:00
|
|
|
return nt::GetEntryFlags(StringRef(name, name_len));
|
2015-06-27 10:22:59 -07:00
|
|
|
}
|
|
|
|
|
|
2015-07-17 07:21:07 -07:00
|
|
|
void NT_DeleteEntry(const char *name, unsigned int name_len) {
|
|
|
|
|
nt::DeleteEntry(StringRef(name, name_len));
|
|
|
|
|
}
|
2015-06-27 10:22:59 -07:00
|
|
|
|
2015-07-17 07:21:07 -07:00
|
|
|
void NT_DeleteAllEntries(void) { nt::DeleteAllEntries(); }
|
2015-06-27 10:22:59 -07:00
|
|
|
|
|
|
|
|
struct NT_EntryInfo *NT_GetEntryInfo(const char *prefix,
|
|
|
|
|
unsigned int prefix_len, int types,
|
|
|
|
|
unsigned int *count) {
|
2015-07-17 08:47:25 -07:00
|
|
|
auto info_v = nt::GetEntryInfo(StringRef(prefix, prefix_len), types);
|
|
|
|
|
*count = info_v.size();
|
|
|
|
|
if (info_v.size() == 0) return nullptr;
|
|
|
|
|
|
|
|
|
|
// create array and copy into it
|
|
|
|
|
NT_EntryInfo* info = static_cast<NT_EntryInfo*>(
|
|
|
|
|
std::malloc(info_v.size() * sizeof(NT_EntryInfo)));
|
|
|
|
|
for (size_t i = 0; i < info_v.size(); ++i) ConvertToC(info_v[i], &info[i]);
|
|
|
|
|
return info;
|
2015-06-27 10:22:59 -07:00
|
|
|
}
|
|
|
|
|
|
2015-07-17 07:21:07 -07:00
|
|
|
void NT_Flush(void) { nt::Flush(); }
|
2015-06-27 10:22:59 -07:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Callback Creation Functions
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
unsigned int NT_AddEntryListener(const char *prefix, size_t prefix_len,
|
|
|
|
|
void *data,
|
2015-07-23 01:02:53 -07:00
|
|
|
NT_EntryListenerCallback callback,
|
|
|
|
|
int immediate_notify) {
|
2015-07-17 08:47:25 -07:00
|
|
|
return nt::AddEntryListener(
|
|
|
|
|
StringRef(prefix, prefix_len),
|
2015-07-23 01:02:53 -07:00
|
|
|
[=](unsigned int uid, StringRef name, std::shared_ptr<Value> value,
|
|
|
|
|
bool is_new) {
|
|
|
|
|
callback(uid, data, name.data(), name.size(), &value->value(), is_new);
|
|
|
|
|
},
|
|
|
|
|
immediate_notify != 0);
|
2015-06-27 10:22:59 -07:00
|
|
|
}
|
2015-07-17 08:47:25 -07:00
|
|
|
|
2015-07-17 07:21:07 -07:00
|
|
|
void NT_RemoveEntryListener(unsigned int entry_listener_uid) {
|
|
|
|
|
nt::RemoveEntryListener(entry_listener_uid);
|
|
|
|
|
}
|
2015-07-17 08:47:25 -07:00
|
|
|
|
2015-06-27 10:22:59 -07:00
|
|
|
unsigned int NT_AddConnectionListener(void *data,
|
|
|
|
|
NT_ConnectionListenerCallback callback) {
|
2015-07-17 08:47:25 -07:00
|
|
|
return nt::AddConnectionListener(
|
2015-08-27 23:48:40 -07:00
|
|
|
[=](unsigned int uid, bool connected, const ConnectionInfo &conn) {
|
2015-07-17 08:47:25 -07:00
|
|
|
NT_ConnectionInfo conn_c;
|
|
|
|
|
ConvertToC(conn, &conn_c);
|
2015-08-27 23:48:40 -07:00
|
|
|
callback(uid, data, connected ? 1 : 0, &conn_c);
|
2015-07-17 08:47:25 -07:00
|
|
|
DisposeConnectionInfo(&conn_c);
|
|
|
|
|
});
|
2015-06-27 10:22:59 -07:00
|
|
|
}
|
2015-07-17 08:47:25 -07:00
|
|
|
|
2015-07-17 07:21:07 -07:00
|
|
|
void NT_RemoveConnectionListener(unsigned int conn_listener_uid) {
|
|
|
|
|
nt::RemoveConnectionListener(conn_listener_uid);
|
|
|
|
|
}
|
2015-06-27 10:22:59 -07:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Remote Procedure Call Functions
|
|
|
|
|
*/
|
|
|
|
|
|
2015-08-13 13:12:15 -07:00
|
|
|
void NT_CreateRpc(const char *name, size_t name_len, const char *def,
|
|
|
|
|
size_t def_len, void *data, NT_RpcCallback callback) {
|
|
|
|
|
nt::CreateRpc(
|
|
|
|
|
StringRef(name, name_len), StringRef(def, def_len),
|
|
|
|
|
[=](StringRef name, StringRef params) -> std::string {
|
2015-07-17 08:47:25 -07:00
|
|
|
size_t results_len;
|
2015-08-13 13:12:15 -07:00
|
|
|
char* results_c = callback(data, name.data(), name.size(),
|
|
|
|
|
params.data(), params.size(), &results_len);
|
|
|
|
|
std::string results(results_c, results_len);
|
2015-07-17 08:47:25 -07:00
|
|
|
std::free(results_c);
|
|
|
|
|
return results;
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-07-17 07:21:07 -07:00
|
|
|
|
2015-08-13 13:12:15 -07:00
|
|
|
void NT_CreatePolledRpc(const char *name, size_t name_len, const char *def,
|
|
|
|
|
size_t def_len) {
|
|
|
|
|
nt::CreatePolledRpc(StringRef(name, name_len), StringRef(def, def_len));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int NT_PollRpc(int blocking, NT_RpcCallInfo* call_info) {
|
|
|
|
|
RpcCallInfo call_info_cpp;
|
|
|
|
|
if (!nt::PollRpc(blocking, &call_info_cpp))
|
|
|
|
|
return 0;
|
|
|
|
|
ConvertToC(call_info_cpp, call_info);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NT_PostRpcResponse(unsigned int rpc_id, unsigned int call_uid,
|
|
|
|
|
const char *result, size_t result_len) {
|
|
|
|
|
nt::PostRpcResponse(rpc_id, call_uid, StringRef(result, result_len));
|
2015-07-17 07:21:07 -07:00
|
|
|
}
|
|
|
|
|
|
2015-06-27 10:22:59 -07:00
|
|
|
unsigned int NT_CallRpc(const char *name, size_t name_len,
|
2015-08-13 13:12:15 -07:00
|
|
|
const char *params, size_t params_len) {
|
|
|
|
|
return nt::CallRpc(StringRef(name, name_len), StringRef(params, params_len));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *NT_GetRpcResult(int blocking, unsigned int call_uid, size_t *result_len) {
|
|
|
|
|
std::string result;
|
|
|
|
|
if (!nt::GetRpcResult(blocking, call_uid, &result)) return nullptr;
|
|
|
|
|
|
|
|
|
|
// convert result
|
|
|
|
|
*result_len = result.size();
|
|
|
|
|
char *result_cstr;
|
|
|
|
|
ConvertToC(result, &result_cstr);
|
|
|
|
|
return result_cstr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *NT_PackRpcDefinition(const NT_RpcDefinition *def, size_t *packed_len) {
|
|
|
|
|
auto packed = nt::PackRpcDefinition(ConvertFromC(*def));
|
|
|
|
|
|
|
|
|
|
// convert result
|
|
|
|
|
*packed_len = packed.size();
|
|
|
|
|
char *packed_cstr;
|
|
|
|
|
ConvertToC(packed, &packed_cstr);
|
|
|
|
|
return packed_cstr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int NT_UnpackRpcDefinition(const char *packed, size_t packed_len,
|
|
|
|
|
NT_RpcDefinition *def) {
|
|
|
|
|
nt::RpcDefinition def_v;
|
|
|
|
|
if (!nt::UnpackRpcDefinition(StringRef(packed, packed_len), &def_v))
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
// convert result
|
|
|
|
|
ConvertToC(def_v, def);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *NT_PackRpcValues(const NT_Value **values, size_t values_len,
|
|
|
|
|
size_t *packed_len) {
|
2015-07-17 08:47:25 -07:00
|
|
|
// create input vector
|
2015-08-13 13:12:15 -07:00
|
|
|
std::vector<std::shared_ptr<Value>> values_v;
|
|
|
|
|
values_v.reserve(values_len);
|
|
|
|
|
for (size_t i = 0; i < values_len; ++i)
|
|
|
|
|
values_v.push_back(ConvertFromC(*values[i]));
|
2015-07-17 08:47:25 -07:00
|
|
|
|
|
|
|
|
// make the call
|
2015-08-13 13:12:15 -07:00
|
|
|
auto packed = nt::PackRpcValues(values_v);
|
|
|
|
|
|
|
|
|
|
// convert result
|
|
|
|
|
*packed_len = packed.size();
|
|
|
|
|
char *packed_cstr;
|
|
|
|
|
ConvertToC(packed, &packed_cstr);
|
|
|
|
|
return packed_cstr;
|
2015-07-17 07:21:07 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-13 13:12:15 -07:00
|
|
|
NT_Value **NT_UnpackRpcValues(const char *packed, size_t packed_len,
|
|
|
|
|
const NT_Type *types, size_t types_len) {
|
|
|
|
|
auto values_v = nt::UnpackRpcValues(StringRef(packed, packed_len),
|
|
|
|
|
ArrayRef<NT_Type>(types, types_len));
|
|
|
|
|
if (values_v.size() == 0) return nullptr;
|
2015-07-17 08:47:25 -07:00
|
|
|
|
|
|
|
|
// create array and copy into it
|
2015-08-13 13:12:15 -07:00
|
|
|
NT_Value** values = static_cast<NT_Value**>(
|
|
|
|
|
std::malloc(values_v.size() * sizeof(NT_Value*)));
|
|
|
|
|
for (size_t i = 0; i < values_v.size(); ++i) {
|
|
|
|
|
values[i] = static_cast<NT_Value*>(std::malloc(sizeof(NT_Value)));
|
|
|
|
|
ConvertToC(*values_v[i], values[i]);
|
2015-07-17 08:47:25 -07:00
|
|
|
}
|
2015-08-13 13:12:15 -07:00
|
|
|
return values;
|
2015-07-17 07:21:07 -07:00
|
|
|
}
|
2015-06-27 10:22:59 -07:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Client/Server Functions
|
|
|
|
|
*/
|
|
|
|
|
|
2015-07-16 01:38:27 -07:00
|
|
|
void NT_SetNetworkIdentity(const char *name, size_t name_len) {
|
2015-07-17 07:21:07 -07:00
|
|
|
nt::SetNetworkIdentity(StringRef(name, name_len));
|
2015-07-16 01:38:27 -07:00
|
|
|
}
|
|
|
|
|
|
2015-06-27 10:22:59 -07:00
|
|
|
void NT_StartServer(const char *persist_filename, const char *listen_address,
|
2015-07-16 01:38:27 -07:00
|
|
|
unsigned int port) {
|
2015-07-17 07:21:07 -07:00
|
|
|
nt::StartServer(persist_filename, listen_address, port);
|
2015-07-16 01:38:27 -07:00
|
|
|
}
|
|
|
|
|
|
2015-07-17 07:21:07 -07:00
|
|
|
void NT_StopServer(void) { nt::StopServer(); }
|
2015-07-16 01:38:27 -07:00
|
|
|
|
|
|
|
|
void NT_StartClient(const char *server_name, unsigned int port) {
|
2015-07-17 07:21:07 -07:00
|
|
|
nt::StartClient(server_name, port);
|
2015-07-16 01:38:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NT_StopClient(void) {
|
2015-07-17 07:21:07 -07:00
|
|
|
nt::StopClient();
|
2015-07-16 01:38:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NT_SetUpdateRate(double interval) {
|
2015-07-17 07:21:07 -07:00
|
|
|
nt::SetUpdateRate(interval);
|
2015-07-16 01:38:27 -07:00
|
|
|
}
|
|
|
|
|
|
2015-06-27 10:22:59 -07:00
|
|
|
struct NT_ConnectionInfo *NT_GetConnections(size_t *count) {
|
2015-07-17 08:47:25 -07:00
|
|
|
auto conn_v = nt::GetConnections();
|
|
|
|
|
*count = conn_v.size();
|
|
|
|
|
if (conn_v.size() == 0) return nullptr;
|
|
|
|
|
|
|
|
|
|
// create array and copy into it
|
|
|
|
|
NT_ConnectionInfo *conn = static_cast<NT_ConnectionInfo *>(
|
|
|
|
|
std::malloc(conn_v.size() * sizeof(NT_ConnectionInfo)));
|
|
|
|
|
for (size_t i = 0; i < conn_v.size(); ++i) ConvertToC(conn_v[i], &conn[i]);
|
|
|
|
|
return conn;
|
2015-06-27 10:22:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Persistent Functions
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const char *NT_SavePersistent(const char *filename) {
|
2015-07-17 07:21:07 -07:00
|
|
|
return nt::SavePersistent(filename);
|
2015-06-27 10:22:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *NT_LoadPersistent(const char *filename,
|
|
|
|
|
void (*warn)(size_t line, const char *msg)) {
|
2015-07-17 07:21:07 -07:00
|
|
|
return nt::LoadPersistent(filename, warn);
|
2015-06-27 10:22:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Utility Functions
|
|
|
|
|
*/
|
|
|
|
|
|
2015-07-31 22:41:26 -07:00
|
|
|
void NT_SetLogger(NT_LogFunc func, unsigned int min_level) {
|
|
|
|
|
nt::SetLogger(func, min_level);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-27 10:22:59 -07:00
|
|
|
void NT_DisposeValue(NT_Value *value) {
|
|
|
|
|
switch (value->type) {
|
|
|
|
|
case NT_UNASSIGNED:
|
|
|
|
|
case NT_BOOLEAN:
|
|
|
|
|
case NT_DOUBLE:
|
|
|
|
|
break;
|
|
|
|
|
case NT_STRING:
|
|
|
|
|
case NT_RAW:
|
|
|
|
|
case NT_RPC:
|
|
|
|
|
std::free(value->data.v_string.str);
|
|
|
|
|
break;
|
|
|
|
|
case NT_BOOLEAN_ARRAY:
|
|
|
|
|
std::free(value->data.arr_boolean.arr);
|
|
|
|
|
break;
|
|
|
|
|
case NT_DOUBLE_ARRAY:
|
|
|
|
|
std::free(value->data.arr_double.arr);
|
|
|
|
|
break;
|
|
|
|
|
case NT_STRING_ARRAY: {
|
|
|
|
|
for (size_t i = 0; i < value->data.arr_string.size; i++)
|
|
|
|
|
std::free(value->data.arr_string.arr[i].str);
|
|
|
|
|
std::free(value->data.arr_string.arr);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
2015-07-17 08:47:25 -07:00
|
|
|
assert(false && "unknown value type");
|
2015-06-27 10:22:59 -07:00
|
|
|
}
|
|
|
|
|
value->type = NT_UNASSIGNED;
|
|
|
|
|
value->last_change = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NT_InitValue(NT_Value *value) {
|
|
|
|
|
value->type = NT_UNASSIGNED;
|
|
|
|
|
value->last_change = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NT_DisposeString(NT_String *str) {
|
|
|
|
|
std::free(str->str);
|
|
|
|
|
str->str = nullptr;
|
|
|
|
|
str->len = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NT_InitString(NT_String *str) {
|
|
|
|
|
str->str = nullptr;
|
|
|
|
|
str->len = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NT_DisposeConnectionInfoArray(NT_ConnectionInfo *arr, size_t count) {
|
2015-07-17 08:47:25 -07:00
|
|
|
for (size_t i = 0; i < count; i++) DisposeConnectionInfo(&arr[i]);
|
2015-06-27 10:22:59 -07:00
|
|
|
std::free(arr);
|
|
|
|
|
}
|
2015-08-13 13:12:15 -07:00
|
|
|
|
|
|
|
|
void NT_DisposeRpcDefinition(NT_RpcDefinition *def) {
|
|
|
|
|
NT_DisposeString(&def->name);
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < def->num_params; ++i) {
|
|
|
|
|
NT_DisposeString(&def->params[i].name);
|
|
|
|
|
NT_DisposeValue(&def->params[i].def_value);
|
|
|
|
|
}
|
|
|
|
|
std::free(def->params);
|
|
|
|
|
def->params = nullptr;
|
|
|
|
|
def->num_params = 0;
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < def->num_results; ++i)
|
|
|
|
|
NT_DisposeString(&def->results[i].name);
|
|
|
|
|
std::free(def->results);
|
|
|
|
|
def->results = nullptr;
|
|
|
|
|
def->num_results = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NT_DisposeRpcCallInfo(NT_RpcCallInfo *call_info) {
|
|
|
|
|
NT_DisposeString(&call_info->name);
|
|
|
|
|
NT_DisposeString(&call_info->params);
|
|
|
|
|
}
|