Skip to content
Snippets Groups Projects
Select Git revision
  • 5038964f746f9306aa3fbb38a83cafb146f40069
  • master default protected
  • parallel_trapping
  • offload_trapping
  • script_devel
  • unify_iterations
  • containers-m10
  • magma_refinement
  • release9
  • enable_svd
  • parallel_angles_gmu
  • containers-m8
  • parallel_angles
  • profile_omp_leonardo
  • test_nvidia_profiler
  • containers
  • shaditest
  • test1
  • main
  • 3-error-in-run-the-program
  • experiment
  • NP_TMcode-M10a.03
  • NP_TMcode-M10a.02
  • NP_TMcode-M10a.01
  • NP_TMcode-M10a.00
  • NP_TMcode-M9.01
  • NP_TMcode-M9.00
  • NP_TMcode-M8.03
  • NP_TMcode-M8.02
  • NP_TMcode-M8.01
  • NP_TMcode-M8.00
  • NP_TMcode-M7.00
  • v0.0
33 results

pycompare.py

Blame
  • ZMQPublisher.hpp 2.20 KiB
    #ifndef __ZMQPUBLISHER_HPP__
    #define __ZMQPUBLISHER_HPP__
    
    #include <zmq.hpp>
    #include <zmq_addon.hpp>
    #include "ZMQDictionary.hpp"
    
    #define DEFAULT_ADDRESS std::string("127.0.0.1")
    #define DEFAULT_PORT    16001
    
    
    /**
     * This class implements a publisher object over a ZeroMQ socket, single topic only.
     * It exposes a publish method which sends a dictionary of key, value format over the ZMQ socket.
     */
    class ZMQPublisher
    {
    public:
        /**
         * Constructors. Initializes the ZMQPublisher object with the given topic, address and port.
         */
        ZMQPublisher(const std::string& topic, const std::string address, const unsigned int port);
        ZMQPublisher(const std::string& topic) : ZMQPublisher(topic, DEFAULT_ADDRESS, DEFAULT_PORT) {};
        ZMQPublisher(const std::string& topic, const std::string address) : ZMQPublisher(topic, address, DEFAULT_PORT) {};
        ZMQPublisher(const std::string& topic, const unsigned int port) : ZMQPublisher(topic, DEFAULT_ADDRESS, port) {};
    
        /**
         * Destructor.
         */
        ~ZMQPublisher();
    
        /**
         * Public publisher method. This method accepts a ZMQDictionary object reference,
         * it converts it to a json-ified string and calls the protected publisher method.
         * @param dictionary, a json-like dictionary containing tuples of key, value format.
         */
        virtual void publish(const ZMQDictionary& dictionary);
    
        /**
         * Name of the topic on which the messages will be sent.
         */
        const std::string topic;
    
    protected:
        /**
         * Protected publisher method. This method sends a tuple (topic, payload) over the ZMQ socket.
         * @param payload, a json-ified string.
         */
        virtual void publish(const std::string& payload);
    
    private:
        /**
         * ZMQ constant buffer which references the topic name.
         */
        const zmq::const_buffer m_topic;
    
        /**
         * ZMQ context shared pointer. We use a pointer since the context must not be destroyed for communications to work properly.
         */
        std::shared_ptr<zmq::context_t> m_context;
    
        /**
         * ZMQ socket shared pointer. We use a pointer since the socket must not be destroyed for communications to work properly.
         */
        std::shared_ptr<zmq::socket_t> m_socket;
    };
    
    
    #endif /*__ZMQPUBLISHER_HPP__*/