~thomas-voss/location-service/ramp-up-abi-stability

« back to all changes in this revision

Viewing changes to src/location/providers/geoclue/provider.cpp

  • Committer: Thomas Voß
  • Date: 2016-06-27 11:05:34 UTC
  • mfrom: (258.1.3 simplify-namespaces)
  • Revision ID: thomas.voss@canonical.com-20160627110534-vgl06rzgh7if12uo
Merge lp:~thomas-voss/location-service/simplify-namespaces

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
#include "provider.h"
21
21
 
22
 
namespace cul = com::ubuntu::location;
23
 
namespace culpg = com::ubuntu::location::providers::geoclue;
24
 
 
25
22
namespace dbus = core::dbus;
26
23
 
27
24
namespace
33
30
}
34
31
}
35
32
 
36
 
void culpg::Provider::start()
 
33
void location::providers::geoclue::Provider::start()
37
34
{
38
35
    if (!worker.joinable())
39
36
        worker = std::move(std::thread{std::bind(&dbus::Bus::run, bus)});
40
37
}
41
38
 
42
 
void culpg::Provider::stop()
 
39
void location::providers::geoclue::Provider::stop()
43
40
{
44
41
    bus->stop();
45
42
    if (worker.joinable())
46
43
        worker.join();
47
44
}
48
45
 
49
 
void culpg::Provider::on_position_changed(const fd::Geoclue::Position::Signals::PositionChanged::ArgumentType& arg)
 
46
void location::providers::geoclue::Provider::on_position_changed(const fd::Geoclue::Position::Signals::PositionChanged::ArgumentType& arg)
50
47
{
51
48
    fd::Geoclue::Position::FieldFlags flags{static_cast<unsigned long>(std::get<0>(arg))};
52
 
    cul::Position pos
 
49
    location::Position pos
53
50
    {
54
51
        flags.test(fd::Geoclue::Position::Field::latitude) ?
55
 
            cul::wgs84::Latitude{std::get<2>(arg)* cul::units::Degrees} : cul::wgs84::Latitude{},
 
52
            location::wgs84::Latitude{std::get<2>(arg)* location::units::Degrees} : location::wgs84::Latitude{},
56
53
        flags.test(fd::Geoclue::Position::Field::longitude) ?
57
 
            cul::wgs84::Longitude{std::get<3>(arg)* cul::units::Degrees} : cul::wgs84::Longitude{}
 
54
            location::wgs84::Longitude{std::get<3>(arg)* location::units::Degrees} : location::wgs84::Longitude{}
58
55
    };
59
56
 
60
57
    if (flags.test(fd::Geoclue::Position::Field::altitude))
61
 
        pos.altitude = cul::wgs84::Altitude{std::get<4>(arg)* cul::units::Meters};
 
58
        pos.altitude = location::wgs84::Altitude{std::get<4>(arg)* location::units::Meters};
62
59
 
63
 
    cul::Update<cul::Position> update(pos);
 
60
    location::Update<location::Position> update(pos);
64
61
    mutable_updates().position(update);
65
62
}
66
63
 
67
 
void culpg::Provider::on_velocity_changed(const fd::Geoclue::Velocity::Signals::VelocityChanged::ArgumentType& arg)
 
64
void location::providers::geoclue::Provider::on_velocity_changed(const fd::Geoclue::Velocity::Signals::VelocityChanged::ArgumentType& arg)
68
65
{
69
66
    fd::Geoclue::Velocity::FieldFlags flags{static_cast<unsigned long>(std::get<0>(arg))};
70
67
    if (flags.none())
71
68
        return;
72
69
    if (flags.test(fd::Geoclue::Velocity::Field::speed))
73
70
    {
74
 
        cul::Update<cul::Velocity> update
 
71
        location::Update<location::Velocity> update
75
72
        {
76
 
            std::get<2>(arg) * cul::units::MetersPerSecond,
77
 
            cul::Clock::now()
 
73
            std::get<2>(arg) * location::units::MetersPerSecond,
 
74
            location::Clock::now()
78
75
        };
79
76
        mutable_updates().velocity(update);
80
77
    }
81
78
 
82
79
    if (flags.test(fd::Geoclue::Velocity::Field::direction))
83
80
    {
84
 
        cul::Update<cul::Heading> update
 
81
        location::Update<location::Heading> update
85
82
        {
86
 
            std::get<3>(arg) * cul::units::Degrees,
87
 
            cul::Clock::now()
 
83
            std::get<3>(arg) * location::units::Degrees,
 
84
            location::Clock::now()
88
85
        };
89
86
 
90
87
        mutable_updates().heading(update);
91
88
    }
92
89
}
93
90
 
94
 
cul::Provider::Ptr culpg::Provider::create_instance(const cul::ProviderFactory::Configuration& config)
 
91
location::Provider::Ptr location::providers::geoclue::Provider::create_instance(const location::ProviderFactory::Configuration& config)
95
92
{
96
 
    culpg::Provider::Configuration pConfig;
 
93
    location::providers::geoclue::Provider::Configuration pConfig;
97
94
    pConfig.name = config.count(Configuration::key_name()) > 0 ?
98
95
                   config.get<std::string>(Configuration::key_name()) : throw std::runtime_error("Missing bus-name");
99
96
    pConfig.path = config.count(Configuration::key_path()) > 0 ?
100
97
                   config.get<std::string>(Configuration::key_path()) : throw std::runtime_error("Missing bus-path");
101
 
    return cul::Provider::Ptr{new culpg::Provider{pConfig}};
 
98
    return location::Provider::Ptr{new location::providers::geoclue::Provider{pConfig}};
102
99
}
103
100
 
104
 
culpg::Provider::Provider(const culpg::Provider::Configuration& config) 
105
 
        : com::ubuntu::location::Provider(config.features, config.requirements),
 
101
location::providers::geoclue::Provider::Provider(const location::providers::geoclue::Provider::Configuration& config)
 
102
        : location::Provider(config.features, config.requirements),
106
103
          bus(the_session_bus()),
107
104
          service(dbus::Service::use_service(bus, config.name)),
108
105
          object(service->object_for_path(config.path)),
110
107
          signal_velocity_changed(object->get_signal<fd::Geoclue::Velocity::Signals::VelocityChanged>())
111
108
{
112
109
    position_updates_connection = signal_position_changed->connect(
113
 
            std::bind(&culpg::Provider::on_position_changed, this, std::placeholders::_1));
 
110
            std::bind(&location::providers::geoclue::Provider::on_position_changed, this, std::placeholders::_1));
114
111
    velocity_updates_connection = signal_velocity_changed->connect(
115
 
            std::bind(&culpg::Provider::on_velocity_changed, this, std::placeholders::_1));
 
112
            std::bind(&location::providers::geoclue::Provider::on_velocity_changed, this, std::placeholders::_1));
116
113
 
117
114
    auto info = object->invoke_method_synchronously<
118
115
        fd::Geoclue::GetProviderInfo,
127
124
              << static_cast<fd::Geoclue::Status>(status.value()) << "]" <<std::endl;
128
125
}
129
126
 
130
 
culpg::Provider::~Provider() noexcept
 
127
location::providers::geoclue::Provider::~Provider() noexcept
131
128
{
132
129
    stop();
133
130
}
134
131
 
135
 
bool culpg::Provider::matches_criteria(const cul::Criteria&)
 
132
bool location::providers::geoclue::Provider::matches_criteria(const location::Criteria&)
136
133
{
137
134
    return true;
138
135
}
139
136
 
140
 
void culpg::Provider::start_position_updates()
 
137
void location::providers::geoclue::Provider::start_position_updates()
141
138
{
142
139
    start();
143
140
}
144
141
 
145
 
void culpg::Provider::stop_position_updates()
 
142
void location::providers::geoclue::Provider::stop_position_updates()
146
143
{
147
144
    stop();
148
145
}
149
146
 
150
 
void culpg::Provider::start_velocity_updates()
 
147
void location::providers::geoclue::Provider::start_velocity_updates()
151
148
{
152
149
    start();
153
150
}
154
151
 
155
 
void culpg::Provider::stop_velocity_updates()
 
152
void location::providers::geoclue::Provider::stop_velocity_updates()
156
153
{
157
154
    stop();
158
155
}    
159
156
 
160
 
void culpg::Provider::start_heading_updates()
 
157
void location::providers::geoclue::Provider::start_heading_updates()
161
158
{
162
159
    start();
163
160
}
164
161
 
165
 
void culpg::Provider::stop_heading_updates()
 
162
void location::providers::geoclue::Provider::stop_heading_updates()
166
163
{
167
164
    stop();
168
165
}