-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhilipsCtrl.cpp
More file actions
148 lines (112 loc) · 3.03 KB
/
Copy pathPhilipsCtrl.cpp
File metadata and controls
148 lines (112 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "configure.h"
#include "Agent.h"
#include "event.h"
#include "safeQ.h"
#include <iostream>
#include <string.h>
#include <string>
#include <stdio.h>
#include <time.h>
#include <ctime>
#include <unistd.h>
using namespace std;
class PhilipsCtrlEvent: public Event{
public:
PhilipsCtrlEvent(){}
~PhilipsCtrlEvent(){}
void SetEventFloor(string _floor) {e_floor = _floor;}
void SetEventRoom(string _room) {e_room = _room;}
void SetEventTopic(string _topic) {e_topic = _topic;}
void SetEventTime();
bool SetEventOperation(bool _op);
string GetEventFloor()const {return e_floor;}
string GetEventRoom()const {return e_room;}
string GetEventTopic()const {return e_topic;}
string GetEventTime()const {return e_time;}
string GetEventOperation()const {return e_operation;}
private:
string e_topic;
string e_floor;
string e_room;
string e_time;
string e_operation;
};
class PhilipsCtrl: public Agent{
public:
PhilipsCtrl();
~PhilipsCtrl();
void Initialize(shared_ptr<Configuration> _confInfo, HubAPI* _hub);
void Run();
string GetAgentFloor()const {return a_floor;}
string GetAgentConfig()const {return a_config;}
string GetAgentRoom()const {return a_room;}
shared_ptr<Event> CreateEvent();
void GetNotification(shared_ptr<Event> event);
private:
HubAPI* a_hub;
bool a_opFlag = false;
string a_id;
string a_type;
string a_room;
string a_floor;
string a_log;
string a_config;
//SafeMsgQueue<shared_ptr<Event>> m_ctrlQ;
};
PhilipsCtrl:: PhilipsCtrl(){
}
PhilipsCtrl:: ~PhilipsCtrl(){
}
void PhilipsCtrl::Initialize(shared_ptr<Configuration> _confInfo, HubAPI* _hub){
a_id = _confInfo->GetId();
a_type = _confInfo->GetOriginalType();
a_room = _confInfo->GetRoom();
a_floor = _confInfo->GetFloor();
a_log = _confInfo->GetLog();
a_config = _confInfo->GetConfig();
a_hub = _hub;
}
void PhilipsCtrl::Run(){
shared_ptr<Agent>self(this);
a_hub->Subscribe(self);
sleep(2);
cout << "Controller " << a_id << " - subscribed" << endl;
}
shared_ptr<Event> PhilipsCtrl::CreateEvent(){
shared_ptr<PhilipsCtrlEvent> phEve(new PhilipsCtrlEvent());
phEve->SetEventRoom(a_room);
phEve->SetEventFloor(a_floor);
phEve->SetEventTopic(a_type);
phEve->SetEventTime();
if(phEve->SetEventOperation(a_opFlag)){
a_opFlag = true;
}
else{
a_opFlag = false;
}
return phEve;
}
void PhilipsCtrl::GetNotification(shared_ptr<Event> event){
sleep(2);
cout << "Philips Controller id: " << a_id << " received event: " <<
event->GetEventOperation() << " " << event->GetEventTime() <<endl;
}
//----------Functions for PhilipsCtrlEvent-------------//
void PhilipsCtrlEvent::SetEventTime(){
time_t _tm =time(NULL);
struct tm* curtime = localtime (&_tm);
e_time = asctime(curtime);
}
bool PhilipsCtrlEvent::SetEventOperation(bool _op){
if (_op){
e_operation = "OFF";
return false;
}
e_operation = "ON";
return true;
}
//-----------Extern Functions for all S.O-------------//
extern "C" shared_ptr<PhilipsCtrl> create(){
shared_ptr<PhilipsCtrl> philH(new PhilipsCtrl());
return philH;
}