1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #ifndef __INTEL_OCREFLECT_H_20140708
22 #define __INTEL_OCREFLECT_H_20140708
26 /* Runtime reflection support. */
37 #include "OCProperties.h"
39 namespace OC { namespace OCReflect {
42 class remote_resource;
48 template <typename NarrowT>
49 NarrowT property(const OC::OCReflect::entity& entity);
51 OC::OCReflect::method method(const std::string& name);
54 /* This type originally represented a binding to a server-- I think it can probably
55 be factored out soon: */
58 OC::OCResource& resource;
60 std::string resource_location;
63 remote_resource(OC::OCResource& resource_, const std::string& resource_location_)
64 : resource(resource_),
65 resource_location(resource_location_)
69 OC::OCReflect::entity operator()(const std::string& name);
74 // underlying type; data buffer; ctor may only be invoked from a remote resource
79 OC::OCResource *resource; // observing ptr
84 /* This default ctor will go away once real narrowing is functional-- here to placate the compiler for now.
85 - Ultimately, you should never be able to construct one of these in an invalid state. */
87 : resource { nullptr }
90 method(OC::OCResource& resource_, const std::string& name_)
91 : resource(&resource_),
96 /* Note that this declaration will likely change in the near future: */
97 template <class ...TS>
98 OC::OCReflect::tagged_property operator()(TS ...xs)
100 return OC::OCReflect::tagged_property();
104 }} // namespace OC::OCReflect
106 // Convert to underlying OCStack C API (and, some handy C-wrangling utilities):
107 namespace OC { namespace OCReflect { namespace OCStack {
109 void release(char *in);
110 void release(char **in);
111 char *strdup(const char *s);
112 char *strdup(const std::string& s);
113 size_t length(char **in);
114 char **convert(const std::vector<std::string>& vs);
116 std::string convert(const property_binding& npb);
117 std::vector<std::string> convert(const property_binding_vector& psv);
119 OC::OCReflect::property_type as_property_type(const std::string& pt_rep);
120 OC::OCReflect::property_binding as_property_binding(const std::string& pb_rep);
121 OC::OCReflect::property_binding_vector as_property_binding_vector(const std::vector<std::string>& pb_reps);
123 char *flatten(const std::vector<std::string>& input, const std::string& delim = ";");
124 std::vector<std::string> expand(const char *flattened_string, const std::string& delim = ";");
126 }}} // namespace OC::OCReflect::OCStack