1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* vim:expandtab:shiftwidth=4:tabstop=4:
3 : */
4 : /* ***** BEGIN LICENSE BLOCK *****
5 : * Version: NPL 1.1/GPL 2.0/LGPL 2.1
6 : *
7 : *
8 : * The contents of this file are subject to the Mozilla Public
9 : * License Version 1.1 (the "License"); you may not use this file
10 : * except in compliance with the License. You may obtain a copy of
11 : * the License at http://www.mozilla.org/MPL/
12 : *
13 : * Software distributed under the License is distributed on an "AS
14 : * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
15 : * implied. See the License for the specific language governing
16 : * rights and limitations under the License.
17 : *
18 : * The Original Code is Novell code.
19 : *
20 : * The Initial Developer of the Original Code is Novell, Inc.
21 : * Portions created by the Initial Developer are Copyright (C) 2006
22 : * the Initial Developer. All Rights Reserved.
23 : *
24 : * Original Author: Robert O'Callahan (rocallahan@novell.com)
25 : *
26 : * Contributor(s):
27 : *
28 : * Alternatively, the contents of this file may be used under the terms of
29 : * either the GNU General Public License Version 2 or later (the "GPL"), or
30 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 : * in which case the provisions of the GPL or the LGPL are applicable instead
32 : * of those above. If you wish to allow use of your version of this file only
33 : * under the terms of either the GPL or the LGPL, and not to allow others to
34 : * use your version of this file under the terms of the NPL, indicate your
35 : * decision by deleting the provisions above and replace them with the notice
36 : * and other provisions required by the GPL or the LGPL. If you do not delete
37 : * the provisions above, a recipient may use your version of this file under
38 : * the terms of any one of the NPL, the GPL or the LGPL.
39 : *
40 : * ***** END LICENSE BLOCK ***** */
41 :
42 : #ifndef NSDBUSSERVICE_H_
43 : #define NSDBUSSERVICE_H_
44 :
45 : #define DBUS_API_SUBJECT_TO_CHANGE
46 : #include <dbus/dbus.h>
47 :
48 : #include "nsITimer.h"
49 : #include "nsCOMPtr.h"
50 :
51 1386 : class DBusClient {
52 : public:
53 : virtual void RegisterWithConnection(DBusConnection* connection) = 0;
54 : virtual void UnregisterWithConnection(DBusConnection* connection) = 0;
55 : virtual bool HandleMessage(DBusMessage* msg) = 0;
56 : };
57 :
58 : #define NS_DBUS_IID \
59 : { 0xba4f79b7, 0x0d4c, 0x4b3a, { 0x8a, 0x85, 0x6f, 0xb3, 0x0d, 0xce, 0xf5, 0x11 } }
60 :
61 : /**
62 : * The nsDBusService component interfaces with DBUS to communicate with daemons
63 : * in systems supporting DBUS. It links dynamically to the DBUS libraries so
64 : * will not load on systems without those libraries ... but that's harmless.
65 : *
66 : * Currently the only daemon we communicate with is NetworkManager. We listen
67 : * for NetworkManager state changes; we set nsIOService's offline status to
68 : * FALSE when NetworkManager reports NM_STATE_CONNECTED, and to TRUE otherwise.
69 : * We also solicit the current status from NetworkManager when this component
70 : * gets loaded.
71 : *
72 : * In the future we could extend this class to talk to other daemons.
73 : *
74 : * Currently all communication is asynchronous. This isn't hard to implement
75 : * and avoids blocking our main thread.
76 : */
77 : class nsDBusService : public nsISupports
78 : {
79 : public:
80 : nsDBusService();
81 : virtual ~nsDBusService();
82 :
83 : NS_DECL_ISUPPORTS
84 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_DBUS_IID)
85 :
86 : static already_AddRefed<nsDBusService> Get();
87 :
88 : nsresult AddClient(DBusClient* client);
89 : void RemoveClient(DBusClient* client);
90 :
91 : DBusPendingCall* SendWithReply(DBusClient* client, DBusMessage* message);
92 :
93 : // these should be private but we need to call them from static functions
94 : bool HandleMessage(DBusMessage* message);
95 : void DoTimerCallback(nsITimer* aTimer);
96 :
97 : private:
98 : nsresult CreateConnection();
99 : void DropConnection();
100 : void HandleDBusDisconnect();
101 :
102 : static nsDBusService* gSingleton;
103 :
104 : DBusConnection* mConnection;
105 : nsCOMPtr<nsITimer> mReconnectTimer;
106 : DBusClient* mSingleClient;
107 : };
108 :
109 : #endif /*NSDBUSSERVICE_H_*/
|