toolkit/system/dbus/nsDBusService.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* vim:expandtab:shiftwidth=4:tabstop=4:
michael@0 3 */
michael@0 4 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #ifndef NSDBUSSERVICE_H_
michael@0 9 #define NSDBUSSERVICE_H_
michael@0 10
michael@0 11 #define DBUS_API_SUBJECT_TO_CHANGE
michael@0 12 #include <dbus/dbus.h>
michael@0 13
michael@0 14 #include "nsITimer.h"
michael@0 15 #include "nsCOMPtr.h"
michael@0 16
michael@0 17 class DBusClient {
michael@0 18 public:
michael@0 19 virtual void RegisterWithConnection(DBusConnection* connection) = 0;
michael@0 20 virtual void UnregisterWithConnection(DBusConnection* connection) = 0;
michael@0 21 virtual bool HandleMessage(DBusMessage* msg) = 0;
michael@0 22 };
michael@0 23
michael@0 24 #define NS_DBUS_IID \
michael@0 25 { 0xba4f79b7, 0x0d4c, 0x4b3a, { 0x8a, 0x85, 0x6f, 0xb3, 0x0d, 0xce, 0xf5, 0x11 } }
michael@0 26
michael@0 27 /**
michael@0 28 * The nsDBusService component interfaces with DBUS to communicate with daemons
michael@0 29 * in systems supporting DBUS. It links dynamically to the DBUS libraries so
michael@0 30 * will not load on systems without those libraries ... but that's harmless.
michael@0 31 *
michael@0 32 * Currently the only daemon we communicate with is NetworkManager. We listen
michael@0 33 * for NetworkManager state changes; we set nsIOService's offline status to
michael@0 34 * FALSE when NetworkManager reports NM_STATE_CONNECTED, and to TRUE otherwise.
michael@0 35 * We also solicit the current status from NetworkManager when this component
michael@0 36 * gets loaded.
michael@0 37 *
michael@0 38 * In the future we could extend this class to talk to other daemons.
michael@0 39 *
michael@0 40 * Currently all communication is asynchronous. This isn't hard to implement
michael@0 41 * and avoids blocking our main thread.
michael@0 42 */
michael@0 43 class nsDBusService : public nsISupports
michael@0 44 {
michael@0 45 public:
michael@0 46 nsDBusService();
michael@0 47 virtual ~nsDBusService();
michael@0 48
michael@0 49 NS_DECL_ISUPPORTS
michael@0 50 NS_DECLARE_STATIC_IID_ACCESSOR(NS_DBUS_IID)
michael@0 51
michael@0 52 static already_AddRefed<nsDBusService> Get();
michael@0 53
michael@0 54 nsresult AddClient(DBusClient* client);
michael@0 55 void RemoveClient(DBusClient* client);
michael@0 56
michael@0 57 DBusPendingCall* SendWithReply(DBusClient* client, DBusMessage* message);
michael@0 58
michael@0 59 // these should be private but we need to call them from static functions
michael@0 60 bool HandleMessage(DBusMessage* message);
michael@0 61 void DoTimerCallback(nsITimer* aTimer);
michael@0 62
michael@0 63 private:
michael@0 64 nsresult CreateConnection();
michael@0 65 void DropConnection();
michael@0 66 void HandleDBusDisconnect();
michael@0 67
michael@0 68 static nsDBusService* gSingleton;
michael@0 69
michael@0 70 DBusConnection* mConnection;
michael@0 71 nsCOMPtr<nsITimer> mReconnectTimer;
michael@0 72 DBusClient* mSingleClient;
michael@0 73 };
michael@0 74
michael@0 75 NS_DEFINE_STATIC_IID_ACCESSOR(nsDBusService, NS_DBUS_IID)
michael@0 76
michael@0 77 #endif /*NSDBUSSERVICE_H_*/

mercurial