aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2016-03-17 09:59:32 -0500
committerCharles Kerr <charles.kerr@canonical.com>2016-03-17 09:59:32 -0500
commitc63d90da0f1d9cbd1eee5dd66a9828c51cc8dcc9 (patch)
treeb5ef7bc596476d6d64f128a7a12e5dd002eafe57
parent65eba5e107b0499aec4bed55be202bf1df6710bb (diff)
downloadayatana-indicator-display-c63d90da0f1d9cbd1eee5dd66a9828c51cc8dcc9.tar.gz
ayatana-indicator-display-c63d90da0f1d9cbd1eee5dd66a9828c51cc8dcc9.tar.bz2
ayatana-indicator-display-c63d90da0f1d9cbd1eee5dd66a9828c51cc8dcc9.zip
de-dupe use of dbus names
-rw-r--r--src/dbus-names.h42
-rw-r--r--src/usb-snap.cpp34
-rw-r--r--tests/integration/usb-manager-test.cpp13
-rw-r--r--tests/unit/usb-snap-test.cpp13
-rw-r--r--tests/utils/dbus-types.h5
5 files changed, 71 insertions, 36 deletions
diff --git a/src/dbus-names.h b/src/dbus-names.h
new file mode 100644
index 0000000..753b8c8
--- /dev/null
+++ b/src/dbus-names.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2016 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+#pragma once
+
+namespace DBusNames
+{
+ namespace Notify
+ {
+ static constexpr char const * NAME = "org.freedesktop.Notifications";
+ static constexpr char const * PATH = "/org/freedesktop/Notifications";
+ static constexpr char const * INTERFACE = "org.freedesktop.Notifications";
+
+ namespace ActionInvoked
+ {
+ static constexpr char const * NAME = "ActionInvoked";
+ }
+
+ namespace NotificationClosed
+ {
+ static constexpr char const * NAME = "NotificationClosed";
+ enum Reason { EXPIRED=1, DISMISSED=2, API=3, UNDEFINED=4 };
+ }
+ }
+}
+
diff --git a/src/usb-snap.cpp b/src/usb-snap.cpp
index c42f9f0..41c78c6 100644
--- a/src/usb-snap.cpp
+++ b/src/usb-snap.cpp
@@ -17,6 +17,7 @@
* Charles Kerr <charles.kerr@canonical.com>
*/
+#include <src/dbus-names.h>
#include <src/usb-snap.h>
#include <glib/gi18n.h>
@@ -48,9 +49,9 @@ public:
if (m_notification_id != 0) {
GError* error {};
g_dbus_connection_call_sync(m_bus,
- BUS_NAME,
- OBJECT_PATH,
- IFACE_NAME,
+ DBusNames::Notify::NAME,
+ DBusNames::Notify::PATH,
+ DBusNames::Notify::INTERFACE,
"CloseNotification",
g_variant_new("(u)", m_notification_id),
nullptr,
@@ -93,10 +94,10 @@ private:
m_bus = G_DBUS_CONNECTION(g_object_ref(G_OBJECT(bus)));
m_subscription_id = g_dbus_connection_signal_subscribe(m_bus,
- BUS_NAME,
- IFACE_NAME,
+ DBusNames::Notify::NAME,
+ DBusNames::Notify::INTERFACE,
nullptr,
- OBJECT_PATH,
+ DBusNames::Notify::PATH,
nullptr,
G_DBUS_SIGNAL_FLAGS_NONE,
on_notification_signal_static,
@@ -128,9 +129,9 @@ private:
&hints_builder,
-1);
g_dbus_connection_call(m_bus,
- BUS_NAME,
- OBJECT_PATH,
- IFACE_NAME,
+ DBusNames::Notify::NAME,
+ DBusNames::Notify::PATH,
+ DBusNames::Notify::INTERFACE,
"Notify",
args,
G_VARIANT_TYPE("(u)"),
@@ -172,12 +173,12 @@ private:
GVariant* parameters,
gpointer gself)
{
- g_return_if_fail(!g_strcmp0(object_path, OBJECT_PATH));
- g_return_if_fail(!g_strcmp0(interface_name, IFACE_NAME));
+ g_return_if_fail(!g_strcmp0(object_path, DBusNames::Notify::PATH));
+ g_return_if_fail(!g_strcmp0(interface_name, DBusNames::Notify::INTERFACE));
auto self = static_cast<Impl*>(gself);
- if (!g_strcmp0(signal_name, "ActionInvoked"))
+ if (!g_strcmp0(signal_name, DBusNames::Notify::ActionInvoked::NAME))
{
uint32_t id {};
const char* action_name {};
@@ -185,7 +186,7 @@ private:
if (id == self->m_notification_id)
self->on_action_invoked(action_name);
}
- else if (!g_strcmp0(signal_name, "NotificationClosed"))
+ else if (!g_strcmp0(signal_name, DBusNames::Notify::NotificationClosed::NAME))
{
uint32_t id {};
uint32_t close_reason {};
@@ -211,7 +212,7 @@ private:
void on_notification_closed(uint32_t close_reason)
{
- if (close_reason == CloseReason::EXPIRED)
+ if (close_reason == DBusNames::Notify::NotificationClosed::Reason::EXPIRED)
m_on_user_response(AdbdClient::PKResponse::DENY, false);
m_notification_id = 0;
@@ -220,11 +221,6 @@ private:
static constexpr char const * ACTION_ALLOW {"allow"};
static constexpr char const * ACTION_DENY {"deny"};
- static constexpr char const * BUS_NAME {"org.freedesktop.Notifications" };
- static constexpr char const * IFACE_NAME {"org.freedesktop.Notifications" };
- static constexpr char const * OBJECT_PATH {"/org/freedesktop/Notifications" };
- enum CloseReason { EXPIRED=1, DISMISSED=2, API=3, UNDEFINED=4 };
-
const std::string m_fingerprint;
core::Signal<AdbdClient::PKResponse,bool> m_on_user_response;
GCancellable* m_cancellable {};
diff --git a/tests/integration/usb-manager-test.cpp b/tests/integration/usb-manager-test.cpp
index 5e3377d..82c170e 100644
--- a/tests/integration/usb-manager-test.cpp
+++ b/tests/integration/usb-manager-test.cpp
@@ -25,6 +25,7 @@
#include <tests/utils/gtest-qt-print-helpers.h>
#include <tests/utils/qdbus-helpers.h>
+#include <src/dbus-names.h>
#include <src/usb-manager.h>
#include <libqtdbustest/DBusTestRunner.h>
@@ -93,10 +94,10 @@ protected:
OrgFreedesktopDBusMockInterface& notificationsMockInterface()
{
- return dbusMock.mockInterface("org.freedesktop.Notifications",
- "/org/freedesktop/Notifications",
- "org.freedesktop.Notifications",
- QDBusConnection::SessionBus);
+ return dbusMock.mockInterface(DBusNames::Notify::NAME,
+ DBusNames::Notify::PATH,
+ DBusNames::Notify::INTERFACE,
+ QDBusConnection::SessionBus);
}
QtDBusTest::DBusTestRunner dbusTestRunner;
@@ -151,8 +152,8 @@ TEST_F(UsbManagerFixture, Allow)
// click on allow in the notification
notificationsMockInterface().EmitSignal(
- DBusTypes::NOTIFY_DBUS_INTERFACE,
- "ActionInvoked",
+ DBusNames::Notify::INTERFACE,
+ DBusNames::Notify::ActionInvoked::NAME,
"us",
QVariantList() << uint32_t(1) << "allow"
);
diff --git a/tests/unit/usb-snap-test.cpp b/tests/unit/usb-snap-test.cpp
index e8f8bb2..dc17696 100644
--- a/tests/unit/usb-snap-test.cpp
+++ b/tests/unit/usb-snap-test.cpp
@@ -23,6 +23,7 @@
#include <tests/utils/glib-fixture.h>
#include <tests/utils/gtest-qt-print-helpers.h>
+#include <src/dbus-names.h>
#include <src/usb-snap.h>
#include <glib.h>
@@ -75,10 +76,10 @@ protected:
OrgFreedesktopDBusMockInterface& notificationsMockInterface()
{
- return dbusMock.mockInterface("org.freedesktop.Notifications",
- "/org/freedesktop/Notifications",
- "org.freedesktop.Notifications",
- QDBusConnection::SessionBus);
+ return dbusMock.mockInterface(DBusNames::Notify::NAME,
+ DBusNames::Notify::PATH,
+ DBusNames::Notify::INTERFACE,
+ QDBusConnection::SessionBus);
}
QtDBusTest::DBusTestRunner dbusTestRunner;
@@ -144,8 +145,8 @@ TEST_F(UsbSnapFixture, TestRoundTrip)
// fake a user interaction with the fdo notification
notificationsMockInterface().EmitSignal(
- DBusTypes::NOTIFY_DBUS_INTERFACE,
- "ActionInvoked",
+ DBusNames::Notify::INTERFACE,
+ DBusNames::Notify::ActionInvoked::NAME,
"us",
QVariantList() << id << test.action_to_invoke);
diff --git a/tests/utils/dbus-types.h b/tests/utils/dbus-types.h
index c2dfb81..3b3a02d 100644
--- a/tests/utils/dbus-types.h
+++ b/tests/utils/dbus-types.h
@@ -39,9 +39,4 @@ namespace DBusTypes
qDBusRegisterMetaType<QVariantDictMap>();
qDBusRegisterMetaType<QStringMap>();
}
- static constexpr char const* NOTIFY_DBUS_NAME = "org.freedesktop.Notifications";
-
- static constexpr char const* NOTIFY_DBUS_INTERFACE = "org.freedesktop.Notifications";
-
- static constexpr char const* NOTIFY_DBUS_PATH = "/org/freedesktop/Notifications";
}