5827932f3802b263a7a291a36b767532c9510cde
[platform/upstream/iotivity.git] / service / notification-manager / NotificationManager / src / LinuxMain.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 <stdio.h>
22 #include <stdlib.h>
23 #include <memory>
24 #include "OCApi.h"
25 #include "OCPlatform.h"
26 #include "NotificationManager.h"
27
28 using namespace OC;
29
30 class NotificationService
31 {
32
33 public:
34
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;
38
39     void onObserve(AttributeMap &inputAttMap)
40     {
41         std::cout << endl;
42         std::cout << "========================================================" << endl;
43         std::cout << "On Observe:\n";
44         for(auto it = inputAttMap.begin() ; it != inputAttMap.end() ; ++it)
45         {
46             std::cout << "\tAttribute name: " << it->first << " value: ";
47
48             for(auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr)
49             {
50                 std::cout << "\t" << *valueItr << " ";
51             }
52
53             std::cout << std::endl;
54         }
55     }
56
57     void onFoundCandidate(std::shared_ptr< OCResource > resource)
58     {
59         s_startHosting(resource);
60     }
61
62 };
63
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;
67
68 int main(void)
69 {
70
71     std::cout << endl;
72     std::cout << "========================================================" << endl;
73     std::cout << "Start Notification Manager : Hosting v0.5\n";
74
75     NotificationService a;
76
77     NotificationManager *Ptr = NotificationManager::getInstance();
78     Ptr->initialize();
79
80     Ptr->setOnFoundHostingCandidate(
81             std::function< void(std::shared_ptr< OCResource > resource) >(
82                     std::bind(&NotificationService::onFoundCandidate , a , std::placeholders::_1)));
83     Ptr->setOnObserve(
84             std::function< void(AttributeMap &inputAttMap) >(
85                     std::bind(&NotificationService::onObserve , a , std::placeholders::_1)));
86
87     Ptr->setFindHosting(a.s_findHostingCandidate);
88     Ptr->setStartHosting(a.s_startHosting);
89     Ptr->setAddExtraStr(a.s_addExtraStr);
90
91     a.s_addExtraStr("visual");
92     a.s_findHostingCandidate();
93
94     while(true)
95     {
96         char signal;
97         cin >> signal;
98
99         switch(signal)
100         {
101         case 'q':
102         case 'Q':
103                 std::cout << endl;
104                         std::cout << "========================================================" << endl;
105                         std::cout << "End Notification Manager : Hosting v0.5\n";
106                 return true;
107         default:
108                 break;
109         }
110     }
111
112     std::cout << endl;
113     std::cout << "========================================================" << endl;
114     std::cout << "End Notification Manager : Hosting v0.5\n";
115
116     return true;
117 }