Commit 25333246 authored by legoc's avatar legoc
Browse files

Implemented OutputStreamSocket::receive() with optional Output result

parent 686608fd
......@@ -5,6 +5,7 @@
* Added Instance::waitFor() and Instance::waitFor(int) for python binding.
* Implemented subscriber and requester with optional string result in receive() function.
* Implemented Instance::getResult() with optional string result.
* Implemented OutputStreamSocket::receive() with optional Output result.
1.0.2
-----
......
......@@ -17,8 +17,9 @@
#ifndef CAMEO_OUTPUTSTREAMSOCKET_H_
#define CAMEO_OUTPUTSTREAMSOCKET_H_
#include <memory>
#include "Event.h"
#include <memory>
#include <optional>
namespace cameo {
......@@ -59,7 +60,7 @@ public:
void setApplicationId(int id);
bool receive(Output& ouput);
std::optional<Output> receive();
void cancel();
bool isEnded() const;
bool isCanceled() const;
......
......@@ -57,7 +57,7 @@ void OutputStreamSocket::setApplicationId(int id) {
m_applicationId = id;
}
bool OutputStreamSocket::receive(Output& output) {
std::optional<Output> OutputStreamSocket::receive() {
// Loop on receive() because in case of configuration multiple=yes, messages can come from different instances.
while (true) {
......@@ -67,7 +67,7 @@ bool OutputStreamSocket::receive(Output& output) {
// Cancel can only come from this instance.
if (messageType == message::Event::CANCEL) {
m_canceled = true;
return false;
return {};
}
// Get the second part of the message.
......@@ -91,22 +91,25 @@ bool OutputStreamSocket::receive(Output& output) {
// Terminate the stream if type of message is ENDSTREAM.
if (messageType == message::Event::ENDSTREAM) {
m_ended = true;
return false;
return {};
}
// Here the type of message is STREAM.
string line = event[message::ApplicationStream::MESSAGE].GetString();
bool endOfLine = event[message::ApplicationStream::EOL].GetBool();
Output output;
output.m_id = id;
output.m_message = line;
output.m_endOfLine = endOfLine;
return true;
return optional<Output>(output);
}
// Here, the application id is different from id, then re-iterate.
}
return {};
}
void OutputStreamSocket::cancel() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment