firebase:: messaging:: PollableListener
#include <messaging.h>
A listener that can be polled to consume pendingMessages.
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 tokens via theOnMessage virtual function, this class will queue up the message internally in a thread-safe manner so that it can be consumed withPollMessage. For example:
::firebase::messaging::PollableListenerlistener;::firebase::messaging::Initialize(app,&listener);while(true){std::stringtoken;if(listener.PollRegistrationToken(&token)){LogMessage("Received a registration token");}::firebase::messaging::Messagemessage;while(listener.PollMessage(&message)){LogMessage("Received a new message");}// Remainder of application logic...}
Inheritance
Inherits from:firebase::messaging::ListenerConstructors and Destructors | |
|---|---|
PollableListener()The default constructor. | |
~PollableListener()The required virtual destructor. |
Public functions | |
|---|---|
OnMessage(constMessage & message) | virtual voidAn implementation of OnMessage which adds the incoming messages to a queue, which can be consumed by callingPollMessage. |
OnTokenReceived(const char *token) | virtual voidAn implementation of OnTokenReceived which stores the incoming token so that it can be consumed by callingPollRegistrationToken. |
PollMessage(Message *message) | boolReturns the first message queued up, if any. |
PollRegistrationToken(std::string *token) | boolReturns the registration key, if a new one has been received. |
Public functions
OnMessage
virtualvoidOnMessage(constMessage&message)
An implementation ofOnMessage which adds the incoming messages to a queue, which can be consumed by callingPollMessage.
OnTokenReceived
virtualvoidOnTokenReceived(constchar*token)
An implementation ofOnTokenReceived which stores the incoming token so that it can be consumed by callingPollRegistrationToken.
PollMessage
boolPollMessage(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 themessage argument and the function will returntrue. If there are no pending messages,false is returned. This function should be called in a loop until all messages have been consumed, like so:
::firebase::messaging::Messagemessage;while(listener.PollMessage(&message)){LogMessage("Received a new message");}
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | Returns true if there was a pending message,false otherwise. |
PollRegistrationToken
boolPollRegistrationToken(std::string*token)
Returns the registration key, if a new one has been received.
When a new registration token is received, it is cached internally and can be retrieved by callingPollRegistrationToken. The cached registration token will be used to populate thetoken argument, then the cache will be cleared and the function will returntrue. If there is no cached registration token this function retunsfalse.
std::stringtoken;if(listener.PollRegistrationToken(&token)){LogMessage("Received a registration token");}
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | Returns true if there was a new token,false otherwise. |
PollableListener
PollableListener()
The default constructor.
~PollableListener
virtual~PollableListener()
The required virtual destructor.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-01-23 UTC.