Initial merge-commit of the OIC code. Should successfully do discovery for single...
[platform/upstream/iotivity.git] / include / OCReflect.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
5
6 #ifndef __INTEL_OCREFLECT_H_20140708
7  #define __INTEL_OCREFLECT_H_20140708
8
9 #include <iostream> 
10
11 /* Runtime reflection support. */
12
13 #include <tuple>
14 #include <string>
15 #include <vector>
16 #include <memory>
17 #include <cstring>
18 #include <cstdlib>
19 #include <functional>
20
21 #include "OCServer.h"
22 #include "OCProperties.h"
23
24 namespace OC { namespace OCReflect {
25
26 struct service;
27 class  remote_resource;
28 struct entity;
29 class  method;
30
31 struct service
32 {
33  template <typename NarrowT>
34  NarrowT property(const OC::OCReflect::entity& entity);
35
36  OC::OCReflect::method method(const std::string& name);
37 };
38
39 /* This type originally represented a binding to a server-- I think it can probably
40 be factored out soon: */
41 class remote_resource
42 {
43  OC::OCResource&    resource;
44
45  std::string        resource_location;
46
47  public:
48  remote_resource(OC::OCResource& resource_, const std::string& resource_location_)
49   : resource(resource_),
50     resource_location(resource_location_)
51  {}
52
53  public:
54  OC::OCReflect::entity operator()(const std::string& name);
55 };
56
57 struct entity
58 {
59  // underlying type; data buffer; ctor may only be invoked from a remote resource
60 };
61
62 class method
63 {
64  OC::OCResource *resource;  // observing ptr
65
66  std::string name;
67
68  public:
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. */
71  method()
72   : resource { nullptr }
73  {}
74  
75  method(OC::OCResource& resource_, const std::string& name_)
76   : resource(&resource_), 
77     name(name_)
78  {}
79
80  public:
81  /* Note that this declaration will likely change in the near future: */
82  template <class ...TS>
83  OC::OCReflect::tagged_property operator()(TS ...xs)
84  {
85     return OC::OCReflect::tagged_property();
86  };
87 };
88
89 }} // namespace OC::OCReflect
90
91 // Convert to underlying OCStack C API (and, some handy C-wrangling utilities):
92 namespace OC { namespace OCReflect { namespace to_OCStack  {
93
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);
101
102 char *flatten(const std::vector<std::string>& input, const std::string& delim = ";");
103
104 }}} // namespace OC::OCReflect::to_OCStack
105
106 #endif