SmartSoft Component-Developer API
Public Member Functions | List of all members
Smart::IEventClientPattern< ActivationType, EventType > Class Template Referenceabstract

Handles the event service on client side. More...

#include <smartIEventClientPattern_T.h>

Inheritance diagram for Smart::IEventClientPattern< ActivationType, EventType >:
Smart::IClientPattern Smart::InputSubject< EventInputType< EventType > > Smart::ICommunicationPattern Smart::IShutdownObserver

Public Member Functions

 IEventClientPattern (IComponent *component)
 Constructor (not wired with a service provider). More...
 
 IEventClientPattern (IComponent *component, const std::string &server, const std::string &service)
 Connection Constructor (implicitly wiring with specified service provider). More...
 
virtual ~IEventClientPattern ()
 Destructor. More...
 
virtual StatusCode activate (const EventMode &mode, const ActivationType &parameter, EventIdPtr &id)=0
 Activate an event with the provided parameters in either "single" or "continuous" mode. More...
 
virtual StatusCode deactivate (const EventIdPtr id)=0
 Deactivate the event with the specified identifier. More...
 
virtual StatusCode tryEvent (const EventIdPtr id)=0
 Check whether event has already fired and return immediately with status information. More...
 
virtual StatusCode getEvent (const EventIdPtr id, EventType &event, const Duration &timeout=Duration::max())=0
 Blocking call which waits for the event to fire and then consumes the event. More...
 
virtual StatusCode getNextEvent (const EventIdPtr id, EventType &event, const Duration &timeout=Duration::max())=0
 Blocking call which waits for the next event. 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< EventInputType< EventType > >
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< EventInputType< EventType > >
virtual void attach (IInputHandler< EventInputType< EventType > > *handler, const unsigned int &prescaleFactor=1)
 Attach an IInputHandler<InputType> instance. More...
 
virtual void detach (IInputHandler< EventInputType< EventType > > *handler)
 Detach an IInputHandler<InputType> instance. More...
 
virtual bool notify_input (const EventInputType< EventType > &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 ActivationType, class EventType>
class Smart::IEventClientPattern< ActivationType, EventType >

Handles the event service on client side.

Template parameters:

Demonstrated in fifth example

Constructor & Destructor Documentation

◆ IEventClientPattern() [1/2]

template<class ActivationType , class EventType >
Smart::IEventClientPattern< ActivationType, EventType >::IEventClientPattern ( IComponent component)
inline

Constructor (not wired with a service provider).

connect() / disconnect() can always be used to change the status of the connection.

Parameters
componentthe management class of the component

◆ IEventClientPattern() [2/2]

template<class ActivationType , class EventType >
Smart::IEventClientPattern< ActivationType, EventType >::IEventClientPattern ( 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)

◆ ~IEventClientPattern()

template<class ActivationType , class EventType >
virtual Smart::IEventClientPattern< ActivationType, EventType >::~IEventClientPattern ( )
inlinevirtual

Destructor.

The destructor calls disconnect().

Member Function Documentation

◆ activate()

template<class ActivationType , class EventType >
virtual StatusCode Smart::IEventClientPattern< ActivationType, EventType >::activate ( const EventMode mode,
const ActivationType &  parameter,
EventIdPtr id 
)
pure virtual

Activate an event with the provided parameters in either "single" or "continuous" mode.

Parameters
mode"single" or "continuous" mode
parameteractivation parameter class (Communication Object)
idis set to the unique id of the event activation
Returns
status code
  • SMART_OK : everything is ok, event is activated and id contains a valid activation identifier.
  • SMART_DISCONNECTED : activation not possible since not connected to a server. No valid activation identifier id returned.
  • SMART_ERROR_COMMUNICATION : communication problems, event not activated, id is not a valid activation identifier.
  • SMART_ERROR : something went wrong, event not activated, id is not a valid activation identifier.

◆ deactivate()

template<class ActivationType , class EventType >
virtual StatusCode Smart::IEventClientPattern< ActivationType, EventType >::deactivate ( const EventIdPtr  id)
pure virtual

Deactivate the event with the specified identifier.

An event must always be deactivated, even if it has already fired in single mode. This is just necessary for cleanup procedures and provides a uniform user API independently of the event mode. Calling deactivate() while there are blocking calls aborts them with the appropriate status code.

Parameters
idof event to be disabled
Returns
status code
  • SMART_OK : everything is ok and event is deactivated
  • SMART_WRONGID : there is no active event available with this id
  • SMART_ERROR_COMMUNICATION : communication problems, event not deactivated
  • SMART_ERROR : something went wrong, event not deactivated

(Hint: can not return SMART_DISCONNECTED since then each event is for sure also deactivated resulting in SMART_WRONGID)

◆ getEvent()

template<class ActivationType , class EventType >
virtual StatusCode Smart::IEventClientPattern< ActivationType, EventType >::getEvent ( const EventIdPtr  id,
EventType &  event,
const Duration timeout = Duration::max() 
)
pure virtual

Blocking call which waits for the event to fire and then consumes the event.

This method consumes an event. Returns immediately if an unconsumed event is available. Blocks otherwise till event becomes available. If method is called concurrently from several threads with the same id and method is blocking, then every call returns with the same event once the event fired. If there is however already an unconsumed event available, then only one out of the concurrent calls consumes the event and the other calls return with appropriate status codes.

Parameters
idof the event activation
eventis set to the returned event if fired (Communication Object)
timeoutis the timeout time to block the method maximally (default value zero block infinitelly)
  • single mode:

Since an event in single mode fires only once, return immediately if the event is already consumed. Also return immediately with an available and unconsumed event and consume it. Otherwise wait until the event fires.

Returns status code:

  • SMART_OK : event fired and event is consumed and returned.
  • SMART_PASSIVE : event fired and got consumed already. Returns immediately without valid event since it can not fire again in single mode.
  • SMART_CANCELLED : waiting for the event to fire has been aborted or blocking is not not allowed anymore. Therefore no valid event is returned.
  • SMART_DISCONNECTED : client is disconnected or got disconnected while waiting and therefore no valid event is returned and the activation identifier id is also not valid any longer due to automatic deactivation.
  • SMART_NOTACTIVATED : got deactivated while waiting and therefore event not valid and also id not valid any longer.
  • SMART_WRONGID : there is no activation available with this id and therefore event not valid.
  • continuous mode:

Returns immediately if an unconsumed event is available. Returns the newest unconsumed event since activation. Otherwise waits until the event fires again.

Returns status code:

  • SMART_OK : unconsumed event is available and event is consumed and returned. Due to the overwriting behavior, only the latest event is available.
  • SMART_CANCELLED : blocking is not allowed anymore therefore blocking call has been aborted and event is not valid.
  • SMART_DISCONNECTED : got disconnected while waiting and therefore event not valid and also id not valid any longer due to automatic deactivation.
  • SMART_NOTACTIVATED : got deactivated while waiting and therefore event not valid and also id not valid any longer.
  • SMART_WRONGID : there is no activation available with this id and therefore event not valid.

◆ getNextEvent()

template<class ActivationType , class EventType >
virtual StatusCode Smart::IEventClientPattern< ActivationType, EventType >::getNextEvent ( const EventIdPtr  id,
EventType &  event,
const Duration timeout = Duration::max() 
)
pure virtual

Blocking call which waits for the next event.

This methods waits for the next arriving event to make sure that only events arriving after entering the method are considered. Method consumes event. An old event that has been fired is ignored (in contrary to getEvent()). If method is called concurrently from several threads with the same id, then every call returns with the same event once the event fired.

Parameters
idof the event activation
eventis set to the returned event if fired (Communication Object)
timeoutis the timeout time to block the method maximally (default value zero block infinitelly)
  • single mode:

In single mode one misses the event if it fired before entering this member function.

Returns status code:

  • SMART_OK : event fired while waiting for the event and event is consumed and returned
  • SMART_PASSIVE : event already fired between activation and calling this member function and is therefore missed or event has already been consumed and can not fire again in single mode. Does not block indefinitely and returns no valid event.
  • SMART_CANCELLED : event not yet fired and waiting for the event has been aborted or blocking is not allowed anymore. No valid event is returned.
  • SMART_DISCONNECTED : got disconnected while waiting and therefore event not valid and also id not valid any longer due to automatic deactivation.
  • SMART_NOTACTIVATED : got deactivated while waiting and therefore event not valid and also id not valid any longer.
  • SMART_WRONGID : there is no activation available with this id and therefore event not valid.
  • continuous mode:

Makes sure that only events fired after entering this member function are considered.

Returns status code:

  • SMART_OK : event fired while waiting for the event and event is consumed and returned
  • SMART_CANCELLED : waiting for the next event has been aborted or blocking is not allowed anymore. No valid event is returned.
  • SMART_DISCONNECTED : got disconnected while waiting and therefore event not valid and also id not valid any longer due to automatic deactivation.
  • SMART_NOTACTIVATED : got deactivated while waiting and therefore event not valid and also id not valid any longer.
  • SMART_WRONGID : there is no activation available with this id and therefore event not valid.

◆ tryEvent()

template<class ActivationType , class EventType >
virtual StatusCode Smart::IEventClientPattern< ActivationType, EventType >::tryEvent ( const EventIdPtr  id)
pure virtual

Check whether event has already fired and return immediately with status information.

This method does not consume an available event.

Parameters
idof the event activation to be checked
Returns
status code
  • single mode:
    • SMART_OK : event fired already, is still available and can be consumed by calling getEvent(),
    • SMART_ACTIVE : event has not yet fired
    • SMART_PASSIVE : event fired already and is already consumed.
    • SMART_WRONGID : there is no activation available with this id
  • continuous mode:
    • SMART_OK : unconsumed event is available. Since events are overwritten this means that at least one new event has been received since the last event consumption.
    • SMART_ACTIVE : currently there is no unconsumed event available.
    • SMART_WRONGID : there is no activation available with this id

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