SmartSoft Component-Developer API
Public Member Functions | List of all members
Smart::IPushClientPattern< DataType > Class Template Referenceabstract

Client part of the Push pattern to provide a flexible publish/subscribe service. More...

#include <smartIPushClientPattern_T.h>

Inheritance diagram for Smart::IPushClientPattern< DataType >:
Smart::IClientPattern Smart::InputSubject< DataType > Smart::ICommunicationPattern Smart::IShutdownObserver

Public Member Functions

 IPushClientPattern (IComponent *component)
 Constructor (not wired with service provider and not exposed as port). More...
 
 IPushClientPattern (IComponent *component, const std::string &server, const std::string &service)
 Connection Constructor (implicitly wiring with specified service provider). More...
 
virtual ~IPushClientPattern ()=default
 Destructor. More...
 
virtual StatusCode subscribe (const unsigned int &prescale=1)=0
 Subscribe at the server to periodically get every n-th update. More...
 
virtual StatusCode unsubscribe ()=0
 Unsubscribe to get no more updates. More...
 
virtual StatusCode getUpdate (DataType &d)=0
 Non-blocking call to immediately return the latest available data buffered at the client side from the most recent update. More...
 
virtual StatusCode getUpdateWait (DataType &d, const Duration &timeout=Duration::max())=0
 Blocking call which waits until the next update is received. More...
 
- Public Member Functions inherited from Smart::IClientPattern
 IClientPattern (IComponent *component)
 Default Constructor (not yet connecting with any service provider). More...
 
 IClientPattern (IComponent *component, const std::string &server, const std::string &service)
 Connection Constructor (implicitly connecting with specified service provider). More...
 
virtual ~IClientPattern ()=default
 Default destructor. More...
 
virtual StatusCode connect (const std::string &server, const std::string &service)=0
 Connect this service requestor to the denoted service provider. More...
 
virtual StatusCode disconnect ()=0
 Disconnect the service requestor from the service provider. More...
 
virtual StatusCode blocking (const bool blocking)=0
 Allow or abort and reject blocking calls. More...
 
- Public Member Functions inherited from Smart::ICommunicationPattern
 ICommunicationPattern (IComponent *component)
 Default Constructor initializing an IShutdownObserver. More...
 
virtual ~ICommunicationPattern ()=default
 Default Destructor. More...
 
- Public Member Functions inherited from Smart::IShutdownObserver
 IShutdownObserver (ShutdownSubject *subject=nullptr)
 The default constructor. More...
 
virtual ~IShutdownObserver ()
 The default destructor. More...
 
- Public Member Functions inherited from Smart::InputSubject< DataType >
virtual ~InputSubject ()=default
 Default destructor. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Smart::IClientPattern
bool is_shutting_down () const
 
virtual void on_shutdown () override
 implements individual shutdown strategy The default behavior for each client during component shutdown is to call disconnect() which automatically disconnects the current client instance. More...
 
 IClientPattern ()=delete
 
- Protected Member Functions inherited from Smart::ICommunicationPattern
 ICommunicationPattern (const ICommunicationPattern &)=delete
 
ICommunicationPatternoperator= (const ICommunicationPattern &)=delete
 
 ICommunicationPattern ()=delete
 
- Protected Member Functions inherited from Smart::IShutdownObserver
void attach_self_to (ShutdownSubject *subject)
 call this method from within the constructor of derived classes More...
 
void detach_self_from (ShutdownSubject *subject)
 this method is called within the destructor More...
 
- Protected Member Functions inherited from Smart::InputSubject< DataType >
virtual void attach (IInputHandler< DataType > *handler, const unsigned int &prescaleFactor=1)
 Attach an IInputHandler<InputType> instance. More...
 
virtual void detach (IInputHandler< DataType > *handler)
 Detach an IInputHandler<InputType> instance. More...
 
virtual bool notify_input (const DataType &input)
 Notifies all attached IInputHandler instances about incoming data. More...
 
- Protected Attributes inherited from Smart::IClientPattern
std::string connectionServerName
 the server-name used for the last connection (can be used in derived classes) More...
 
std::string connectionServiceName
 the service-name used for the last connection (can be used in derived classes) More...
 
std::atomic< bool > is_blocking
 the flag indicating the current blocking state of this client (can be used in derived classes) More...
 
- Protected Attributes inherited from Smart::ICommunicationPattern
IComponenticomponent
 the internal pointer to the component (can be accessed in derived classes) More...
 

Detailed Description

template<class DataType>
class Smart::IPushClientPattern< DataType >

Client part of the Push pattern to provide a flexible publish/subscribe service.

Clients can subscribe to regularly get every n-th update. This class inherits the API from IClientPattern.

Template parameters

Constructor & Destructor Documentation

◆ IPushClientPattern() [1/2]

template<class DataType >
Smart::IPushClientPattern< DataType >::IPushClientPattern ( IComponent component)
inline

Constructor (not wired with service provider and not exposed as port).

connect() / disconnect() can always be used to change the status of the instance. Instance is not connected to a service provider and is not exposed as port wireable from outside the component.

Parameters
componentthe management class of the component

◆ IPushClientPattern() [2/2]

template<class DataType >
Smart::IPushClientPattern< DataType >::IPushClientPattern ( IComponent component,
const std::string &  server,
const std::string &  service 
)
inline

Connection Constructor (implicitly wiring with specified service provider).

Connects to the denoted service and blocks until the connection has been established. Blocks infinitely if denoted service becomes unavailable since constructor performs retries. Blocking is useful to simplify startup of components which have mutual dependencies. connect() / disconnect() can always be used to change the status of the instance.

Parameters
componentthe management class of the component
servername of the server (i.e. the component-name to connect to)
servicename of the service (i.e. the port-name of the component to connect to)

◆ ~IPushClientPattern()

template<class DataType >
virtual Smart::IPushClientPattern< DataType >::~IPushClientPattern ( )
virtualdefault

Destructor.

The destructor calls disconnect() and therefore properly cleans up every pending data reception and removes the instance from the set of wireable ports.

Member Function Documentation

◆ getUpdate()

template<class DataType >
virtual StatusCode Smart::IPushClientPattern< DataType >::getUpdate ( DataType &  d)
pure virtual

Non-blocking call to immediately return the latest available data buffered at the client side from the most recent update.

No data is returned as long as no update is received since subscription. To avoid returning old data, no data is returned after the client is unsubscribed or when the server is not active.

Parameters
dis set to the newest currently available data
Returns
status code
  • SMART_OK : everything ok and latest data since client got subscribed is returned.
  • SMART_NODATA : client has not yet received an update since subscription and therefore no data is available and no data is returned.
  • SMART_NOTACTIVATED : the server is currently not active and does therefore not provide updates at the expected rate. No valid data returned.
  • SMART_UNSUBSCRIBED : no data available since client is not subscribed and can therefore not receive updates. Method does not return old data from last subscription since these might be based on too old parameter settings. To get data one has to be subscribed.
  • SMART_DISCONNECTED : no data returned since client is even not connected to a server.
  • SMART_ERROR : something went wrong

◆ getUpdateWait()

template<class DataType >
virtual StatusCode Smart::IPushClientPattern< DataType >::getUpdateWait ( DataType &  d,
const Duration timeout = Duration::max() 
)
pure virtual

Blocking call which waits until the next update is received.

Blocking is aborted with the appropriate status if either the server gets deactivated, the client gets unsubscribed or disconnected or if blocking is not allowed any more at the client.

Parameters
dis set to the newest currently available data
timeoutis the timeout time to block the method maximally (default value max blocks infinitely)
Returns
status code
  • SMART_OK : everything is ok and just received data is returned.
  • SMART_CANCELLED : blocking is not allowed or is not allowed anymore. Waiting for the next update is aborted and no valid data is returned.
  • SMART_NOTACTIVATED : the server is currently not active and does therefore not provide updates at the expected rate. No valid data returned.
  • SMART_UNSUBSCRIBED : returns immediately without data if the client is not subscribed.
  • SMART_DISCONNECTED : returns immediately without data since client is even not connected to a server.
  • SMART_ERROR : something went completely wrong and no valid data returned.

◆ subscribe()

template<class DataType >
virtual StatusCode Smart::IPushClientPattern< DataType >::subscribe ( const unsigned int &  prescale = 1)
pure virtual

Subscribe at the server to periodically get every n-th update.

A newly subscribed client gets the next available new data and is then updated with regard to its individual prescale-factor. If the prescale factor is omitted then every update will be received.

Parameters
prescalewhole-numbered value to set the update rate to every n-th value (must be greater than 0)
Returns
status code
  • SMART_OK : everything is ok and client is subscribed
  • SMART_DISCONNECTED : client is not connected to a server and can therefore not subscribe for updates, not subscribed
  • SMART_ERROR_COMMUNICATION : communication problems, not subscribed
  • SMART_ERROR : something went wrong, not subscribed

◆ unsubscribe()

template<class DataType >
virtual StatusCode Smart::IPushClientPattern< DataType >::unsubscribe ( )
pure virtual

Unsubscribe to get no more updates.

All blocking calls are aborted with the appropriate status and yet received and still buffered data is deleted to avoid returning old data.

Returns
status code
  • SMART_OK : everything is ok and client is now unsubscribed or has already been unsubscribed
  • SMART_ERROR_COMMUNICATION : communication problems, not unsubscribed
  • SMART_ERROR : something went wrong, not unsubscribed

(can not return SMART_DISCONNECTED since then client is for sure also unsubscribed which results in SMART_OK)


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