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