9#include <boost/algorithm/string/join.hpp>
33 template <
typename T,
int x=-1,
int y=-1>
54 virtual void read(
void);
62 virtual void write(
void);
166 inline std::shared_ptr<Parameter>
ptr(
void)
192 bool mqtt(std::shared_ptr<MQTT::Publisher> publisher,
int qos = 0,
bool retain =
false);
201template<
typename T,
int x,
int y>
202SOIL::Parameter<T, x, y>::Parameter(std::shared_ptr<SOIL::Element> parent, std::string uuid, std::string name, std::string description, std::string unit,
bool constant, std::string ontology,
Range<T> range,
SOIL::TIME time) :
SOIL::
Figure<T, x, y>(parent, uuid, name, description, unit, ontology, range, time), constant(constant)
204 if (
uuid.substr(0, 3) !=
"PAR")
206 throw std::logic_error(
"UUIDs for parameters must start with PAR!");
212template<
typename T,
int x,
int y>
217template<
typename T,
int x,
int y>
218inline std::shared_ptr<SOIL::Parameter<T, x, y> >
SOIL::Parameter<T, x, y>::create(std::shared_ptr<Element> parent, std::string uuid, std::string name, std::string description, std::string unit,
bool constant, std::string ontology,
Range<T> range,
TIME time)
220 Parameter<T, x, y>* parameter =
new Parameter<T, x, y>(parent, uuid, name, description, unit, constant, ontology, range, time);
221 return parameter->
ptr();
224template<
typename T,
int x,
int y>
232template<
typename T,
int x,
int y>
237 json_root[U(
"constant")] = HTTP::Json::boolean(constant);
242template<
typename T,
int x,
int y>
247template<
typename T,
int x,
int y>
253template<
typename T,
int x,
int y>
260 response.set_body(body);
262 response.set_status_code(HTTP::Status::OK);
267template<
typename T,
int x,
int y>
270 auto task = message.extract_json();
276 if (external_json.has_field(U(
"timestamp")))
278 timestamp = to_value<TIME>(external_json[U(
"timestamp")]);
292 response.set_body(this->wjson());
293 response.set_status_code(HTTP::Status::Created);
299template<
typename T,
int x,
int y>
302 std::string topic = boost::algorithm::join(this->fqid(),
"/");
303 return publisher->publish(topic, this->
json(), qos, retain);
std::vector< web::http::method > allowed_methods
Allowed methods.
std::string uuid
Local UUID.
std::string description
Description.
std::string ontology
Ontology identifier.
std::shared_ptr< Element > parent
Parent Pointer.
std::recursive_mutex mutex
Element Mutex.
std::shared_ptr< Element > self
Self Pointer.
HTTP::Response handle_get(HTTP::Request message, std::smatch match=std::smatch()) override
HTTP GET Handler.
std::shared_ptr< Parameter > ptr(void)
Get Pointer.
virtual void read(void)
Read callback.
Parameter(std::shared_ptr< Element > parent, std::string uuid, std::string name, std::string description, std::string unit, bool constant=false, std::string ontology="", Range< T > range=Range< T >(), TIME time=TIME())
Constructor.
Parameter< T, x, y > & operator=(const Container< T, x, y > &value)
Assignment operator.
bool mqtt(std::shared_ptr< MQTT::Publisher > publisher, int qos=0, bool retain=false)
Publish to MQTT.
HTTP::Response handle_patch(HTTP::Request message, std::smatch match=std::smatch()) override
HTTP PATCH Handler.
static std::shared_ptr< Parameter > create(std::shared_ptr< Element > parent, std::string uuid, std::string name, std::string description, std::string unit, bool constant=false, std::string ontology="", Range< T > range=Range< T >(), TIME time=TIME())
Create new Parameter.
HTTP::Json wjson(void) override
HTTP JSON.
bool constant
Constant flag.
virtual void write(void)
Write callback.
static DLL boost::posix_time::ptime utc_now(void)
Current Time.
web::json::value Json
HTTP JSON.
web::http::http_request Request
HTTP Request.
web::http::http_response Response
HTTP Response.