Commit 1f17f7b3 authored by legoc's avatar legoc
Browse files

Added optional second message to Request retrieved as binary message.

parent 5016da24
......@@ -9,4 +9,4 @@
* Renamed ERROR into FAILURE.
* Implementation of unmanaged applications.
* Implemented This static instance without pointer so that it is not necessary to call This::terminate() except if the destruction of the static instance is not automatic.
* Added two binary parts message for publisher/subscriber.
\ No newline at end of file
* Added two binary parts message for publisher/subscriber and requester/responder.
\ No newline at end of file
......@@ -936,11 +936,11 @@ Request::Request(std::auto_ptr<RequestImpl> & impl) :
Request::~Request() {
}
const std::string& Request::getBinaryData() const {
const std::string& Request::getBinary() const {
return m_impl->m_message;
}
std::string Request::getData() const {
std::string Request::get() const {
string data;
parse(m_impl->m_message, data);
......@@ -948,6 +948,10 @@ std::string Request::getData() const {
return data;
}
const std::string& Request::getSecondBinaryPart() const {
return m_impl->m_message2;
}
void Request::replyBinary(const std::string& response) {
m_impl->replyBinary(response);
}
......@@ -1084,6 +1088,10 @@ void Requester::send(const std::string& request) {
m_impl->send(request);
}
void Requester::sendTwoBinaryParts(const std::string& request1, const std::string& request2) {
m_impl->sendTwoBinaryParts(request1, request2);
}
bool Requester::receiveBinary(std::string& response) {
return m_impl->receiveBinary(response);
}
......
......@@ -359,8 +359,9 @@ class Request {
public:
~Request();
const std::string& getBinaryData() const;
std::string getData() const;
const std::string& getBinary() const;
std::string get() const;
const std::string& getSecondBinaryPart() const;
void replyBinary(const std::string& response);
void reply(const std::string& response);
......@@ -420,6 +421,7 @@ public:
void sendBinary(const std::string& request);
void send(const std::string& request);
void sendTwoBinaryParts(const std::string& request1, const std::string& request2);
bool receiveBinary(std::string& response);
bool receive(std::string& response);
......
......@@ -43,6 +43,7 @@ enum ProtoType {
PROTO_CONNECTPORT,
PROTO_REMOVEPORT,
PROTO_REQUEST,
PROTO_REQUEST2,
PROTO_RESPONSE,
PROTO_CANCEL,
PROTO_SETRESULT,
......
......@@ -40,6 +40,7 @@ public:
const application::This * m_application;
std::string m_requesterEndpoint;
std::string m_message;
std::string m_message2;
int m_requesterApplicationId;
};
......
......@@ -83,6 +83,28 @@ void RequesterImpl::send(const std::string& request) {
sendBinary(result);
}
void RequesterImpl::sendTwoBinaryParts(const std::string& request1, const std::string& request2) {
stringstream requesterEndpoint;
requesterEndpoint << m_application->getUrl() << ":" << m_requesterPort;
string strRequestType = m_application->m_impl->createRequest(PROTO_REQUEST);
string strRequestData;
proto::Request requestCommand;
requestCommand.set_applicationid(m_application->getId());
requestCommand.set_message(request1);
requestCommand.set_message2(request2);
requestCommand.set_endpoint(requesterEndpoint.str());
requestCommand.SerializeToString(&strRequestData);
zmq::message_t* reply = m_application->m_impl->tryRequestWithOnePartReply(strRequestType, strRequestData, m_responderEndpoint);
proto::RequestResponse requestResponse;
requestResponse.ParseFromArray((*reply).data(), (*reply).size());
delete reply;
}
bool RequesterImpl::receiveBinary(std::string& response) {
zmq::message_t * message = new zmq::message_t;
......
......@@ -40,6 +40,7 @@ public:
void sendBinary(const std::string& request);
void send(const std::string& request);
void sendTwoBinaryParts(const std::string& request1, const std::string& request2);
bool receiveBinary(std::string& response);
bool receive(std::string& response);
......
......@@ -105,6 +105,11 @@ std::auto_ptr<RequestImpl> ResponderImpl::receive() {
// Create the request
result = auto_ptr<RequestImpl>(new RequestImpl(m_application, messageRequest.endpoint(), messageRequest.message(), messageRequest.applicationid()));
// Set message 2 if it exists.
if (messageRequest.has_message2()) {
result->m_message2 = messageRequest.message2();
}
} else if (messageType.type() == proto::MessageType_Type_CANCEL) {
m_ended = true;
......
......@@ -210,7 +210,8 @@ message PublisherResponse {
message Request {
required int32 applicationId = 1;
required bytes message = 2;
required string endpoint = 3;
optional bytes message2 = 3;
required string endpoint = 4;
}
message StartedUnmanagedCommand {
......
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