1 //******************************************************************
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
25 #include "OCPlatform.h"
26 #include "NotificationManager.h"
30 class NotificationService
35 static std::function< void(std::shared_ptr< OCResource > resource) > s_startHosting;
36 static std::function< void() > s_findHostingCandidate;
37 static std::function< void(std::string) > s_addExtraStr;
39 void onObserve(AttributeMap &inputAttMap)
42 std::cout << "========================================================" << endl;
43 std::cout << "On Observe:\n";
44 for(auto it = inputAttMap.begin() ; it != inputAttMap.end() ; ++it)
46 std::cout << "\tAttribute name: " << it->first << " value: ";
48 for(auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr)
50 std::cout << "\t" << *valueItr << " ";
53 std::cout << std::endl;
57 void onFoundCandidate(std::shared_ptr< OCResource > resource)
59 s_startHosting(resource);
64 std::function< void(std::shared_ptr< OCResource > resource) > NotificationService::s_startHosting;
65 std::function< void() > NotificationService::s_findHostingCandidate;
66 std::function< void(std::string) > NotificationService::s_addExtraStr;
72 std::cout << "========================================================" << endl;
73 std::cout << "Start Notification Manager : Hosting v0.5\n";
75 NotificationService a;
77 NotificationManager *Ptr = NotificationManager::getInstance();
80 Ptr->setOnFoundHostingCandidate(
81 std::function< void(std::shared_ptr< OCResource > resource) >(
82 std::bind(&NotificationService::onFoundCandidate , a , std::placeholders::_1)));
84 std::function< void(AttributeMap &inputAttMap) >(
85 std::bind(&NotificationService::onObserve , a , std::placeholders::_1)));
87 Ptr->setFindHosting(a.s_findHostingCandidate);
88 Ptr->setStartHosting(a.s_startHosting);
89 Ptr->setAddExtraStr(a.s_addExtraStr);
91 a.s_addExtraStr("visual");
92 a.s_findHostingCandidate();
104 std::cout << "========================================================" << endl;
105 std::cout << "End Notification Manager : Hosting v0.5\n";
113 std::cout << "========================================================" << endl;
114 std::cout << "End Notification Manager : Hosting v0.5\n";