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