Initial merge-commit of the OIC code. Should successfully do discovery for single...
[platform/upstream/iotivity.git] / include / OCServer.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
5
6 /// @file OCServer.h 
7
8 /// @brief      This file contains the declaration of classes and its members required to provide 
9 ///                     functionality of a server. A server role supports resoruce registration, binding 
10 ///                     and advertisement. 
11
12 #ifndef __OCSERVER_H
13 #define __OCSERVER_H
14
15 #include <map>
16 #include <string>
17
18 #include "OCObject.h"
19 #include "OCSecurityModel.h"
20
21 namespace OC { namespace OCReflect {
22
23 struct method_binding;
24 struct property_binding;
25
26 }} // namespace OC::OCReflect
27
28 namespace OC 
29 {
30         /**
31         @brief  A server instance which is the starting point for a UB device that wishes to host a 
32                         set of resource(s) for other devices. 
33         */
34         class OCServer
35         {
36     private:
37         std::map<std::string, OC::OCReflect::method_binding>    method_bindings;
38
39         public:
40                 OCServer(void);
41                 virtual ~OCServer(void);
42
43                 /**
44                 * @fn   This registers a security model for access control to resources under this service.
45                 * 
46                 * @param model - Security Model required for access to this service and control/view of it's
47                 *        services.
48                 */
49                 void setSecurityModel(OCSecurityModel model) ;
50
51                 /**
52                 * @fn   Registers a resource with the service.
53                 * 
54                 * @param object - The OCObject that handles the resource requests
55                 * @param url - The URL under the resource.
56                 * @param accessControl - The access control handler that determines whether the remote device is
57                 *        allowed to access this resource. If NULL, all access is granted.
58                 */
59                 void registerResource(OCObject *object, std::string url/* TODO: , AccessControl accessControl */);
60
61                 /**
62                 * @fn   Unregisters a resource with the service.
63                 * 
64                 * @param object - The OCObject to be unregistered.
65                 */
66                 void unregisterResource(OCObject *object);
67
68                 /**
69                 * @fn   Starts the open connectivity service.
70                 * 
71                 * Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread
72                 */
73                 void start();
74
75                 /**
76                 * Stops the open connectivity service.
77                 * 
78                 * Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread
79                 */
80                 void stop();
81
82                 public:
83                 void bind(const OC::OCReflect::method_binding& mb);
84
85                 void bind(const OC::OCReflect::property_binding& pb)
86                 {}
87
88                 template <class T>
89                 void registerResource(T *object, const std::string& base_URI)
90                 {}
91
92         public:
93         const std::map<std::string, OC::OCReflect::method_binding>& methods() const { return method_bindings; }
94         };
95 }
96
97 #endif //__OCSERVER_H