forked from windelbouwman/lognplot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.cpp
More file actions
68 lines (56 loc) · 1.74 KB
/
Copy pathclient.cpp
File metadata and controls
68 lines (56 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "client.h"
namespace lognplot {
TcpClient::TcpClient()
: handle(0)
{
}
void TcpClient::Connect(const char* address)
{
this->handle = lognplot_client_new(address);
if (!this->handle)
{
throw ClientException("Connection to lognplot GUI failed");
}
}
void TcpClient::Disconnect()
{
lognplot_client_close(this->handle);
this->handle = 0;
}
void TcpClient::SendSample(const char* name, const double timestamp, const double value)
{
lognplot_result_t result = lognplot_client_send_sample(this->handle, name, timestamp, value);
if (result != LOGNPLOT_RESULT_OK) {
throw ClientException("Sending sample failed");
}
}
void TcpClient::SendSamples(const char* name, const size_t count, double* timestamps, double* values)
{
lognplot_result_t result = lognplot_client_send_samples(this->handle, name, count, timestamps, values);
if (result != LOGNPLOT_RESULT_OK) {
throw ClientException("Sending samples failed");
}
}
void TcpClient::SendSampled(const char* name, const double timestamp, const double dt, const size_t count, double* values)
{
lognplot_result_t result = lognplot_client_send_sampled_samples(this->handle, name, timestamp, dt, count, values);
if (result != LOGNPLOT_RESULT_OK) {
throw ClientException("Sending sampled samples failed");
}
}
void TcpClient::SendText(const char* name, const double timestamp, const char* text)
{
lognplot_result_t result = lognplot_client_send_text(this->handle, name, timestamp, text);
if (result != LOGNPLOT_RESULT_OK) {
throw ClientException("Sending text failed");
}
}
ClientException::ClientException(const char* msg)
: msg(msg)
{
}
const char * ClientException::what () const throw ()
{
return msg;
}
}