Bug 312793. Make Linux builds listen to dbus for NetworkManager events so we can go online/offline automatically. r=caillon,bsmedberg sr=darin

This commit is contained in:
roc+%cs.cmu.edu 2006-12-04 20:42:31 +00:00
Родитель a4c80af646
Коммит b965ced77c
9 изменённых файлов: 740 добавлений и 1 удалений

Просмотреть файл

@ -463,6 +463,9 @@ MOZ_GTK_LDFLAGS = @MOZ_GTK_LDFLAGS@
MOZ_GTK2_CFLAGS = @MOZ_GTK2_CFLAGS@ MOZ_GTK2_CFLAGS = @MOZ_GTK2_CFLAGS@
MOZ_GTK2_LIBS = @MOZ_GTK2_LIBS@ MOZ_GTK2_LIBS = @MOZ_GTK2_LIBS@
MOZ_DBUS_GLIB_CFLAGS = @MOZ_DBUS_GLIB_CFLAGS@
MOZ_DBUS_GLIB_LIBS = @MOZ_DBUS_GLIB_LIBS@
MOZ_XLIB_CFLAGS = @MOZ_XLIB_CFLAGS@ MOZ_XLIB_CFLAGS = @MOZ_XLIB_CFLAGS@
MOZ_XLIB_LDFLAGS = @MOZ_XLIB_LDFLAGS@ MOZ_XLIB_LDFLAGS = @MOZ_XLIB_LDFLAGS@

Просмотреть файл

@ -5156,6 +5156,32 @@ AC_SUBST(MOZ_ENABLE_GNOMEUI)
AC_SUBST(MOZ_GNOMEUI_CFLAGS) AC_SUBST(MOZ_GNOMEUI_CFLAGS)
AC_SUBST(MOZ_GNOMEUI_LIBS) AC_SUBST(MOZ_GNOMEUI_LIBS)
dnl ========================================================
dnl = dbus support
dnl ========================================================
if test "$MOZ_ENABLE_GTK2"
then
MOZ_ENABLE_DBUS=1
MOZ_ARG_DISABLE_BOOL(dbus,
[ --disable-dbus Disable dbus support (default: force, optional at runtime) ],
MOZ_ENABLE_DBUS=,
MOZ_ENABLE_DBUS=force)
if test "$MOZ_ENABLE_DBUS"
then
PKG_CHECK_MODULES(MOZ_DBUS_GLIB, dbus-glib-1)
fi
if test "$MOZ_ENABLE_DBUS"; then
AC_DEFINE(MOZ_ENABLE_DBUS)
fi
fi
AC_SUBST(MOZ_ENABLE_DBUS)
AC_SUBST(MOZ_DBUS_GLIB_CFLAGS)
AC_SUBST(MOZ_DBUS_GLIB_LIBS)
dnl ======================================================== dnl ========================================================
dnl = Setting MOZ_EXTRA_X11CONVERTERS turns on additional dnl = Setting MOZ_EXTRA_X11CONVERTERS turns on additional
dnl = converters in intl/uconv that are used only by X11 gfx dnl = converters in intl/uconv that are used only by X11 gfx

Просмотреть файл

@ -0,0 +1,70 @@
# ###### BEGIN LICENSE BLOCK ######
# Version: NPL 1.1/GPL 2.0/LGPL 2.1
#
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is Novell code.
#
# The Initial Developer of the Original Code is Novell, Inc.
# Portions created by the Initial Developer are Copyright (C) 2006
# the Initial Developer. All Rights Reserved.
#
# Original Author: Robert O'Callahan (rocallahan@novell.com)
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the NPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the NPL, the GPL or the LGPL.
#
# ###### END LICENSE BLOCK ######
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = dbus
LIBRARY_NAME = dbusservice
GRE_MODULE = 1
#EXPORT_LIBRARY = 1
IS_COMPONENT = 1
FORCE_SHARED_LIB = 1
REQUIRES = xpcom \
string \
necko \
embedcomponents \
$(NULL)
EXTRA_DSO_LDOPTS = $(MOZ_DBUS_GLIB_LIBS)
CPPSRCS = \
nsDBusModule.cpp \
nsDBusService.cpp \
nsNetworkManagerListener.cpp \
$(NULL)
include $(topsrcdir)/config/rules.mk
CXXFLAGS += $(TK_CFLAGS) $(MOZ_DBUS_GLIB_CFLAGS)
CXXFLAGS := $(subst -pedantic,,$(CXXFLAGS))

Просмотреть файл

@ -0,0 +1,70 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Novell code.
*
* The Initial Developer of the Original Code is Novell, Inc.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Original Author: Robert O'Callahan (rocallahan@novell.com)
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsServiceManagerUtils.h"
#include "nsICategoryManager.h"
#include "nsIGenericFactory.h"
#include "nsIAppStartupNotifier.h"
#include "nsNetworkManagerListener.h"
#include "nsNetCID.h"
#define NS_DBUS_NETWORK_LINK_SERVICE_CLASSNAME "DBus Network Link Status"
#define NS_DBUS_NETWORK_LINK_SERVICE_CID \
{ 0x75a500a2, \
0x0030, \
0x40f7, \
{ 0x86, 0xf8, 0x63, 0xf2, 0x25, 0xb9, 0x40, 0xae } \
}
/* ===== XPCOM registration stuff ======== */
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsNetworkManagerListener, Init)
static const nsModuleComponentInfo components[] = {
{ NS_DBUS_NETWORK_LINK_SERVICE_CLASSNAME,
NS_DBUS_NETWORK_LINK_SERVICE_CID,
NS_NETWORK_LINK_SERVICE_CONTRACTID,
nsNetworkManagerListenerConstructor,
nsnull,
nsnull,
},
};
NS_IMPL_NSGETMODULE(nsDBusModule, components)

Просмотреть файл

@ -0,0 +1,175 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Novell code.
*
* The Initial Developer of the Original Code is Novell, Inc.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Original Author: Robert O'Callahan (rocallahan@novell.com)
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsDBusService.h"
#include "nsComponentManagerUtils.h"
#include <glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <dbus/dbus-glib.h>
nsDBusService::nsDBusService() {
mConnection = nsnull;
mSingleClient = nsnull;
}
nsDBusService::~nsDBusService() {
NS_ASSERTION(!mSingleClient, "Client failed to unregister");
DropConnection();
if (mReconnectTimer) {
mReconnectTimer->Cancel();
}
gSingleton = nsnull;
}
NS_IMPL_ISUPPORTS1(nsDBusService, nsDBusService)
NS_DEFINE_STATIC_IID_ACCESSOR(nsDBusService, NS_DBUS_IID)
nsDBusService* nsDBusService::gSingleton = nsnull;
already_AddRefed<nsDBusService>
nsDBusService::Get() {
if (!gSingleton) {
gSingleton = new nsDBusService();
}
NS_IF_ADDREF(gSingleton);
return gSingleton;
}
nsresult
nsDBusService::AddClient(DBusClient* client) {
NS_ASSERTION(!mSingleClient, "Only one client supported right now");
mSingleClient = client;
nsresult rv = CreateConnection();
if (NS_FAILED(rv)) {
mSingleClient = nsnull;
}
return rv;
}
void
nsDBusService::RemoveClient(DBusClient* client) {
NS_ASSERTION(mSingleClient == client, "Removing wrong client");
mSingleClient = nsnull;
}
DBusPendingCall*
nsDBusService::SendWithReply(DBusClient* client, DBusMessage* message) {
DBusPendingCall* reply = nsnull;
if (mConnection) {
if (!dbus_connection_send_with_reply(mConnection, message, &reply, -1)) {
reply = nsnull;
}
}
dbus_message_unref(message);
return reply;
}
PRBool nsDBusService::HandleMessage(DBusMessage* message) {
if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL,
"Disconnected")) {
HandleDBusDisconnect();
return PR_FALSE;
}
return mSingleClient && mSingleClient->HandleMessage(message);
}
static DBusHandlerResult dbus_filter(DBusConnection* connection,
DBusMessage* message,
void* user_data) {
return NS_STATIC_CAST(nsDBusService*, user_data)->HandleMessage(message)
? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
void nsDBusService::DoTimerCallback(nsITimer *aTimer) {
if (aTimer == mReconnectTimer.get()) {
nsresult rv = CreateConnection();
if (NS_SUCCEEDED(rv)) {
mReconnectTimer->Cancel();
mReconnectTimer = nsnull;
}
}
}
static void TimerCallback(nsITimer *aTimer, void *aClosure) {
NS_STATIC_CAST(nsDBusService*, aClosure)->DoTimerCallback(aTimer);
}
void nsDBusService::DropConnection() {
if (mConnection) {
if (mSingleClient) {
mSingleClient->UnregisterWithConnection(mConnection);
}
dbus_connection_unref(mConnection);
mConnection = nsnull;
}
}
void nsDBusService::HandleDBusDisconnect() {
DropConnection();
nsresult rv;
mReconnectTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
if (NS_FAILED(rv))
return;
rv = mReconnectTimer->InitWithFuncCallback(TimerCallback, this,
5000, nsITimer::TYPE_REPEATING_SLACK);
if (NS_FAILED(rv)) {
mReconnectTimer = nsnull;
return;
}
}
nsresult nsDBusService::CreateConnection() {
mConnection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
if (!mConnection)
return NS_ERROR_FAILURE;
dbus_connection_set_exit_on_disconnect(mConnection, PR_FALSE);
dbus_connection_setup_with_g_main(mConnection, NULL);
if (!dbus_connection_add_filter(mConnection, dbus_filter, this, NULL))
return NS_ERROR_FAILURE;
mSingleClient->RegisterWithConnection(mConnection);
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,112 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Novell code.
*
* The Initial Developer of the Original Code is Novell, Inc.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Original Author: Robert O'Callahan (rocallahan@novell.com)
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef NSDBUSSERVICE_H_
#define NSDBUSSERVICE_H_
#define DBUS_API_SUBJECT_TO_CHANGE
#include <dbus/dbus.h>
#include "nsITimer.h"
#include "nsCOMPtr.h"
class DBusClient {
public:
virtual void RegisterWithConnection(DBusConnection* connection) = 0;
virtual void UnregisterWithConnection(DBusConnection* connection) = 0;
virtual PRBool HandleMessage(DBusMessage* msg) = 0;
};
#define NS_DBUS_IID \
{ 0xba4f79b7, 0x0d4c, 0x4b3a, { 0x8a, 0x85, 0x6f, 0xb3, 0x0d, 0xce, 0xf5, 0x11 } }
/**
* The nsDBusService component interfaces with DBUS to communicate with daemons
* in systems supporting DBUS. It links dynamically to the DBUS libraries so
* will not load on systems without those libraries ... but that's harmless.
*
* Currently the only daemon we communicate with is NetworkManager. We listen
* for NetworkManager state changes; we set nsIOService's offline status to
* FALSE when NetworkManager reports NM_STATE_CONNECTED, and to TRUE otherwise.
* We also solicit the current status from NetworkManager when this component
* gets loaded. In addition to setting IOService, we also set the
* "browser.offline" preference (because Firefox treats that preference as
* authoritative). We have to wait until prefs have been loaded before setting
* "browser.offline".
*
* In the future we could extend this class to talk to other daemons.
*
* Currently all communication is asynchronous. This isn't hard to implement
* and avoids blocking our main thread.
*/
class nsDBusService : public nsISupports
{
public:
nsDBusService();
virtual ~nsDBusService();
NS_DECL_ISUPPORTS
NS_DECLARE_STATIC_IID_ACCESSOR(NS_DBUS_IID)
static already_AddRefed<nsDBusService> Get();
nsresult AddClient(DBusClient* client);
void RemoveClient(DBusClient* client);
DBusPendingCall* SendWithReply(DBusClient* client, DBusMessage* message);
// these should be private but we need to call them from static functions
PRBool HandleMessage(DBusMessage* message);
void DoTimerCallback(nsITimer* aTimer);
private:
nsresult CreateConnection();
void DropConnection();
void HandleDBusDisconnect();
static nsDBusService* gSingleton;
DBusConnection* mConnection;
nsCOMPtr<nsITimer> mReconnectTimer;
DBusClient* mSingleClient;
};
#endif /*NSDBUSSERVICE_H_*/

Просмотреть файл

@ -0,0 +1,199 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Novell code.
*
* The Initial Developer of the Original Code is Novell, Inc.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Original Author: Robert O'Callahan (rocallahan@novell.com)
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsNetworkManagerListener.h"
#include "nsNetCID.h"
#include "nsServiceManagerUtils.h"
#include "nsIObserverService.h"
#include "nsStringAPI.h"
// 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"
typedef enum NMState
{
NM_STATE_UNKNOWN = 0,
NM_STATE_ASLEEP,
NM_STATE_CONNECTING,
NM_STATE_CONNECTED,
NM_STATE_DISCONNECTED
} NMState;
nsNetworkManagerListener::nsNetworkManagerListener() :
mLinkUp(PR_TRUE), mNetworkManagerActive(PR_FALSE),
mOK(PR_TRUE), mManageIOService(PR_TRUE)
{
}
nsNetworkManagerListener::~nsNetworkManagerListener() {
if (mDBUS) {
mDBUS->RemoveClient(this);
}
}
NS_IMPL_ISUPPORTS1(nsNetworkManagerListener, nsINetworkLinkService)
nsresult
nsNetworkManagerListener::GetIsLinkUp(PRBool* aIsUp) {
*aIsUp = mLinkUp;
return NS_OK;
}
nsresult
nsNetworkManagerListener::GetLinkStatusKnown(PRBool* aKnown) {
*aKnown = mNetworkManagerActive;
return NS_OK;
}
nsresult
nsNetworkManagerListener::Init() {
mDBUS = nsDBusService::Get();
if (!mDBUS)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = mDBUS->AddClient(this);
if (NS_FAILED(rv)) {
mDBUS = nsnull;
return rv;
}
if (!mOK)
return NS_ERROR_FAILURE;
return NS_OK;
}
static void
NetworkStatusNotify(DBusPendingCall *pending, void* user_data) {
DBusMessage* msg = dbus_pending_call_steal_reply(pending);
if (!msg)
return;
if (dbus_message_get_type(msg) == DBUS_MESSAGE_TYPE_METHOD_RETURN) {
NS_STATIC_CAST(nsNetworkManagerListener*, user_data)->UpdateNetworkStatus(msg);
}
dbus_message_unref(msg);
}
void
nsNetworkManagerListener::RegisterWithConnection(DBusConnection* connection) {
DBusError error;
dbus_error_init(&error);
dbus_bus_add_match(connection,
"type='signal',"
"interface='" NM_DBUS_INTERFACE "',"
"sender='" NM_DBUS_SERVICE "',"
"path='" NM_DBUS_PATH "'", &error);
mOK = !dbus_error_is_set(&error);
dbus_error_free(&error);
if (!mOK)
return;
DBusMessage* msg =
dbus_message_new_method_call(NM_DBUS_SERVICE, NM_DBUS_PATH,
NM_DBUS_INTERFACE, "state");
if (!msg) {
mOK = PR_FALSE;
return;
}
DBusPendingCall* reply = mDBUS->SendWithReply(this, msg);
if (!reply) {
mOK = PR_FALSE;
return;
}
dbus_pending_call_set_notify(reply, NetworkStatusNotify, this, NULL);
dbus_pending_call_unref(reply);
}
void
nsNetworkManagerListener::NotifyNetworkStatusObservers() {
nsCOMPtr<nsIObserverService> observerService =
do_GetService("@mozilla.org/observer-service;1");
if (!observerService)
return;
const PRUnichar* status;
if (mNetworkManagerActive) {
status = mLinkUp ? NS_LITERAL_STRING(NS_NETWORK_LINK_DATA_UP).get()
: NS_LITERAL_STRING(NS_NETWORK_LINK_DATA_DOWN).get();
} else {
status = NS_LITERAL_STRING(NS_NETWORK_LINK_DATA_UNKNOWN).get();
}
observerService->NotifyObservers(NS_STATIC_CAST(nsISupports*, this),
NS_NETWORK_LINK_TOPIC, status);
}
void
nsNetworkManagerListener::UnregisterWithConnection(DBusConnection* connection) {
mNetworkManagerActive = PR_FALSE;
NotifyNetworkStatusObservers();
}
PRBool
nsNetworkManagerListener::HandleMessage(DBusMessage* message) {
if (dbus_message_is_signal(message, NM_DBUS_INTERFACE,
NM_DBUS_SIGNAL_STATE_CHANGE)) {
UpdateNetworkStatus(message);
return PR_TRUE;
}
return PR_FALSE;
}
void
nsNetworkManagerListener::UpdateNetworkStatus(DBusMessage* msg) {
PRInt32 result;
if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &result,
DBUS_TYPE_INVALID))
return;
mNetworkManagerActive = PR_TRUE;
PRBool wasUp = mLinkUp;
mLinkUp = result == NM_STATE_CONNECTED;
if (wasUp == mLinkUp)
return;
NotifyNetworkStatusObservers();
}

Просмотреть файл

@ -0,0 +1,80 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Novell code.
*
* The Initial Developer of the Original Code is Novell, Inc.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Original Author: Robert O'Callahan (rocallahan@novell.com)
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef NSNETWORKMANAGERLISTENER_H_
#define NSNETWORKMANAGERLISTENER_H_
#include "nsINetworkLinkService.h"
#include "nsDBusService.h"
class nsNetworkManagerListener : public nsINetworkLinkService,
public DBusClient {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSINETWORKLINKSERVICE
nsNetworkManagerListener();
virtual ~nsNetworkManagerListener();
nsresult Init();
virtual void RegisterWithConnection(DBusConnection* connection);
virtual void UnregisterWithConnection(DBusConnection* connection);
virtual PRBool HandleMessage(DBusMessage* msg);
/**
* This gets called when NetworkManager sends us a StateChange signal,
* or when we receive a reply to our inquiry.
* The message contains the current NMState.
*/
void UpdateNetworkStatus(DBusMessage* message);
private:
void NotifyNetworkStatusObservers();
nsCOMPtr<nsDBusService> mDBUS;
PRPackedBool mLinkUp;
PRPackedBool mNetworkManagerActive;
PRPackedBool mOK;
PRPackedBool mManageIOService;
};
#endif /*NSNETWORKMANAGERLISTENER_H_*/

Просмотреть файл

@ -200,7 +200,7 @@ tier_toolkit_dirs += tools/jprof
endif endif
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
tier_toolkit_dirs += xpfe/bootstrap/appleevents tier_toolkit_dirs += xpfe/bootstrap/appleevents
endif endif
tier_toolkit_dirs += \ tier_toolkit_dirs += \
@ -273,6 +273,10 @@ ifdef MOZ_ENABLE_GNOME_COMPONENT
tier_toolkit_dirs += toolkit/system/gnome tier_toolkit_dirs += toolkit/system/gnome
endif endif
ifdef MOZ_ENABLE_DBUS
tier_toolkit_dirs += toolkit/system/dbus
endif
ifdef MOZ_LEAKY ifdef MOZ_LEAKY
tier_toolkit_dirs += tools/leaky tier_toolkit_dirs += tools/leaky
endif endif