gpg::MessageListenerHelper

#include <message_listener_helper.h>

Defines a helper which can be used to provide IMessageListener callbacks to the SDK without defining the full IMessageListener interface.

Summary

Callbacks configured on this object will be invoked as described in the nearby connections API. Callbacks not explicitly set will do nothing.

Constructors and Destructors

MessageListenerHelper()
MessageListenerHelper(std::shared_ptr< MessageListenerHelperImpl > impl)
Constructs a MessageListenerHelper from a shared_ptr to a MessageListenerHelperImpl.

Public types

OnDisconnectedCallback typedef
std::function< void(int64_t client_id, const std::string &remote_endpoint_id)>
OnDisconnectedCallback is called when a remote endpoint disconnects.
OnMessageReceivedCallback typedef
std::function< void(int64_t client_id, const std::string &remote_endpoint_id, const std::vector< uint8_t > &payload, bool is_reliable)>
OnMessageReceivedCallback is called when a message is received from a remote endpoint.

Public functions

SetOnDisconnectedCallback(OnDisconnectedCallback callback)
Set the OnDisconnectedCallback.
SetOnMessageReceivedCallback(OnMessageReceivedCallback callback)
Set the OnMessageReceivedCallback.

Public types

OnDisconnectedCallback

std::function< void(int64_t client_id, const std::string &remote_endpoint_id)> OnDisconnectedCallback

OnDisconnectedCallback is called when a remote endpoint disconnects.

client_id is the ID of the NearbyConnections instance that received the disconnect message. remote_endpoint_id is the ID of the remote endpoint that disconnected.

OnMessageReceivedCallback

std::function< void(int64_t client_id, const std::string &remote_endpoint_id, const std::vector< uint8_t > &payload, bool is_reliable)> OnMessageReceivedCallback

OnMessageReceivedCallback is called when a message is received from a remote endpoint.

client_id is the ID of the NearbyConnections instance that received this message. remote_endpoint_id is the ID of the remote endpoint that sent the message. payload contains the bytes of the message. is_reliable is true if the message was sent reliably, false otherwise.

Public functions

MessageListenerHelper

 MessageListenerHelper()

MessageListenerHelper

 MessageListenerHelper(
  std::shared_ptr< MessageListenerHelperImpl > impl
)

Constructs a MessageListenerHelper from a shared_ptr to a MessageListenerHelperImpl.

Intended for internal use by the API.

SetOnDisconnectedCallback

MessageListenerHelper & SetOnDisconnectedCallback(
  OnDisconnectedCallback callback
)

Set the OnDisconnectedCallback.

SetOnMessageReceivedCallback

MessageListenerHelper & SetOnMessageReceivedCallback(
  OnMessageReceivedCallback callback
)

Set the OnMessageReceivedCallback.