1 //******************************************************************
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 #ifndef __INTEL_OCREFLECT_H_20140708
7 #define __INTEL_OCREFLECT_H_20140708
11 /* Runtime reflection support. */
22 #include "OCProperties.h"
24 namespace OC { namespace OCReflect {
27 class remote_resource;
33 template <typename NarrowT>
34 NarrowT property(const OC::OCReflect::entity& entity);
36 OC::OCReflect::method method(const std::string& name);
39 /* This type originally represented a binding to a server-- I think it can probably
40 be factored out soon: */
43 OC::OCResource& resource;
45 std::string resource_location;
48 remote_resource(OC::OCResource& resource_, const std::string& resource_location_)
49 : resource(resource_),
50 resource_location(resource_location_)
54 OC::OCReflect::entity operator()(const std::string& name);
59 // underlying type; data buffer; ctor may only be invoked from a remote resource
64 OC::OCResource *resource; // observing ptr
69 /* This default ctor will go away once real narrowing is functional-- here to placate the compiler for now.
70 - Ultimately, you should never be able to construct one of these in an invalid state. */
72 : resource { nullptr }
75 method(OC::OCResource& resource_, const std::string& name_)
76 : resource(&resource_),
81 /* Note that this declaration will likely change in the near future: */
82 template <class ...TS>
83 OC::OCReflect::tagged_property operator()(TS ...xs)
85 return OC::OCReflect::tagged_property();
89 }} // namespace OC::OCReflect
91 // Convert to underlying OCStack C API (and, some handy C-wrangling utilities):
92 namespace OC { namespace OCReflect { namespace to_OCStack {
94 void release(char **in);
95 char *strdup(const char *s);
96 char *strdup(const std::string& s);
97 size_t length(char **in);
98 char **convert(const std::vector<std::string>& vs);
99 std::string convert(const named_property_binding& npb);
100 std::vector<std::string> convert(const named_property_binding_vector& psv);
102 char *flatten(const std::vector<std::string>& input, const std::string& delim = ";");
104 }}} // namespace OC::OCReflect::to_OCStack