Appearance
class flake::Service
#include <Service.h>
Public Functions
Name | |
---|---|
void * | handle() |
Service() | |
virtual | ~Service() |
virtual TagArray | defaultPropset() Returns the default TagArray for the propset. |
virtual void | onInitialized() This function is called when the service is initialized. |
virtual bool | isInitialized() Checks if the service is initialized. |
virtual int | setPropertyRequested(uint32_t tag, Property & value, const PropArray & transaction, bool internal) Set the requested property value. |
virtual int | getPropertyRequested(uint32_t tag, Property & value) Get the requested property value. |
virtual int | broadcast(const string command, PropArray & params) Broadcasts a command with parameters. |
void | beginUpdate() Begins the update process for the Service. |
virtual int8_t | commitUpdate(int timeout_ms =0) Commits the updates made to the Service. |
virtual int | setProperties(PropArray & properties, int timeout_ms) Sets the properties of the service. |
virtual int | set(Property & property) Sets a property value. |
virtual int | set(const Property & property) Sets the value of a property. |
virtual Property | get(uint32_t tag) Get the property value for the specified tag. |
virtual int | on(uint32_t tag, std::function< int(Property &, const PropArray &, bool)> cb) Registers a callback function for a specific tag. |
virtual int | onMessage(string message, std::function< int(PropArray &, PropArray &)> cb) Registers a callback function for a specific message. |
const uniqueId_t | id() Get the unique identifier for the service. |
virtual int8_t | handleCustomMessage(string message, PropArray & params, PropArray & outProps) Handles a custom message. |
virtual int8_t | handleStreamData(Stream * stream, byte * data, int len) Handles the stream data. |
Protected Functions
Name | |
---|---|
Connection * | connection() |
Protected Attributes
Name | |
---|---|
void * | hObj |
std::map< uint32_t, std::function< int(Property &, const PropArray &, bool)> > | p_callbacks |
std::map< std::string, std::function< int(PropArray &, PropArray &)> > | m_callbacks |
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 handle
cpp
void * handle()
function Service
cpp
Service()
function ~Service
cpp
virtual ~Service()
function defaultPropset
cpp
virtual TagArray defaultPropset()
Returns the default TagArray for the propset.
Return: The default TagArray for the propset.
This function returns the default TagArray for the propset. It creates and returns an empty TagArray.
function onInitialized
cpp
virtual void onInitialized()
This function is called when the service is initialized.
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()
Checks if the service is initialized.
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 setPropertyRequested
cpp
virtual int setPropertyRequested(
uint32_t tag,
Property & value,
const PropArray & transaction,
bool internal
)
Set the requested property value.
Parameters:
- tag The unique identifier for the property.
- value The value to set the property to.
- transaction The array of properties being modified together as a transaction.
- internal A flag indicating if the request is internal.
Return: int The result of setting the property. Returns E_IGNORED if the tag is not registered with a callback function. Returns the result of the callback function if the tag has a registered callback function.
This virtual function is called internally when the value of a property marked with TAG_ACTIONABLE is requested to be set. It should be overridden in derived classes to handle the specific property, as the default implementation will return E_IGNORED for all properties.
function getPropertyRequested
cpp
virtual int getPropertyRequested(
uint32_t tag,
Property & value
)
Get the requested property value.
Parameters:
- tag The unique identifier for the property.
- value The variable where the requested property value will be stored.
Return: int The result of getting the property. Returns E_IGNORED if the tag is not registered with a callback function. Returns the result of the callback function if the tag has a registered callback function.
This virtual function is called when a property value is requested. It should be overridden in derived classes to handle the specific property.
function broadcast
cpp
virtual int broadcast(
const string command,
PropArray & params
)
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 beginUpdate
cpp
void beginUpdate()
Begins the update process for the Service.
This function is used to start the property update process for the Service. It can be called before making any changes to the Service's propertiess, when multiple calls to set() should be executed simultaneously.
function commitUpdate
cpp
virtual int8_t commitUpdate(
int timeout_ms =0
)
Commits the updates made to the Service.
Parameters:
- timeout_ms The timeout in milliseconds for the commit operation. If set to 0, the commit will not wait for completion and return immediately. If set to a positive value, the commit will wait for the specified timeout.
Return: int8_t The result of the commit operation. Returns 0 if the commit is successful. Returns an error code if the commit fails.
This function is called to commit the updates made to the Service.
function setProperties
cpp
virtual int setProperties(
PropArray & properties,
int timeout_ms
)
Sets the properties of the service.
Parameters:
- properties The array of properties to be set.
- timeout_ms The timeout in milliseconds for the set operation. If set to 0, the set operation will not wait for completion and return immediately. If set to a positive value, the set operation will wait for the specified timeout.
Return: int The result of setting the properties. Returns 0 if the set operation is successful. Returns an error code if the set operation fails.
This function is called to set the properties of the service.
function set
cpp
virtual int set(
Property & property
)
Sets a property value.
Parameters:
- property The property to be set.
Return: int The result of setting the property value. Returns 0 if the property is set successfully. Returns an error code if the property cannot be set.
This function is called to set the value of a property. It can be overridden in derived classes to handle specific properties.
function set
cpp
virtual int set(
const Property & property
)
Sets the value of a property.
Parameters:
- property The property to be set.
Return: int The result of setting the property value. Returns 0 if the property is set successfully. Returns an error code if the property cannot be set.
This function is called to set the value of a property.
function get
cpp
virtual Property get(
uint32_t tag
)
Get the property value for the specified tag.
Parameters:
- tag The unique identifier for the property.
See: Service::getPropertyRequested(uint32_t tag, Property &value)
Return: The property value.
This function is used to retrieve the value of a property based on its tag. It searches for the property with the given tag and returns its value.
function on
cpp
virtual int on(
uint32_t tag,
std::function< int(Property &, const PropArray &, bool)> cb
)
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 onMessage
cpp
virtual int onMessage(
string message,
std::function< int(PropArray &, PropArray &)> cb
)
Registers a callback function for a specific message.
Parameters:
- message The unique identifier for the message.
- cb The callback function to handle the message.
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 message. When the specified message is received, the registered callback function will be called to handle the message.
function id
cpp
const uniqueId_t id()
Get the unique identifier for the service.
Return: The unique identifier for the service.
This function is used to retrieve the unique identifier for the service. It returns the unique identifier of the service.
function handleCustomMessage
cpp
virtual int8_t handleCustomMessage(
string message,
PropArray & params,
PropArray & outProps
)
Handles a custom message.
Parameters:
- message The custom message.
- params The array of parameters associated with the message.
- outProps The array of properties to be sent as a response to the message.
Return: int8_t The result of handling the custom message. Returns 0 if the message is handled successfully. Returns an error code if the message cannot be handled.
This virtual function is called internally when a custom message is received. It should be overridden in derived classes to handle the specific message.
function handleStreamData
cpp
virtual int8_t handleStreamData(
Stream * stream,
byte * data,
int len
)
Handles the stream data.
Parameters:
- stream Pointer to a Stream object.
- data Pointer to the byte array containing the stream data.
- len The length of the byte array.
Return: int8_t The result of handling the stream data.
This virtual function is called internally to handle stream data. It should be overridden in derived classes to handle the specific stream data.
Protected Functions Documentation
function connection
cpp
Connection * connection()
Protected Attributes Documentation
variable hObj
cpp
void* flake::Service::hObj
variable p_callbacks
cpp
std::map<uint32_t, std::function<int (Property&, const PropArray&, bool)> > flake::Service::p_callbacks
variable m_callbacks
cpp
std::map<std::string, std::function<int (PropArray&, PropArray&)> > flake::Service::m_callbacks