toolkit/system/dbus/nsDBusService.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/system/dbus/nsDBusService.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,77 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* vim:expandtab:shiftwidth=4:tabstop=4:
     1.6 + */
     1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    1.10 +
    1.11 +#ifndef NSDBUSSERVICE_H_
    1.12 +#define NSDBUSSERVICE_H_
    1.13 +
    1.14 +#define DBUS_API_SUBJECT_TO_CHANGE
    1.15 +#include <dbus/dbus.h>
    1.16 +
    1.17 +#include "nsITimer.h"
    1.18 +#include "nsCOMPtr.h"
    1.19 +
    1.20 +class DBusClient {
    1.21 +public:
    1.22 +  virtual void RegisterWithConnection(DBusConnection* connection) = 0;
    1.23 +  virtual void UnregisterWithConnection(DBusConnection* connection) = 0;
    1.24 +  virtual bool HandleMessage(DBusMessage* msg) = 0;
    1.25 +};
    1.26 +
    1.27 +#define NS_DBUS_IID \
    1.28 +  { 0xba4f79b7, 0x0d4c, 0x4b3a, { 0x8a, 0x85, 0x6f, 0xb3, 0x0d, 0xce, 0xf5, 0x11 } }
    1.29 +
    1.30 +/**
    1.31 + * The nsDBusService component interfaces with DBUS to communicate with daemons
    1.32 + * in systems supporting DBUS. It links dynamically to the DBUS libraries so
    1.33 + * will not load on systems without those libraries ... but that's harmless.
    1.34 + *
    1.35 + * Currently the only daemon we communicate with is NetworkManager. We listen
    1.36 + * for NetworkManager state changes; we set nsIOService's offline status to
    1.37 + * FALSE when NetworkManager reports NM_STATE_CONNECTED, and to TRUE otherwise.
    1.38 + * We also solicit the current status from NetworkManager when this component
    1.39 + * gets loaded.
    1.40 + * 
    1.41 + * In the future we could extend this class to talk to other daemons.
    1.42 + * 
    1.43 + * Currently all communication is asynchronous. This isn't hard to implement
    1.44 + * and avoids blocking our main thread.
    1.45 + */
    1.46 +class nsDBusService : public nsISupports
    1.47 +{
    1.48 +public:
    1.49 +  nsDBusService();
    1.50 +  virtual ~nsDBusService();
    1.51 +
    1.52 +  NS_DECL_ISUPPORTS
    1.53 +  NS_DECLARE_STATIC_IID_ACCESSOR(NS_DBUS_IID)
    1.54 +
    1.55 +  static already_AddRefed<nsDBusService> Get();
    1.56 +  
    1.57 +  nsresult AddClient(DBusClient* client);
    1.58 +  void RemoveClient(DBusClient* client);
    1.59 +
    1.60 +  DBusPendingCall* SendWithReply(DBusClient* client, DBusMessage* message);
    1.61 +
    1.62 +  // these should be private but we need to call them from static functions
    1.63 +  bool HandleMessage(DBusMessage* message);
    1.64 +  void DoTimerCallback(nsITimer* aTimer);
    1.65 +
    1.66 +private:
    1.67 +  nsresult CreateConnection();
    1.68 +  void DropConnection();
    1.69 +  void HandleDBusDisconnect();
    1.70 +
    1.71 +  static nsDBusService* gSingleton;
    1.72 +  
    1.73 +  DBusConnection*    mConnection;
    1.74 +  nsCOMPtr<nsITimer> mReconnectTimer;
    1.75 +  DBusClient*        mSingleClient;
    1.76 +};
    1.77 +
    1.78 +NS_DEFINE_STATIC_IID_ACCESSOR(nsDBusService, NS_DBUS_IID)
    1.79 +
    1.80 +#endif /*NSDBUSSERVICE_H_*/

mercurial