Friendly LWM2M client
wpp::Instance Class Referenceabstract

Instance is interface class that implements manipulation with derived class resources. The main target of this class is to encapsulate operations like resource write and read by core, for avoid multiple definition of this mechanism in instance implementation classes. And give generalised interface to resources for core(server). More...

#include <Instance.h>

+ Inheritance diagram for wpp::Instance:
+ Collaboration diagram for wpp::Instance:

Public Member Functions

 Instance (lwm2m_context_t &context, const OBJ_LINK_T &id)
 
virtual ~Instance ()
 
 Instance (const Instance &)=delete
 
 Instance (Instance &&)=delete
 
Instanceoperator= (const Instance &)=delete
 
Instanceoperator= (Instance &&)=delete
 
OBJ_LINK_T getLink () const
 
OBJ_ID getObjectID () const
 
ID_T getInstanceID () const
 
lwm2m_context_t & getContext ()
 Return context that can be used by derived class. More...
 
WppClientgetClient ()
 Helpfull methods to get client instances. More...
 
WppRegistrygetRegistry ()
 Helpfull methods to get registry instances. More...
 
uint8_t readAsServer (lwm2m_server_t *server, int *numDataP, lwm2m_data_t **dataArray)
 This methods is called by the core when the server wants to read, write, discover, execute the value of the resource. User should not call this methods directly. More...
 
uint8_t writeAsServer (lwm2m_server_t *server, int numData, lwm2m_data_t *dataArray, lwm2m_write_type_t writeType)
 
uint8_t executeAsServer (lwm2m_server_t *server, ID_T resId, uint8_t *buffer, int length)
 
uint8_t discoverAsServer (lwm2m_server_t *server, int *numDataP, lwm2m_data_t **dataArray)
 
- Public Member Functions inherited from wpp::InstSubject
void opSubscribe (InstOpObserver *observer)
 Subscribes an observer to receive notifications about instance resource operations. More...
 
void opUnsubscribe (InstOpObserver *observer)
 Unsubscribes an observer from receiving notifications about instance resource operations. More...
 
void eventSubscribe (InstEventObserver *observer)
 Subscribes an observer to receive notifications about custom instance events. More...
 
void eventUnsubscribe (InstEventObserver *observer)
 Unsubscribes an observer from receiving notifications about custom instance events. More...
 
- Public Member Functions inherited from wpp::ResourceContainer
 ResourceContainer ()=default
 
virtual ~ResourceContainer ()=default
 
bool isSingle (ID_T resId)
 Check if the resource is SINGLE. More...
 
bool isMultiple (ID_T resId)
 Check if the resource is MULTIPLE. More...
 
bool isExist (ID_T resId)
 Check if the instance ID is exist. More...
 
bool isExist (ID_T resId, ID_T resInstId)
 Check if the instance ID is exist. More...
 
size_t instCount (ID_T resId)
 Get the number of resource instances. More...
 
std::vector< ID_TinstIds (ID_T resId)
 Returns vector with available ids of resource instances. More...
 
ID_T newInstId (ID_T resId)
 Find first available instance ID that is not used. More...
 
template<typename T >
bool set (ID_T resId, const T &value)
 Set data value by copy for the resource. More...
 
template<typename T >
bool set (ID_T resId, ID_T resInstId, const T &value)
 Set data value by copy for the resource instance. More...
 
template<typename T >
bool set (ID_T resId, T &&value)
 Set data value by move for the resource. More...
 
template<typename T >
bool set (ID_T resId, ID_T resInstId, T &&value)
 Set data value by move for the resource instance. More...
 
template<typename T >
const T & get (ID_T resId, ID_T resInstId=SINGLE_INSTANCE_ID)
 
template<typename T >
bool add (ID_T resId, const T &value)
 Add new instance with data value by copy for the MULTIPLE resource. More...
 
template<typename T >
bool add (ID_T resId, T &&value)
 Add new instance with data value by move for the MULTIPLE resource. More...
 
bool removeRes (ID_T resId, ID_T resInstId)
 Remove resource instance if resource is MULTIPLE and instance exists, if the resource is SINGLE remove is not possible. More...
 
bool clearRes (ID_T resId)
 Remove all instances. More...
 

Protected Member Functions

void notifyResChanged (ID_T resId, ID_T resInstId=ID_T_MAX_VAL)
 Notify server about resource value change. More...
 
std::vector< Resource * > getInstantiatedResList ()
 This method return list with resources that has been instantiated. If resources does not exist then return empty list. More...
 
std::vector< Resource * > getInstantiatedResList (const ItemOp &filter)
 
std::vector< Resource * > getResList ()
 This method return list with all resources that has been defined. If resources does not exist then return empty list. More...
 
void resourceOperationNotifier (ItemOp::TYPE type, ID_T resId, ID_T resInstId) override
 Handle information about resource operation (WRITE, DELETE). Called by ResourceContainer after resource operation performed. More...
 
virtual void serverOperationNotifier (Instance *securityInst, ItemOp::TYPE type, const ResLink &resLink)=0
 This method must be implemented by the derived class, and handle information about resource operation (WRITE, EXECUTE). Called by Instance after resource operation performed by SERVER if the operation is
WRITE, if the operation is EXECUTE then called before this operation. When the EXECUTE operation, the handler that was set before the serverOperationNotifier() call is used. More...
 
virtual void userOperationNotifier (ItemOp::TYPE type, const ResLink &resLink)=0
 This method must be implemented by the derived class, and handle information about resource operation (WRITE, DELETE). Called by Instance after resource operation performed by the USER. More...
 
- Protected Member Functions inherited from wpp::InstSubject
void operationNotify (Instance &inst, const ResLink &resLink, ItemOp::TYPE type)
 Notifies the observers about an operation on an instance resource. More...
 
void eventNotify (Instance &inst, EVENT_ID_T eventId)
 Notifies the observers about a custom instance event. More...
 
- Protected Member Functions inherited from wpp::ResourceContainer
void setupResources (const std::vector< Resource > &resources)
 This methods setup resources list. More...
 
void setupResources (std::vector< Resource > &&resources)
 
Resourceresource (ID_T resId)
 This method return resource ptr if it exists. If resources does not exist then return NULL. More...
 
std::vector< Resource > & resources ()
 This method return list with all resources that has been defined. More...
 

Detailed Description

Instance is interface class that implements manipulation with derived class resources. The main target of this class is to encapsulate operations like resource write and read by core, for avoid multiple definition of this mechanism in instance implementation classes. And give generalised interface to resources for core(server).

Note: It should be noted that the interface of the instance responsible for communication with the client is specified through get()/set() methods, but the developer can define his interface at the Instance implementation level, whether it will be setters and getters or more abstract methods with algorithm encapsulation, it is not important. It is important that the developer is responsible for notifying the core about resource changes, if the value of any of the resources changes, then the developer MUST immediately call the method Instance::notifyResChanged(). It is necessary to notify about the change for all resources except those marked as EXECUTE.

Definition at line 40 of file Instance.h.

Constructor & Destructor Documentation

◆ Instance() [1/3]

wpp::Instance::Instance ( lwm2m_context_t &  context,
const OBJ_LINK_T id 
)
inline

Definition at line 42 of file Instance.h.

◆ ~Instance()

virtual wpp::Instance::~Instance ( )
inlinevirtual

Definition at line 43 of file Instance.h.

◆ Instance() [2/3]

wpp::Instance::Instance ( const Instance )
delete

◆ Instance() [3/3]

wpp::Instance::Instance ( Instance &&  )
delete

Member Function Documentation

◆ discoverAsServer()

uint8_t wpp::Instance::discoverAsServer ( lwm2m_server_t *  server,
int *  numDataP,
lwm2m_data_t **  dataArray 
)

Definition at line 513 of file Instance.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeAsServer()

uint8_t wpp::Instance::executeAsServer ( lwm2m_server_t *  server,
ID_T  resId,
uint8_t *  buffer,
int  length 
)

Definition at line 491 of file Instance.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getClient()

WppClient & wpp::Instance::getClient ( )

Helpfull methods to get client instances.

Definition at line 54 of file Instance.cpp.

+ Here is the call graph for this function:

◆ getContext()

lwm2m_context_t & wpp::Instance::getContext ( )

Return context that can be used by derived class.

Definition at line 50 of file Instance.cpp.

+ Here is the caller graph for this function:

◆ getInstanceID()

ID_T wpp::Instance::getInstanceID ( ) const
inline

Definition at line 53 of file Instance.h.

+ Here is the caller graph for this function:

◆ getInstantiatedResList() [1/2]

std::vector< Resource * > wpp::Instance::getInstantiatedResList ( )
protected

This method return list with resources that has been instantiated. If resources does not exist then return empty list.

Definition at line 24 of file Instance.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInstantiatedResList() [2/2]

std::vector< Resource * > wpp::Instance::getInstantiatedResList ( const ItemOp filter)
protected

Definition at line 32 of file Instance.cpp.

+ Here is the call graph for this function:

◆ getLink()

OBJ_LINK_T wpp::Instance::getLink ( ) const
inline

Definition at line 51 of file Instance.h.

◆ getObjectID()

OBJ_ID wpp::Instance::getObjectID ( ) const
inline

Definition at line 52 of file Instance.h.

+ Here is the caller graph for this function:

◆ getRegistry()

WppRegistry & wpp::Instance::getRegistry ( )

Helpfull methods to get registry instances.

Definition at line 58 of file Instance.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getResList()

std::vector< Resource * > wpp::Instance::getResList ( )
protected

This method return list with all resources that has been defined. If resources does not exist then return empty list.

Definition at line 40 of file Instance.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ notifyResChanged()

void wpp::Instance::notifyResChanged ( ID_T  resId,
ID_T  resInstId = ID_T_MAX_VAL 
)
protected

Notify server about resource value change.

Definition at line 17 of file Instance.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=() [1/2]

Instance& wpp::Instance::operator= ( const Instance )
delete

◆ operator=() [2/2]

Instance& wpp::Instance::operator= ( Instance &&  )
delete

◆ readAsServer()

uint8_t wpp::Instance::readAsServer ( lwm2m_server_t *  server,
int *  numDataP,
lwm2m_data_t **  dataArray 
)

This methods is called by the core when the server wants to read, write, discover, execute the value of the resource. User should not call this methods directly.

Parameters
securityInst- Contains security instance ID when request retrieved from server or ID_T_MAX_VAL if request initiated by core.

Definition at line 423 of file Instance.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resourceOperationNotifier()

void wpp::Instance::resourceOperationNotifier ( ItemOp::TYPE  type,
ID_T  resId,
ID_T  resInstId 
)
overrideprotectedvirtual

Handle information about resource operation (WRITE, DELETE). Called by ResourceContainer after resource operation performed.

Implements wpp::ResourceContainer.

Definition at line 46 of file Instance.cpp.

+ Here is the call graph for this function:

◆ serverOperationNotifier()

virtual void wpp::Instance::serverOperationNotifier ( Instance securityInst,
ItemOp::TYPE  type,
const ResLink resLink 
)
protectedpure virtual

This method must be implemented by the derived class, and handle information about resource operation (WRITE, EXECUTE). Called by Instance after resource operation performed by SERVER if the operation is
WRITE, if the operation is EXECUTE then called before this operation. When the EXECUTE operation, the handler that was set before the serverOperationNotifier() call is used.

Parameters
securityInst- Contains security instance when the request received from the server or NULL if the request is initiated by the core.

Implemented in wpp::FirmwareUpdate, wpp::ConnectivityMonitoring, wpp::AudioClip, wpp::Lwm2mAccessControl, wpp::Device, wpp::Lwm2mServer, and wpp::Lwm2mSecurity.

+ Here is the caller graph for this function:

◆ userOperationNotifier()

virtual void wpp::Instance::userOperationNotifier ( ItemOp::TYPE  type,
const ResLink resLink 
)
protectedpure virtual

This method must be implemented by the derived class, and handle information about resource operation (WRITE, DELETE). Called by Instance after resource operation performed by the USER.

Implemented in wpp::FirmwareUpdate, wpp::ConnectivityMonitoring, wpp::AudioClip, wpp::Lwm2mAccessControl, wpp::Device, wpp::Lwm2mServer, and wpp::Lwm2mSecurity.

+ Here is the caller graph for this function:

◆ writeAsServer()

uint8_t wpp::Instance::writeAsServer ( lwm2m_server_t *  server,
int  numData,
lwm2m_data_t *  dataArray,
lwm2m_write_type_t  writeType 
)

Definition at line 467 of file Instance.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: