|
@@ -16,15 +16,16 @@
|
|
|
using namespace aman;
|
|
|
|
|
|
AircraftReporter::AircraftReporter() noexcept :
|
|
|
- m_initialized(false),
|
|
|
m_socket() { }
|
|
|
|
|
|
bool AircraftReporter::initialize(const Communication& configuration) {
|
|
|
- if (true == this->m_initialized || false == configuration.valid)
|
|
|
- return this->m_initialized;
|
|
|
+ if (nullptr != this->m_socket)
|
|
|
+ return true;
|
|
|
+ if (false == configuration.valid)
|
|
|
+ return false;
|
|
|
|
|
|
- this->m_socket = zmq::socket_t(ZmqContext::context(), zmq::socket_type::pub);
|
|
|
- this->m_socket.set(zmq::sockopt::immediate, true);
|
|
|
+ this->m_socket = std::make_unique<zmq::socket_t>(ZmqContext::instance().context(), zmq::socket_type::pub);
|
|
|
+ this->m_socket->set(zmq::sockopt::immediate, true);
|
|
|
|
|
|
/* configure the encryption */
|
|
|
if (false == this->setSocketKey(configuration.serverPublicIdentifier, zmq::sockopt::curve_serverkey))
|
|
@@ -36,32 +37,34 @@ bool AircraftReporter::initialize(const Communication& configuration) {
|
|
|
|
|
|
/* connect to the server */
|
|
|
try {
|
|
|
- this->m_socket.connect("tcp://" + configuration.address + ":" + std::to_string(configuration.portReporter));
|
|
|
+ this->m_socket->connect("tcp://" + configuration.address + ":" + std::to_string(configuration.portReporter));
|
|
|
}
|
|
|
catch (zmq::error_t&) {
|
|
|
+ this->m_socket = std::unique_ptr<zmq::socket_t>();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- this->m_initialized = true;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
bool AircraftReporter::deinitialize() {
|
|
|
- if (false == this->m_initialized)
|
|
|
+ if (nullptr == this->m_socket)
|
|
|
return true;
|
|
|
|
|
|
- this->m_socket.close();
|
|
|
+ this->m_socket->close();
|
|
|
+ this->m_socket = std::make_unique<zmq::socket_t>();
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
bool AircraftReporter::send(zmq::message_t& message) {
|
|
|
bool retval = false;
|
|
|
|
|
|
- if (true == this->m_initialized) {
|
|
|
+ if (nullptr != this->m_socket) {
|
|
|
try {
|
|
|
- auto bla = message.size();
|
|
|
- auto result = this->m_socket.send(message, zmq::send_flags::none);
|
|
|
- retval = result.value() == bla;
|
|
|
+ auto size = message.size();
|
|
|
+ auto result = this->m_socket->send(message, zmq::send_flags::none);
|
|
|
+ retval = result.value() == size;
|
|
|
}
|
|
|
catch (zmq::error_t&) {
|
|
|
return false;
|