TA1622 - Updated the copyright company from Intel Corporation to Intel Mobile Communi...
[platform/upstream/iotivity.git] / include / OCReflect.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef __INTEL_OCREFLECT_H_20140708
22  #define __INTEL_OCREFLECT_H_20140708
23
24 #include <iostream> 
25
26 /* Runtime reflection support. */
27
28 #include <tuple>
29 #include <string>
30 #include <vector>
31 #include <memory>
32 #include <cstring>
33 #include <cstdlib>
34 #include <functional>
35
36 #include "OCServer.h"
37 #include "OCProperties.h"
38
39 namespace OC { namespace OCReflect {
40
41 struct service;
42 class  remote_resource;
43 struct entity;
44 class  method;
45
46 struct service
47 {
48  template <typename NarrowT>
49  NarrowT property(const OC::OCReflect::entity& entity);
50
51  OC::OCReflect::method method(const std::string& name);
52 };
53
54 /* This type originally represented a binding to a server-- I think it can probably
55 be factored out soon: */
56 class remote_resource
57 {
58  OC::OCResource&    resource;
59
60  std::string        resource_location;
61
62  public:
63  remote_resource(OC::OCResource& resource_, const std::string& resource_location_)
64   : resource(resource_),
65     resource_location(resource_location_)
66  {}
67
68  public:
69  OC::OCReflect::entity operator()(const std::string& name);
70 };
71
72 struct entity
73 {
74  // underlying type; data buffer; ctor may only be invoked from a remote resource
75 };
76
77 class method
78 {
79  OC::OCResource *resource;  // observing ptr
80
81  std::string name;
82
83  public:
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. */
86  method()
87   : resource { nullptr }
88  {}
89  
90  method(OC::OCResource& resource_, const std::string& name_)
91   : resource(&resource_), 
92     name(name_)
93  {}
94
95  public:
96  /* Note that this declaration will likely change in the near future: */
97  template <class ...TS>
98  OC::OCReflect::tagged_property operator()(TS ...xs)
99  {
100     return OC::OCReflect::tagged_property();
101  };
102 };
103
104 }} // namespace OC::OCReflect
105
106 // Convert to underlying OCStack C API (and, some handy C-wrangling utilities):
107 namespace OC { namespace OCReflect { namespace OCStack  {
108
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);
115
116 std::string convert(const property_binding& npb);
117 std::vector<std::string> convert(const property_binding_vector& psv);
118
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);
122
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 = ";");
125
126 }}} // namespace OC::OCReflect::OCStack
127
128 #endif