Merge lp:~thomas-voss/location-service/add-snapcraft-setup-next into lp:location-service

Proposed by Thomas Voß
Status: Merged
Approved by: Thomas Voß
Approved revision: 268
Merged at revision: 267
Proposed branch: lp:~thomas-voss/location-service/add-snapcraft-setup-next
Merge into: lp:location-service
Diff against target: 408 lines (+290/-18)
9 files modified
3rd-party/ichnaea/CMakeLists.txt (+3/-16)
CMakeLists.txt (+4/-0)
snapcraft.yaml (+96/-0)
src/location/CMakeLists.txt (+1/-0)
src/location/always_granting_permission_manager.h (+44/-0)
src/location/cmds/run.cpp (+3/-2)
src/location/providers/mls/CMakeLists.txt (+2/-0)
src/location/system_configuration.cpp (+83/-0)
src/location/system_configuration.h (+54/-0)
To merge this branch: bzr merge lp:~thomas-voss/location-service/add-snapcraft-setup-next
Reviewer Review Type Date Requested Status
Simon Fels (community) Approve
Thomas Voß Pending
Review via email: mp+304073@code.launchpad.net
To post a comment you must log in.
268. By Thomas Voß

Wire up system configuration into cmds::Run.

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=== modified file '3rd-party/ichnaea/CMakeLists.txt'
2--- 3rd-party/ichnaea/CMakeLists.txt 2016-08-14 19:36:05 +0000
3+++ 3rd-party/ichnaea/CMakeLists.txt 2016-08-26 14:52:08 +0000
4@@ -11,14 +11,12 @@
5 find_package(Threads)
6
7 pkg_check_modules(NET_CPP net-cpp REQUIRED)
8-pkg_check_modules(UBUNTU_LOCATION_SERVICE_CONNECTIVITY ubuntu-location-service-connectivity REQUIRED)
9
10 include_directories(
11 include
12 src
13
14- ${NET_CPP_INCLUDE_DIRS}
15- ${UBUNTU_LOCATION_SERVICE_CONNECTIVITY_INCLUDE_DIRS})
16+ ${NET_CPP_INCLUDE_DIRS})
17
18 add_library(
19 ichnaea
20@@ -50,19 +48,8 @@
21
22 target_link_libraries(
23 ichnaea
24-
25+
26 ${CMAKE_THREAD_LIBS_INIT}
27- ${NET_CPP_LDFLAGS}
28- ${UBUNTU_LOCATION_SERVICE_CONNECTIVITY_LDFLAGS})
29-
30-add_executable(
31- ichnaea-client
32-
33- examples/client.cpp)
34-
35-target_link_libraries(
36- ichnaea-client
37-
38- ichnaea)
39+ ${NET_CPP_LDFLAGS})
40
41 add_subdirectory(tests)
42
43=== modified file 'CMakeLists.txt'
44--- CMakeLists.txt 2016-08-24 14:12:05 +0000
45+++ CMakeLists.txt 2016-08-26 14:52:08 +0000
46@@ -2,6 +2,10 @@
47
48 project(ubuntu-location-service)
49
50+if (DEFINED SNAPPY_UBUNTU_CORE)
51+ add_definitions(-DSNAPPY_UBUNTU_CORE)
52+endif()
53+
54 # We haven't received version information via the packaging setup.
55 # For that, we try to determine sensible values on our own, ensuring
56 # plain old invocations to cmake still work as expected.
57
58=== added file 'snapcraft.yaml'
59--- snapcraft.yaml 1970-01-01 00:00:00 +0000
60+++ snapcraft.yaml 2016-08-26 14:52:08 +0000
61@@ -0,0 +1,96 @@
62+name: locationd
63+version: 3.0.0+16.10.20160616-0ubuntu1
64+summary: Location service mediates access to positioning providers.
65+description: |
66+ Location service mediates access to positioning providers.
67+
68+ **Note** Currently only the dummy provider is supported in this snap. Additional
69+ providers will be made available in the near future.
70+
71+ Please find the source for this snap at https://code.launchpad.net/location-service
72+
73+apps:
74+ run:
75+ daemon: simple
76+ command: bin/locationd run --bus system
77+ slots: [service, cli]
78+ plugs: [network-manager]
79+ cli:
80+ command: bin/locationd status --bus system
81+ plugs: [cli]
82+ monitor:
83+ command: bin/locationd monitor --bus system
84+ plugs: [client]
85+
86+slots:
87+ service:
88+ interface: location-observe
89+ cli:
90+ interface: location-control
91+plugs:
92+ client:
93+ interface: location-observe
94+ cli:
95+ interface: location-control
96+
97+parts:
98+ location-service:
99+ plugin: cmake
100+ configflags:
101+ - -DCMAKE_VERBOSE_MAKEFILE=ON
102+ - -DSNAPPY_UBUNTU_CORE=yes
103+ - -DUBUNTU_LOCATION_SERVICE_VERSION_MAJOR=3
104+ source: .
105+ build-packages:
106+ - curl
107+ - doxygen
108+ - gcc
109+ - geoclue-ubuntu-geoip
110+ - gettext
111+ - google-mock
112+ - graphviz
113+ - g++
114+ - libapparmor-dev
115+ - libboost-filesystem-dev
116+ - libboost-program-options-dev
117+ - libboost-system-dev
118+ - libc6-dev
119+ - libdbus-1-dev
120+ - libdbus-cpp-dev
121+ - libgoogle-glog-dev
122+ - libgtest-dev
123+ - libiw-dev
124+ - libjson-c-dev
125+ - libnet-cpp-dev
126+ - libprocess-cpp-dev
127+ - libtrust-store-dev
128+ - libproperties-cpp-dev
129+ - libubuntu-platform-hardware-api-headers
130+ - libubuntu-platform-hardware-api-dev
131+ - trust-store-bin
132+ stage-packages:
133+ - geoclue-ubuntu-geoip
134+ - libapparmor1
135+ - libboost-filesystem1.58.0
136+ - libboost-program-options1.58.0
137+ - libboost-system1.58.0
138+ - libdbus-cpp5
139+ - libgflags2v5
140+ - libgoogle-glog0v5
141+ - libjson-c2
142+ - libnet-cpp2
143+ - libprocess-cpp3
144+ - libtrust-store2
145+ - libubuntu-platform-hardware-api3
146+ filesets:
147+ licenses:
148+ - usr/share/doc/*/*copyright*
149+ snap:
150+ - bin/locationd
151+ - etc/dbus-1/system.d
152+ - etc/gps.conf
153+ - lib/
154+ - lib/libubuntu-location-service*
155+ - share/ubuntu-location-service
156+ - usr/lib/
157+ - $licenses
158
159=== modified file 'src/location/CMakeLists.txt'
160--- src/location/CMakeLists.txt 2016-08-24 14:12:05 +0000
161+++ src/location/CMakeLists.txt 2016-08-26 14:52:08 +0000
162@@ -30,6 +30,7 @@
163 space_vehicle.cpp
164 time_based_update_policy.cpp
165 set_name_for_thread.cpp
166+ system_configuration.cpp
167 time_since_boot.cpp
168 wifi_and_cell_reporting_state.cpp
169
170
171=== added file 'src/location/always_granting_permission_manager.h'
172--- src/location/always_granting_permission_manager.h 1970-01-01 00:00:00 +0000
173+++ src/location/always_granting_permission_manager.h 2016-08-26 14:52:08 +0000
174@@ -0,0 +1,44 @@
175+/*
176+ * Copyright © 2016 Canonical Ltd.
177+ *
178+ * This program is free software: you can redistribute it and/or modify it
179+ * under the terms of the GNU Lesser General Public License version 3,
180+ * as published by the Free Software Foundation.
181+ *
182+ * This program is distributed in the hope that it will be useful,
183+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
184+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
185+ * GNU Lesser General Public License for more details.
186+ *
187+ * You should have received a copy of the GNU Lesser General Public License
188+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
189+ *
190+ * Authored by: Scott Sweeny <scott.sweeny@canonical.com>
191+ */
192+#ifndef LOCATION_ALWAYS_GRANTING_PERMISSION_MANAGER_H_
193+#define LOCATION_ALWAYS_GRANTING_PERMISSION_MANAGER_H_
194+
195+#include <location/permission_manager.h>
196+
197+namespace core { namespace dbus {
198+class Bus;
199+}}
200+
201+namespace location
202+{
203+// A PermissionManager implementation which always returns granted since
204+// permissions are handed by interfaces in Snappy
205+class AlwaysGrantingPermissionManager : public PermissionManager
206+{
207+public:
208+ AlwaysGrantingPermissionManager() = default;
209+
210+ // From PermissionManager
211+ Result check_permission_for_credentials(const Criteria&, const Credentials&) override
212+ {
213+ return Result::granted;
214+ }
215+};
216+}
217+
218+#endif // LOCATION_ALWAYS_GRANTING_PERMISSION_MANAGER_H_
219
220=== modified file 'src/location/cmds/run.cpp'
221--- src/location/cmds/run.cpp 2016-08-12 11:52:37 +0000
222+++ src/location/cmds/run.cpp 2016-08-26 14:52:08 +0000
223@@ -25,6 +25,7 @@
224 #include <location/serializing_bus.h>
225 #include <location/service_with_engine.h>
226 #include <location/settings.h>
227+#include <location/system_configuration.h>
228 #include <location/trust_store_permission_manager.h>
229
230 #include <location/dbus/skeleton/service.h>
231@@ -40,7 +41,7 @@
232 : CommandWithFlagsAndAction{cli::Name{"run"}, cli::Usage{"run"}, cli::Description{"runs the daemon"}},
233 testing{false},
234 bus{core::dbus::WellKnownBus::system},
235- settings{"/var/lib/ubuntu-location-service/config.ini"}
236+ settings{SystemConfiguration::instance().runtime_persistent_data_dir()}
237 {
238 flag(cli::make_flag(cli::Name{"testing"}, cli::Description{"whether we are running under testing, defaults to false"}, testing));
239 flag(cli::make_flag(cli::Name{"bus"}, cli::Description{"bus instance to connect to, defaults to system"}, bus));
240@@ -98,7 +99,7 @@
241 std::make_shared<location::dbus::skeleton::Service::DBusDaemonCredentialsResolver>(outgoing),
242 std::make_shared<location::dbus::skeleton::Service::ObjectPathGenerator>(),
243 // Incoming requests are verified by talking to a trust-store instance.
244- location::TrustStorePermissionManager::create_default_instance_with_bus(outgoing)
245+ SystemConfiguration::instance().create_permission_manager(outgoing)
246 };
247
248 rt->start();
249
250=== modified file 'src/location/providers/mls/CMakeLists.txt'
251--- src/location/providers/mls/CMakeLists.txt 2016-08-14 19:36:05 +0000
252+++ src/location/providers/mls/CMakeLists.txt 2016-08-26 14:52:08 +0000
253@@ -6,6 +6,8 @@
254 target_link_libraries(
255 mls
256
257+ ubuntu-location-service-connectivity
258+
259 ichnaea)
260
261 set(
262
263=== added file 'src/location/system_configuration.cpp'
264--- src/location/system_configuration.cpp 1970-01-01 00:00:00 +0000
265+++ src/location/system_configuration.cpp 2016-08-26 14:52:08 +0000
266@@ -0,0 +1,83 @@
267+/*
268+ * Copyright © 2016 Canonical Ltd.
269+ *
270+ * This program is free software: you can redistribute it and/or modify it
271+ * under the terms of the GNU Lesser General Public License version 3,
272+ * as published by the Free Software Foundation.
273+ *
274+ * This program is distributed in the hope that it will be useful,
275+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
276+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
277+ * GNU Lesser General Public License for more details.
278+ *
279+ * You should have received a copy of the GNU Lesser General Public License
280+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
281+ *
282+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
283+ * Scott Sweeny <scott.sweeny@canonical.com>
284+ */
285+#include <location/system_configuration.h>
286+
287+#include <location/always_granting_permission_manager.h>
288+#include <location/trust_store_permission_manager.h>
289+
290+#include <location/logging.h>
291+
292+#include <core/posix/this_process.h>
293+
294+namespace env = core::posix::this_process::env;
295+
296+#if defined(SNAPPY_UBUNTU_CORE)
297+namespace
298+{
299+struct SnappySystemConfiguration : public location::SystemConfiguration
300+{
301+ fs::path runtime_persistent_data_dir() const
302+ {
303+ std::string data_dir = env::get("SNAP_DATA");
304+ if (!data_dir.empty()) {
305+ return data_dir;
306+ } else {
307+ LOG(WARNING) << "SNAP_DATA environment variable is not defined.";
308+
309+ // If SNAP_DATA isn't set it's almost certain we're not running
310+ // from a snap, so return the conventional path
311+ return "/var/lib/ubuntu-location-service";
312+ }
313+ }
314+
315+ location::PermissionManager::Ptr create_permission_manager(const std::shared_ptr<core::dbus::Bus>&) const
316+ {
317+ return std::make_shared<location::AlwaysGrantingPermissionManager>();
318+ }
319+};
320+}
321+
322+location::SystemConfiguration& location::SystemConfiguration::instance()
323+{
324+ static SnappySystemConfiguration config;
325+ return config;
326+}
327+#else
328+namespace
329+{
330+struct UbuntuSystemConfiguration : public location::SystemConfiguration
331+{
332+ fs::path runtime_persistent_data_dir() const
333+ {
334+ return "/var/lib/ubuntu-location-service";
335+ }
336+
337+ location::PermissionManager::Ptr create_permission_manager(const std::shared_ptr<core::dbus::Bus>& bus) const
338+ {
339+ return location::TrustStorePermissionManager::create_default_instance_with_bus(bus);
340+ }
341+};
342+}
343+
344+location::SystemConfiguration& location::SystemConfiguration::instance()
345+{
346+ static UbuntuSystemConfiguration config;
347+ return config;
348+}
349+#endif // SNAPPY_UBUNTU_CORE
350
351=== added file 'src/location/system_configuration.h'
352--- src/location/system_configuration.h 1970-01-01 00:00:00 +0000
353+++ src/location/system_configuration.h 2016-08-26 14:52:08 +0000
354@@ -0,0 +1,54 @@
355+/*
356+ * Copyright © 2016 Canonical Ltd.
357+ *
358+ * This program is free software: you can redistribute it and/or modify it
359+ * under the terms of the GNU Lesser General Public License version 3,
360+ * as published by the Free Software Foundation.
361+ *
362+ * This program is distributed in the hope that it will be useful,
363+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
364+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
365+ * GNU Lesser General Public License for more details.
366+ *
367+ * You should have received a copy of the GNU Lesser General Public License
368+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
369+ *
370+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
371+ * Scott Sweeny <scott.sweeny@canonical.com>
372+ */
373+#ifndef LOCATION_SYSTEM_CONFIGURATION_H_
374+#define LOCATION_SYSTEM_CONFIGURATION_H_
375+
376+#include <location/permission_manager.h>
377+
378+#include <boost/filesystem.hpp>
379+
380+#include <core/dbus/bus.h>
381+
382+namespace fs = boost::filesystem;
383+
384+namespace location
385+{
386+class SystemConfiguration
387+{
388+public:
389+ // A singleton is ugly, but it's the easier way forward
390+ // if we want to contain snappy-specific setup for now.
391+ static SystemConfiguration& instance();
392+
393+ virtual ~SystemConfiguration() = default;
394+
395+ // runtime_data_dir returns the path to the directory the service should
396+ // use to store runtime persistent data.
397+ virtual fs::path runtime_persistent_data_dir() const = 0;
398+
399+ // create_permission_manager returns an instance of PermissionManager that
400+ // is meant to be used by the service to verify incoming connection requests.
401+ virtual PermissionManager::Ptr create_permission_manager(const std::shared_ptr<core::dbus::Bus>& bus) const = 0;
402+
403+protected:
404+ SystemConfiguration() = default;
405+};
406+}
407+
408+#endif // LOCATION_SYSTEM_CONFIGURATION_H_

Subscribers

People subscribed via source and target branches

to all changes: