diff --git a/toolkit/system/dbus/nsNetworkManagerListener.cpp b/toolkit/system/dbus/nsNetworkManagerListener.cpp index 6cef7e481fdb..7f5910c9ad27 100644 --- a/toolkit/system/dbus/nsNetworkManagerListener.cpp +++ b/toolkit/system/dbus/nsNetworkManagerListener.cpp @@ -1,10 +1,9 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* vim:expandtab:shiftwidth=4:tabstop=4: - */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - + #include "nsNetworkManagerListener.h" #include "nsNetCID.h" @@ -16,23 +15,24 @@ // Define NetworkManager API constants. This avoids a dependency on // NetworkManager-devel. #define NM_DBUS_SERVICE "org.freedesktop.NetworkManager" -#define NM_DBUS_PATH "/org/freedesktop/NetworkManager" -#define NM_DBUS_INTERFACE "org.freedesktop.NetworkManager" -#define NM_DBUS_SIGNAL_STATE_CHANGE "StateChange" /* Deprecated in 0.7.x */ -#define NM_DBUS_SIGNAL_STATE_CHANGED "StateChanged" +#define NM_DBUS_PATH "/org/freedesktop/NetworkManager" +#define NM_DBUS_INTERFACE "org.freedesktop.NetworkManager" +#define NM_DBUS_SIGNAL_STATE_CHANGE "StateChange" /* Deprecated in 0.7.x */ +#define NM_DBUS_SIGNAL_STATE_CHANGED "StateChanged" #define NM_STATE_CONNECTED_OLD 3 /* Before NM 0.9.0 */ #define NM_STATE_CONNECTED_LOCAL 50 #define NM_STATE_CONNECTED_SITE 60 #define NM_STATE_CONNECTED_GLOBAL 70 -nsNetworkManagerListener::nsNetworkManagerListener() : - mLinkUp(true), mNetworkManagerActive(false), +nsNetworkManagerListener::nsNetworkManagerListener() + : mLinkUp(true), mNetworkManagerActive(false), mOK(true) { } -nsNetworkManagerListener::~nsNetworkManagerListener() { +nsNetworkManagerListener::~nsNetworkManagerListener() +{ if (mDBUS) { mDBUS->RemoveClient(this); } @@ -41,13 +41,15 @@ nsNetworkManagerListener::~nsNetworkManagerListener() { NS_IMPL_ISUPPORTS1(nsNetworkManagerListener, nsINetworkLinkService) nsresult -nsNetworkManagerListener::GetIsLinkUp(bool* aIsUp) { +nsNetworkManagerListener::GetIsLinkUp(bool* aIsUp) +{ *aIsUp = mLinkUp; return NS_OK; } nsresult -nsNetworkManagerListener::GetLinkStatusKnown(bool* aKnown) { +nsNetworkManagerListener::GetLinkStatusKnown(bool* aKnown) +{ *aKnown = mNetworkManagerActive; return NS_OK; } @@ -63,25 +65,30 @@ nsNetworkManagerListener::GetLinkType(uint32_t *aLinkType) } nsresult -nsNetworkManagerListener::Init() { +nsNetworkManagerListener::Init() +{ mDBUS = nsDBusService::Get(); - if (!mDBUS) + if (!mDBUS) { return NS_ERROR_OUT_OF_MEMORY; + } nsresult rv = mDBUS->AddClient(this); if (NS_FAILED(rv)) { mDBUS = nullptr; return rv; } - if (!mOK) + if (!mOK) { return NS_ERROR_FAILURE; + } return NS_OK; } static void -NetworkStatusNotify(DBusPendingCall *pending, void* user_data) { +NetworkStatusNotify(DBusPendingCall *pending, void* user_data) +{ DBusMessage* msg = dbus_pending_call_steal_reply(pending); - if (!msg) + if (!msg) { return; + } if (dbus_message_get_type(msg) == DBUS_MESSAGE_TYPE_METHOD_RETURN) { static_cast(user_data)->UpdateNetworkStatus(msg); } @@ -89,10 +96,11 @@ NetworkStatusNotify(DBusPendingCall *pending, void* user_data) { } void -nsNetworkManagerListener::RegisterWithConnection(DBusConnection* connection) { +nsNetworkManagerListener::RegisterWithConnection(DBusConnection* connection) +{ DBusError error; dbus_error_init(&error); - + dbus_bus_add_match(connection, "type='signal'," "interface='" NM_DBUS_INTERFACE "'," @@ -100,9 +108,9 @@ nsNetworkManagerListener::RegisterWithConnection(DBusConnection* connection) { "path='" NM_DBUS_PATH "'", &error); mOK = !dbus_error_is_set(&error); dbus_error_free(&error); - if (!mOK) + if (!mOK) { return; - + } DBusMessage* msg = dbus_message_new_method_call(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "state"); @@ -110,7 +118,7 @@ nsNetworkManagerListener::RegisterWithConnection(DBusConnection* connection) { mOK = false; return; } - + DBusPendingCall* reply = mDBUS->SendWithReply(this, msg); if (!reply) { mOK = false; @@ -125,9 +133,9 @@ void nsNetworkManagerListener::NotifyNetworkStatusObservers() { nsCOMPtr observerService = do_GetService("@mozilla.org/observer-service;1"); - if (!observerService) + if (!observerService) { return; - + } const PRUnichar* status; if (mNetworkManagerActive) { status = mLinkUp ? NS_LITERAL_STRING(NS_NETWORK_LINK_DATA_UP).get() @@ -141,13 +149,15 @@ nsNetworkManagerListener::NotifyNetworkStatusObservers() { } void -nsNetworkManagerListener::UnregisterWithConnection(DBusConnection* connection) { +nsNetworkManagerListener::UnregisterWithConnection(DBusConnection* connection) +{ mNetworkManagerActive = false; NotifyNetworkStatusObservers(); } bool -nsNetworkManagerListener::HandleMessage(DBusMessage* message) { +nsNetworkManagerListener::HandleMessage(DBusMessage* message) +{ if (dbus_message_is_signal(message, NM_DBUS_INTERFACE, NM_DBUS_SIGNAL_STATE_CHANGE) || dbus_message_is_signal(message, NM_DBUS_INTERFACE, @@ -159,21 +169,24 @@ nsNetworkManagerListener::HandleMessage(DBusMessage* message) { } void -nsNetworkManagerListener::UpdateNetworkStatus(DBusMessage* msg) { +nsNetworkManagerListener::UpdateNetworkStatus(DBusMessage* msg) +{ int32_t result; if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &result, - DBUS_TYPE_INVALID)) + DBUS_TYPE_INVALID)) { return; + } mNetworkManagerActive = true; - + bool wasUp = mLinkUp; mLinkUp = result == NM_STATE_CONNECTED_OLD || result == NM_STATE_CONNECTED_LOCAL || result == NM_STATE_CONNECTED_SITE || result == NM_STATE_CONNECTED_GLOBAL; - if (wasUp == mLinkUp) + if (wasUp == mLinkUp) { return; + } NotifyNetworkStatusObservers(); } diff --git a/toolkit/system/dbus/nsNetworkManagerListener.h b/toolkit/system/dbus/nsNetworkManagerListener.h index 3f61aa11546e..a45878f6b924 100644 --- a/toolkit/system/dbus/nsNetworkManagerListener.h +++ b/toolkit/system/dbus/nsNetworkManagerListener.h @@ -1,6 +1,5 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* vim:expandtab:shiftwidth=4:tabstop=4: - */ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */