Class shared_memory::Exchange_manager_consumer¶
-
template<class Serializable, int QUEUE_SIZE>
class shared_memory::Exchange_manager_consumer¶ Public Functions
-
Exchange_manager_consumer(std::string segment_id, std::string object_id, bool leading, bool autolock = true)¶
An exchange_manager_consumer reads from the shared memory serialized items produced by an instance of exchange_manager_producer (which should use the same segment_id and object_id), possibly running in a separate process.
- Parameters
segment_id – id of the shared memory segment
object_id – id of the shared memory object prefix
the – consumer is to be “permanent”, while different producers may provide data. Implies the deletion of the underlying share memory upon destruction.
mutex – locking mechanism internally managed by the producer. If false, lock has to be “manually” called. This allows for example to set several items in one shot
-
~Exchange_manager_consumer()¶
-
void lock()¶
lock the mutex required for writting in the shared memory without any collision with any producer.
Should be called before calls to “consume”. Not required if the constructor was called with autolock set to true
-
void unlock()¶
unlock the mutex for writting in the shared memory without any collision with any producer.
Not required if the constructor was called with autolock set to true
-
bool consume(Serializable &serializable)¶
read from the underlying shared memory a serialized object (set by a producer).
Should be called only if ready_to_consume returns true.
- Returns
true if an item has been read
-
bool ready_to_consume()¶
returns true if a producer is also running.
‘consume’ should be called only if ready_to_consume returns true.
-
bool purge_feedbacks()¶
When this instance consumes an item, the item id is written in a shared queue for the producer to read (and acquire the feedback the item has been consumed).
This shared queue may get full (e.g the producer does not read it fast enough), in which case the item id is buffered in this instance. If this instance stops to consume, the buffered item ids will never be written in the shared queue, and the producer will not receive the corresponding feedback. This attempts to write the buffered ids into the queue, and returns true if the buffer is not empty after the call (i.e. some feedbacks have not been sent yet), false otherwise. Usage: to call before exit until true is returned
-
int nb_char_read()¶
returns the number of char that have been read from the exchange queue.
For debugging purposes
-
bool is_producer_queue_empty() const¶
-
bool is_consumer_queue_empty() const¶
Public Static Functions
-
static void clean_mutex(std::string segment_id)¶
-
static void clean_memory(std::string segment_id)¶
Private Types
-
typedef Exchange_manager_memory<Serializable, QUEUE_SIZE> Memory¶
Private Functions
-
void reset()¶
-
Exchange_manager_consumer(std::string segment_id, std::string object_id, bool leading, bool autolock = true)¶