iotivity 0.9.0
[platform/upstream/iotivity.git] / service / notification-manager / NotificationManager / src / RegistrationManager.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 Samsung Electronics 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 #include "RegistrationManager.h"
22
23 RegistrationManager *RegistrationManager::s_instance = NULL;
24 mutex RegistrationManager::s_mutexForCreation;
25
26 RegistrationManager::RegistrationManager()
27 {
28 }
29
30 RegistrationManager::~RegistrationManager()
31 {
32 }
33
34 RegistrationManager *RegistrationManager::getInstance()
35 {
36         if(!s_instance)
37         {
38                 s_mutexForCreation.lock();
39                 if(s_instance)
40                 {
41                         s_instance = new RegistrationManager();
42                 }
43                 s_mutexForCreation.unlock();
44         }
45
46         return s_instance;
47 }
48
49 int RegistrationManager::addResource()
50 {
51     return 0;
52 }
53
54 int RegistrationManager::removeResource()
55 {
56     return 0;
57 }
58
59 int RegistrationManager::updateResource()
60 {
61     return 0;
62 }
63
64 bool RegistrationManager::registerNMResource(VirtualRepresentation &resourceObject ,
65         std::shared_ptr< OCResource > resource)
66 {
67     std::string uri = resourceObject.getUri();
68     std::string type = resourceObject.getResourceTypeName();
69     std::string interface = resourceObject.getResourceInterface();
70
71     OCResourceHandle resourceHandle;
72
73     OCStackResult result;
74     result = registerResource(resourceHandle , uri , type ,
75                 interface ,
76                 std::function<
77                         OCEntityHandlerResult(const std::shared_ptr< OCResourceRequest > request ,
78                                 const std::shared_ptr< OCResourceResponse > response) >(
79                         std::bind(&VirtualRepresentation::entityHandler , resourceObject ,
80                                         std::placeholders::_1 , std::placeholders::_2)) ,
81                 resourceObject.getResourceProperty());
82
83     resourceObject.setResourceHandle(resourceHandle);
84
85     if(OC_STACK_OK != result)
86     {
87         return false;
88     }
89     else
90     {
91         QueryParamsMap queryParmaMap;
92         resource->observe(ObserveType::Observe , queryParmaMap ,
93                 std::function<
94                         void(const HeaderOptions headerOption,
95                                         const OCRepresentation& rep , const int& eCode ,
96                                 const int& sequenceNumber) >(
97                         std::bind(&VirtualRepresentation::onObserve , resourceObject ,
98                                 std::placeholders::_1 , std::placeholders::_2 ,
99                                 std::placeholders::_3 , std::placeholders::_4)));
100     }
101
102     return true;
103 }
104
105 bool RegistrationManager::unregisterResource()
106 {
107     return true;
108 }
109