Line data Source code
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 : #include <unistd.h>
9 :
10 : #ifndef __WakeLockListener_h__
11 : #define __WakeLockListener_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/ipc/DBusConnectionRefPtr.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 : {
31 : public:
32 : NS_DECL_ISUPPORTS;
33 :
34 : static WakeLockListener* GetSingleton(bool aCreate = true);
35 : static void Shutdown();
36 :
37 : virtual nsresult Callback(const nsAString& topic,
38 : const nsAString& state) override;
39 :
40 : private:
41 : WakeLockListener();
42 0 : ~WakeLockListener() = default;
43 :
44 : static mozilla::StaticRefPtr<WakeLockListener> sSingleton;
45 :
46 : #ifdef MOZ_ENABLE_DBUS
47 : RefPtr<DBusConnection> mConnection;
48 : #endif
49 : // Map of topic names to |WakeLockTopic|s.
50 : // We assume a small, finite-sized set of topics.
51 : nsClassHashtable<nsStringHashKey, WakeLockTopic> mTopics;
52 : };
53 :
54 : #endif // __WakeLockListener_h__
|