OctopOS  0.6.0
Data communication bus for SPACE HAUC
Public Member Functions | List of all members
subscriber< T > Class Template Reference

#include <subscriber.h>

Inheritance diagram for subscriber< T >:
subscriber_manager tentacle

Public Member Functions

 subscriber (std::string topic_name, key_t shared_queue)
 
bool data_available ()
 
get_data ()
 
Optional< T > get_data_async ()
 
 ~subscriber ()
 

Additional Inherited Members

- Static Public Member Functions inherited from subscriber_manager
static void * wait_for_data (void *data)
 
- Protected Types inherited from tentacle
enum  role_t { SUBSCRIBER, PUBLISHER }
 
- Protected Member Functions inherited from subscriber_manager
 subscriber_manager (key_t shared_queue)
 
- Protected Member Functions inherited from tentacle
 tentacle (key_t msg_key)
 
bool write (long type, std::string data)
 
bool write (std::pair< long, std::string > pair)
 
- Static Protected Member Functions inherited from subscriber_manager
static bool register_cb (callback cb, std::string topic, uint size, subscriber_manager *sub)
 
- Static Protected Member Functions inherited from tentacle
static long getTempId (role_t role)
 
static std::pair< long, std::string > read (long type, bool block=true, bool under=false)
 
- Static Protected Attributes inherited from subscriber_manager
static std::unordered_map< std::string, std::tuple< sem_id_t, shm_object *, generic_t * > > topic_memory
 
static std::unordered_map< std::string, octopOS_id_ttopic_ids
 
static std::unordered_map< std::string, std::vector< callback > > registered_callbacks
 
static std::mutex topic_ids_lock
 
static std::mutex topic_memory_lock
 
static std::mutex registered_callbacks_lock
 
- Static Protected Attributes inherited from tentacle
static int message_que
 
static intptr_t * shared_data = NULL
 

Detailed Description

template<typename T>
class subscriber< T >

subscriber is used to retrtieve the data published to a topic so it can be used in the client application. This class provides an easy interface for reading off a topic's data_queue. T is the type of data assosciated with the topic.

Constructor & Destructor Documentation

◆ subscriber()

template<typename T >
subscriber< T >::subscriber ( std::string  topic_name,
key_t  shared_queue 
)
inline

Created a new subscriber to a specific topic. Intializes mutex and condition variable for data_queue protection.

Parameters
topic_nameThe Name of the topic to be subscribed to.
shared_queueThe key for the message queue to construct a tentacle on.

The lambda is the callback. It pushes the new data onto the data_queue.

◆ ~subscriber()

template<typename T >
subscriber< T >::~subscriber ( )
inline

Frees pthread primatives

Member Function Documentation

◆ data_available()

template<typename T >
bool subscriber< T >::data_available ( )
inline

Is data available to read?

Returns
Whether data is available.

◆ get_data()

template<typename T >
T subscriber< T >::get_data ( )
inline

Reads from the top of the data queue. If there is no data this will block untill signaled from the callback that there is data available.

Returns
The top of the queue. Is type T.

◆ get_data_async()

template<typename T >
Optional<T> subscriber< T >::get_data_async ( )
inline

Reads from the top of the data queue if there is data. Will not block and and returns an empty Optional. You must check if the data is defined before using it.

Returns
Optional<T>

The documentation for this class was generated from the following file: