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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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.
34 #include "OCPropertyTypes.h"
35 #include "OCSecurityModel.h"
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.
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: */
51 std::map<std::string, OC::OCReflect::method_binding> method_bindings;
52 std::map<std::string, OC::OCReflect::property_binding> property_bindings;
56 virtual ~OCServer(void);
59 * @fn This registers a security model for access control to resources under this service.
61 * @param model - Security Model required for access to this service and control/view of it's
64 void setSecurityModel(OCSecurityModel model) ;
67 * @fn Registers a resource with the service.
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.
74 void registerResource(OCObject *object, std::string url/* TODO: , AccessControl accessControl */);
77 * @fn Unregisters a resource with the service.
79 * @param object - The OCObject to be unregistered.
81 void unregisterResource(OCObject *object);
84 * @fn Starts the open connectivity service.
86 * Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread
91 * Stops the open connectivity service.
93 * Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread
98 void bind(const OC::OCReflect::method_binding& mb);
99 void bind(const OC::OCReflect::property_binding& pb);
102 void registerResource(T *object, const std::string& base_URI)
105 // Note that these transfer the /binding information/ (signatures, etc.) not data (which could be /very/ expensive):
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; }
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
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);
119 // Set a property's value:
120 void set(const OC::OCReflect::property& p);
124 #endif //__OCSERVER_H