ubuntu-location-service  ..
An aggregating location service providing positioning and geocoding capabilities to applications.
skeleton.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012-2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  */
18 #ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_SERVICE_SKELETON_H_
19 #define LOCATION_SERVICE_COM_UBUNTU_LOCATION_SERVICE_SKELETON_H_
20 
24 
25 #include <core/dbus/dbus.h>
26 #include <core/dbus/object.h>
27 #include <core/dbus/property.h>
28 #include <core/dbus/skeleton.h>
29 
30 #include <core/dbus/interfaces/properties.h>
31 
32 namespace com
33 {
34 namespace ubuntu
35 {
36 namespace location
37 {
38 namespace service
39 {
40 class Skeleton
41  : public core::dbus::Skeleton<com::ubuntu::location::service::Interface>,
42  public std::enable_shared_from_this<Skeleton>
43 {
44 public:
45  typedef std::shared_ptr<Skeleton> Ptr;
46 
47  // Models resolution of an incoming dbus message to the credentials of the message sender.
49  {
50  typedef std::shared_ptr<CredentialsResolver> Ptr;
51 
52  CredentialsResolver() = default;
53  virtual ~CredentialsResolver() = default;
54 
55  // Resolves the sender of msg to the respective credentials.
56  virtual Credentials resolve_credentials_for_incoming_message(const core::dbus::Message::Ptr& msg) = 0;
57  };
58 
59  // Implements CredentialsResolver by reaching out to the dbus daemon and
60  // invoking:
61  // * GetConnectionUnixProcessID
62  // * GetConnectionUnixUser
64  {
65  // Sets up a new instance for the given bus connection.
66  DBusDaemonCredentialsResolver(const core::dbus::Bus::Ptr& bus);
67 
68  // Resolves the sender of msg to pid, uid by calling out to the dbus daemon.
69  Credentials resolve_credentials_for_incoming_message(const core::dbus::Message::Ptr& msg);
70 
71  // Stub for accessing the dbus daemon.
72  core::dbus::DBus daemon;
73  };
74 
75  // Models the generation of stable and unique object paths for client-specific sessions.
76  // The requirements for the resulting object path are:
77  // * Unique for the entire system over its complete lifetime
78  // * Stable with respect to an app. That is, one app is always assigned the same object path.
80  {
81  typedef std::shared_ptr<ObjectPathGenerator> Ptr;
82 
83  ObjectPathGenerator() = default;
84  virtual ~ObjectPathGenerator() = default;
85 
86  // Calculates an object path from pid and uid. The default implementation
87  // creates the path according to the following steps:
88  // [1.] Query the AppArmor profile name for pid in credentials.
89  // [1.1] If the process is running unconfined, rely on a counter to assemble the session name.
90  // [1.2] If the process is confined, use the AppArmor profile name to generate the path.
91  virtual core::dbus::types::ObjectPath object_path_for_caller_credentials(const Credentials& credentials);
92  };
93 
95  {
96  // DBus connection set up for handling requests to the service.
97  core::dbus::Bus::Ptr incoming;
98  // DBus connection for reaching out to other services in a non-blocking way.
99  core::dbus::Bus::Ptr outgoing;
100  // An implementation of CredentialsResolver for resolving incoming message sender
101  // to Credentials = uid, pid.
103  // An implementation of ObjectPathGenerator for generating session names.
105  // Permission manager implementation for verifying incoming requests.
107  };
108 
109  Skeleton(const Configuration& configuration);
110  ~Skeleton() noexcept;
111 
112  // From com::ubuntu::location::service::Interface
113  core::Property<bool>& does_satellite_based_positioning();
114  core::Property<bool>& does_report_cell_and_wifi_ids();
115  core::Property<bool>& is_online();
116  core::Property<std::map<SpaceVehicle::Key, SpaceVehicle>>& visible_space_vehicles();
117 
118 private:
119  // Handles incoming message calls for create_session_for_criteria.
120  // Dispatches to the actual implementation, and manages object lifetimes.
121  void handle_create_session_for_criteria(const core::dbus::Message::Ptr& msg);
122 
123  // Tries to register the given session under the given path in the session store.
124  // Returns true iff the session has been added to the store.
125  bool add_to_session_store_for_path(
126  const core::dbus::types::ObjectPath& path,
127  const session::Interface::Ptr& session);
128 
129  // Called whenever the value of the respective property changes.
130  void on_does_satellite_based_positioning_changed(bool value);
131  // Called whenever the value of the respective property changes.
132  void on_does_report_cell_and_wifi_ids_changed(bool value);
133  // Called whenever the value of the respective property changes.
134  void on_is_online_changed(bool value);
135 
136  // Stores the configuration passed in at creation time.
137  Configuration configuration;
138  // The skeleton object representing com.ubuntu.location.service.Interface on the bus.
139  core::dbus::Object::Ptr object;
140  // We emit property changes manually.
141  core::dbus::Signal
142  <
143  core::dbus::interfaces::Properties::Signals::PropertiesChanged,
144  core::dbus::interfaces::Properties::Signals::PropertiesChanged::ArgumentType
145  >::Ptr properties_changed;
146 
147  // DBus properties as exposed on the bus for com.ubuntu.location.service.Interface
148  struct
149  {
150  std::shared_ptr< core::dbus::Property<Interface::Properties::DoesSatelliteBasedPositioning> > does_satellite_based_positioning;
151  std::shared_ptr< core::dbus::Property<Interface::Properties::DoesReportCellAndWifiIds> > does_report_cell_and_wifi_ids;
152  std::shared_ptr< core::dbus::Property<Interface::Properties::IsOnline> > is_online;
153  std::shared_ptr< core::dbus::Property<Interface::Properties::VisibleSpaceVehicles> > visible_space_vehicles;
154  } properties;
155  // We sign up to property changes here, to be able to report them to the bus
156  struct
157  {
158  core::ScopedConnection does_satellite_based_positioning;
159  core::ScopedConnection does_report_cell_and_wifi_ids;
160  core::ScopedConnection is_online;
161  } connections;
162  // Guards the session store.
163  std::mutex guard;
164  // Keeps track of running sessions, keying them by their unique object path.
165  std::map<dbus::types::ObjectPath, std::shared_ptr<session::Interface>> session_store;
166 };
167 }
168 }
169 }
170 }
171 #endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_SERVICE_SKELETON_H_
core::ScopedConnection does_satellite_based_positioning
Definition: skeleton.h:158
std::shared_ptr< core::dbus::Property< Interface::Properties::DoesReportCellAndWifiIds > > does_report_cell_and_wifi_ids
Definition: skeleton.h:151
core::Property< std::map< SpaceVehicle::Key, SpaceVehicle > > & visible_space_vehicles()
std::shared_ptr< PermissionManager > Ptr
virtual core::dbus::types::ObjectPath object_path_for_caller_credentials(const Credentials &credentials)
Definition: codec.h:35
STL namespace.
Definition: accuracy.h:23
core::Property< bool > & does_report_cell_and_wifi_ids()
std::shared_ptr< core::dbus::Property< Interface::Properties::IsOnline > > is_online
Definition: skeleton.h:152
std::shared_ptr< core::dbus::Property< Interface::Properties::DoesSatelliteBasedPositioning > > does_satellite_based_positioning
Definition: skeleton.h:150
Credentials resolve_credentials_for_incoming_message(const core::dbus::Message::Ptr &msg)
Credentials of a remote session.
Skeleton(const Configuration &configuration)
core::ScopedConnection is_online
Definition: skeleton.h:160
core::Property< bool > & does_satellite_based_positioning()
The Interface class models the primary interface to the location service.
Definition: interface.h:46
virtual Credentials resolve_credentials_for_incoming_message(const core::dbus::Message::Ptr &msg)=0
std::shared_ptr< CredentialsResolver > Ptr
Definition: skeleton.h:50
std::shared_ptr< ObjectPathGenerator > Ptr
Definition: skeleton.h:81
core::ScopedConnection does_report_cell_and_wifi_ids
Definition: skeleton.h:159
core::Property< bool > & is_online()
std::shared_ptr< Skeleton > Ptr
Definition: skeleton.h:45
A space-vehicle as visible to providers.
Definition: space_vehicle.h:33
std::shared_ptr< core::dbus::Property< Interface::Properties::VisibleSpaceVehicles > > visible_space_vehicles
Definition: skeleton.h:153