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
|
#include "com/ubuntu/location/service/session/stub.h"
#include <org/freedesktop/dbus/stub.h>
#include <functional>
namespace cul = com::ubuntu::location;
namespace culs = com::ubuntu::location::service;
namespace culss = com::ubuntu::location::service::session;
namespace dbus = org::freedesktop::dbus;
culss::Stub::Stub(
const dbus::Bus::Ptr& bus,
const dbus::types::ObjectPath& session_path)
: dbus::Stub<culss::Interface>(bus),
session_path(session_path),
object(access_service()->add_object_for_path(session_path))
{
object->install_method_handler<culss::Interface::UpdatePosition>(
std::bind(&Stub::update_position, this, std::placeholders::_1));
object->install_method_handler<culss::Interface::UpdateHeading>(
std::bind(&Stub::update_heading, this, std::placeholders::_1));
object->install_method_handler<culss::Interface::UpdateVelocity>(
std::bind(&Stub::update_velocity, this, std::placeholders::_1));
}
const dbus::types::ObjectPath& culss::Stub::path() const
{
return session_path;
}
void culss::Stub::start_position_updates()
{
auto result = object->invoke_method_synchronously<Interface::StartPositionUpdates,void>();
if (result.is_error())
throw std::runtime_error(result.error());
}
void culss::Stub::stop_position_updates() noexcept
{
auto result = object->invoke_method_synchronously<Interface::StopPositionUpdates,void>();
if (result.is_error())
throw std::runtime_error(result.error());
}
void culss::Stub::start_velocity_updates()
{
auto result = object->invoke_method_synchronously<Interface::StartVelocityUpdates,void>();
if (result.is_error())
throw std::runtime_error(result.error());
}
void culss::Stub::stop_velocity_updates() noexcept
{
auto result = object->invoke_method_synchronously<Interface::StopVelocityUpdates,void>();
if (result.is_error())
throw std::runtime_error(result.error());
}
void culss::Stub::start_heading_updates()
{
auto result = object->invoke_method_synchronously<Interface::StartHeadingUpdates,void>();
if (result.is_error())
throw std::runtime_error(result.error());
}
void culss::Stub::stop_heading_updates() noexcept
{
auto result = object->invoke_method_synchronously<Interface::StopHeadingUpdates,void>();
if (result.is_error())
throw std::runtime_error(result.error());
}
void culss::Stub::update_heading(DBusMessage* msg)
{
auto incoming = dbus::Message::from_raw_message(msg);
try
{
Update<Heading> update; incoming->reader() >> update;
access_heading_updates_channel()(update);
access_bus()->send(dbus::Message::make_method_return(msg)->get());
} catch(const std::runtime_error& e)
{
access_bus()->send(dbus::Message::make_error(msg, Interface::Errors::ErrorParsingUpdate::name(), e.what())->get());
}
}
void culss::Stub::update_position(DBusMessage* msg)
{
auto incoming = dbus::Message::from_raw_message(msg);
try
{
Update<Position> update; incoming->reader() >> update;
access_position_updates_channel()(update);
access_bus()->send(dbus::Message::make_method_return(msg)->get());
} catch(const std::runtime_error& e)
{
access_bus()->send(dbus::Message::make_error(msg, Interface::Errors::ErrorParsingUpdate::name(), e.what())->get());
}
}
void culss::Stub::update_velocity(DBusMessage* msg)
{
auto incoming = dbus::Message::from_raw_message(msg);
try
{
Update<Velocity> update; incoming->reader() >> update;
access_velocity_updates_channel()(update);
access_bus()->send(dbus::Message::make_method_return(msg)->get());
} catch(const std::runtime_error& e)
{
access_bus()->send(dbus::Message::make_error(msg, Interface::Errors::ErrorParsingUpdate::name(), e.what())->get());
}
}
|