firebase::messaging::PollableListener

#include <messaging.h>

A listener that can be polled to consume pending Messages and registration events.

Summary

This class is intended to be used with applications that have a main loop that frequently updates, such as in the case of a game that has a main loop that updates 30 to 60 times a second. Rather than respond to incoming messages and registration events via the OnMessage, OnRegistrationReceived, or OnUnregistrationReceived virtual functions, this class will queue up events internally in a thread-safe manner so that they can be consumed with PollMessage, PollRegistration, or PollUnregistration.

Inheritance

Inherits from: firebase::messaging::Listener

Constructors and Destructors

PollableListener()
The default constructor.
~PollableListener()
The required virtual destructor.

Public functions

OnMessage(const Message & message) override
virtual void
An implementation of OnMessage which adds incoming messages to a queue, which can be consumed by calling PollMessage.
OnRegistrationReceived(const char *installationId) override
virtual void
An implementation of OnRegistrationReceived which stores the incoming installation ID so that it can be consumed by calling PollRegistration.
OnTokenReceived(const char *token) override
virtual void
Deprecated. Use OnRegistrationReceived(const char*) instead.
An implementation of OnTokenReceived which stores the incoming token so that it can be consumed by calling PollRegistrationToken.
OnUnregistrationReceived(const char *installationId) override
virtual void
An implementation of OnUnregistrationReceived which stores the incoming installation ID so that it can be consumed by calling PollUnregistration.
PollMessage(Message *message)
bool
Returns the first message queued up, if any.
PollRegistration(std::string *installation_id)
bool
Returns the registration installation ID, if a new one has been received.
PollRegistrationToken(std::string *token)
bool
Deprecated. Use PollRegistration(std::string*) instead.
Returns the registration key, if a new one has been received.
PollUnregistration(std::string *installation_id)
bool
Returns the unregistration installation ID, if an unregistration has occurred.

Public functions

OnMessage

virtual void OnMessage(
  const Message & message
) override

An implementation of OnMessage which adds incoming messages to a queue, which can be consumed by calling PollMessage.

OnRegistrationReceived

virtual void OnRegistrationReceived(
  const char *installationId
) override

An implementation of OnRegistrationReceived which stores the incoming installation ID so that it can be consumed by calling PollRegistration.

OnTokenReceived

virtual void OnTokenReceived(
  const char *token
) override

An implementation of OnTokenReceived which stores the incoming token so that it can be consumed by calling PollRegistrationToken.

Deprecated. Use OnRegistrationReceived(const char*) instead.

OnUnregistrationReceived

virtual void OnUnregistrationReceived(
  const char *installationId
) override

An implementation of OnUnregistrationReceived which stores the incoming installation ID so that it can be consumed by calling PollUnregistration.

PollMessage

bool PollMessage(
  Message *message
)

Returns the first message queued up, if any.

If one or more messages has been received, the first message in the queue will be popped and used to populate the message argument and the function will return true. If there are no pending messages, false is returned. This function should be called in a loop until all messages have been consumed.

Details
Parameters
message
The Message struct to be populated. If there were no pending messages, message is not modified.
Returns
Returns true if there was a pending message, false otherwise.

PollRegistration

bool PollRegistration(
  std::string *installation_id
)

Returns the registration installation ID, if a new one has been received.

When a new registration installation ID is received, it is cached internally and can be retrieved by calling PollRegistration. The cached installation ID will be used to populate the installation_id argument, then the cache will be cleared and the function will return true. If there is no cached registration installation ID, this function returns false.

Details
Parameters
installation_id
A string to be populated with the new installation ID.
Returns
Returns true if there was a new installation ID, false otherwise.

PollRegistrationToken

bool PollRegistrationToken(
  std::string *token
)

Returns the registration key, if a new one has been received.

Deprecated. Use PollRegistration(std::string*) instead.

PollUnregistration

bool PollUnregistration(
  std::string *installation_id
)

Returns the unregistration installation ID, if an unregistration has occurred.

When an unregistration event is received, it is cached internally and can be retrieved by calling PollUnregistration. The cached unregistration installation ID will be used to populate the installation_id argument, then the cache will be cleared and the function will return true. If there is no cached unregistration installation ID, this function returns false.

Details
Parameters
installation_id
A string to be populated with the unregistered installation ID.
Returns
Returns true if there was an unregistration event, false otherwise.

PollableListener

 PollableListener()

The default constructor.

~PollableListener

virtual  ~PollableListener()

The required virtual destructor.