nl::Weave::Profiles::Echo_Next::WeaveEchoServer

#include <src/lib/profiles/echo/Next/WeaveEchoServer.h>

Accepts EchoRequest messages from a peer node and responds with an EchoResponse message.

Summary

The WeaveEchoServer class implements the responder side of the Weave Echo protocol. Similar to the ICMP ping protocol, the Weave Echo protocol can be used to test the liveness and reachability of a Weave node.

Applications can use the WeaveEchoServer class to enable automatic response to incoming EchoRequest messages. A corresponding class exists for initiating echo requests (see WeaveEchoClient).

By default the WeaveEchoServer responds immediately to an EchoRequest with response containing the same payload as the request. However this behavior can be altered by the application during processing of the EchoRequestReceived API event.

API Events

During the course of its operation, the WeaveEchoServer object will call up to the application to request specific actions or deliver notifications of important events. These API event calls are made to the currently configured callback function on the server object. Except where noted, applications are free to alter the state of the server during an event callback. One overall exception is the object's Shutdown() method, which may never be called during a callback.

The following API events are defined:

EchoRequestReceived

An EchoRequest message was received from a peer. Arguments to the event contain the request payload, the exchange context over which the message was received and meta-information about the request message.

If the application chooses, it may alter the output arguments to the event to force a delay in responding or to suppress the response altogether. Additionally, it may alter the contents of the payload buffer, which will become the payload for the response message.

EchoResponseSent

An EchoResponse message was sent, or failed to be sent. Arguments to the event contain the error that resulted from sending the message (if any) and the exchange context over which the message was sent.

Inheritance

Inherits from: nl::Weave::WeaveServerBase
Direct Known Subclasses: nl::Weave::DeviceLayer::Internal::EchoServer

Constructors and Destructors

WeaveEchoServer(void)
Default constructor for WeaveEchoServer.

Public types

EchoFunct)(uint64_t nodeId, IPAddress nodeAddr, PacketBuffer *payload) typedef
void(*
EventCallback)(void *appState, EventType eventType, const InEventParam &inParam, OutEventParam &outParam) typedef
void(*
EventType{
  kEvent_EchoRequestReceived = 1,
  kEvent_EchoResponseSent = 2,
  kEvent_DefaultCheck = 100
}
enum

Public attributes

AppState
void *
A pointer to application-specific data.
OnEchoRequestReceived
EchoFunct

Public functions

GetEventCallback(void) const
EventCallback
Returns a pointer to the API event callback function currently configured on the WeaveEchoServer object.
Init(WeaveExchangeManager *exchangeMgr, EventCallback eventCallback, void *appState)
Initialize a WeaveEchoServer object.
Init(WeaveExchangeManager *exchangeMgr)
Initialize a WeaveEchoServer object.
SetEventCallback(EventCallback eventCallback)
void
Sets the API event callback function on the WeaveEchoServer object.
Shutdown(void)
Shutdown a previously initialized WeaveEchoServer object.

Public static functions

DefaultEventHandler(void *appState, EventType eventType, const InEventParam & inParam, OutEventParam & outParam)
void
Default handler for WeaveEchoServer API events.

Structs

nl::Weave::Profiles::Echo_Next::WeaveEchoServer::InEventParam

Input parameters to WeaveEchoServer API event.

nl::Weave::Profiles::Echo_Next::WeaveEchoServer::OutEventParam

Output parameters to WeaveEchoServer API event.

Public types

EchoFunct

void(* EchoFunct)(uint64_t nodeId, IPAddress nodeAddr, PacketBuffer *payload)

EventCallback

void(* EventCallback)(void *appState, EventType eventType, const InEventParam &inParam, OutEventParam &outParam)

EventType

 EventType
Properties
kEvent_DefaultCheck

Used to verify correct default event handling in the application.

kEvent_EchoRequestReceived

An EchoRequest message was received from a peer.

kEvent_EchoResponseSent

An EchoResponse message was sent, or failed to be sent.

Public attributes

AppState

void * AppState

A pointer to application-specific data.

OnEchoRequestReceived

EchoFunct OnEchoRequestReceived

Public functions

GetEventCallback

EventCallback GetEventCallback(
  void
) const 

Returns a pointer to the API event callback function currently configured on the WeaveEchoServer object.

Init

WEAVE_ERROR Init(
  WeaveExchangeManager *exchangeMgr,
  EventCallback eventCallback,
  void *appState
)

Initialize a WeaveEchoServer object.

Initialize a WeaveEchoServer object to respond to echo messages from a peer.

Details
Parameters
[in] exchangeMgr
A pointer to the WeaveExchangeManager object.
[in] eventCallback
A pointer to a function that will be called by the WeaveEchoServer object to deliver API events to the application.
[in] appState
A pointer to an application-defined object which will be passed back to the application whenever an API event occurs.

Init

WEAVE_ERROR Init(
  WeaveExchangeManager *exchangeMgr
)

Initialize a WeaveEchoServer object.

Initialize a WeaveEchoServer object to respond to echo messages from a peer.

DEPRECATED: Please use Init(WeaveExchangeManager * exchangeMgr, EventCallback eventCallback, void * appState).

Details
Parameters
[in] exchangeMgr
A pointer to the WeaveExchangeManager object.
[in] eventCallback
A pointer to a function that will be called by the WeaveEchoServer object to deliver API events to the application.
[in] appState
A pointer to an application-defined object which will be passed back to the application whenever an API event occurs.

SetEventCallback

void SetEventCallback(
  EventCallback eventCallback
)

Sets the API event callback function on the WeaveEchoServer object.

Shutdown

WEAVE_ERROR Shutdown(
  void
)

Shutdown a previously initialized WeaveEchoServer object.

Note that this method can only be called if the Init() method has been called previously.

WeaveEchoServer

 WeaveEchoServer(
  void
)

Default constructor for WeaveEchoServer.

Public static functions

DefaultEventHandler

void DefaultEventHandler(
  void *appState,
  EventType eventType,
  const InEventParam & inParam,
  OutEventParam & outParam
)

Default handler for WeaveEchoServer API events.

Applications are required to call this method for any API events that they don't recognize or handle. Supplied parameters must be the same as those passed by the server object to the application's event handler function.

Details
Parameters
[in] appState
A pointer to application-defined state information associated with the server object.
[in] eventType
Event ID passed by the event callback
[in] inParam
Reference of input event parameters passed by the event callback
[in] outParam
Reference of output event parameters passed by the event callback