michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim:expandtab:shiftwidth=4:tabstop=4: michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef NSDBUSSERVICE_H_ michael@0: #define NSDBUSSERVICE_H_ michael@0: michael@0: #define DBUS_API_SUBJECT_TO_CHANGE michael@0: #include michael@0: michael@0: #include "nsITimer.h" michael@0: #include "nsCOMPtr.h" michael@0: michael@0: class DBusClient { michael@0: public: michael@0: virtual void RegisterWithConnection(DBusConnection* connection) = 0; michael@0: virtual void UnregisterWithConnection(DBusConnection* connection) = 0; michael@0: virtual bool HandleMessage(DBusMessage* msg) = 0; michael@0: }; michael@0: michael@0: #define NS_DBUS_IID \ michael@0: { 0xba4f79b7, 0x0d4c, 0x4b3a, { 0x8a, 0x85, 0x6f, 0xb3, 0x0d, 0xce, 0xf5, 0x11 } } michael@0: michael@0: /** michael@0: * The nsDBusService component interfaces with DBUS to communicate with daemons michael@0: * in systems supporting DBUS. It links dynamically to the DBUS libraries so michael@0: * will not load on systems without those libraries ... but that's harmless. michael@0: * michael@0: * Currently the only daemon we communicate with is NetworkManager. We listen michael@0: * for NetworkManager state changes; we set nsIOService's offline status to michael@0: * FALSE when NetworkManager reports NM_STATE_CONNECTED, and to TRUE otherwise. michael@0: * We also solicit the current status from NetworkManager when this component michael@0: * gets loaded. michael@0: * michael@0: * In the future we could extend this class to talk to other daemons. michael@0: * michael@0: * Currently all communication is asynchronous. This isn't hard to implement michael@0: * and avoids blocking our main thread. michael@0: */ michael@0: class nsDBusService : public nsISupports michael@0: { michael@0: public: michael@0: nsDBusService(); michael@0: virtual ~nsDBusService(); michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_DBUS_IID) michael@0: michael@0: static already_AddRefed Get(); michael@0: michael@0: nsresult AddClient(DBusClient* client); michael@0: void RemoveClient(DBusClient* client); michael@0: michael@0: DBusPendingCall* SendWithReply(DBusClient* client, DBusMessage* message); michael@0: michael@0: // these should be private but we need to call them from static functions michael@0: bool HandleMessage(DBusMessage* message); michael@0: void DoTimerCallback(nsITimer* aTimer); michael@0: michael@0: private: michael@0: nsresult CreateConnection(); michael@0: void DropConnection(); michael@0: void HandleDBusDisconnect(); michael@0: michael@0: static nsDBusService* gSingleton; michael@0: michael@0: DBusConnection* mConnection; michael@0: nsCOMPtr mReconnectTimer; michael@0: DBusClient* mSingleClient; michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsDBusService, NS_DBUS_IID) michael@0: michael@0: #endif /*NSDBUSSERVICE_H_*/