SOIL C++
C++ Unified Device Interface
SOIL::Object Class Reference

Object Class. More...

#include <Object.h>

Inheritance diagram for SOIL::Object:
SOIL::Element HTTP::Resource

Public Member Functions

 Object (std::shared_ptr< Element > parent, std::string uuid, std::string name, std::string description, std::string ontology="")
 Constructor. More...
 
 ~Object ()
 Destructor. More...
 
web::json::value wjson (void)
 HTTP JSON. More...
 
virtual void read (void)
 Read callback. More...
 
virtual HTTP::Json insert (HTTP::Json body)
 Insert callback. More...
 
virtual void remove (void)
 Remove callback. More...
 
HTTP::Response handle_get (HTTP::Request message, std::smatch match=std::smatch()) override
 HTTP GET Handler. More...
 
HTTP::Response handle_put (HTTP::Request message, std::smatch match=std::smatch()) override
 HTTP PUT Handler. More...
 
HTTP::Response handle_delete (HTTP::Request message, std::smatch match=std::smatch()) override
 HTTP DELETE Handler. More...
 
std::shared_ptr< Objectptr (void)
 Get Pointer. More...
 
- Public Member Functions inherited from SOIL::Element
 Element (std::shared_ptr< Element > parent, std::string uuid, std::string name, std::string description, std::string ontology="")
 Constructor. More...
 
virtual ~Element ()
 Destructor. More...
 
std::vector< std::string > fqid (void)
 FQID. More...
 
std::shared_ptr< Elementoperator[] (std::string fqid)
 Access Operator. More...
 
std::shared_ptr< Elementadd (std::string uuid, std::shared_ptr< Element > child)
 Add Child Element. More...
 
std::shared_ptr< Elementadd (std::string uuid, Element *child)
 Add Child Element. More...
 
bool insert (std::string uuid, std::shared_ptr< Element > child)
 Add Child Element. More...
 
bool insert (std::string uuid, Element *child)
 Add Child Element. More...
 
bool remove (std::string uuid)
 Remove Child element. More...
 
template<typename T >
T * cast (void)
 Get dynamically casted pointer. More...
 
bool is_object (void) const
 Is Object? More...
 
bool is_variable (void) const
 Is Variable? More...
 
bool is_function (void) const
 Is Function? More...
 
bool is_parameter (void) const
 Is Parameter? More...
 
virtual HTTP::Json wjson (void)
 HTTP JSON. More...
 
virtual std::string json (void)
 JSON string. More...
 
HTTP::Response handle (HTTP::Request request, std::smatch match=std::smatch())
 HTTP Handler. More...
 
- Public Member Functions inherited from HTTP::Resource
 Resource ()
 Constructor. More...
 
 ~Resource ()
 Default Destructor. More...
 
virtual Response handle (Request message, std::smatch match=std::smatch())
 HTTP Handler. More...
 
virtual Response handle_get (Request message, std::smatch match=std::smatch())
 HTTP GET Handler. More...
 
virtual Response handle_put (Request message, std::smatch match=std::smatch())
 HTTP PUT Handler. More...
 
virtual Response handle_post (Request message, std::smatch match=std::smatch())
 HTTP POST Handler. More...
 
virtual Response handle_delete (Request message, std::smatch match=std::smatch())
 HTTP DELETE Handler. More...
 
virtual Response handle_patch (Request message, std::smatch match=std::smatch())
 HTTP PATCH Handler. More...
 
virtual Response handle_options (Request message, std::smatch match=std::smatch())
 HTTP OPTIONS Handler. More...
 
virtual Response handle_head (Request message, std::smatch match=std::smatch())
 HTTP HEAD Handler. More...
 
virtual Response handle_exception (Request message, std::exception &exception, std::smatch match=std::smatch())
 HTTP Exception handler. More...
 

Static Public Member Functions

static std::shared_ptr< Objectcreate (std::shared_ptr< Element > parent, std::string uuid, std::string name, std::string description, std::string ontology="")
 Create new Object. More...
 
- Static Public Member Functions inherited from HTTP::Resource
static web::json::value request_info (Request message, std::smatch match=std::smatch())
 Request Info. More...
 

Additional Inherited Members

- Public Attributes inherited from SOIL::Element
std::map< std::string, std::shared_ptr< Element > > children
 Children Map. More...
 
std::shared_ptr< Elementparent
 Parent Pointer. More...
 
std::shared_ptr< Elementself
 Self Pointer. More...
 
std::string uuid
 Local UUID. More...
 
std::string name
 Name. More...
 
std::string description
 Description. More...
 
std::string ontology
 Ontology identifier. More...
 
std::recursive_mutex mutex
 Element Mutex. More...
 
- Protected Member Functions inherited from HTTP::Resource
void apply_headers (Response &response)
 Apply headers. More...
 
- Protected Attributes inherited from HTTP::Resource
std::vector< web::http::method > allowed_methods
 Allowed methods. More...
 
std::string content_type
 Content type. More...
 
std::string allowed_origins
 Allowed Origins. More...
 

Detailed Description

Class implementing the SOIL Object type. The purpose of Objects is mainly to organize the overall system. Only Objects can have child items, which can be added or removed during runtime. Objects support HTTP GET (read), PUT (add child) and DELETE (remove child) verbs. This class directly inherits from Elememt.

Todo:
The HTTP handlers may be moved to protected if HTTP::Server is declared as friend class. Currently this is not done to alllow for greater flexibility.

Definition at line 18 of file Object.h.

Constructor & Destructor Documentation

◆ Object()

SOIL::Object::Object ( std::shared_ptr< Element parent,
std::string  uuid,
std::string  name,
std::string  description,
std::string  ontology = "" 
)

Default constructor for SOIL elements, to be called from derived classes.

Parameters
[in]parentShared pointer to parent object. Can be set to NULL for the creation of a root object
[in]uuidLocally Unique identifier
[in]nameHuman-readable name
[in]descriptionHuman-readable description
[in]ontologyOntology reference, is set to null if an empty string is passed
Precondition
The ontology referred to must be defined elsewhere and is decoupled from the code.

Definition at line 4 of file Object.cpp.

◆ ~Object()

SOIL::Object::~Object ( )

Standard destructor. The main destruction occurs in the destructor of Element, i.e. the references to the child elements are deleted, e.g. they go out of scope is this was the last shared pointer.

Definition at line 14 of file Object.cpp.

Member Function Documentation

◆ create()

std::shared_ptr< SOIL::Object > SOIL::Object::create ( std::shared_ptr< Element parent,
std::string  uuid,
std::string  name,
std::string  description,
std::string  ontology = "" 
)
static

Create a new Object using the default constructor and return a shared pointer reference. This is the preferred method for manual creation with consistent lifecycle handling.

Parameters
[in]parentShared pointer to parent object. Can be set to NULL for the creation of a root object
[in]uuidLocally Unique identifier
[in]nameHuman-readable name
[in]descriptionHuman-readable description
[in]ontologyOntology reference, is set to null if an empty string is passed
Precondition
The ontology referred to must be defined elsewhere and is decoupled from the code.

Definition at line 18 of file Object.cpp.

◆ handle_delete()

HTTP::Response SOIL::Object::handle_delete ( HTTP::Request  message,
std::smatch  match = std::smatch() 
)
overridevirtual

Handler that is called by the server on HTTP requests on a DELETE method. This function deletes an element. It should not be overridden directly in subclasses, instead the remove() function should be overriden. It is mandatory to implement a custom logic in the aforementioned function to allow PUT to properly work. If manual deletaion is not foreseen, you may consider overriding allowed_methods without DELETE.

If no exception is thrown, an empty response with result code OK is returned, otherwise an Internal Error will be provided.

Parameters
[in]messageIncoming HTTP request as preprocessed by cpprestsdk
[in]matchMatch result of the request path that led to this resource
Returns
Outgoing HTTP response to be processed by cpprestdsk

Reimplemented from HTTP::Resource.

Definition at line 75 of file Object.cpp.

◆ handle_get()

HTTP::Response SOIL::Object::handle_get ( HTTP::Request  message,
std::smatch  match = std::smatch() 
)
overridevirtual

Handler that is called by the server on HTTP requests on a GET method. This function returns a representation of the Object to the requesting party. It should not be overridden directly in subclasses, instead the read() function should be overriden.

Parameters
[in]messageIncoming HTTP request as preprocessed by cpprestsdk
[in]matchMatch result of the request path that led to this resource
Returns
Outgoing HTTP response to be processed by cpprestdsk

Reimplemented from HTTP::Resource.

Definition at line 54 of file Object.cpp.

◆ handle_put()

HTTP::Response SOIL::Object::handle_put ( HTTP::Request  message,
std::smatch  match = std::smatch() 
)
overridevirtual

Handler that is called by the server on HTTP requests on a PUT method. This function inserts an element to the objects children. It should not be overridden directly in subclasses, instead the HTTP::Json insert(HTTP::Json body) function should be overriden. It is mandatory to implement a custom logic in the aforementioned function to allow PUT to properly work. If manual insertion is not foreseen, you may consider overriding allowed_methods without PUT. The minimum requirement to the body is that it contains an valid UUID key with value, the templates and further logic may be implemented by server.

Parameters
[in]messageIncoming HTTP request as preprocessed by cpprestsdk
[in]matchMatch result of the request path that led to this resource
Returns
Outgoing HTTP response to be processed by cpprestdsk

Reimplemented from HTTP::Resource.

Definition at line 63 of file Object.cpp.

◆ insert()

HTTP::Json SOIL::Object::insert ( HTTP::Json  body)
virtual

Function that is called when a new child object is insterted via HTTP PUT. This function muss be implemented by the deriving class.

Exceptions
std::logic_errorIf the derived class does not contain an implementation, an exception is thrown here. The exception will be caught in the HTTP handler of the server and returns with an HTTP Internal Error (500) code.
Parameters
[in]bodyHTTP JSON body passed to PUT
Returns
HTTP JSON object corresponding to the created Object, as required per good HTTP practice.

Definition at line 44 of file Object.cpp.

◆ ptr()

std::shared_ptr< Object > SOIL::Object::ptr ( void  )
inline

Return a shared pointer casted to the Object type to element itself.

Returns
Casted pointer

Definition at line 149 of file Object.h.

◆ read()

void SOIL::Object::read ( void  )
virtual

Read callback that can be implemented by deriving classes to perform custom build logic on read actions, e.g. update the value from an external storage. Declared virtual to make sure the derived method is called first. Any exception that may be occurring will be caught in the HTTP handler.

Definition at line 40 of file Object.cpp.

◆ remove()

void SOIL::Object::remove ( void  )
virtual

Callback hook for subclasses to add custom business logic to the HTTP DELETE operation, e.g. to act on external resoruces. Otherwise the object will just be deleted.

Definition at line 49 of file Object.cpp.

◆ wjson()

HTTP::Json SOIL::Object::wjson ( void  )
virtual

Get a HTTP JSON object corresponding to the function including arguments and returns

Returns
JSON object

Reimplemented from SOIL::Element.

Definition at line 24 of file Object.cpp.


The documentation for this class was generated from the following files: