Music Hub ..
A session-wide music playback service
dbus.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2013-2014 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * 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 * Author: Jim Hodapp <jim.hodapp@canonical.com>
17 */
18
19#ifndef CORE_UBUNTU_MEDIA_APPARMOR_DBUS_H_
20#define CORE_UBUNTU_MEDIA_APPARMOR_DBUS_H_
21
22#include <core/dbus/bus.h>
23#include <core/dbus/macros.h>
24#include <core/dbus/object.h>
25#include <core/dbus/service.h>
26
27#include <string>
28#include <chrono>
29
30// TODO(tvoss): This really should live in trust-store, providing a straightforward
31// way for parties involved in managing trust relationships to query peers' apparmor
32// profiles. Please see https://bugs.launchpad.net/trust-store/+bug/1350736 for the
33// related bug
34namespace org
35{
36namespace freedesktop
37{
38namespace dbus
39{
40struct DBus
41{
42 static const std::string& name()
43 {
44 static const std::string s = "org.freedesktop.DBus";
45 return s;
46 }
47
48 // Gets the AppArmor confinement string associated with the unique connection name. If
49 // D-Bus is not performing AppArmor mediation, the
50 // org.freedesktop.DBus.Error.AppArmorSecurityContextUnknown error is returned.
51 DBUS_CPP_METHOD_DEF(GetConnectionAppArmorSecurityContext, DBus)
52
53 struct Stub
54 {
55 // Creates a new stub instance for the given object to access
56 // DBus functionality.
57 Stub(const core::dbus::Object::Ptr& object) : object{object}
58 {
59 }
60
61 // Creates a new stub instance for the given bus connection
62 Stub(const core::dbus::Bus::Ptr& bus)
63 : object
64 {
65 core::dbus::Service::use_service<org::freedesktop::dbus::DBus>(bus)
66 ->object_for_path(core::dbus::types::ObjectPath{"/org/freedesktop/DBus"})
67 }
68 {
69 }
70
71 // Gets the AppArmor confinement string associated with the unique connection name. If
72 // D-Bus is not performing AppArmor mediation, the
73 // org.freedesktop.DBus.Error.AppArmorSecurityContextUnknown error is returned.
74 //
75 // Invokes the given handler on completion.
77 const std::string& name,
78 std::function<void(const std::string&)> handler)
79 {
80 object->invoke_method_asynchronously_with_callback<GetConnectionAppArmorSecurityContext, std::string>(
81 [handler](const core::dbus::Result<std::string>& result)
82 {
83 if (not result.is_error()) handler(result.value());
84 }, name);
85 }
86
87 core::dbus::Object::Ptr object;
88 };
89};
90}
91}
92}
93
94#endif // CORE_UBUNTU_MEDIA_APPARMOR_DBUS_H_
Definition: dbus.h:35
Stub(const core::dbus::Object::Ptr &object)
Definition: dbus.h:57
core::dbus::Object::Ptr object
Definition: dbus.h:87
void get_connection_app_armor_security_async(const std::string &name, std::function< void(const std::string &)> handler)
Definition: dbus.h:76
Stub(const core::dbus::Bus::Ptr &bus)
Definition: dbus.h:62
static const std::string & name()
Definition: dbus.h:42