-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathulsProvider.cpp
149 lines (105 loc) · 5 KB
/
ulsProvider.cpp
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
147
148
149
#include "ulsProvider.hpp"
#include "geoclueProvider.hpp"
using namespace core::dbus;
using namespace com::ubuntu::location;
void ULSObject::emitPositionChangedSignal(Position pos) {
// Notifies ULS of changed position
auto sig = this->obj->get_signal<WolfpackMemberInterface::Signals::PositionChanged>();
sig->emit(pos);
}
void ULSObject::emitVelocityChangedSignal(Velocity pos) {
// Notifies ULS of changed velocity
auto sig = this->obj->get_signal<WolfpackMemberInterface::Signals::VelocityChanged>();
sig->emit(pos);
}
void ULSObject::emitHeadingChangedSignal(Heading pos) {
// Notifies ULS of changed heading
auto sig = this->obj->get_signal<WolfpackMemberInterface::Signals::HeadingChanged>();
sig->emit(pos);
}
void ULSObject::registerRequiresMethod() {
// We need ot register the require method, so the ULS understands we have data for it
std::function<void(const core::dbus::Message::Ptr&)> func = [this](const core::dbus::Message::Ptr& msg){
int r;
msg->reader() >> r;
auto reply = Message::make_method_return(msg);
reply->writer() << true;
this->bus->send(reply);
};
this->obj->install_method_handler<WolfpackMemberInterface::Method::Requires>(func); /// Pointer to signal
}
void ULSObject::registerStartHeadingUpdatesMethod() {
// Enables Heading updates if ULS asks for it
std::function<void(const core::dbus::Message::Ptr&)> func = [this](const core::dbus::Message::Ptr& msg){
std::cerr << "Start heading updates" << "\n";
auto reply = Message::make_method_return(msg);
this->gcobj->startHeadingUpdates();
this->bus->send(reply);
};
this->obj->install_method_handler<WolfpackMemberInterface::Method::StartHeadingUpdates>(func);
}
void ULSObject::registerStopHeadingUpdatesMethod() {
// Disables Heading updates if ULS asks for it
std::function<void(const core::dbus::Message::Ptr&)> func = [this](const core::dbus::Message::Ptr& msg){
std::cerr << "Stop heading updates" << "\n";
auto reply = Message::make_method_return(msg);
this->gcobj->stopHeadingUpdates();
this->bus->send(reply);
};
this->obj->install_method_handler<WolfpackMemberInterface::Method::StopHeadingUpdates>(func);
}
void ULSObject::registerStartVelocityUpdatesMethod() {
// Enables Velocity updates if ULS asks for it
std::function<void(const core::dbus::Message::Ptr&)> func = [this](const core::dbus::Message::Ptr& msg){
std::cerr << "Start velocity updates" << "\n";
auto reply = Message::make_method_return(msg);
this->gcobj->startVelocityUpdates();
this->bus->send(reply);
};
this->obj->install_method_handler<WolfpackMemberInterface::Method::StartVelocityUpdates>(func);
}
void ULSObject::registerStopVelocityUpdatesMethod() {
// Disables Velocity updates if ULS asks for it
std::function<void(const core::dbus::Message::Ptr&)> func = [this](const core::dbus::Message::Ptr& msg){
std::cerr << "Stop velocity updates" << "\n";
auto reply = Message::make_method_return(msg);
this->gcobj->stopVelocityUpdates();
this->bus->send(reply);
};
this->obj->install_method_handler<WolfpackMemberInterface::Method::StopVelocityUpdates>(func);
}
void ULSObject::registerStartPositionUpdatesMethod() {
// Enables Position updates if ULS asks for it
std::function<void(const core::dbus::Message::Ptr&)> func = [this](const core::dbus::Message::Ptr& msg){
std::cerr << "Start position updates" << "\n";
auto reply = Message::make_method_return(msg);
this->gcobj->startPositionUpdates();
this->bus->send(reply);
};
this->obj->install_method_handler<WolfpackMemberInterface::Method::StartPositionUpdates>(func);
}
void ULSObject::registerStopPositionUpdatesMethod() {
// Disables Position updates if ULS asks for it
std::function<void(const core::dbus::Message::Ptr&)> func = [this](const core::dbus::Message::Ptr& msg){
std::cerr << "Stop position updates" << "\n";
auto reply = Message::make_method_return(msg);
this->gcobj->stopPositionUpdates();
this->bus->send(reply);
};
this->obj->install_method_handler<WolfpackMemberInterface::Method::StopPositionUpdates>(func);
}
void ULSObject::registerOnReferenceLocationChangedMethod() {
// This method needs to be implemented, because the ULS asks for it
// Doesn't do anything at the moment
std::function<void(const core::dbus::Message::Ptr&)> func = [this](const core::dbus::Message::Ptr& msg){
// Only implemented because it doesn't work otherwise
auto reply = Message::make_method_return(msg);
this->bus->send(reply);
};
this->obj->install_method_handler<WolfpackMemberInterface::Method::OnReferenceLocationChanged>(func);
}
ULSObject::ULSObject(std::shared_ptr<core::dbus::Object> obj, std::shared_ptr<GeoclueObject> gcobj, Bus::Ptr bus) {
this->obj = obj;
this->gcobj = gcobj;
this->bus = bus;
}