1
#include "com/ubuntu/location/service/session/stub.h"
3
#include <org/freedesktop/dbus/stub.h>
7
namespace cul = com::ubuntu::location;
8
namespace culs = com::ubuntu::location::service;
9
namespace culss = com::ubuntu::location::service::session;
10
namespace dbus = org::freedesktop::dbus;
13
const dbus::Bus::Ptr& bus,
14
const dbus::types::ObjectPath& session_path)
15
: dbus::Stub<culss::Interface>(bus),
16
session_path(session_path),
17
object(access_service()->add_object_for_path(session_path))
19
object->install_method_handler<culss::Interface::UpdatePosition>(
20
std::bind(&Stub::update_position, this, std::placeholders::_1));
21
object->install_method_handler<culss::Interface::UpdateHeading>(
22
std::bind(&Stub::update_heading, this, std::placeholders::_1));
23
object->install_method_handler<culss::Interface::UpdateVelocity>(
24
std::bind(&Stub::update_velocity, this, std::placeholders::_1));
27
const dbus::types::ObjectPath& culss::Stub::path() const
32
void culss::Stub::start_position_updates()
34
auto result = object->invoke_method_synchronously<Interface::StartPositionUpdates,void>();
36
if (result.is_error())
37
throw std::runtime_error(result.error());
40
void culss::Stub::stop_position_updates() noexcept
42
auto result = object->invoke_method_synchronously<Interface::StopPositionUpdates,void>();
44
if (result.is_error())
45
throw std::runtime_error(result.error());
48
void culss::Stub::start_velocity_updates()
50
auto result = object->invoke_method_synchronously<Interface::StartVelocityUpdates,void>();
52
if (result.is_error())
53
throw std::runtime_error(result.error());
56
void culss::Stub::stop_velocity_updates() noexcept
58
auto result = object->invoke_method_synchronously<Interface::StopVelocityUpdates,void>();
60
if (result.is_error())
61
throw std::runtime_error(result.error());
64
void culss::Stub::start_heading_updates()
66
auto result = object->invoke_method_synchronously<Interface::StartHeadingUpdates,void>();
68
if (result.is_error())
69
throw std::runtime_error(result.error());
72
void culss::Stub::stop_heading_updates() noexcept
74
auto result = object->invoke_method_synchronously<Interface::StopHeadingUpdates,void>();
76
if (result.is_error())
77
throw std::runtime_error(result.error());
80
void culss::Stub::update_heading(DBusMessage* msg)
82
auto incoming = dbus::Message::from_raw_message(msg);
85
Update<Heading> update; incoming->reader() >> update;
86
access_heading_updates_channel()(update);
87
access_bus()->send(dbus::Message::make_method_return(msg)->get());
88
} catch(const std::runtime_error& e)
90
access_bus()->send(dbus::Message::make_error(msg, Interface::Errors::ErrorParsingUpdate::name(), e.what())->get());
94
void culss::Stub::update_position(DBusMessage* msg)
96
auto incoming = dbus::Message::from_raw_message(msg);
99
Update<Position> update; incoming->reader() >> update;
100
access_position_updates_channel()(update);
101
access_bus()->send(dbus::Message::make_method_return(msg)->get());
102
} catch(const std::runtime_error& e)
104
access_bus()->send(dbus::Message::make_error(msg, Interface::Errors::ErrorParsingUpdate::name(), e.what())->get());
108
void culss::Stub::update_velocity(DBusMessage* msg)
110
auto incoming = dbus::Message::from_raw_message(msg);
113
Update<Velocity> update; incoming->reader() >> update;
114
access_velocity_updates_channel()(update);
115
access_bus()->send(dbus::Message::make_method_return(msg)->get());
116
} catch(const std::runtime_error& e)
118
access_bus()->send(dbus::Message::make_error(msg, Interface::Errors::ErrorParsingUpdate::name(), e.what())->get());
b'\\ No newline at end of file'