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