Merge "Patch 1 : Adding Arduino WiFi support. This requires updated Arduino WiFi...
[platform/upstream/iotivity.git] / include / OCServer.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 /// @file OCServer.h 
22
23 /// @brief      This file contains the declaration of classes and its members required to provide 
24 ///                     functionality of a server. A server role supports resoruce registration, binding 
25 ///                     and advertisement. 
26
27 #ifndef __OCSERVER_H
28 #define __OCSERVER_H
29
30 #include <map>
31 #include <string>
32
33 #include "OCObject.h"
34 #include "OCPropertyTypes.h"
35 #include "OCSecurityModel.h"
36
37 namespace OC 
38 {
39         /**
40         @brief  A server instance which is the starting point for a UB device that wishes to host a 
41                         set of resource(s) for other devices. 
42         */
43         class OCServer
44         {
45     /* 1) It may be worth considering Boost's lock-free containers here;
46        2) The only reason bindings rather than the "real things" are shown in this case is because of
47        an assumption that the real things lie within the C layer. In practice, there's no firm reason
48        why it needs to be one way or the other-- in fact, a pure C++ implementation might as well
49        just store all the actual methods and properties in one place: */
50     private:
51         std::map<std::string, OC::OCReflect::method_binding>      method_bindings;
52         std::map<std::string, OC::OCReflect::property_binding>    property_bindings; 
53
54         public:
55                 OCServer(void);
56                 virtual ~OCServer(void);
57
58                 /**
59                 * @fn   This registers a security model for access control to resources under this service.
60                 * 
61                 * @param model - Security Model required for access to this service and control/view of it's
62                 *        services.
63                 */
64                 void setSecurityModel(OCSecurityModel model) ;
65
66                 /**
67                 * @fn   Registers a resource with the service.
68                 * 
69                 * @param object - The OCObject that handles the resource requests
70                 * @param url - The URL under the resource.
71                 * @param accessControl - The access control handler that determines whether the remote device is
72                 *        allowed to access this resource. If NULL, all access is granted.
73                 */
74                 void registerResource(OCObject *object, std::string url/* TODO: , AccessControl accessControl */);
75
76                 /**
77                 * @fn   Unregisters a resource with the service.
78                 * 
79                 * @param object - The OCObject to be unregistered.
80                 */
81                 void unregisterResource(OCObject *object);
82
83                 /**
84                 * @fn   Starts the open connectivity service.
85                 * 
86                 * Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread
87                 */
88                 void start();
89
90                 /**
91                 * Stops the open connectivity service.
92                 * 
93                 * Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread
94                 */
95                 void stop();
96
97                 public:
98                 void bind(const OC::OCReflect::method_binding& mb);
99                 void bind(const OC::OCReflect::property_binding& pb);
100
101                 template <class T>
102                 void registerResource(T *object, const std::string& base_URI)
103                 {}
104
105         // Note that these transfer the /binding information/ (signatures, etc.) not data (which could be /very/ expensive):
106         public:
107         const std::map<std::string, OC::OCReflect::method_binding>& methods()       const { return method_bindings; }
108         const std::map<std::string, OC::OCReflect::property_binding>& properties()  const { return property_bindings; }
109
110         // Transfer data:
111         public:
112         // Look up the method from the binding, call the function, return a full property as result:
113         // OC::OCReflect::property call(const std::pair<std::string, OC::OCReflect::method_binding>& method); // other signatures possible, this is an example
114
115         // Look up the property from the binding, return a full property (ie. with a data value):
116         OC::OCReflect::property get(const std::string& p_name);
117         OC::OCReflect::property get(const OC::OCReflect::property_binding& pb);
118
119         // Set a property's value:
120         void set(const OC::OCReflect::property& p);
121         };
122 }
123
124 #endif //__OCSERVER_H