There are Two modifications.
[platform/upstream/iotivity.git] / service / notification-manager / NotificationManager / src / HostingInterface.cpp
1 /*
2  * HostingInterface.cpp
3  *
4  *  Created on: 2014. 10. 15.
5  *      Author: jyong2
6  */
7
8 #include "HostingInterface.h"
9
10 HostingInterface::HostingInterface()
11 {
12
13 }
14
15 HostingInterface::~HostingInterface()
16 {
17         // TODO Auto-generated destructor stub
18 }
19
20 int HostingInterface::setOnFoundHostingCandidate(
21         std::function< void(std::shared_ptr< OCResource > resource) > func)
22 {
23     if(func != NULL)
24     {
25         try
26         {
27                 ResourceManager::getInstance()->m_onFoundforHosting = func;
28         }
29         catch(exception &e)
30         {
31             return false;
32         }
33     }
34     else
35     {
36         ResourceManager::getInstance()->m_onFoundforHosting = std::function<
37                 void(std::shared_ptr< OCResource > resource) >(
38                 std::bind(&ResourceManager::onFoundforHostingDefault , ResourceManager::getInstance() ,
39                         std::placeholders::_1));
40     }
41
42     return true;
43 }
44
45 int HostingInterface::setOnObserve(std::function< void(AttributeMap &inputAttMap, OCResourceHandle resourceHandle) > func)
46 {
47     if(func != NULL)
48     {
49         try
50         {
51                 ResourceManager::getInstance()->m_onObserve = func;
52         }
53         catch(exception &e)
54         {
55             return false;
56         }
57     }
58     else
59     {
60         ResourceManager::getInstance()->m_onObserve = std::function<
61                         void(AttributeMap &inputAttMap, OCResourceHandle resourceHandle) >(
62                         std::bind(&ResourceManager::onObserveDefault , ResourceManager::getInstance() ,
63                                 std::placeholders::_1, std::placeholders::_2));
64     }
65
66     return true;
67 }
68
69 int HostingInterface::setNotifyObservers(std::function< void(OCResourceHandle resourceHandle) > &func)
70 {
71         try
72         {
73                 func = std::function< void(OCResourceHandle resourceHandle) >(
74                                 std::bind(&ResourceManager::notifyObservers , ResourceManager::getInstance() ,
75                                                 std::placeholders::_1));
76         }
77         catch(exception &e)
78         {
79                 return false;
80         }
81
82         return true;
83 }
84
85 int HostingInterface::setStartHosting(
86         std::function< void(std::shared_ptr< OCResource > resource) > &func)
87 {
88     try
89     {
90         func = std::function< void(std::shared_ptr< OCResource > resource) >(
91                 std::bind(&ResourceManager::startHosting , ResourceManager::getInstance() ,
92                         std::placeholders::_1));
93     }
94     catch(exception &e)
95     {
96         return false;
97     }
98
99     return true;
100 }
101
102 int HostingInterface::setFindHosting(std::function< void(bool isHosting) > &func)
103 {
104     try
105     {
106         func = std::function< void(bool isHosting) >(
107                         std::bind(&ResourceManager::findNMResource ,
108                                         ResourceManager::getInstance() ,
109                                                 std::placeholders::_1));
110     }
111     catch(exception &e)
112     {
113         return false;
114     }
115
116     return true;
117 }
118
119 int HostingInterface::setAddExtraStr(std::function< void(std::string) > &func)
120 {
121     try
122     {
123         func = std::function< void(std::string str) >(
124                 std::bind(&ResourceManager::addExtraStr , ResourceManager::getInstance() ,
125                         std::placeholders::_1));
126     }
127     catch(exception &e)
128     {
129         return false;
130     }
131
132     return true;
133 }