Merge lp:~thomas-voss/location-service/minimize-exposed-header-surface into lp:location-service

Proposed by Thomas Voß
Status: Merged
Approved by: Thomas Voß
Approved revision: 260
Merged at revision: 260
Proposed branch: lp:~thomas-voss/location-service/minimize-exposed-header-surface
Merge into: lp:location-service
Diff against target: 2243 lines (+2070/-4)
18 files modified
include/location/service.h (+164/-0)
src/location/CMakeLists.txt (+12/-0)
src/location/dbus/codec.h (+45/-0)
src/location/dbus/service.h (+171/-0)
src/location/dbus/session.h (+204/-0)
src/location/dbus/skeleton/service.cpp (+308/-0)
src/location/dbus/skeleton/service.h (+195/-0)
src/location/dbus/skeleton/session.cpp (+346/-0)
src/location/dbus/skeleton/session.h (+118/-0)
src/location/dbus/stub/service.cpp (+82/-0)
src/location/dbus/stub/service.h (+65/-0)
src/location/dbus/stub/session.cpp (+215/-0)
src/location/dbus/stub/session.h (+72/-0)
src/location/providers/remote/interface.h (+1/-1)
src/location/service.cpp (+69/-0)
src/location/service/interface.h (+1/-1)
src/location/service/session/interface_p.h (+1/-1)
tests/position_test.cpp (+1/-1)
To merge this branch: bzr merge lp:~thomas-voss/location-service/minimize-exposed-header-surface
Reviewer Review Type Date Requested Status
Simon Fels (community) Approve
Thomas Voß Pending
Review via email: mp+298522@code.launchpad.net

Commit message

Minimize the number of exposed headers.
Expose a new class location::Service exposing locationd's functionality.

Description of the change

Minimize the number of exposed headers.
Expose a new class location::Service exposing locationd's functionality.

To post a comment you must log in.
Revision history for this message
Simon Fels (morphis) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed directory 'include/location/providers'
2=== removed directory 'include/location/providers/remote'
3=== removed directory 'include/location/service'
4=== added file 'include/location/service.h'
5--- include/location/service.h 1970-01-01 00:00:00 +0000
6+++ include/location/service.h 2016-06-28 11:55:15 +0000
7@@ -0,0 +1,164 @@
8+/*
9+ * Copyright © 2012-2013 Canonical Ltd.
10+ *
11+ * This program is free software: you can redistribute it and/or modify it
12+ * under the terms of the GNU Lesser General Public License version 3,
13+ * as published by the Free Software Foundation.
14+ *
15+ * This program is distributed in the hope that it will be useful,
16+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+ * GNU Lesser General Public License for more details.
19+ *
20+ * You should have received a copy of the GNU Lesser General Public License
21+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
22+ *
23+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
24+ */
25+#ifndef LOCATION_SERVICE_H_
26+#define LOCATION_SERVICE_H_
27+
28+#include <location/space_vehicle.h>
29+#include <location/heading.h>
30+#include <location/position.h>
31+#include <location/velocity.h>
32+#include <location/update.h>
33+
34+#include <core/property.h>
35+
36+#include <chrono>
37+#include <functional>
38+
39+namespace location
40+{
41+struct Criteria;
42+
43+/**
44+ * @brief The Interface class models the primary interface to the location service.
45+ */
46+class Service
47+{
48+public:
49+ // Safe us some typing.
50+ typedef std::shared_ptr<Service> Ptr;
51+
52+ /**
53+ * @brief Models a session with the location service.
54+ */
55+ class Session
56+ {
57+ public:
58+ /**
59+ * @brief Encapsulates updates provided for this session, and the ability to enable/disable updates.
60+ */
61+ struct Updates
62+ {
63+ /**
64+ * @brief The Status enum models the possible states of updates.
65+ */
66+ enum class Status
67+ {
68+ enabled, ///< Updates are enabled and delivered to this session.
69+ disabled ///< Updates are disabled and not delivered to this session.
70+ };
71+
72+ core::Property<Update<Position>> position{}; ///< @brief Updates for position measurements.
73+ core::Property<Status> position_status{Status::disabled}; ///< @brief Status of position updates, mutable.
74+ core::Property<Update<Heading>> heading{}; ///< @brief Updates for the heading measurements.
75+ core::Property<Status> heading_status{Status::disabled}; ///< @brief Status of position updates, mutable.
76+ core::Property<Update<Velocity>> velocity{}; ///< @brief Updates for velocity measurements.
77+ core::Property<Status> velocity_status{Status::disabled}; ///< @brief Status of velocity updates, mutable.
78+ };
79+
80+ // Safe us some typing.
81+ typedef std::shared_ptr<Session> Ptr;
82+
83+ /** @cond */
84+ Session(const Session&) = delete;
85+ virtual ~Session() = default;
86+ Session& operator=(const Session&) = delete;
87+ /** @endcond */
88+
89+ /**
90+ * @brief Provides access to the updates delivered for this session.
91+ * @return A mutable reference to updates.
92+ */
93+ virtual Updates& updates() = 0;
94+
95+ protected:
96+ Session() = default;
97+ };
98+
99+ /// @brief State enumerates the known states of the service.
100+ enum class State
101+ {
102+ disabled, ///< The service has been disabled by the user.
103+ enabled, ///< The service is enabled but not actively carrying out positioning.
104+ active ///< The service is actively trying to determine the position of the device.
105+ };
106+
107+ /** @cond */
108+ Service(const Service&) = delete;
109+ Service& operator=(const Service&) = delete;
110+ virtual ~Service() = default;
111+ /** @endcond */
112+
113+ /**
114+ * @brief The overall state of the service.
115+ * @return a getable/observable property.
116+ */
117+ virtual const core::Property<State>& state() const = 0;
118+
119+ /**
120+ * @brief Whether the service uses satellite-based positioning.
121+ * @return A setable/getable/observable property.
122+ */
123+ virtual core::Property<bool>& does_satellite_based_positioning() = 0;
124+
125+ /**
126+ * @brief Whether the overall service and its positioning engine is online or not.
127+ * @return A setable/getable/observable property.
128+ */
129+ virtual core::Property<bool>& is_online() = 0;
130+
131+ /**
132+ * @brief Whether the engine and its providers/reporters do call home to
133+ * report reference locations together with wifi and cell ids.
134+ *
135+ * We consider this feature privacy sensitive and it defaults to false. The
136+ * user has to explicitly opt-in into this feature.
137+ *
138+ * @return A setable/getable/observable property.
139+ */
140+ virtual core::Property<bool>& does_report_cell_and_wifi_ids() = 0;
141+
142+ /**
143+ * @brief All space vehicles currently visible.
144+ */
145+ virtual core::Property<std::map<SpaceVehicle::Key, SpaceVehicle>>& visible_space_vehicles() = 0;
146+
147+ /**
148+ * @brief Starts a new session for the given criteria
149+ * @throw std::runtime_error in case of errors.
150+ * @param criteria The client's requirements in terms of accuraccy and functionality
151+ * @return A session instance.
152+ */
153+ virtual Session::Ptr create_session_for_criteria(const Criteria& criteria) = 0;
154+
155+protected:
156+ Service() = default;
157+};
158+
159+/// @brief operator== returns true if lhs == rhs.
160+bool operator==(Service::State lhs, Service::State rhs);
161+/// @brief operator != returns true if !(lhs == rhs).
162+bool operator!=(Service::State lhs, Service::State rhs);
163+
164+/// @brief operator<< inserts state into the out.
165+std::ostream& operator<<(std::ostream& out, Service::State state);
166+/// @brief operator>> extracts state from in.
167+std::istream& operator>>(std::istream& in, Service::State& state);
168+
169+}
170+
171+#endif // LOCATION_SERVICE_H_
172
173=== removed directory 'include/location/service/session'
174=== modified file 'src/location/CMakeLists.txt'
175--- src/location/CMakeLists.txt 2016-06-27 06:44:50 +0000
176+++ src/location/CMakeLists.txt 2016-06-28 11:55:15 +0000
177@@ -39,6 +39,18 @@
178
179 boost_ptree_settings.cpp
180
181+ service.cpp
182+
183+ dbus/skeleton/service.h
184+ dbus/skeleton/service.cpp
185+ dbus/skeleton/session.h
186+ dbus/skeleton/session.cpp
187+
188+ dbus/stub/service.h
189+ dbus/stub/service.cpp
190+ dbus/stub/session.h
191+ dbus/stub/session.cpp
192+
193 service/default_configuration.cpp
194 service/default_permission_manager.cpp
195 service/harvester.cpp
196
197=== renamed file 'include/location/configuration.h' => 'src/location/configuration.h'
198=== added directory 'src/location/dbus'
199=== renamed file 'include/location/codec.h' => 'src/location/dbus/codec.h'
200--- include/location/codec.h 2016-06-26 21:17:03 +0000
201+++ src/location/dbus/codec.h 2016-06-28 11:55:15 +0000
202@@ -25,6 +25,7 @@
203 #include <location/space_vehicle.h>
204 #include <location/update.h>
205 #include <location/velocity.h>
206+#include <location/service.h>
207 #include <location/service/state.h>
208 #include <location/units/units.h>
209 #include <location/wgs84/altitude.h>
210@@ -42,6 +43,49 @@
211 namespace helper
212 {
213 template<>
214+struct TypeMapper<location::Service::State>
215+{
216+ constexpr static ArgumentType type_value()
217+ {
218+ return ArgumentType::string;
219+ }
220+
221+ constexpr static bool is_basic_type()
222+ {
223+ return true;
224+ }
225+ constexpr static bool requires_signature()
226+ {
227+ return false;
228+ }
229+
230+ static std::string signature()
231+ {
232+ static const std::string s = TypeMapper<std::string>::signature();
233+ return s;
234+ }
235+};
236+}
237+
238+template<>
239+struct Codec<location::Service::State>
240+{
241+ static void encode_argument(Message::Writer& writer, const location::Service::State& in)
242+ {
243+ std::stringstream ss; ss << in; auto s = ss.str();
244+ writer.push_stringn(s.c_str(), s.size());
245+ }
246+
247+ static void decode_argument(Message::Reader& reader, location::Service::State& in)
248+ {
249+ auto s = reader.pop_string();
250+ std::stringstream ss{s}; ss >> in;
251+ }
252+};
253+
254+namespace helper
255+{
256+template<>
257 struct TypeMapper<location::service::State>
258 {
259 constexpr static ArgumentType type_value()
260@@ -81,6 +125,7 @@
261 std::stringstream ss{s}; ss >> in;
262 }
263 };
264+
265 namespace helper
266 {
267 template<typename T>
268
269=== added file 'src/location/dbus/service.h'
270--- src/location/dbus/service.h 1970-01-01 00:00:00 +0000
271+++ src/location/dbus/service.h 2016-06-28 11:55:15 +0000
272@@ -0,0 +1,171 @@
273+/*
274+ * Copyright © 2012-2013 Canonical Ltd.
275+ *
276+ * This program is free software: you can redistribute it and/or modify it
277+ * under the terms of the GNU Lesser General Public License version 3,
278+ * as published by the Free Software Foundation.
279+ *
280+ * This program is distributed in the hope that it will be useful,
281+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
282+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
283+ * GNU Lesser General Public License for more details.
284+ *
285+ * You should have received a copy of the GNU Lesser General Public License
286+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
287+ *
288+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
289+ */
290+#ifndef LOCATION_DBUS_SERVICE_H_
291+#define LOCATION_DBUS_SERVICE_H_
292+
293+#include <location/service.h>
294+#include <location/space_vehicle.h>
295+
296+#include <core/dbus/traits/service.h>
297+#include <core/dbus/types/object_path.h>
298+
299+namespace location
300+{
301+namespace dbus
302+{
303+struct Service
304+{
305+ inline static const std::string& path()
306+ {
307+ static const std::string s{"/location/Service"};
308+ return s;
309+ }
310+
311+ struct Errors
312+ {
313+ struct InsufficientPermissions
314+ {
315+ inline static std::string name() { return "com.ubuntu.location.Service.Error.InsufficientPermissions";}
316+ };
317+ struct CreatingSession
318+ {
319+ inline static std::string name() { return "com.ubuntu.location.Service.Error.CreatingSession"; }
320+ };
321+ };
322+
323+ struct CreateSessionForCriteria
324+ {
325+ typedef dbus::Service Interface;
326+
327+ inline static const std::string& name()
328+ {
329+ static const std::string s{"CreateSessionForCriteria"};
330+ return s;
331+ }
332+
333+ typedef core::dbus::types::ObjectPath ResultType;
334+
335+ inline static const std::chrono::milliseconds default_timeout()
336+ {
337+ return std::chrono::seconds{25};
338+ }
339+ };
340+
341+ struct Properties
342+ {
343+ struct State
344+ {
345+ inline static const std::string& name()
346+ {
347+ static const std::string s{"State"};
348+ return s;
349+ }
350+
351+ typedef location::dbus::Service Interface;
352+ typedef location::Service::State ValueType;
353+ static const bool readable = true;
354+ static const bool writable = true;
355+ };
356+
357+ struct DoesSatelliteBasedPositioning
358+ {
359+ inline static const std::string& name()
360+ {
361+ static const std::string s{"DoesSatelliteBasedPositioning"};
362+ return s;
363+ }
364+
365+ typedef location::dbus::Service Interface;
366+ typedef bool ValueType;
367+ static const bool readable = true;
368+ static const bool writable = true;
369+ };
370+
371+ struct DoesReportCellAndWifiIds
372+ {
373+ inline static const std::string& name()
374+ {
375+ static const std::string s{"DoesReportCellAndWifiIds"};
376+ return s;
377+ }
378+
379+ typedef location::dbus::Service Interface;
380+ typedef bool ValueType;
381+ static const bool readable = true;
382+ static const bool writable = true;
383+ };
384+
385+ struct IsOnline
386+ {
387+ inline static const std::string& name()
388+ {
389+ static const std::string s{"IsOnline"};
390+ return s;
391+ }
392+
393+ typedef location::dbus::Service Interface;
394+ typedef bool ValueType;
395+ static const bool readable = true;
396+ static const bool writable = true;
397+ };
398+
399+ struct VisibleSpaceVehicles
400+ {
401+ inline static const std::string& name()
402+ {
403+ static const std::string s{"VisibleSpaceVehicles"};
404+ return s;
405+ }
406+
407+ typedef location::dbus::Service Interface;
408+ typedef std::map<SpaceVehicle::Key, SpaceVehicle> ValueType;
409+
410+ static const bool readable = true;
411+ static const bool writable = false;
412+ };
413+ };
414+
415+ Service() = delete;
416+
417+ };
418+}
419+}
420+
421+namespace core
422+{
423+namespace dbus
424+{
425+namespace traits
426+{
427+template<>
428+struct Service<location::dbus::Service>
429+{
430+ static const std::string& interface_name()
431+ {
432+ static const std::string s
433+ {
434+ "com.ubuntu.location.Service"
435+ };
436+ return s;
437+ }
438+};
439+}
440+}
441+}
442+
443+#endif // LOCATION_DBUS_SERVICE_H_
444
445=== added file 'src/location/dbus/session.h'
446--- src/location/dbus/session.h 1970-01-01 00:00:00 +0000
447+++ src/location/dbus/session.h 2016-06-28 11:55:15 +0000
448@@ -0,0 +1,204 @@
449+/*
450+ * Copyright © 2012-2013 Canonical Ltd.
451+ *
452+ * This program is free software: you can redistribute it and/or modify it
453+ * under the terms of the GNU Lesser General Public License version 3,
454+ * as published by the Free Software Foundation.
455+ *
456+ * This program is distributed in the hope that it will be useful,
457+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
458+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
459+ * GNU Lesser General Public License for more details.
460+ *
461+ * You should have received a copy of the GNU Lesser General Public License
462+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
463+ *
464+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
465+ */
466+
467+#ifndef LOCATION_DBUS_SESSION_H_
468+#define LOCATION_DBUS_SESSION_H_
469+
470+#include <chrono>
471+#include <string>
472+
473+namespace location
474+{
475+namespace dbus
476+{
477+struct Session
478+{
479+ struct UpdatePosition
480+ {
481+ typedef dbus::Session Interface;
482+
483+ inline static const std::string& name()
484+ {
485+ static const std::string s{"UpdatePosition"};
486+ return s;
487+ }
488+
489+ typedef void ResultType;
490+
491+ inline static const std::chrono::milliseconds default_timeout() { return std::chrono::seconds{1}; }
492+ };
493+
494+ struct UpdateVelocity
495+ {
496+ typedef dbus::Session Interface;
497+
498+ inline static const std::string& name()
499+ {
500+ static const std::string s{"UpdateVelocity"};
501+ return s;
502+ }
503+
504+ typedef void ResultType;
505+
506+ inline static const std::chrono::milliseconds default_timeout() { return std::chrono::seconds{1}; }
507+ };
508+
509+ struct UpdateHeading
510+ {
511+ typedef dbus::Session Interface;
512+
513+ inline static const std::string& name()
514+ {
515+ static const std::string s{"UpdateHeading"};
516+ return s;
517+ }
518+
519+ typedef void ResultType;
520+
521+ inline static const std::chrono::milliseconds default_timeout() { return std::chrono::seconds{1}; }
522+ };
523+
524+ struct StartPositionUpdates
525+ {
526+ typedef dbus::Session Interface;
527+
528+ inline static const std::string& name()
529+ {
530+ static const std::string s{"StartPositionUpdates"};
531+ return s;
532+ }
533+
534+ typedef void ResultType;
535+
536+ inline static const std::chrono::milliseconds default_timeout() { return std::chrono::seconds{5}; }
537+ };
538+
539+ struct StopPositionUpdates
540+ {
541+ typedef dbus::Session Interface;
542+
543+ inline static const std::string& name()
544+ {
545+ static const std::string s{"StopPositionUpdates"};
546+ return s;
547+ }
548+
549+ typedef void ResultType;
550+
551+ inline static const std::chrono::milliseconds default_timeout() { return std::chrono::seconds{5}; }
552+ };
553+
554+ struct StartVelocityUpdates
555+ {
556+ typedef dbus::Session Interface;
557+
558+ inline static const std::string& name()
559+ {
560+ static const std::string s{"StartVelocityUpdates"};
561+ return s;
562+ }
563+
564+ typedef void ResultType;
565+
566+ inline static const std::chrono::milliseconds default_timeout() { return std::chrono::seconds{5}; }
567+ };
568+
569+ struct StopVelocityUpdates
570+ {
571+ typedef dbus::Session Interface;
572+
573+ inline static const std::string& name()
574+ {
575+ static const std::string s{"StopVelocityUpdates"};
576+ return s;
577+ }
578+
579+ typedef void ResultType;
580+
581+ inline static const std::chrono::milliseconds default_timeout() { return std::chrono::seconds{5}; }
582+ };
583+
584+ struct StartHeadingUpdates
585+ {
586+ typedef dbus::Session Interface;
587+
588+ inline static const std::string& name()
589+ {
590+ static const std::string s{"StartHeadingUpdates"};
591+ return s;
592+ }
593+
594+ typedef void ResultType;
595+
596+ inline static const std::chrono::milliseconds default_timeout() { return std::chrono::seconds{5}; }
597+ };
598+
599+ struct StopHeadingUpdates
600+ {
601+ typedef dbus::Session Interface;
602+
603+ inline static const std::string& name()
604+ {
605+ static const std::string s{"StopHeadingUpdates"};
606+ return s;
607+ }
608+
609+ typedef void ResultType;
610+
611+ inline static const std::chrono::milliseconds default_timeout() { return std::chrono::seconds{5}; }
612+ };
613+
614+ struct Errors
615+ {
616+ struct ErrorParsingUpdate
617+ {
618+ inline static std::string name(){return "com.ubuntu.location.Service.Session.ErrorParsingUpdate";}
619+ };
620+
621+ struct ErrorStartingUpdate
622+ {
623+ inline static std::string name(){return "com.ubuntu.location.Service.Session.ErrorStartingUpdate";}
624+ };
625+ };
626+};
627+}
628+}
629+
630+namespace core
631+{
632+namespace dbus
633+{
634+namespace traits
635+{
636+template<>
637+struct Service<location::dbus::Session>
638+{
639+ static const std::string& interface_name()
640+ {
641+ static const std::string s
642+ {
643+ "com.ubuntu.location.Service.Session"
644+ };
645+ return s;
646+ }
647+};
648+}
649+}
650+}
651+
652+#endif // LOCATION_DBUS_SESSION_H_
653
654=== added directory 'src/location/dbus/skeleton'
655=== added file 'src/location/dbus/skeleton/service.cpp'
656--- src/location/dbus/skeleton/service.cpp 1970-01-01 00:00:00 +0000
657+++ src/location/dbus/skeleton/service.cpp 2016-06-28 11:55:15 +0000
658@@ -0,0 +1,308 @@
659+/*
660+ * Copyright © 2012-2013 Canonical Ltd.
661+ *
662+ * This program is free software: you can redistribute it and/or modify it
663+ * under the terms of the GNU Lesser General Public License version 3,
664+ * as published by the Free Software Foundation.
665+ *
666+ * This program is distributed in the hope that it will be useful,
667+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
668+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
669+ * GNU Lesser General Public License for more details.
670+ *
671+ * You should have received a copy of the GNU Lesser General Public License
672+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
673+ *
674+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
675+ */
676+
677+#include <location/dbus/skeleton/service.h>
678+#include <location/dbus/skeleton/session.h>
679+
680+#include <location/dbus/codec.h>
681+
682+#include <location/criteria.h>
683+#include <location/logging.h>
684+
685+namespace
686+{
687+const std::vector<std::string>& the_empty_array_of_invalidated_properties()
688+{
689+ static const std::vector<std::string> v; return v;
690+}
691+
692+core::dbus::Message::Ptr the_empty_reply()
693+{
694+ return core::dbus::Message::Ptr{};
695+}
696+}
697+
698+location::dbus::skeleton::Service::DBusDaemonCredentialsResolver::DBusDaemonCredentialsResolver(const core::dbus::Bus::Ptr& bus)
699+ : daemon(bus)
700+{
701+}
702+
703+location::service::Credentials
704+location::dbus::skeleton::Service::DBusDaemonCredentialsResolver::resolve_credentials_for_incoming_message(const core::dbus::Message::Ptr& msg)
705+{
706+ return location::service::Credentials
707+ {
708+ static_cast<pid_t>(daemon.get_connection_unix_process_id(msg->sender())),
709+ static_cast<uid_t>(daemon.get_connection_unix_user(msg->sender()))
710+ };
711+}
712+
713+core::dbus::types::ObjectPath location::dbus::skeleton::Service::ObjectPathGenerator::object_path_for_caller_credentials(const location::service::Credentials&)
714+{
715+ static std::uint32_t index{0};
716+ std::stringstream ss; ss << "/sessions/" << index++;
717+
718+ return core::dbus::types::ObjectPath{ss.str()};
719+}
720+
721+
722+location::dbus::skeleton::Service::Service(const location::dbus::skeleton::Service::Configuration& configuration)
723+ : configuration(configuration),
724+ daemon(configuration.incoming),
725+ object(configuration.service->add_object_for_path(location::dbus::Service::path())),
726+ properties_changed(object->get_signal<core::dbus::interfaces::Properties::Signals::PropertiesChanged>()),
727+ properties
728+ {
729+ object->get_property<location::dbus::Service::Properties::State>(),
730+ object->get_property<location::dbus::Service::Properties::DoesSatelliteBasedPositioning>(),
731+ object->get_property<location::dbus::Service::Properties::DoesReportCellAndWifiIds>(),
732+ object->get_property<location::dbus::Service::Properties::IsOnline>(),
733+ object->get_property<location::dbus::Service::Properties::VisibleSpaceVehicles>()
734+ },
735+ connections
736+ {
737+ properties.state->changed().connect([this](State state)
738+ {
739+ on_state_changed(state);
740+ }),
741+ properties.does_satellite_based_positioning->changed().connect([this](bool value)
742+ {
743+ on_does_satellite_based_positioning_changed(value);
744+ }),
745+ properties.does_report_cell_and_wifi_ids->changed().connect([this](bool value)
746+ {
747+ on_does_report_cell_and_wifi_ids_changed(value);
748+ }),
749+ properties.is_online->changed().connect([this](bool value)
750+ {
751+ on_is_online_changed(value);
752+ })
753+ }
754+{
755+ object->install_method_handler<location::dbus::Service::CreateSessionForCriteria>([this](const core::dbus::Message::Ptr& msg)
756+ {
757+ handle_create_session_for_criteria(msg);
758+ });
759+}
760+
761+location::dbus::skeleton::Service::~Service() noexcept
762+{
763+ object->uninstall_method_handler<location::dbus::Service::CreateSessionForCriteria>();
764+}
765+
766+core::Property<location::Service::State>& location::dbus::skeleton::Service::mutable_state()
767+{
768+ return *properties.state;
769+}
770+
771+void location::dbus::skeleton::Service::handle_create_session_for_criteria(const core::dbus::Message::Ptr& in)
772+{
773+ VLOG(1) << __PRETTY_FUNCTION__;
774+
775+ auto sender = in->sender();
776+ auto reply = the_empty_reply();
777+ auto thiz = shared_from_this();
778+
779+ try
780+ {
781+ Criteria criteria;
782+ in->reader() >> criteria;
783+
784+ auto credentials =
785+ configuration.credentials_resolver->resolve_credentials_for_incoming_message(in);
786+
787+ auto result =
788+ configuration.permission_manager->check_permission_for_credentials(criteria, credentials);
789+
790+ if (service::PermissionManager::Result::rejected == result) throw std::runtime_error
791+ {
792+ "Client lacks permissions to access the service with the given criteria"
793+ };
794+
795+ auto path =
796+ configuration.object_path_generator->object_path_for_caller_credentials(credentials);
797+
798+ auto stub =
799+ core::dbus::Service::use_service(configuration.outgoing, sender);
800+
801+ location::dbus::skeleton::Session::Configuration config
802+ {
803+ path,
804+ location::dbus::skeleton::Session::Local
805+ {
806+ create_session_for_criteria(criteria),
807+ configuration.incoming,
808+ configuration.service->add_object_for_path(path)
809+ },
810+ location::dbus::skeleton::Session::Remote
811+ {
812+ stub->object_for_path(path)
813+ }
814+ };
815+
816+ auto watcher = daemon.make_service_watcher(sender);
817+ watcher->owner_changed().connect([thiz, path](const std::string&, const std::string&)
818+ {
819+ thiz->remove_from_session_store_for_path(path);
820+ });
821+
822+ if (not add_to_session_store_for_path(path, std::move(watcher), std::make_shared<location::dbus::skeleton::Session>(config)))
823+ {
824+ reply = core::dbus::Message::make_error(
825+ in,
826+ location::dbus::Service::Errors::CreatingSession::name(),
827+ "Refused to create second session for same process");
828+ } else
829+ {
830+ reply = core::dbus::Message::make_method_return(in);
831+ reply->writer() << path;
832+ }
833+
834+ } catch(const std::exception& e)
835+ {
836+ // We only send a very generic error message to the client to avoid
837+ // leaking any sort of internal error handling details to untrusted
838+ // apps.
839+ reply = core::dbus::Message::make_error(
840+ in,
841+ location::dbus::Service::Errors::CreatingSession::name(),
842+ "Error creating session");
843+ // We log the error for debugging purposes.
844+ SYSLOG(ERROR) << "Error creating session: " << e.what();
845+ }
846+
847+ // We are done processing the request and try to send out the result to the client.
848+ try
849+ {
850+ configuration.incoming->send(reply);
851+ } catch(const std::exception& e)
852+ {
853+ // We log the error for debugging purposes.
854+ SYSLOG(ERROR) << "Error sending reply to session creation request: " << e.what();
855+ }
856+}
857+
858+bool location::dbus::skeleton::Service::add_to_session_store_for_path(
859+ const core::dbus::types::ObjectPath& path,
860+ std::unique_ptr<core::dbus::ServiceWatcher> watcher,
861+ const Session::Ptr& session)
862+{
863+ std::lock_guard<std::mutex> lg(guard);
864+ bool inserted = false;
865+ std::tie(std::ignore, inserted) = session_store.insert(std::make_pair(path, Element{std::move(watcher), session}));
866+ return inserted;
867+}
868+
869+void location::dbus::skeleton::Service::remove_from_session_store_for_path(const core::dbus::types::ObjectPath& path)
870+{
871+ std::lock_guard<std::mutex> lg(guard);
872+ session_store.erase(path);
873+}
874+
875+void location::dbus::skeleton::Service::on_state_changed(location::Service::State state)
876+{
877+ std::map<std::string, core::dbus::types::Variant> dict
878+ {
879+ {
880+ location::dbus::Service::Properties::State::name(),
881+ core::dbus::types::Variant::encode(state)
882+ }
883+ };
884+
885+ properties_changed->emit(
886+ std::tie(
887+ core::dbus::traits::Service<location::dbus::Service>::interface_name(),
888+ dict,
889+ the_empty_array_of_invalidated_properties()));
890+}
891+
892+
893+void location::dbus::skeleton::Service::on_does_satellite_based_positioning_changed(bool value)
894+{
895+ std::map<std::string, core::dbus::types::Variant> dict
896+ {
897+ {
898+ location::dbus::Service::Properties::DoesSatelliteBasedPositioning::name(),
899+ core::dbus::types::Variant::encode(value)
900+ }
901+ };
902+
903+ properties_changed->emit(
904+ std::tie(
905+ core::dbus::traits::Service<location::dbus::Service>::interface_name(),
906+ dict,
907+ the_empty_array_of_invalidated_properties()));
908+}
909+
910+void location::dbus::skeleton::Service::on_does_report_cell_and_wifi_ids_changed(bool value)
911+{
912+ std::map<std::string, core::dbus::types::Variant> dict
913+ {
914+ {
915+ location::dbus::Service::Properties::DoesReportCellAndWifiIds::name(),
916+ core::dbus::types::Variant::encode(value)
917+ }
918+ };
919+
920+ properties_changed->emit(
921+ std::tie(
922+ core::dbus::traits::Service<location::dbus::Service>::interface_name(),
923+ dict,
924+ the_empty_array_of_invalidated_properties()));
925+}
926+
927+void location::dbus::skeleton::Service::on_is_online_changed(bool value)
928+{
929+ std::map<std::string, core::dbus::types::Variant> dict
930+ {
931+ {
932+ location::dbus::Service::Properties::IsOnline::name(),
933+ core::dbus::types::Variant::encode(value)
934+ }
935+ };
936+ properties_changed->emit(
937+ std::tie(
938+ core::dbus::traits::Service<location::dbus::Service>::interface_name(),
939+ dict,
940+ the_empty_array_of_invalidated_properties()));
941+}
942+
943+const core::Property<location::Service::State>& location::dbus::skeleton::Service::state() const
944+{
945+ return *properties.state;
946+}
947+
948+core::Property<bool>& location::dbus::skeleton::Service::does_satellite_based_positioning()
949+{
950+ return *properties.does_satellite_based_positioning;
951+}
952+
953+core::Property<bool>& location::dbus::skeleton::Service::does_report_cell_and_wifi_ids()
954+{
955+ return *properties.does_report_cell_and_wifi_ids;
956+}
957+
958+core::Property<bool>& location::dbus::skeleton::Service::is_online()
959+{
960+ return *properties.is_online;
961+}
962+
963+core::Property<std::map<location::SpaceVehicle::Key, location::SpaceVehicle>>& location::dbus::skeleton::Service::visible_space_vehicles()
964+{
965+ return *properties.visible_space_vehicles;
966+}
967
968=== added file 'src/location/dbus/skeleton/service.h'
969--- src/location/dbus/skeleton/service.h 1970-01-01 00:00:00 +0000
970+++ src/location/dbus/skeleton/service.h 2016-06-28 11:55:15 +0000
971@@ -0,0 +1,195 @@
972+/*
973+ * Copyright © 2012-2013 Canonical Ltd.
974+ *
975+ * This program is free software: you can redistribute it and/or modify it
976+ * under the terms of the GNU Lesser General Public License version 3,
977+ * as published by the Free Software Foundation.
978+ *
979+ * This program is distributed in the hope that it will be useful,
980+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
981+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
982+ * GNU Lesser General Public License for more details.
983+ *
984+ * You should have received a copy of the GNU Lesser General Public License
985+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
986+ *
987+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
988+ */
989+
990+#ifndef LOCATION_DBUS_SKELETON_SERVICE_H_
991+#define LOCATION_DBUS_SKELETON_SERVICE_H_
992+
993+#include <location/service.h>
994+
995+#include <location/dbus/service.h>
996+
997+#include <location/service/permission_manager.h>
998+
999+#include <core/dbus/dbus.h>
1000+#include <core/dbus/object.h>
1001+#include <core/dbus/property.h>
1002+#include <core/dbus/service_watcher.h>
1003+#include <core/dbus/skeleton.h>
1004+
1005+#include <core/dbus/interfaces/properties.h>
1006+
1007+namespace location
1008+{
1009+namespace dbus
1010+{
1011+namespace skeleton
1012+{
1013+class Service
1014+ : public location::Service,
1015+ public std::enable_shared_from_this<Service>
1016+{
1017+public:
1018+ typedef std::shared_ptr<Service> Ptr;
1019+
1020+ // Models resolution of an incoming dbus message to the credentials of the message sender.
1021+ struct CredentialsResolver
1022+ {
1023+ typedef std::shared_ptr<CredentialsResolver> Ptr;
1024+
1025+ CredentialsResolver() = default;
1026+ virtual ~CredentialsResolver() = default;
1027+
1028+ // Resolves the sender of msg to the respective credentials.
1029+ virtual service::Credentials resolve_credentials_for_incoming_message(const core::dbus::Message::Ptr& msg) = 0;
1030+ };
1031+
1032+ // Implements CredentialsResolver by reaching out to the dbus daemon and
1033+ // invoking:
1034+ // * GetConnectionUnixProcessID
1035+ // * GetConnectionUnixUser
1036+ struct DBusDaemonCredentialsResolver : public CredentialsResolver
1037+ {
1038+ // Sets up a new instance for the given bus connection.
1039+ DBusDaemonCredentialsResolver(const core::dbus::Bus::Ptr& bus);
1040+
1041+ // Resolves the sender of msg to pid, uid by calling out to the dbus daemon.
1042+ service::Credentials resolve_credentials_for_incoming_message(const core::dbus::Message::Ptr& msg);
1043+
1044+ // Stub for accessing the dbus daemon.
1045+ core::dbus::DBus daemon;
1046+ };
1047+
1048+ // Models the generation of stable and unique object paths for client-specific sessions.
1049+ // The requirements for the resulting object path are:
1050+ // * Unique for the entire system over its complete lifetime
1051+ // * Stable with respect to an app. That is, one app is always assigned the same object path.
1052+ struct ObjectPathGenerator
1053+ {
1054+ typedef std::shared_ptr<ObjectPathGenerator> Ptr;
1055+
1056+ ObjectPathGenerator() = default;
1057+ virtual ~ObjectPathGenerator() = default;
1058+
1059+ // Calculates an object path from pid and uid. The default implementation
1060+ // creates the path according to the following steps:
1061+ // [1.] Query the AppArmor profile name for pid in credentials.
1062+ // [1.1] If the process is running unconfined, rely on a counter to assemble the session name.
1063+ // [1.2] If the process is confined, use the AppArmor profile name to generate the path.
1064+ virtual core::dbus::types::ObjectPath object_path_for_caller_credentials(const service::Credentials& credentials);
1065+ };
1066+
1067+ struct Configuration
1068+ {
1069+ // DBus connection set up for handling requests to the service.
1070+ core::dbus::Bus::Ptr incoming;
1071+ // DBus connection for reaching out to other services in a non-blocking way.
1072+ core::dbus::Bus::Ptr outgoing;
1073+ // Service instance that the skeleton should be exposed upon.
1074+ core::dbus::Service::Ptr service;
1075+ // An implementation of CredentialsResolver for resolving incoming message sender
1076+ // to Credentials = uid, pid.
1077+ CredentialsResolver::Ptr credentials_resolver;
1078+ // An implementation of ObjectPathGenerator for generating session names.
1079+ ObjectPathGenerator::Ptr object_path_generator;
1080+ // Permission manager implementation for verifying incoming requests.
1081+ service::PermissionManager::Ptr permission_manager;
1082+ };
1083+
1084+ Service(const Configuration& configuration);
1085+ ~Service() noexcept;
1086+
1087+ // From location::service::Interface
1088+ const core::Property<State>& state() const;
1089+ core::Property<bool>& does_satellite_based_positioning();
1090+ core::Property<bool>& does_report_cell_and_wifi_ids();
1091+ core::Property<bool>& is_online();
1092+ core::Property<std::map<SpaceVehicle::Key, SpaceVehicle>>& visible_space_vehicles();
1093+
1094+protected:
1095+ // Enable subclasses to alter the state.
1096+ core::Property<State>& mutable_state();
1097+private:
1098+ // Handles incoming message calls for create_session_for_criteria.
1099+ // Dispatches to the actual implementation, and manages object lifetimes.
1100+ void handle_create_session_for_criteria(const core::dbus::Message::Ptr& msg);
1101+
1102+ // Tries to register the given session under the given path in the session store.
1103+ // Returns true iff the session has been added to the store.
1104+ bool add_to_session_store_for_path(
1105+ const core::dbus::types::ObjectPath& path,
1106+ std::unique_ptr<core::dbus::ServiceWatcher> watcher,
1107+ const Session::Ptr& session);
1108+
1109+ // Removes the session with the given path from the session store.
1110+ void remove_from_session_store_for_path(const core::dbus::types::ObjectPath& path);
1111+
1112+ // Called whenever the overall state of the service changes.
1113+ void on_state_changed(State state);
1114+ // Called whenever the value of the respective property changes.
1115+ void on_does_satellite_based_positioning_changed(bool value);
1116+ // Called whenever the value of the respective property changes.
1117+ void on_does_report_cell_and_wifi_ids_changed(bool value);
1118+ // Called whenever the value of the respective property changes.
1119+ void on_is_online_changed(bool value);
1120+
1121+ // Stores the configuration passed in at creation time.
1122+ Configuration configuration;
1123+ // We observe sessions if they have died and resigned from the bus.
1124+ core::dbus::DBus daemon;
1125+ // The skeleton object representing com.ubuntu.location.service.Interface on the bus.
1126+ core::dbus::Object::Ptr object;
1127+ // We emit property changes manually.
1128+ core::dbus::Signal
1129+ <
1130+ core::dbus::interfaces::Properties::Signals::PropertiesChanged,
1131+ core::dbus::interfaces::Properties::Signals::PropertiesChanged::ArgumentType
1132+ >::Ptr properties_changed;
1133+
1134+ // DBus properties as exposed on the bus for com.ubuntu.location.service.Interface
1135+ struct
1136+ {
1137+ std::shared_ptr< core::dbus::Property<location::dbus::Service::Properties::State> > state;
1138+ std::shared_ptr< core::dbus::Property<location::dbus::Service::Properties::DoesSatelliteBasedPositioning> > does_satellite_based_positioning;
1139+ std::shared_ptr< core::dbus::Property<location::dbus::Service::Properties::DoesReportCellAndWifiIds> > does_report_cell_and_wifi_ids;
1140+ std::shared_ptr< core::dbus::Property<location::dbus::Service::Properties::IsOnline> > is_online;
1141+ std::shared_ptr< core::dbus::Property<location::dbus::Service::Properties::VisibleSpaceVehicles> > visible_space_vehicles;
1142+ } properties;
1143+ // We sign up to property changes here, to be able to report them to the bus
1144+ struct
1145+ {
1146+ core::ScopedConnection state;
1147+ core::ScopedConnection does_satellite_based_positioning;
1148+ core::ScopedConnection does_report_cell_and_wifi_ids;
1149+ core::ScopedConnection is_online;
1150+ } connections;
1151+ // Guards the session store.
1152+ std::mutex guard;
1153+ // We track sessions and their respective watchers.
1154+ struct Element
1155+ {
1156+ std::unique_ptr<core::dbus::ServiceWatcher> watcher;
1157+ std::shared_ptr<location::Service::Session> session;
1158+ };
1159+ // Keeps track of running sessions, keying them by their unique object path.
1160+ std::map<core::dbus::types::ObjectPath, Element> session_store;
1161+};
1162+}
1163+}
1164+}
1165+
1166+#endif // LOCATION_DBUS_SKELETON_SERVICE_H_
1167
1168=== added file 'src/location/dbus/skeleton/session.cpp'
1169--- src/location/dbus/skeleton/session.cpp 1970-01-01 00:00:00 +0000
1170+++ src/location/dbus/skeleton/session.cpp 2016-06-28 11:55:15 +0000
1171@@ -0,0 +1,346 @@
1172+/*
1173+ * Copyright © 2012-2013 Canonical Ltd.
1174+ *
1175+ * This program is free software: you can redistribute it and/or modify it
1176+ * under the terms of the GNU Lesser General Public License version 3,
1177+ * as published by the Free Software Foundation.
1178+ *
1179+ * This program is distributed in the hope that it will be useful,
1180+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1181+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1182+ * GNU Lesser General Public License for more details.
1183+ *
1184+ * You should have received a copy of the GNU Lesser General Public License
1185+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1186+ *
1187+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
1188+ */
1189+#include <location/dbus/skeleton/session.h>
1190+
1191+#include <location/dbus/codec.h>
1192+#include <location/dbus/session.h>
1193+
1194+#include <location/logging.h>
1195+
1196+#include <functional>
1197+
1198+namespace
1199+{
1200+core::dbus::Message::Ptr the_empty_reply()
1201+{
1202+ return core::dbus::Message::Ptr{};
1203+}
1204+}
1205+
1206+location::dbus::skeleton::Session::Session(const location::dbus::skeleton::Session::Configuration& config)
1207+ : configuration(config),
1208+ connections
1209+ {
1210+ configuration.local.impl->updates().position.changed().connect(
1211+ [this](const location::Update<location::Position>& position)
1212+ {
1213+ on_position_changed(position);
1214+ }),
1215+ configuration.local.impl->updates().heading.changed().connect(
1216+ [this](const location::Update<location::Heading>& heading)
1217+ {
1218+ on_heading_changed(heading);
1219+ }),
1220+ configuration.local.impl->updates().velocity.changed().connect(
1221+ [this](const location::Update<location::Velocity>& velocity)
1222+ {
1223+ on_velocity_changed(velocity);
1224+ })
1225+ }
1226+{
1227+ configuration.local.object->install_method_handler<location::dbus::Session::StartPositionUpdates>([this](const core::dbus::Message::Ptr& msg)
1228+ {
1229+ on_start_position_updates(msg);
1230+ });
1231+
1232+ configuration.local.object->install_method_handler<location::dbus::Session::StopPositionUpdates>([this](const core::dbus::Message::Ptr& msg)
1233+ {
1234+ on_stop_position_updates(msg);
1235+ });
1236+
1237+ configuration.local.object->install_method_handler<location::dbus::Session::StartVelocityUpdates>([this](const core::dbus::Message::Ptr& msg)
1238+ {
1239+ on_start_velocity_updates(msg);
1240+ });
1241+
1242+ configuration.local.object->install_method_handler<location::dbus::Session::StopVelocityUpdates>([this](const core::dbus::Message::Ptr& msg)
1243+ {
1244+ on_stop_velocity_updates(msg);
1245+ });
1246+
1247+ configuration.local.object->install_method_handler<location::dbus::Session::StartHeadingUpdates>([this](const core::dbus::Message::Ptr& msg)
1248+ {
1249+ on_start_heading_updates(msg);
1250+ });
1251+
1252+ configuration.local.object->install_method_handler<location::dbus::Session::StopHeadingUpdates>([this](const core::dbus::Message::Ptr& msg)
1253+ {
1254+ on_stop_heading_updates(msg);
1255+ });
1256+}
1257+
1258+location::dbus::skeleton::Session::~Session() noexcept
1259+{
1260+ configuration.local.object->uninstall_method_handler<location::dbus::Session::StartPositionUpdates>();
1261+ configuration.local.object->uninstall_method_handler<location::dbus::Session::StopPositionUpdates>();
1262+ configuration.local.object->uninstall_method_handler<location::dbus::Session::StartVelocityUpdates>();
1263+ configuration.local.object->uninstall_method_handler<location::dbus::Session::StopVelocityUpdates>();
1264+ configuration.local.object->uninstall_method_handler<location::dbus::Session::StartHeadingUpdates>();
1265+ configuration.local.object->uninstall_method_handler<location::dbus::Session::StopHeadingUpdates>();
1266+}
1267+
1268+void location::dbus::skeleton::Session::on_start_position_updates(const core::dbus::Message::Ptr& msg)
1269+{
1270+ VLOG(10) << "MethodHandler for location::dbus::Session::StartPositionUpdates";
1271+
1272+ auto reply = the_empty_reply();
1273+
1274+ try
1275+ {
1276+ configuration.local.impl->updates().position_status = Updates::Status::enabled;
1277+ reply = core::dbus::Message::make_method_return(msg);
1278+ } catch(const std::runtime_error& e)
1279+ {
1280+ // We only provide a generic error message to avoid leaking
1281+ // any sort of private data to unprivileged clients.
1282+ reply = core::dbus::Message::make_error(
1283+ msg,
1284+ location::dbus::Session::Errors::ErrorStartingUpdate::name(),
1285+ "Could not enable position updates");
1286+ SYSLOG(ERROR) << e.what();
1287+ }
1288+
1289+ try
1290+ {
1291+ configuration.local.bus->send(reply);
1292+ } catch(const std::exception& e)
1293+ {
1294+ SYSLOG(ERROR) << e.what();
1295+ }
1296+}
1297+
1298+void location::dbus::skeleton::Session::on_stop_position_updates(const core::dbus::Message::Ptr& msg)
1299+{
1300+ VLOG(10) << "MethodHandler for location::dbus::Session::StopPositionUpdates";
1301+ auto reply = the_empty_reply();
1302+
1303+ try
1304+ {
1305+ configuration.local.impl->updates().position_status = Updates::Status::disabled;
1306+ reply = core::dbus::Message::make_method_return(msg);
1307+ } catch(const std::runtime_error& e)
1308+ {
1309+ // We only provide a generic error message to avoid leaking
1310+ // any sort of private data to unprivileged clients.
1311+ reply = core::dbus::Message::make_error(
1312+ msg,
1313+ location::dbus::Session::Errors::ErrorStartingUpdate::name(),
1314+ "Could not disable position updates");
1315+ SYSLOG(ERROR) << e.what();
1316+ }
1317+
1318+ try
1319+ {
1320+ configuration.local.bus->send(reply);
1321+ } catch(const std::exception& e)
1322+ {
1323+ SYSLOG(ERROR) << e.what();
1324+ }
1325+}
1326+
1327+void location::dbus::skeleton::Session::on_start_heading_updates(const core::dbus::Message::Ptr& msg)
1328+{
1329+ VLOG(10) << "MethodHandler for location::dbus::Session::StartHeadingUpdates";
1330+ auto reply = the_empty_reply();
1331+
1332+ try
1333+ {
1334+ configuration.local.impl->updates().position_status = Updates::Status::enabled;
1335+ reply = core::dbus::Message::make_method_return(msg);
1336+ } catch(const std::runtime_error& e)
1337+ {
1338+ // We only provide a generic error message to avoid leaking
1339+ // any sort of private data to unprivileged clients.
1340+ reply = core::dbus::Message::make_error(
1341+ msg,
1342+ location::dbus::Session::Errors::ErrorStartingUpdate::name(),
1343+ "Could not enable position updates");
1344+ SYSLOG(ERROR) << e.what();
1345+ }
1346+
1347+ try
1348+ {
1349+ configuration.local.bus->send(reply);
1350+ } catch(const std::exception& e)
1351+ {
1352+ SYSLOG(ERROR) << e.what();
1353+ }
1354+}
1355+
1356+void location::dbus::skeleton::Session::on_stop_heading_updates(const core::dbus::Message::Ptr& msg)
1357+{
1358+ VLOG(10) << "MethodHandler for location::dbus::Session::StopHeadingUpdates";
1359+ auto reply = the_empty_reply();
1360+ try
1361+ {
1362+ configuration.local.impl->updates().heading_status = Updates::Status::disabled;
1363+ reply = core::dbus::Message::make_method_return(msg);
1364+ } catch(const std::runtime_error& e)
1365+ {
1366+ // We only provide a generic error message to avoid leaking
1367+ // any sort of private data to unprivileged clients.
1368+ reply = core::dbus::Message::make_error(
1369+ msg,
1370+ location::dbus::Session::Errors::ErrorStartingUpdate::name(),
1371+ "Could not enable position updates");
1372+ SYSLOG(ERROR) << e.what();
1373+ }
1374+
1375+ try
1376+ {
1377+ configuration.local.bus->send(reply);
1378+ } catch(const std::exception& e)
1379+ {
1380+ SYSLOG(ERROR) << e.what();
1381+ }
1382+}
1383+
1384+void location::dbus::skeleton::Session::on_start_velocity_updates(const core::dbus::Message::Ptr& msg)
1385+{
1386+ VLOG(10) << "MethodHandler for location::dbus::Session::StartVelocityUpdates";
1387+ auto reply = the_empty_reply();
1388+ try
1389+ {
1390+ configuration.local.impl->updates().velocity_status = Updates::Status::enabled;
1391+ reply = core::dbus::Message::make_method_return(msg);
1392+ } catch(const std::runtime_error& e)
1393+ {
1394+ // We only provide a generic error message to avoid leaking
1395+ // any sort of private data to unprivileged clients.
1396+ reply = core::dbus::Message::make_error(
1397+ msg,
1398+ location::dbus::Session::Errors::ErrorStartingUpdate::name(),
1399+ "Could not enable position updates");
1400+ SYSLOG(ERROR) << e.what();
1401+ }
1402+
1403+ try
1404+ {
1405+ configuration.local.bus->send(reply);
1406+ } catch(const std::exception& e)
1407+ {
1408+ SYSLOG(ERROR) << e.what();
1409+ }
1410+}
1411+
1412+void location::dbus::skeleton::Session::on_stop_velocity_updates(const core::dbus::Message::Ptr& msg)
1413+{
1414+ VLOG(10) << "MethodHandler for location::dbus::Session::StopVelocityUpdates";
1415+ auto reply = the_empty_reply();
1416+ try
1417+ {
1418+ configuration.local.impl->updates().velocity_status = Updates::Status::disabled;
1419+ reply = core::dbus::Message::make_method_return(msg);
1420+ } catch(const std::runtime_error& e)
1421+ {
1422+ // We only provide a generic error message to avoid leaking
1423+ // any sort of private data to unprivileged clients.
1424+ reply = core::dbus::Message::make_error(
1425+ msg,
1426+ location::dbus::Session::Errors::ErrorStartingUpdate::name(),
1427+ "Could not enable position updates");
1428+ SYSLOG(ERROR) << e.what();
1429+ }
1430+
1431+ try
1432+ {
1433+ configuration.local.bus->send(reply);
1434+ } catch(const std::exception& e)
1435+ {
1436+ SYSLOG(ERROR) << e.what();
1437+ }
1438+}
1439+
1440+// Invoked whenever the actual session impl. for the session reports a position update.
1441+void location::dbus::skeleton::Session::on_position_changed(const location::Update<location::Position>& position)
1442+{
1443+ VLOG(10) << __PRETTY_FUNCTION__;
1444+ try
1445+ {
1446+ configuration.remote.object->invoke_method_asynchronously_with_callback<location::dbus::Session::UpdatePosition, void>([](const core::dbus::Result<void>& result)
1447+ {
1448+ if (result.is_error())
1449+ {
1450+ VLOG(10) << "Failed to communicate position update to client: " << result.error().print();
1451+ }
1452+ }, position);
1453+ } catch(const std::exception&)
1454+ {
1455+ // We consider the session to be dead once we hit an exception here.
1456+ // We thus remove it from the central and end its lifetime.
1457+ // on_session_died();
1458+ } catch(...)
1459+ {
1460+ }
1461+}
1462+
1463+// Invoked whenever the actual session impl. reports a heading update.
1464+void location::dbus::skeleton::Session::on_heading_changed(const location::Update<location::Heading>& heading)
1465+{
1466+ VLOG(10) << __PRETTY_FUNCTION__;
1467+ try
1468+ {
1469+ configuration.remote.object->invoke_method_asynchronously_with_callback<location::dbus::Session::UpdateHeading, void>([](const core::dbus::Result<void>& result)
1470+ {
1471+ if (result.is_error())
1472+ {
1473+ VLOG(10) << "Failed to communicate heading update to client: " << result.error().print();
1474+ }
1475+ }, heading);
1476+ } catch(const std::exception&)
1477+ {
1478+ // We consider the session to be dead once we hit an exception here.
1479+ // We thus remove it from the central and end its lifetime.
1480+ //on_session_died();
1481+ } catch(...)
1482+ {
1483+ }
1484+}
1485+
1486+// Invoked whenever the actual session impl. reports a velocity update.
1487+void location::dbus::skeleton::Session::on_velocity_changed(const location::Update<location::Velocity>& velocity)
1488+{
1489+ VLOG(10) << __PRETTY_FUNCTION__;
1490+ try
1491+ {
1492+ configuration.remote.object->invoke_method_asynchronously_with_callback<location::dbus::Session::UpdateVelocity, void>([](const core::dbus::Result<void>& result)
1493+ {
1494+ if (result.is_error())
1495+ {
1496+ VLOG(10) << "Failed to communicate velocity update to client: " << result.error().print();
1497+ }
1498+ }, velocity);
1499+ } catch(const std::exception&)
1500+ {
1501+ // We consider the session to be dead once we hit an exception here.
1502+ // We thus remove it from the central and end its lifetime.
1503+ // on_session_died();
1504+ } catch(...)
1505+ {
1506+ }
1507+}
1508+
1509+const core::dbus::types::ObjectPath& location::dbus::skeleton::Session::path() const
1510+{
1511+ return configuration.path;
1512+}
1513+
1514+location::Service::Session::Updates& location::dbus::skeleton::Session::updates()
1515+{
1516+ return configuration.local.impl->updates();
1517+}
1518
1519=== added file 'src/location/dbus/skeleton/session.h'
1520--- src/location/dbus/skeleton/session.h 1970-01-01 00:00:00 +0000
1521+++ src/location/dbus/skeleton/session.h 2016-06-28 11:55:15 +0000
1522@@ -0,0 +1,118 @@
1523+/*
1524+ * Copyright © 2012-2013 Canonical Ltd.
1525+ *
1526+ * This program is free software: you can redistribute it and/or modify it
1527+ * under the terms of the GNU Lesser General Public License version 3,
1528+ * as published by the Free Software Foundation.
1529+ *
1530+ * This program is distributed in the hope that it will be useful,
1531+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1532+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1533+ * GNU Lesser General Public License for more details.
1534+ *
1535+ * You should have received a copy of the GNU Lesser General Public License
1536+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1537+ *
1538+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
1539+ */
1540+#ifndef LOCATION_DBUS_SKELETON_SESSION_H_
1541+#define LOCATION_DBUS_SKELETON_SESSION_H_
1542+
1543+#include <location/service.h>
1544+
1545+#include <location/heading.h>
1546+#include <location/position.h>
1547+#include <location/provider.h>
1548+#include <location/update.h>
1549+#include <location/velocity.h>
1550+
1551+#include <core/dbus/message.h>
1552+#include <core/dbus/object.h>
1553+
1554+#include <memory>
1555+
1556+namespace location
1557+{
1558+namespace dbus
1559+{
1560+namespace skeleton
1561+{
1562+class Session : public location::Service::Session
1563+{
1564+public:
1565+ // All local, i.e., in-process creation-time properties of the Skeleton.
1566+ struct Local
1567+ {
1568+ // The actual implementation of location::service::session::Interface.
1569+ Session::Ptr impl;
1570+ // The bus connection that the object is exposed upon.
1571+ core::dbus::Bus::Ptr bus;
1572+ // The object that the skeleton is mounted upon.
1573+ core::dbus::Object::Ptr object;
1574+ };
1575+
1576+ // We communicate position, heading and velocity updates to the client
1577+ // via an explicit function call. The reason is simple: We want to know
1578+ // whether the client is still alive and responding as expected to make sure
1579+ // that we stop positioning as early as possible.
1580+ struct Remote
1581+ {
1582+ // The remote object corresponding to the client, implementing
1583+ // com.ubuntu.location.service.session.Interface
1584+ core::dbus::Object::Ptr object;
1585+ };
1586+
1587+ struct Configuration
1588+ {
1589+ // The object path of the session object, shared between clients and service.
1590+ core::dbus::types::ObjectPath path;
1591+ // Local attributes
1592+ Local local;
1593+ // Remote attributes
1594+ Remote remote;
1595+ };
1596+
1597+ Session(const Configuration& configuration);
1598+ virtual ~Session() noexcept;
1599+
1600+ virtual const core::dbus::types::ObjectPath& path() const;
1601+
1602+ // From Service::Session
1603+ Updates& updates() override;
1604+
1605+private:
1606+ // Handle incoming requests for Start/StopPositionUpdates
1607+ virtual void on_start_position_updates(const core::dbus::Message::Ptr&);
1608+ virtual void on_stop_position_updates(const core::dbus::Message::Ptr&);
1609+ // Handles incoming requests for Start/StopHeadingUpdates
1610+ virtual void on_start_heading_updates(const core::dbus::Message::Ptr&);
1611+ virtual void on_stop_heading_updates(const core::dbus::Message::Ptr&);
1612+ // Handles incoming requests for Start/StopVelocityUpdates
1613+ virtual void on_start_velocity_updates(const core::dbus::Message::Ptr&);
1614+ virtual void on_stop_velocity_updates(const core::dbus::Message::Ptr&);
1615+
1616+ // Invoked whenever the actual session impl. for the session reports a position update.
1617+ virtual void on_position_changed(const Update<Position>& position);
1618+ // Invoked whenever the actual session impl. reports a heading update.
1619+ virtual void on_heading_changed(const Update<Heading>& heading);
1620+ // Invoked whenever the actual session impl. reports a velocity update.
1621+ virtual void on_velocity_changed(const Update<Velocity>& velocity);
1622+
1623+ // Stores all attributes passed at creation time.
1624+ Configuration configuration;
1625+ // Scoped connections for automatically disconnecting on destruction
1626+ struct
1627+ {
1628+ // Corresponds to position updates coming in from the actual implementation instance.
1629+ core::ScopedConnection position_changed;
1630+ // Corresponds to heading updates coming in from the actual implementation instance.
1631+ core::ScopedConnection heading_changed;
1632+ // Corresponds to velocity updates coming in from the actual implementation instance.
1633+ core::ScopedConnection velocity_changed;
1634+ } connections;
1635+};
1636+}
1637+}
1638+}
1639+
1640+#endif // LOCATION_DBUS_SKELETON_SESSION_H_
1641
1642=== added directory 'src/location/dbus/stub'
1643=== added file 'src/location/dbus/stub/service.cpp'
1644--- src/location/dbus/stub/service.cpp 1970-01-01 00:00:00 +0000
1645+++ src/location/dbus/stub/service.cpp 2016-06-28 11:55:15 +0000
1646@@ -0,0 +1,82 @@
1647+/*
1648+ * Copyright © 2012-2013 Canonical Ltd.
1649+ *
1650+ * This program is free software: you can redistribute it and/or modify it
1651+ * under the terms of the GNU Lesser General Public License version 3,
1652+ * as published by the Free Software Foundation.
1653+ *
1654+ * This program is distributed in the hope that it will be useful,
1655+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1656+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1657+ * GNU Lesser General Public License for more details.
1658+ *
1659+ * You should have received a copy of the GNU Lesser General Public License
1660+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1661+ *
1662+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
1663+ */
1664+
1665+#include <location/dbus/stub/service.h>
1666+#include <location/dbus/stub/session.h>
1667+
1668+#include <location/dbus/codec.h>
1669+#include <location/dbus/service.h>
1670+
1671+#include <location/logging.h>
1672+
1673+#include <core/dbus/property.h>
1674+
1675+location::dbus::stub::Service::Service(const core::dbus::Bus::Ptr& connection,
1676+ const core::dbus::Service::Ptr& service,
1677+ const core::dbus::Object::Ptr& object) :
1678+ connection{connection},
1679+ service{service},
1680+ object{object},
1681+ state_{object->get_property<location::dbus::Service::Properties::State>()},
1682+ does_satellite_based_positioning_{object->get_property<location::dbus::Service::Properties::DoesSatelliteBasedPositioning>()},
1683+ does_report_cell_and_wifi_ids_{object->get_property<location::dbus::Service::Properties::DoesReportCellAndWifiIds>()},
1684+ is_online_{object->get_property<location::dbus::Service::Properties::IsOnline>()},
1685+ visible_space_vehicles_{object->get_property<location::dbus::Service::Properties::VisibleSpaceVehicles>()}
1686+{
1687+}
1688+
1689+location::Service::Session::Ptr location::dbus::stub::Service::create_session_for_criteria(const location::Criteria& criteria)
1690+{
1691+ auto op = object->transact_method<
1692+ location::dbus::Service::CreateSessionForCriteria,
1693+ location::dbus::Service::CreateSessionForCriteria::ResultType
1694+ >(criteria);
1695+
1696+ if (op.is_error())
1697+ {
1698+ std::stringstream ss; ss << __PRETTY_FUNCTION__ << ": " << op.error().print();
1699+ throw std::runtime_error(ss.str());
1700+ }
1701+
1702+ return std::make_shared<location::dbus::stub::Session>(connection, service->add_object_for_path(op.value()));
1703+}
1704+
1705+const core::Property<location::Service::State>& location::dbus::stub::Service::state() const
1706+{
1707+ return *state_;
1708+}
1709+
1710+core::Property<bool>& location::dbus::stub::Service::does_satellite_based_positioning()
1711+{
1712+ return *does_satellite_based_positioning_;
1713+}
1714+
1715+core::Property<bool>& location::dbus::stub::Service::does_report_cell_and_wifi_ids()
1716+{
1717+ return *does_report_cell_and_wifi_ids_;
1718+}
1719+
1720+core::Property<bool>& location::dbus::stub::Service::is_online()
1721+{
1722+ return *is_online_;
1723+}
1724+
1725+core::Property<std::map<location::SpaceVehicle::Key, location::SpaceVehicle>>& location::dbus::stub::Service::visible_space_vehicles()
1726+{
1727+ return *visible_space_vehicles_;
1728+}
1729
1730=== added file 'src/location/dbus/stub/service.h'
1731--- src/location/dbus/stub/service.h 1970-01-01 00:00:00 +0000
1732+++ src/location/dbus/stub/service.h 2016-06-28 11:55:15 +0000
1733@@ -0,0 +1,65 @@
1734+/*
1735+ * Copyright © 2012-2013 Canonical Ltd.
1736+ *
1737+ * This program is free software: you can redistribute it and/or modify it
1738+ * under the terms of the GNU Lesser General Public License version 3,
1739+ * as published by the Free Software Foundation.
1740+ *
1741+ * This program is distributed in the hope that it will be useful,
1742+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1743+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1744+ * GNU Lesser General Public License for more details.
1745+ *
1746+ * You should have received a copy of the GNU Lesser General Public License
1747+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1748+ *
1749+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
1750+ */
1751+#ifndef LOCATION_DBUS_STUB_SERVICE_H_
1752+#define LOCATION_DBUS_STUB_SERVICE_H_
1753+
1754+#include <location/service.h>
1755+
1756+#include <location/dbus/service.h>
1757+
1758+#include <core/dbus/bus.h>
1759+#include <core/dbus/object.h>
1760+#include <core/dbus/property.h>
1761+#include <core/dbus/service.h>
1762+
1763+namespace location
1764+{
1765+namespace dbus
1766+{
1767+namespace stub
1768+{
1769+class Service : public location::Service
1770+{
1771+ public:
1772+ Service(const core::dbus::Bus::Ptr& connection,
1773+ const core::dbus::Service::Ptr& service,
1774+ const core::dbus::Object::Ptr& object);
1775+
1776+ Session::Ptr create_session_for_criteria(const Criteria& criteria) override;
1777+ const core::Property<State>& state() const override;
1778+ core::Property<bool>& does_satellite_based_positioning() override;
1779+ core::Property<bool>& does_report_cell_and_wifi_ids() override;
1780+ core::Property<bool>& is_online() override;
1781+ core::Property<std::map<SpaceVehicle::Key, SpaceVehicle>>& visible_space_vehicles() override;
1782+
1783+ private:
1784+ core::dbus::Bus::Ptr connection;
1785+ core::dbus::Service::Ptr service;
1786+ core::dbus::Object::Ptr object;
1787+
1788+ std::shared_ptr<core::dbus::Property<location::dbus::Service::Properties::State>> state_;
1789+ std::shared_ptr<core::dbus::Property<location::dbus::Service::Properties::DoesSatelliteBasedPositioning>> does_satellite_based_positioning_;
1790+ std::shared_ptr<core::dbus::Property<location::dbus::Service::Properties::DoesReportCellAndWifiIds>> does_report_cell_and_wifi_ids_;
1791+ std::shared_ptr<core::dbus::Property<location::dbus::Service::Properties::IsOnline>> is_online_;
1792+ std::shared_ptr<core::dbus::Property<location::dbus::Service::Properties::VisibleSpaceVehicles>> visible_space_vehicles_;
1793+};
1794+}
1795+}
1796+}
1797+
1798+#endif // LOCATION_DBUS_STUB_SERVICE_H_
1799
1800=== added file 'src/location/dbus/stub/session.cpp'
1801--- src/location/dbus/stub/session.cpp 1970-01-01 00:00:00 +0000
1802+++ src/location/dbus/stub/session.cpp 2016-06-28 11:55:15 +0000
1803@@ -0,0 +1,215 @@
1804+/*
1805+ * Copyright © 2012-2013 Canonical Ltd.
1806+ *
1807+ * This program is free software: you can redistribute it and/or modify it
1808+ * under the terms of the GNU Lesser General Public License version 3,
1809+ * as published by the Free Software Foundation.
1810+ *
1811+ * This program is distributed in the hope that it will be useful,
1812+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1813+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1814+ * GNU Lesser General Public License for more details.
1815+ *
1816+ * You should have received a copy of the GNU Lesser General Public License
1817+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1818+ *
1819+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
1820+ */
1821+
1822+#include <location/dbus/stub/session.h>
1823+#include <location/dbus/codec.h>
1824+#include <location/dbus/session.h>
1825+
1826+#include <location/logging.h>
1827+
1828+location::dbus::stub::Session::Session(const core::dbus::Bus::Ptr& connection,
1829+ const core::dbus::Object::Ptr& object)
1830+ : connection_{connection},
1831+ object_{object},
1832+ position_{updates_.position_status.changed().connect([this](const Updates::Status& status)
1833+ {
1834+ switch(status)
1835+ {
1836+ case Updates::Status::enabled: start_position_updates(); break;
1837+ case Updates::Status::disabled: stop_position_updates(); break;
1838+ }
1839+ })},
1840+ velocity_{updates_.velocity_status.changed().connect([this](const Updates::Status& status)
1841+ {
1842+ switch(status)
1843+ {
1844+ case Updates::Status::enabled: start_velocity_updates(); break;
1845+ case Updates::Status::disabled: stop_velocity_updates(); break;
1846+ }
1847+ })},
1848+ heading_{updates_.heading_status.changed().connect([this](const Updates::Status& status)
1849+ {
1850+ switch(status)
1851+ {
1852+ case Updates::Status::enabled: start_heading_updates(); break;
1853+ case Updates::Status::disabled: stop_heading_updates(); break;
1854+ }
1855+ })}
1856+{
1857+ object_->install_method_handler<location::dbus::Session::UpdatePosition>([this](const core::dbus::Message::Ptr& incoming)
1858+ {
1859+ VLOG(10) << __PRETTY_FUNCTION__;
1860+
1861+ try
1862+ {
1863+ Update<Position> update; incoming->reader() >> update;
1864+ updates_.position = update;
1865+ connection_->send(core::dbus::Message::make_method_return(incoming));
1866+ } catch(const std::runtime_error& e)
1867+ {
1868+ connection_->send(core::dbus::Message::make_error(
1869+ incoming,
1870+ location::dbus::Session::Errors::ErrorParsingUpdate::name(),
1871+ e.what()));
1872+ }
1873+ });
1874+
1875+ object_->install_method_handler<location::dbus::Session::UpdateHeading>([this](const core::dbus::Message::Ptr& incoming)
1876+ {
1877+ VLOG(10) << __PRETTY_FUNCTION__;
1878+
1879+ try
1880+ {
1881+ Update<Heading> update; incoming->reader() >> update;
1882+ updates_.heading = update;
1883+ connection_->send(core::dbus::Message::make_method_return(incoming));
1884+ } catch(const std::runtime_error& e)
1885+ {
1886+ connection_->send(core::dbus::Message::make_error(
1887+ incoming,
1888+ location::dbus::Session::Errors::ErrorParsingUpdate::name(),
1889+ e.what()));
1890+ }
1891+ });
1892+
1893+ object_->install_method_handler<location::dbus::Session::UpdateVelocity>([this](const core::dbus::Message::Ptr& incoming)
1894+ {
1895+ VLOG(10) << __PRETTY_FUNCTION__;
1896+
1897+ try
1898+ {
1899+ Update<Velocity> update; incoming->reader() >> update;
1900+ updates_.velocity = update;
1901+ connection_->send(core::dbus::Message::make_method_return(incoming));
1902+ } catch(const std::runtime_error& e)
1903+ {
1904+ connection_->send(core::dbus::Message::make_error(
1905+ incoming,
1906+ location::dbus::Session::Errors::ErrorParsingUpdate::name(),
1907+ e.what()));
1908+ }
1909+ });
1910+}
1911+
1912+location::dbus::stub::Session::~Session() noexcept
1913+{
1914+ VLOG(10) << __PRETTY_FUNCTION__;
1915+
1916+ object_->uninstall_method_handler<location::dbus::Session::UpdatePosition>();
1917+ object_->uninstall_method_handler<location::dbus::Session::UpdateHeading>();
1918+ object_->uninstall_method_handler<location::dbus::Session::UpdateVelocity>();
1919+}
1920+
1921+void location::dbus::stub::Session::start_position_updates()
1922+{
1923+ VLOG(10) << __PRETTY_FUNCTION__;
1924+
1925+ auto result = object_->transact_method<location::dbus::Session::StartPositionUpdates,void>();
1926+
1927+ if (result.is_error())
1928+ {
1929+ std::stringstream ss; ss << __PRETTY_FUNCTION__ << ": " << result.error().print();
1930+ throw std::runtime_error(ss.str());
1931+ }
1932+}
1933+
1934+void location::dbus::stub::Session::stop_position_updates()
1935+{
1936+ VLOG(10) << __PRETTY_FUNCTION__;
1937+
1938+ try
1939+ {
1940+ auto result = object_->invoke_method_synchronously<location::dbus::Session::StopPositionUpdates,void>();
1941+
1942+ if (result.is_error())
1943+ {
1944+ std::stringstream ss; ss << __PRETTY_FUNCTION__ << ": " << result.error().print();
1945+ throw std::runtime_error(ss.str());
1946+ }
1947+ } catch(const std::runtime_error& e)
1948+ {
1949+ VLOG(1) << e.what();
1950+ }
1951+}
1952+
1953+void location::dbus::stub::Session::start_velocity_updates()
1954+{
1955+ VLOG(10) << __PRETTY_FUNCTION__;
1956+
1957+ auto result = object_->transact_method<location::dbus::Session::StartVelocityUpdates,void>();
1958+
1959+ if (result.is_error())
1960+ {
1961+ std::stringstream ss; ss << __PRETTY_FUNCTION__ << ": " << result.error().print();
1962+ throw std::runtime_error(ss.str());
1963+ }
1964+}
1965+
1966+void location::dbus::stub::Session::stop_velocity_updates()
1967+{
1968+ VLOG(10) << __PRETTY_FUNCTION__;
1969+
1970+ try {
1971+ auto result = object_->transact_method<location::dbus::Session::StopVelocityUpdates,void>();
1972+
1973+ if (result.is_error())
1974+ {
1975+ std::stringstream ss; ss << __PRETTY_FUNCTION__ << ": " << result.error().print();
1976+ throw std::runtime_error(ss.str());
1977+ }
1978+ } catch(const std::runtime_error& e)
1979+ {
1980+ VLOG(1) << e.what();
1981+ }
1982+}
1983+
1984+void location::dbus::stub::Session::start_heading_updates()
1985+{
1986+ VLOG(10) << __PRETTY_FUNCTION__;
1987+
1988+ auto result = object_->transact_method<location::dbus::Session::StartHeadingUpdates,void>();
1989+
1990+ if (result.is_error())
1991+ {
1992+ std::stringstream ss; ss << __PRETTY_FUNCTION__ << ": " << result.error().print();
1993+ throw std::runtime_error(ss.str());
1994+ }
1995+}
1996+
1997+void location::dbus::stub::Session::stop_heading_updates()
1998+{
1999+ VLOG(10) << __PRETTY_FUNCTION__;
2000+
2001+ try {
2002+ auto result = object_->transact_method<location::dbus::Session::StopHeadingUpdates,void>();
2003+
2004+ if (result.is_error())
2005+ {
2006+ std::stringstream ss; ss << __PRETTY_FUNCTION__ << ": " << result.error().print();
2007+ throw std::runtime_error(ss.str());
2008+ }
2009+ } catch(const std::runtime_error& e)
2010+ {
2011+ VLOG(1) << e.what();
2012+ }
2013+}
2014+
2015+location::Service::Session::Updates& location::dbus::stub::Session::updates()
2016+{
2017+ return updates_;
2018+}
2019
2020=== added file 'src/location/dbus/stub/session.h'
2021--- src/location/dbus/stub/session.h 1970-01-01 00:00:00 +0000
2022+++ src/location/dbus/stub/session.h 2016-06-28 11:55:15 +0000
2023@@ -0,0 +1,72 @@
2024+/*
2025+ * Copyright © 2012-2013 Canonical Ltd.
2026+ *
2027+ * This program is free software: you can redistribute it and/or modify it
2028+ * under the terms of the GNU Lesser General Public License version 3,
2029+ * as published by the Free Software Foundation.
2030+ *
2031+ * This program is distributed in the hope that it will be useful,
2032+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2033+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2034+ * GNU Lesser General Public License for more details.
2035+ *
2036+ * You should have received a copy of the GNU Lesser General Public License
2037+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2038+ *
2039+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
2040+ */
2041+
2042+#ifndef LOCATION_DBUS_STUB_SESSION_H_
2043+#define LOCATION_DBUS_STUB_SESSION_H_
2044+
2045+#include <location/service.h>
2046+
2047+#include <location/heading.h>
2048+#include <location/position.h>
2049+#include <location/provider.h>
2050+#include <location/update.h>
2051+#include <location/velocity.h>
2052+
2053+#include <core/dbus/stub.h>
2054+
2055+#include <memory>
2056+
2057+namespace location
2058+{
2059+namespace dbus
2060+{
2061+namespace stub
2062+{
2063+class Session : public location::Service::Session
2064+{
2065+ public:
2066+ Session(const core::dbus::Bus::Ptr& connection,
2067+ const core::dbus::Object::Ptr& object);
2068+ ~Session();
2069+
2070+ void start_position_updates();
2071+ void stop_position_updates();
2072+
2073+ void start_velocity_updates();
2074+ void stop_velocity_updates();
2075+
2076+ void start_heading_updates();
2077+ void stop_heading_updates();
2078+
2079+ Updates& updates() override;
2080+
2081+ private:
2082+ core::dbus::Bus::Ptr connection_;
2083+ core::dbus::Object::Ptr object_;
2084+
2085+ Updates updates_;
2086+
2087+ core::ScopedConnection position_;
2088+ core::ScopedConnection velocity_;
2089+ core::ScopedConnection heading_;
2090+};
2091+}
2092+}
2093+}
2094+
2095+#endif // LOCATION_DBUS_STUB_SESSION_H_
2096
2097=== renamed file 'include/location/default_provider_selection_policy.h' => 'src/location/default_provider_selection_policy.h'
2098=== renamed file 'include/location/fusion_provider.h' => 'src/location/fusion_provider.h'
2099=== renamed file 'include/location/fusion_provider_selection_policy.h' => 'src/location/fusion_provider_selection_policy.h'
2100=== renamed file 'include/location/init_and_shutdown.h' => 'src/location/init_and_shutdown.h'
2101=== renamed file 'include/location/logging.h' => 'src/location/logging.h'
2102=== renamed file 'include/location/newer_or_more_accurate_update_selector.h' => 'src/location/newer_or_more_accurate_update_selector.h'
2103=== renamed file 'include/location/newer_update_selector.h' => 'src/location/newer_update_selector.h'
2104=== renamed file 'include/location/provider_enumerator.h' => 'src/location/provider_enumerator.h'
2105=== renamed file 'include/location/provider_factory.h' => 'src/location/provider_factory.h'
2106=== renamed file 'include/location/provider_selection.h' => 'src/location/provider_selection.h'
2107=== renamed file 'include/location/provider_selection_policy.h' => 'src/location/provider_selection_policy.h'
2108=== renamed file 'include/location/providers/remote/interface.h' => 'src/location/providers/remote/interface.h'
2109--- include/location/providers/remote/interface.h 2016-06-26 21:17:03 +0000
2110+++ src/location/providers/remote/interface.h 2016-06-28 11:55:15 +0000
2111@@ -26,7 +26,7 @@
2112
2113 #include <core/dbus/traits/service.h>
2114
2115-#include <location/codec.h>
2116+#include <location/dbus/codec.h>
2117 #include <location/update.h>
2118
2119 #include <location/heading.h>
2120
2121=== renamed file 'include/location/providers/remote/skeleton.h' => 'src/location/providers/remote/skeleton.h'
2122=== renamed file 'include/location/providers/remote/stub.h' => 'src/location/providers/remote/stub.h'
2123=== renamed file 'include/location/proxy_provider.h' => 'src/location/proxy_provider.h'
2124=== added file 'src/location/service.cpp'
2125--- src/location/service.cpp 1970-01-01 00:00:00 +0000
2126+++ src/location/service.cpp 2016-06-28 11:55:15 +0000
2127@@ -0,0 +1,69 @@
2128+/*
2129+ * Copyright © 2016 Canonical Ltd.
2130+ *
2131+ * This program is free software: you can redistribute it and/or modify it
2132+ * under the terms of the GNU Lesser General Public License version 3,
2133+ * as published by the Free Software Foundation.
2134+ *
2135+ * This program is distributed in the hope that it will be useful,
2136+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2137+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2138+ * GNU Lesser General Public License for more details.
2139+ *
2140+ * You should have received a copy of the GNU Lesser General Public License
2141+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2142+ *
2143+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
2144+ */
2145+
2146+#include <location/service.h>
2147+
2148+#include <map>
2149+#include <type_traits>
2150+
2151+namespace
2152+{
2153+typedef typename std::underlying_type<location::Service::State>::type UT;
2154+
2155+typedef std::pair<std::map<location::Service::State, std::string>, std::map<std::string, location::Service::State>> Lut;
2156+
2157+const Lut& lut()
2158+{
2159+ static const Lut instance
2160+ {
2161+ {
2162+ {location::Service::State::disabled, "disabled"},
2163+ {location::Service::State::enabled, "enabled"},
2164+ {location::Service::State::active, "active"}
2165+ },
2166+ {
2167+ {"disabled", location::Service::State::disabled},
2168+ {"enabled", location::Service::State::enabled},
2169+ {"active", location::Service::State::active}
2170+ }
2171+ };
2172+
2173+ return instance;
2174+}
2175+}
2176+
2177+bool location::operator==(location::Service::State lhs, location::Service::State rhs)
2178+{
2179+ return static_cast<UT>(lhs) == static_cast<UT>(rhs);
2180+}
2181+
2182+bool location::operator!=(location::Service::State lhs, location::Service::State rhs)
2183+{
2184+ return static_cast<UT>(lhs) != static_cast<UT>(rhs);
2185+}
2186+
2187+std::ostream& location::operator<<(std::ostream& out, location::Service::State state)
2188+{
2189+ return out << lut().first.at(state);
2190+}
2191+
2192+std::istream& location::operator>>(std::istream& in, location::Service::State& state)
2193+{
2194+ std::string s; in >> s; state = lut().second.at(s);
2195+ return in;
2196+}
2197
2198=== renamed file 'include/location/service/configuration.h' => 'src/location/service/configuration.h'
2199=== renamed file 'include/location/service/default_permission_manager.h' => 'src/location/service/default_permission_manager.h'
2200=== renamed file 'include/location/service/interface.h' => 'src/location/service/interface.h'
2201--- include/location/service/interface.h 2016-06-26 21:17:03 +0000
2202+++ src/location/service/interface.h 2016-06-28 11:55:15 +0000
2203@@ -256,6 +256,6 @@
2204 }
2205 }
2206
2207-#include <location/codec.h>
2208+#include <location/dbus/codec.h>
2209
2210 #endif // LOCATION_SERVICE_INTERFACE_H_
2211
2212=== renamed file 'include/location/service/permission_manager.h' => 'src/location/service/permission_manager.h'
2213=== renamed file 'include/location/service/session/implementation.h' => 'src/location/service/session/implementation.h'
2214=== renamed file 'include/location/service/session/interface.h' => 'src/location/service/session/interface.h'
2215=== modified file 'src/location/service/session/interface_p.h'
2216--- src/location/service/session/interface_p.h 2016-06-27 06:44:50 +0000
2217+++ src/location/service/session/interface_p.h 2016-06-28 11:55:15 +0000
2218@@ -223,6 +223,6 @@
2219 }
2220 }
2221
2222-#include <location/codec.h>
2223+#include <location/dbus/codec.h>
2224
2225 #endif // LOCATION_SERVICE_SESSION_INTERFACE_P_H_
2226
2227=== renamed file 'include/location/service/session/skeleton.h' => 'src/location/service/session/skeleton.h'
2228=== renamed file 'include/location/service/session/stub.h' => 'src/location/service/session/stub.h'
2229=== renamed file 'include/location/service/skeleton.h' => 'src/location/service/skeleton.h'
2230=== renamed file 'include/location/service/state.h' => 'src/location/service/state.h'
2231=== renamed file 'include/location/service/stub.h' => 'src/location/service/stub.h'
2232=== renamed file 'include/location/update_selector.h' => 'src/location/update_selector.h'
2233=== modified file 'tests/position_test.cpp'
2234--- tests/position_test.cpp 2016-06-26 21:17:03 +0000
2235+++ tests/position_test.cpp 2016-06-28 11:55:15 +0000
2236@@ -43,7 +43,7 @@
2237 EXPECT_TRUE(p.altitude ? true : false);
2238 }
2239
2240-#include <location/codec.h>
2241+#include <location/dbus/codec.h>
2242
2243 #include <core/dbus/message_streaming_operators.h>
2244

Subscribers

People subscribed via source and target branches

to all changes: