LCOV - code coverage report
Current view: top level - zeroeq - receiver.h (source / functions) Hit Total Coverage
Test: ZeroEQ Lines: 1 2 50.0 %
Date: 2017-12-01 01:44:57 Functions: 1 3 33.3 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2014-2017, Human Brain Project
       3             :  *                          Stefan.Eilemann@epfl.ch
       4             :  */
       5             : 
       6             : #ifndef ZEROEQ_RECEIVER_H
       7             : #define ZEROEQ_RECEIVER_H
       8             : 
       9             : #include <zeroeq/api.h>
      10             : #include <zeroeq/types.h>
      11             : 
      12             : #include <memory>
      13             : 
      14             : #include <string>
      15             : #include <vector>
      16             : 
      17             : namespace zeroeq
      18             : {
      19             : namespace connection
      20             : {
      21             : namespace detail
      22             : {
      23             : class Broker;
      24             : }
      25             : }
      26             : 
      27             : /**
      28             :  * Base class for entities receiving data.
      29             :  *
      30             :  * Provides a receive() method, which demultiplexes data between multiple inputs
      31             :  * of multiple instances of receivers. Receivers form a shared group by linking
      32             :  * them at construction time.
      33             :  *
      34             :  * Not intended to be as a final class. Not thread safe.
      35             :  *
      36             :  * Example: @include tests/receiver.cpp
      37             :  */
      38           0 : class Receiver
      39             : {
      40             : public:
      41             :     /** Create a new standalone receiver. */
      42             :     ZEROEQ_API Receiver();
      43             : 
      44             :     /**
      45             :      * Create a shared receiver.
      46             :      *
      47             :      * All receivers sharing a group may receive data when receive() is called
      48             :      * on any of them.
      49             :      *
      50             :      * @param shared another receiver to form a simultaneous receive group with.
      51             :      */
      52             :     ZEROEQ_API explicit Receiver(Receiver& shared);
      53             : 
      54             :     ZEROEQ_API virtual ~Receiver();
      55             :     ZEROEQ_API Receiver(Receiver&&);
      56             :     ZEROEQ_API Receiver& operator=(Receiver&&);
      57             : 
      58             :     /**
      59             :      * Receive at least one event from all shared receivers.
      60             :      *
      61             :      * Using receive( 0 ) is equivalent to polling the receivers for data.
      62             :      *
      63             :      * @param timeout timeout in ms for poll, default blocking poll until at
      64             :      *                least one event is received
      65             :      * @return true if at least one event was received
      66             :      * @throw std::runtime_error when polling failed.
      67             :      */
      68             :     ZEROEQ_API bool receive(const uint32_t timeout = TIMEOUT_INDEFINITE);
      69             : 
      70             : protected:
      71             :     /** Add this receiver's sockets to the given list */
      72             :     virtual void addSockets(std::vector<detail::Socket>& entries) = 0;
      73             : 
      74             :     /**
      75             :      * Process data on a signalled socket.
      76             :      *
      77             :      * @param socket the socket provided from addSockets()
      78             :      * @return true if an event was communicated to the application, false
      79             :      *         otherwise
      80             :      */
      81             :     virtual bool process(detail::Socket& socket) = 0;
      82             : 
      83             :     /**
      84             :      * Update the internal connection list.
      85             :      *
      86             :      * Called on all members of a shared group regularly by receive() to update
      87             :      * their list of sockets.
      88             :      */
      89     1817792 :     virtual void update() {}
      90             : 
      91             :     /**
      92             :      * Add the given connection to the list of receiving sockets.
      93             :      *
      94             :      * @param uri the ZeroMQ address to connect to.
      95             :      */
      96             :     ZEROEQ_API virtual void addConnection(const std::string& uri);
      97             :     friend class connection::detail::Broker;
      98             : 
      99             : private:
     100             :     Receiver& operator=(const Receiver&) = delete;
     101             : 
     102             :     class Impl;
     103             :     std::shared_ptr<Impl> _impl;
     104             : };
     105             : }
     106             : 
     107             : #endif

Generated by: LCOV version 1.11