5 #ifndef CORELINKCLIENT_H 6 #define CORELINKCLIENT_H 15 return CorelinkDLL::getClientState();
18 inline std::vector<std::string> Client::getCommResponseDataHelper(
char* data) {
19 std::vector<std::string> dataParsed;
23 dataCast = (
int*) data;
24 dataParsed = std::vector<std::string>();
25 dataParsed.resize(dataCast[0]);
26 lenHeader = (dataCast[0] + 1) *
sizeof(
int);
28 for (
int i = 0; i < dataCast[0]; ++i) {
29 dataParsed[i] = std::string(data + lenHeader + lenData, dataCast[i + 1]);
30 lenData += dataCast[i + 1];
36 inline std::vector<std::string> Client::getCommResponseData(
const int& commID) {
39 std::vector<std::string> data;
41 responseLen = CorelinkDLL::getCommDataLen(commID);
42 responseMsg =
new char[responseLen];
43 CorelinkDLL::getCommDataStr(commID, responseMsg);
44 data = getCommResponseDataHelper(responseMsg);
48 responseMsg = CorelinkDLL::getCommData(commID, responseLen);
49 data = getCommResponseDataHelper(responseMsg);
50 CorelinkDLL::freeData(responseMsg);
55 inline const char** Client::vecStringToCharArray(
const std::vector<std::string>& vec) {
56 const char** data =
new const char*[vec.size()];
57 for (
int i = 0; i < vec.size();++i) {
58 data[i] = vec[i].c_str();
65 inline StreamData Client::getDataStreamInfo(
int& commID) {
66 std::vector<std::string> dataOut;
67 dataOut = getCommResponseData(commID);
69 int streamID = *(STREAM_ID*)dataOut[0].c_str();
70 int streamRef = CorelinkDLL::getStreamRef(streamID);
72 return StreamData(streamID, *((
int*)dataOut[1].c_str()), *((
int*)dataOut[2].c_str()), dataOut[3], dataOut[4], dataOut[5], streamRef, std::vector<std::string>(dataOut.begin() + 6, dataOut.end()));
77 CorelinkDLL::corelinkConnect(serverIP.c_str(), port, errorID);
78 CorelinkException::GetDLLException(errorID);
83 CorelinkDLL::corelinkConnectPlugin(errorID);
84 CorelinkException::GetDLLException(errorID);
88 if (!CorelinkDLL::getClientState()) {
return; }
91 for (std::size_t i = 0; i < streams.size(); ++i) {
97 CorelinkDLL::corelinkCleanup();
109 len = CorelinkDLL::getTokenLen();
110 if (len == 0) {
return ""; }
111 data =
new char[len];
112 CorelinkDLL::getTokenStr(data);
113 token = std::string(data, len);
117 data = CorelinkDLL::getToken(len);
118 token = std::string(data, len);
119 CorelinkDLL::freeData(data);
126 CorelinkDLL::commListFunctions(commID, errorID);
127 CorelinkException::GetDLLException(errorID);
128 return getCommResponseData(commID);
133 std::vector<std::string> data;
134 CorelinkDLL::commGetFunctionInfo(func.c_str(), commID, errorID);
135 CorelinkException::GetDLLException(errorID);
136 data = getCommResponseData(commID);
142 CorelinkDLL::commListWorkspaces(commID, errorID);
143 CorelinkException::GetDLLException(errorID);
144 return getCommResponseData(commID);
148 return CorelinkDLL::commAddWorkspace(workspace.c_str());
152 return CorelinkDLL::commRmWorkspace(workspace.c_str());
156 rapidjson::Document res = rapidjson::Document();
157 rapidjson::StringBuffer buffer;
158 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
163 if (!json.IsObject()) {
168 jsonStr = buffer.GetString();
169 CorelinkDLL::commGeneric(jsonStr.c_str(), (int) jsonStr.size(), commID, errorID);
170 CorelinkException::GetDLLException(errorID);
171 jsonStr = getCommResponseData(commID)[0];
172 res.Parse(jsonStr.c_str(), jsonStr.size());
177 rapidjson::Document res = rapidjson::Document();
180 CorelinkDLL::commGeneric(json.c_str(), (int) json.size(), commID, errorID);
181 CorelinkException::GetDLLException(errorID);
182 jsonStr = getCommResponseData(commID)[0];
185 res.Parse(jsonStr.c_str(), jsonStr.size());
190 rapidjson::Document res = rapidjson::Document();
193 CorelinkDLL::commGeneric(json, len, commID, errorID);
194 CorelinkException::GetDLLException(errorID);
195 jsonStr = getCommResponseData(commID)[0];
198 res.Parse(jsonStr.c_str(), jsonStr.size());
202 inline std::vector<int>
Client::listStreams(
const std::vector<std::string>& workspaces,
const std::vector<std::string>& types) {
204 std::vector<std::string> response;
205 std::vector<int> data;
206 const char** dataWorkspaces = vecStringToCharArray(workspaces);
207 const char** dataTypes = vecStringToCharArray(types);
208 CorelinkDLL::commListStreams(dataWorkspaces, (
int) workspaces.size(), dataTypes, (int) types.size(), commID, errorID);
209 delete[] dataWorkspaces;
211 CorelinkException::GetDLLException(errorID);
212 response = getCommResponseData(commID);
213 data.resize(response.size());
214 for (
int i = 0; i < response.size(); ++i) {
215 data[i] = *((
int*)response[i].c_str());
222 CorelinkDLL::commGetStreamInfo(streamID, commID, errorID);
223 CorelinkException::GetDLLException(errorID);
224 return getDataStreamInfo(commID);
229 CorelinkDLL::commAddSender(workspace.c_str(), type.c_str(), meta.c_str(), echo, alert, protocol, commID, errorID);
230 CorelinkException::GetDLLException(errorID);
234 inline RecvStream Client::createReceiver(
const std::string& workspace,
const std::vector<std::string>& types,
const std::string& meta,
bool echo,
bool alert,
int protocol) {
236 const char** typeData = vecStringToCharArray(types);
237 CorelinkDLL::commAddReceiver(workspace.c_str(), typeData, (int) types.size(), meta.c_str(), echo, alert, protocol, commID, errorID);
238 CorelinkException::GetDLLException(errorID);
243 bool output = CorelinkDLL::commSubscribe(receiverID, senderID);
248 bool output = CorelinkDLL::commUnsubscribe(receiverID, senderID);
253 bool output = CorelinkDLL::commDisconnect(streamID);
static bool rmWorkspace(const std::string &workspace)
static std::vector< std::string > listServerFunctions()
static bool subscribe(const STREAM_ID &receiverID, const STREAM_ID &senderID)
static RecvStream getReceiverHandler(const STREAM_ID &streamID)
Defines the classes in the wrapper and their relations.
static bool addWorkspace(const std::string &workspace)
static void connect(const std::string &serverIP, int port)
static rapidjson::Document genericComm(const rapidjson::Document &json)
static StreamData streamInfo(const int &streamID)
static RecvStream createReceiver(const std::string &workspace, const std::vector< std::string > &types, const std::string &meta, bool echo, bool alert, int protocol)
static std::string getToken()
static bool rmStream(const STREAM_ID &streamID)
static bool unsubscribe(const STREAM_ID &receiverID, const STREAM_ID &senderID)
static std::vector< std::string > describeServerFunction(const std::string &func)
static SendStream createSender(const std::string &workspace, const std::string &type, const std::string &meta, bool echo, bool alert, int protocol)
static void connectPlugin()
static std::vector< std::string > listWorkspaces()
static std::vector< STREAM_ID > listClientStreams()
static std::vector< int > listStreams(const std::vector< std::string > &workspaces={}, const std::vector< std::string > &types={})
Handles the underlying DLL error messages.