SmartFoxServer 3 C++ Client API 3.1.0-beta
Client API for SmartFoxServer 3
Loading...
Searching...
No Matches
sfs3::event::Listenable< EventType > Class Template Reference

Gives a class the capability to dispatch events, and the methods to listen to them. More...

#include <Listenable.h>

Public Member Functions

void addEventListener (EventType evtType, event::EventListener listener)
 Adds a listener that handles one event type.
void removeEventListener (EventType evtType)
 Removes the listener of one event type.
void removeAllEventListeners ()
 Removes all the listeners that were added.

Detailed Description

template<typename EventType>
class sfs3::event::Listenable< EventType >

Gives a class the capability to dispatch events, and the methods to listen to them.

SmartFox uses it with the SFSEvent type, so these three methods are how an application registers its event handlers.

Member Function Documentation

◆ addEventListener()

template<typename EventType>
void sfs3::event::Listenable< EventType >::addEventListener ( EventType evtType,
event::EventListener listener )
inline

Adds a listener that handles one event type.

There is one listener per event type: a second call with the same type replaces the previous listener.

The listener receives the event as an ApiEvent reference. Cast it to the payload struct of the type you registered for, as listed in SFSEvent.

Parameters
evtTypethe event type to listen to
listenerthe function that handles the event
See also
SFSEvent

◆ removeEventListener()

template<typename EventType>
void sfs3::event::Listenable< EventType >::removeEventListener ( EventType evtType)
inline

Removes the listener of one event type.

Nothing happens if no listener was added for that type.

Parameters
evtTypethe event type that is no longer listened to

◆ removeAllEventListeners()

template<typename EventType>
void sfs3::event::Listenable< EventType >::removeAllEventListeners ( )
inline

Removes all the listeners that were added.

It is useful after a disconnection, to clear all the listeners at once.


The documentation for this class was generated from the following file:
  • event/Listenable.h