Skip to content

Commit

Permalink
remove the builder member and just create a new builder every time it…
Browse files Browse the repository at this point in the history
… is needed.
  • Loading branch information
phlptp committed Aug 14, 2019
1 parent 72b4f14 commit cf850ab
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
48 changes: 34 additions & 14 deletions src/networking/dimeClientInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,19 @@ void dimeClientInterface::init ()
outgoing["name"] = name;
outgoing["listen_to_events"] = false;

std::stringstream ss;
writer->write(outgoing, &ss);
Json_gd::StreamWriterBuilder builder;
builder["commentStyle"] = "None";
builder["indentation"] = " "; // or whatever you like
auto writer = builder.newStreamWriter ();
std::stringstream sstr;
writer->write (outgoing, &sstr);
delete writer;

socket->send (ss.str());
socket->send (sstr.str ());

char buffer[3] = {};
auto sz = socket->recv (buffer, 3, 0);
if ((sz != 2) || (strncmp(buffer, "OK", 3) != 0))
if ((sz != 2) || (strncmp (buffer, "OK", 3) != 0))
{
throw initFailure ();
}
Expand All @@ -71,7 +76,13 @@ void dimeClientInterface::close ()
outgoing["name"] = name;

std::stringstream ss;
writer->write(outgoing, &ss);

Json_gd::StreamWriterBuilder builder;
builder["commentStyle"] = "None";
builder["indentation"] = " "; // or whatever you like
auto writer = builder.newStreamWriter ();
writer->write (outgoing, &ss);
delete writer;

socket->send (ss.str ());

Expand Down Expand Up @@ -110,8 +121,15 @@ void dimeClientInterface::send_var (const std::string &varName, double val, cons
outgoing["args"] = varName;

std::stringstream ss;
writer->write(outgoing, &ss);
socket->send (ss.str());

Json_gd::StreamWriterBuilder builder;
builder["commentStyle"] = "None";
builder["indentation"] = " "; // or whatever you like
auto writer = builder.newStreamWriter ();
writer->write (outgoing, &ss);
delete writer;

socket->send (ss.str ());

char buffer[3];
auto sz = socket->recv (buffer, 3, 0);
Expand All @@ -128,20 +146,22 @@ void dimeClientInterface::send_var (const std::string &varName, double val, cons
outgoingData["meta"]["var_name"] = varName;
encodeVariableMessage (outgoingData, val);

std::stringstream().swap(ss); // reset ss
writer->write(outgoingData, &ss);
std::stringstream ().swap (ss); // reset ss

builder["commentStyle"] = "None";
builder["indentation"] = " "; // or whatever you like
writer = builder.newStreamWriter ();
writer->write (outgoing, &ss);
delete writer;
socket->send (ss.str ());

sz = socket->recv (buffer, 3, 0);
if (sz != 2) // TODO check for "OK"
if (sz != 2) // TODO check for "OK"
{
throw (sendFailure ());
}
}

void dimeClientInterface::broadcast (const std::string &varName, double val)
{
send_var (varName, val);
}
void dimeClientInterface::broadcast (const std::string &varName, double val) { send_var (varName, val); }

void dimeClientInterface::get_devices () {}
1 change: 0 additions & 1 deletion src/networking/dimeClientInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,4 @@ class dimeClientInterface

private:
std::unique_ptr<zmq::socket_t> socket;
std::unique_ptr<Json_gd::StreamWriter> writer{};
};

0 comments on commit cf850ab

Please sign in to comment.