-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finished with documentation first draft
- Loading branch information
Showing
15 changed files
with
627 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// Copyright (c) 2015 Jim Youngquist | ||
// under The MIT License (MIT) | ||
// full text in LICENSE file in root folder of this project. | ||
// | ||
|
||
#include <exception> | ||
|
||
#include "RequestSink.hpp" | ||
|
||
RequestSink::RequestSink(const std::string &url) : | ||
context_{1}, | ||
socket_{context_, ZMQ_REQ}, | ||
url_{url}, | ||
connected_{false} | ||
{} | ||
|
||
bool RequestSink::Send(const std::string &buffer) { | ||
std::vector<uint8_t> byte_buffer(buffer.begin(), buffer.end()); | ||
return Send(byte_buffer); | ||
} | ||
|
||
bool RequestSink::Send(const std::vector<uint8_t> &buffer) { | ||
zmq::message_t request((void*)&buffer[0], buffer.size(), nullptr); | ||
socket_.send(request); | ||
|
||
// Get the reply | ||
zmq::message_t reply; | ||
socket_.recv(&reply); | ||
std::string value{reinterpret_cast<char*>(reply.data()), reply.size()}; | ||
if (value != "Success") { | ||
std::runtime_error(value.c_str()); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool RequestSink::Connect(void) { | ||
socket_.connect(url_.c_str()); | ||
connected_ = true; | ||
|
||
return true; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// Copyright (c) 2015 Jim Youngquist | ||
// under The MIT License (MIT) | ||
// full text in LICENSE file in root folder of this project. | ||
// | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include <zmq.hpp> | ||
|
||
//====================================================================== | ||
/** \brief This class wraps a ZeroMQ request-response socket connection. | ||
* | ||
* It acts as a one-way sink for data. Responses are not actually returned, | ||
* only checked that the "request" was successfully transmitted. | ||
* | ||
* Usage: | ||
\code | ||
RequestSink conn{"tcp://hostname:port"}; | ||
conn.Connect(); | ||
conn.Send("oh my goodness!"); | ||
\endcode | ||
*/ | ||
class RequestSink { | ||
public: | ||
//-------------------------------------------------- | ||
/** \brief Initializes for a connection to a valid ZeroMQ endpoint, but does | ||
* not actually connect to it. | ||
* | ||
* \param url the ZeroMQ url to connect to. | ||
*/ | ||
RequestSink(const std::string &url); | ||
|
||
//-------------------------------------------------- | ||
/** \brief Transmits a string. | ||
* | ||
* \param buffer the string to send. | ||
* | ||
* \returns whether transmission was successful. | ||
*/ | ||
bool Send(const std::string &buffer); | ||
|
||
//-------------------------------------------------- | ||
/** \brief Transmits a byte vector | ||
* | ||
* \param buffer the bytes to send. | ||
* | ||
* \returns whether transmission was successful. | ||
*/ | ||
bool Send(const std::vector<uint8_t> &buffer); | ||
|
||
//-------------------------------------------------- | ||
/** \brief Actually connects to a Request socket. | ||
*/ | ||
bool Connect(void); | ||
|
||
private: | ||
zmq::context_t context_; | ||
zmq::socket_t socket_; | ||
const std::string url_; | ||
bool connected_; | ||
}; |
Oops, something went wrong.