RESTProcess is a common descriptor used for reflecting C++ object attributes and methods to an external scripting environment. It gets its name from one of the obvious use cases: implementing a REST service API endpoint.
To expose a C++ object, run the RESTProcess descriptor as
RESTProcess(registry,name,object);which creates a reference in the registry for the C++ object object under the name name.
The RESTProcess_t
registry object has a method process
that takes two arguments: a path string, containing the method or attribute name, as a dot
separated string, and the arguments to pass to it, as a buffer concept
object (by default a json_pack_t
object).
When the name refers to an attribute, then it is considered the same as a method consisting of overloaded getters and setters. If an argument is passed, then the setter is called, updating the attribute, and if no argument then just the getter is called. Both overloads return the value of the attribute.
The return value is a pointer to a polymorphic object. The most
important method is asBuffer
, which returns a buffer object,
which can be converted into the external scripting environment's
representation (eg JSON):
using RPPtr=std::shared_ptr<RESTProcessBase>; struct RESTProcessBase { virtual RPPtr process(const string& path, const REST_PROCESS_BUFFER& arguments)=0;perform the REST operation, with path being the path string and arguments as body text result of operation is returned as an object, and can be serialised into
REST_PROCESS_BUFFER
using asBuffer.
virtual REST_PROCESS_BUFFER asBuffer() const=0;Return a buffer object reflecting the state of the object referred to by this.
virtual std::vector<Signature> signature() const=0;return signature(s) of the operations
virtual RESTProcess_t list() const=0;return list of subcommands to this
virtual std::string type() const=0;return type name of this
};