1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim:expandtab:shiftwidth=2:tabstop=2: 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/. */ 7 8 #ifndef __WakeLockListener_h__ 9 #define __WakeLockListener_h__ 10 11 #include <unistd.h> 12 13 #include "mozilla/StaticPtr.h" 14 #include "nsHashKeys.h" 15 #include "nsClassHashtable.h" 16 17 #include "nsIDOMWakeLockListener.h" 18 19 #ifdef MOZ_ENABLE_DBUS 20 # include "mozilla/DBusHelpers.h" 21 #endif 22 23 class WakeLockTopic; 24 25 /** 26 * Receives WakeLock events and simply passes it on to the right WakeLockTopic 27 * to inhibit the screensaver. 28 */ 29 class WakeLockListener final : public nsIDOMMozWakeLockListener { 30 public: 31 NS_DECL_ISUPPORTS; 32 33 static WakeLockListener* GetSingleton(bool aCreate = true); 34 static void Shutdown(); 35 36 virtual nsresult Callback(const nsAString& topic, 37 const nsAString& state) override; 38 39 private: 40 WakeLockListener(); 41 ~WakeLockListener() = default; 42 43 bool EnsureDBusConnection(); 44 45 static mozilla::StaticRefPtr<WakeLockListener> sSingleton; 46 47 #ifdef MOZ_ENABLE_DBUS 48 RefPtr<DBusConnection> mConnection; 49 #endif 50 // Map of topic names to |WakeLockTopic|s. 51 // We assume a small, finite-sized set of topics. 52 nsClassHashtable<nsStringHashKey, WakeLockTopic> mTopics; 53 }; 54 55 #endif // __WakeLockListener_h__ 56