Updated license header to reference Apache 2.0 License
[platform/upstream/iotivity.git] / include / OCServer.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Corporation 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 "OCSecurityModel.h"
35
36 namespace OC { namespace OCReflect {
37
38 struct method_binding;
39 struct property_binding;
40
41 }} // namespace OC::OCReflect
42
43 namespace OC 
44 {
45         /**
46         @brief  A server instance which is the starting point for a UB device that wishes to host a 
47                         set of resource(s) for other devices. 
48         */
49         class OCServer
50         {
51     private:
52         std::map<std::string, OC::OCReflect::method_binding>    method_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
100                 void bind(const OC::OCReflect::property_binding& pb)
101                 {}
102
103                 template <class T>
104                 void registerResource(T *object, const std::string& base_URI)
105                 {}
106
107         public:
108         const std::map<std::string, OC::OCReflect::method_binding>& methods() const { return method_bindings; }
109         };
110 }
111
112 #endif //__OCSERVER_H