Skip to content

class flake::Service

More...

#include <platform/flake/Service.h>

Inherits from flake::ObjectDelegate

Public Functions

Name
virtual intset(Property & ) =0
virtual Propertyget(uint32_t ) =0
virtual~Service() =default
virtual ServiceImpl *asServiceImpl()
virtual voidonInitialized() =0
This function is called when the service is initialized.
virtual boolisInitialized() =0
Checks if the service is initialized.
virtual intbroadcast(conststring command, PropArray & params) =0
Broadcasts a command with parameters.
virtual intget(PropArray & pa) =0
Retrieve multiple properties from the object.
virtual intset(PropArray & pa) =0
Set multiple properties on the object.
template <uint32_t PropTag,typenameT >
int
set(T value)
Set the value of a property.
template <uint32_t PropTag>
PropType< PropTag >
get(PropType< PropTag > defval =PropTypeFromTag< TAG_TYPE(PropTag)>::default_value)
Retrieve the value of a specific property.
template <uint32_t PropTag>
int
on(PropCallback< PropTag &~TAG_ACTIONABLE > cb, PropType< PropTag > min, PropType< PropTag > max)
Registers a callback function for a specific tag.
template <uint32_t PropTag>
int
on(PropCallback< PropTag > cb)
template <uint32_t PropTag>
int
onRead(PropCallBackStreamRead cb)
template <uint32_t PropTag>
int
onOpenClose(PropCallBackStreamOpenClose cb)
template <uint32_t PropTag>
int
onWrite(PropCallBackStreamWrite cb)
virtual inton(string message, std::function< int(PropArray &, PropArray &)> cb) =0
virtual voidsetMessageHook(std::function< int(conststring &, PropArray &, PropArray &, void *)> cb, void * ctx) =0
virtual voidsetPropertyHook(std::function< int(uint32_t tag, Property &value, constPropArray &transaction, bool, void *)> cb, void * ctx) =0
virtual intopenProperty(constuint32_t propTag, Stream ** stream) =0
virtual intsync(int timeout_ms =FLAKE_DEFAULT_TIMEOUT_MS) =0
virtual voiddefer() =0
virtual intsyncDeferred(unsigned timeout_ms, bool block) =0
virtual boolhasDeferred() =0
virtual unsignedpendingBytes() =0
virtual voidreset() =0

Additional inherited members

Public Functions inherited from flake::ObjectDelegate

Name
virtual~ObjectDelegate() =default
virtual Object *handle() =0
Return the underlying Object handle for this delegate.
virtual int8_thandleCustomMessage(std::string name, constPropArray & data, PropArray & outProps) =0
Handle an incoming custom (named) message.
virtual int8_thandleStreamOpen(Stream * s) =0
Called when a remote client opens a stream on this object.
virtual int8_thandleStreamClose(Stream * s) =0
Called when a previously opened stream is closed.
virtual int8_thandleStreamWrite(Stream * s, uint8_t * cb, uint16_t len) =0
Called when a remote client writes data into a stream.
virtual int8_thandleStreamRead(Stream * s, uint8_t * cb, uint16_t * len, uint16_t max_len) =0
Called when a remote client reads data from a stream.
virtual intsetPropertyRequested(uint32_t tag, Property & value, constPropArray & transaction, bool internal) =0
Called when a remote client requests to change a property.
virtual intgetPropertyRequested(uint32_t tag, Property & value) =0
Called when a remote client reads a property.
virtual voidpropertyChanged(constProperty & ) =0
Notification that a property has been changed (after commit).

Protected Functions inherited from flake::ObjectDelegate

Name
ObjectDelegate() =default

Detailed Description

cpp
class flake::Service;

This class provides a base implementation for a service. A service is responsible for interacting with properties and handling messages and events.

Public Functions Documentation

function set

cpp
virtual int set(
    Property & 
) =0

function get

cpp
virtual Property get(
    uint32_t 
) =0

function ~Service

cpp
virtual ~Service() =default

function asServiceImpl

cpp
inline virtual ServiceImpl * asServiceImpl()

function onInitialized

cpp
virtual void onInitialized() =0

This function is called when the service is initialized.

Reimplements: flake::ObjectDelegate::onInitialized

This function should be overridden in derived classes to perform any necessary initialization tasks when the service is initialized.

function isInitialized

cpp
virtual bool isInitialized() =0

Checks if the service is initialized.

See: Service::onInitialized()

Return: bool True if the service is initialized, otherwise false.

This function returns a boolean value indicating whether the service is initialized or not.

function broadcast

cpp
virtual int broadcast(
    conststring command,
    PropArray & params
) =0

Broadcasts a command with parameters.

Parameters:

  • command The command to be broadcasted.
  • params The parameters associated with the command.

Return: int The result of the broadcast. Returns 0 if the broadcast is successful. Returns an error code if the broadcast fails.

This function sends a command with parameters to all interested listeners. It should be called when you want to notify other entities about an event or action.

function get

cpp
virtual int get(
    PropArray & pa
) =0

Retrieve multiple properties from the object.

Parameters:

  • pa A reference to an empty PropArray object to be populated.

Return: An integer representing the result of the operation.

  • E_FAILED: If none of the properties could be retrieved
  • E_PARTIAL_SUCCESS: if some of the properties could be retrieved
  • E_OK: if all of the properties could be retrieved.

function set

cpp
virtual int set(
    PropArray & pa
) =0

Set multiple properties on the object.

Parameters:

  • pa The PropArray object containing the properties to be set

Return: An integer representing the result of the operation.

  • E_FAILED: If none of the properties could be set
  • E_PARTIAL_SUCCESS: if some of the properties could be set
  • E_OK: if all of the properties could be set.
  • E_REFUSED: if called from within a property-callback, registered with on

Note: : mind, that you cannot call set from within a property-callback you registered with on

function set

cpp
template <uint32_t PropTag,
typenameT >
inline int set(
    T value
)

Set the value of a property.

Parameters:

  • value The value to be set.

Template Parameters:

  • PropTag The tag of the property.
  • T The type of the value to be set.

Return: An integer representing the result of the operation.

  • E_REFUSED: If the passed value cannot be safely cast to the property's type. or if called from within a property-callback, registered with on
  • E_OK: if the operation succeeded

Note: : mind, that you cannot call set from within a property-callback you registered with on!

This function is used to set the value of a property identified by its tag. The value to be set can be of any type supported by the property, as long as it is convertible to the property's type.

function get

cpp
template <uint32_t PropTag>
inline PropType< PropTag > get(
    PropType< PropTag > defval =PropTypeFromTag< TAG_TYPE(PropTag)>::default_value
)

Retrieve the value of a specific property.

Parameters:

  • defval The default value to be returned if the property value is not found.

Template Parameters:

  • PropTag The tag of the property.

Return: PropType The value of the property or the default value.

This function is used to retrieve the value of a property identified by its tag. If the property value is not found, the default value provided will be returned.

function on

cpp
template <uint32_t PropTag>
inline int on(
    PropCallback< PropTag &~TAG_ACTIONABLE > cb,
    PropType< PropTag > min,
    PropType< PropTag > max
)

Registers a callback function for a specific tag.

Parameters:

  • tag The unique identifier for the property.
  • cb The callback function to handle the property.

Return: int Returns 0 if the registration is successful, or an error code if the registration fails.

This function is used to register a callback function for a specific tag. When the specified tag is encountered during property handling, the registered callback function will be called to handle the property.

function on

cpp
template <uint32_t PropTag>
inline int on(
    PropCallback< PropTag > cb
)

function onRead

cpp
template <uint32_t PropTag>
inline int onRead(
    PropCallBackStreamRead cb
)

function onOpenClose

cpp
template <uint32_t PropTag>
inline int onOpenClose(
    PropCallBackStreamOpenClose cb
)

function onWrite

cpp
template <uint32_t PropTag>
inline int onWrite(
    PropCallBackStreamWrite cb
)

function on

cpp
virtual int on(
    string message,
    std::function< int(PropArray &, PropArray &)> cb
) =0

function setMessageHook

cpp
virtual void setMessageHook(
    std::function< int(conststring &, PropArray &, PropArray &, void *)> cb,
    void * ctx
) =0

function setPropertyHook

cpp
virtual void setPropertyHook(
    std::function< int(uint32_t tag, Property &value, constPropArray &transaction, bool, void *)> cb,
    void * ctx
) =0

function openProperty

cpp
virtual int openProperty(
    constuint32_t propTag,
    Stream ** stream
) =0

function sync

cpp
virtual int sync(
    int timeout_ms =FLAKE_DEFAULT_TIMEOUT_MS
) =0

function defer

cpp
virtual void defer() =0

function syncDeferred

cpp
virtual int syncDeferred(
    unsigned timeout_ms,
    bool block
) =0

function hasDeferred

cpp
virtual bool hasDeferred() =0

function pendingBytes

cpp
virtual unsigned pendingBytes() =0

function reset

cpp
virtual void reset() =0