Appearance
class flake::ObjectDelegate
Interface to be implemented by the application to expose a custom Flake object. More...
#include <platform/flake/Object.h>
Public Functions
| Name | |
|---|---|
| ObjectDelegate(const ObjectDelegate & ) =deleted | |
| ObjectDelegate & | operator=(const ObjectDelegate & ) =deleted |
| ObjectDelegate(ObjectDelegate && ) =deleted | |
| ObjectDelegate & | operator=(ObjectDelegate && ) =deleted |
| virtual | ~ObjectDelegate() =default |
| virtual Object * | handle() =0 Return the underlying Object handle for this delegate. |
| virtual int8_t | handleCustomMessage(const char * name, const PropArray & data, PropArray & outProps) =0 Handle an incoming custom (named) message. |
| virtual int8_t | handleStreamOpen(Stream * s) =0 Called when a remote client opens a stream on this object. |
| virtual int8_t | handleStreamClose(Stream * s) =0 Called when a previously opened stream is closed. |
| virtual int8_t | handleStreamWrite(Stream * s, uint8_t * cb, uint16_t len) =0 Called when a remote client writes data into a stream. |
| virtual int8_t | handleStreamRead(Stream * s, uint8_t * cb, uint16_t * len, uint16_t max_len) =0 Called when a remote client reads data from a stream. |
| virtual int | setPropertyRequested(uint32_t tag, Property & value, const PropArray & transaction, bool internal) =0 Called when a remote client requests to change a property. |
| virtual int | getPropertyRequested(uint32_t tag, Property & value) =0 Called when a remote client reads a property. |
| virtual void | propertyChanged(const Property & ) =0 Notification that a property has been changed (after commit). |
| virtual void | onInitialized() =0 Called once after the object has been fully initialized and registered with the router. |
| virtual void | onUrgentPending() A value of priority FLAKE_PRIO_IMMEDIATE became pending while none was. |
| virtual void | onReportPressure(uint8_t percent) The report storage crossed a fill level upwards. |
| virtual void | onPeerSessionChanged(uint32_t streamTag, bool open) A peer opened or closed a stream on this object. |
Protected Functions
| Name | |
|---|---|
| ObjectDelegate() =default |
Detailed Description
cpp
class flake::ObjectDelegate;Interface to be implemented by the application to expose a custom Flake object.
Note: Non-copyable, non-movable.
Register an ObjectDelegate with Connection::registerObject() to make it discoverable by remote clients. The framework calls the virtual methods below in response to client requests.
Public Functions Documentation
function ObjectDelegate
cpp
ObjectDelegate(
const ObjectDelegate &
) =deletedfunction operator=
cpp
ObjectDelegate & operator=(
const ObjectDelegate &
) =deletedfunction ObjectDelegate
cpp
ObjectDelegate(
ObjectDelegate &&
) =deletedfunction operator=
cpp
ObjectDelegate & operator=(
ObjectDelegate &&
) =deletedfunction ~ObjectDelegate
cpp
virtual ~ObjectDelegate() =defaultfunction handle
cpp
virtual Object * handle() =0Return the underlying Object handle for this delegate.
Return: Pointer to the associated Object.
function handleCustomMessage
cpp
virtual int8_t handleCustomMessage(
const char * name,
const PropArray & data,
PropArray & outProps
) =0Handle an incoming custom (named) message.
Parameters:
- name Name of the message.
- data Input properties.
- outProps Output properties to return to the caller.
Return: Application-defined result code (0 = success).
function handleStreamOpen
cpp
virtual int8_t handleStreamOpen(
Stream * s
) =0Called when a remote client opens a stream on this object.
Parameters:
- s The newly opened Stream.
Return: 0 to accept, non-zero to reject the stream.
function handleStreamClose
cpp
virtual int8_t handleStreamClose(
Stream * s
) =0Called when a previously opened stream is closed.
Parameters:
- s The stream being closed.
Return: 0 on success.
A stream a peer opened may be released as soon as this returns (closed locally or after FLAKE_STREAM_TIMEOUT_MS without access); do not keep s beyond this call. A later open by a peer comes through handleStreamOpen() again.
function handleStreamWrite
cpp
virtual int8_t handleStreamWrite(
Stream * s,
uint8_t * cb,
uint16_t len
) =0Called when a remote client writes data into a stream.
Parameters:
- s The stream.
- cb Buffer containing the incoming bytes.
- len Number of bytes in
cb.
Return: 0 on success, non-zero on error.
function handleStreamRead
cpp
virtual int8_t handleStreamRead(
Stream * s,
uint8_t * cb,
uint16_t * len,
uint16_t max_len
) =0Called when a remote client reads data from a stream.
Parameters:
- s The stream.
- cb Destination buffer.
- len Number of bytes written into
cb. - max_len Capacity of
cb.
Return: 0 on success, non-zero on error.
The implementation fills cb with up to max_len bytes and sets len to the number of bytes actually provided.
function setPropertyRequested
cpp
virtual int setPropertyRequested(
uint32_t tag,
Property & value,
const PropArray & transaction,
bool internal
) =0Called when a remote client requests to change a property.
Parameters:
- tag The property tag being modified.
- value Proposed new value; may be modified by the implementation.
- transaction All properties submitted in the same setProperties() call.
- internal
trueif the change originates from the object itself (local).
Return: E_OK to accept, or a negative error code to reject.
function getPropertyRequested
cpp
virtual int getPropertyRequested(
uint32_t tag,
Property & value
) =0Called when a remote client reads a property.
Parameters:
- tag The property tag being queried.
- value The property to populate.
Return: E_OK on success, or a negative error code.
The implementation may fill value with a freshly computed result.
function propertyChanged
cpp
virtual void propertyChanged(
const Property &
) =0Notification that a property has been changed (after commit).
Parameters:
- property The property that was changed.
function onInitialized
cpp
virtual void onInitialized() =0Called once after the object has been fully initialized and registered with the router.
function onUrgentPending
cpp
inline virtual void onUrgentPending()A value of priority FLAKE_PRIO_IMMEDIATE became pending while none was.
Runs on the core worker; only set a flag or wake a thread here and send from there (Object::flushReport() or Object::sync()).
function onReportPressure
cpp
inline virtual void onReportPressure(
uint8_t percent
)The report storage crossed a fill level upwards.
Parameters:
- percent The level crossed.
Reported once per level (50, 75, 90, 100 %) until the level is left again. At 100 % new samples start to displace older ones of lower history class, or are counted as dropped. Runs on the core worker; send from another thread.
function onPeerSessionChanged
cpp
inline virtual void onPeerSessionChanged(
uint32_t streamTag,
bool open
)A peer opened or closed a stream on this object.
Parameters:
- streamTag Tag of the stream property.
- open
trueon open,falseon close.
Called per opener: two peers on one stream make two sessions. Every session that was reported open is reported closed, also when the connection is lost or the session idles out (see FLAKE_PEER_STREAM_IDLE_MS).
Protected Functions Documentation
function ObjectDelegate
cpp
ObjectDelegate() =default