~sil2100/location-service/gps-arm64

« back to all changes in this revision

Viewing changes to src/location_service/com/ubuntu/location/service/session/stub.cpp

  • Committer: Thomas Voß
  • Date: 2013-05-28 14:20:45 UTC
  • Revision ID: thomas.voss@canonical.com-20130528142045-kq5umqdmm4o53vwk
Initial push.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "com/ubuntu/location/service/session/stub.h"
 
2
 
 
3
#include <org/freedesktop/dbus/stub.h>
 
4
 
 
5
#include <functional>
 
6
 
 
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;
 
11
 
 
12
culss::Stub::Stub(
 
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))
 
18
{
 
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));
 
25
}
 
26
 
 
27
const dbus::types::ObjectPath& culss::Stub::path() const
 
28
{
 
29
    return session_path;
 
30
}
 
31
 
 
32
void culss::Stub::start_position_updates()
 
33
{
 
34
        auto result = object->invoke_method_synchronously<Interface::StartPositionUpdates,void>();
 
35
 
 
36
        if (result.is_error())
 
37
        throw std::runtime_error(result.error());
 
38
}
 
39
 
 
40
void culss::Stub::stop_position_updates() noexcept
 
41
{       
 
42
        auto result = object->invoke_method_synchronously<Interface::StopPositionUpdates,void>();
 
43
 
 
44
        if (result.is_error())
 
45
        throw std::runtime_error(result.error());       
 
46
}
 
47
 
 
48
void culss::Stub::start_velocity_updates()
 
49
{
 
50
        auto result = object->invoke_method_synchronously<Interface::StartVelocityUpdates,void>();
 
51
 
 
52
        if (result.is_error())
 
53
        throw std::runtime_error(result.error());
 
54
}
 
55
 
 
56
void culss::Stub::stop_velocity_updates() noexcept
 
57
{
 
58
        auto result = object->invoke_method_synchronously<Interface::StopVelocityUpdates,void>();
 
59
 
 
60
        if (result.is_error())
 
61
        throw std::runtime_error(result.error());
 
62
}
 
63
 
 
64
void culss::Stub::start_heading_updates()
 
65
{
 
66
        auto result = object->invoke_method_synchronously<Interface::StartHeadingUpdates,void>();
 
67
 
 
68
        if (result.is_error())
 
69
        throw std::runtime_error(result.error());
 
70
}
 
71
 
 
72
void culss::Stub::stop_heading_updates() noexcept
 
73
{
 
74
        auto result = object->invoke_method_synchronously<Interface::StopHeadingUpdates,void>();
 
75
 
 
76
        if (result.is_error())
 
77
        throw std::runtime_error(result.error());
 
78
}
 
79
    
 
80
void culss::Stub::update_heading(DBusMessage* msg)
 
81
{        
 
82
    auto incoming = dbus::Message::from_raw_message(msg);
 
83
    try
 
84
    {
 
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)
 
89
    {
 
90
        access_bus()->send(dbus::Message::make_error(msg, Interface::Errors::ErrorParsingUpdate::name(), e.what())->get());
 
91
    }
 
92
}
 
93
 
 
94
void culss::Stub::update_position(DBusMessage* msg)
 
95
{
 
96
    auto incoming = dbus::Message::from_raw_message(msg);
 
97
    try
 
98
    {
 
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)
 
103
    {
 
104
        access_bus()->send(dbus::Message::make_error(msg, Interface::Errors::ErrorParsingUpdate::name(), e.what())->get());
 
105
    }
 
106
}
 
107
 
 
108
void culss::Stub::update_velocity(DBusMessage* msg)
 
109
{
 
110
    auto incoming = dbus::Message::from_raw_message(msg);
 
111
    try
 
112
    {
 
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)
 
117
    {
 
118
        access_bus()->send(dbus::Message::make_error(msg, Interface::Errors::ErrorParsingUpdate::name(), e.what())->get());
 
119
    }
 
120
}
 
 
b'\\ No newline at end of file'