diff --git a/src/ServiceDiscovery/Services.cpp b/src/ServiceDiscovery/Services.cpp index a4be2fc..7e8cca1 100644 --- a/src/ServiceDiscovery/Services.cpp +++ b/src/ServiceDiscovery/Services.cpp @@ -42,6 +42,10 @@ bool Services::Init(Store &m_variables, zmq::context_t* context_in, SlowControlC return true; } +bool Services::Ready(const unsigned int timeout){ + return m_backend_client.Ready(timeout); +} + // =========================================================================== // Write Functions // --------------- diff --git a/src/ServiceDiscovery/Services.h b/src/ServiceDiscovery/Services.h index 86c6b5f..ffef3d4 100644 --- a/src/ServiceDiscovery/Services.h +++ b/src/ServiceDiscovery/Services.h @@ -38,6 +38,7 @@ namespace ToolFramework { Services(); ~Services(); bool Init(Store &m_variables, zmq::context_t* context_in, SlowControlCollection* sc_vars_in, bool new_service=false); + bool Ready(const unsigned int timeout=10000); // default service discovery broadcast period is 5s, middleman also checks intermittently, compound total time should be <10s... bool SQLQuery(const std::string& database, const std::string& query, std::vector& responses, const unsigned int timeout=SERVICES_DEFAULT_TIMEOUT); bool SQLQuery(const std::string& database, const std::string& query, std::string& response, const unsigned int timeout=SERVICES_DEFAULT_TIMEOUT); diff --git a/src/ServiceDiscovery/ServicesBackend.cpp b/src/ServiceDiscovery/ServicesBackend.cpp index aff94e2..3fbe98f 100644 --- a/src/ServiceDiscovery/ServicesBackend.cpp +++ b/src/ServiceDiscovery/ServicesBackend.cpp @@ -936,3 +936,30 @@ bool ServicesBackend::Receive(zmq::socket_t* sock, std::vector& return true; } +bool ServicesBackend::Ready(int timeout){ + + // poll the output sockets for listeners + // only poll dealer socket, pub sockets always return true immediately so ignore the timeout + // polling the input socket checks for a message, so don't do that. + int ret; + try { + dlr_socket_mutex.lock(); + ret = zmq::poll(&out_polls.at(1), 1, timeout); + dlr_socket_mutex.unlock(); + } catch (zmq::error_t& err){ + std::cerr<<"ServicesBackend::Ready caught "< log=nullptr); // possibly move to constructor + bool Ready(int timeout); // check if zmq sockets have connections bool Initialise(std::string configfile); bool Initialise(Store &varaibles_in); bool Finalise();