• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef PLATFORM_API_SCOPED_WAKE_LOCK_H_
6 #define PLATFORM_API_SCOPED_WAKE_LOCK_H_
7 
8 #include <memory>
9 
10 #include "platform/api/serial_delete_ptr.h"
11 #include "platform/api/task_runner.h"
12 
13 namespace openscreen {
14 
15 // Ensures that the device does not got to sleep. This is used, for example,
16 // while Open Screen is communicating with peers over the network for things
17 // like media streaming.
18 //
19 // The wake lock is RAII: It is automatically engaged when the ScopedWakeLock is
20 // created and released when the ScopedWakeLock is destroyed. Open Screen code
21 // may sometimes create multiple instances. In that case, the wake lock should
22 // be engaged upon creating the first instance, and then held until all
23 // instances have been destroyed.
24 class ScopedWakeLock {
25  public:
26   static SerialDeletePtr<ScopedWakeLock> Create(TaskRunner* task_runner);
27 
28   // Instances are not copied nor moved.
29   ScopedWakeLock(const ScopedWakeLock&) = delete;
30   ScopedWakeLock(ScopedWakeLock&&) = delete;
31   ScopedWakeLock& operator=(const ScopedWakeLock&) = delete;
32   ScopedWakeLock& operator=(ScopedWakeLock&&) = delete;
33 
34   ScopedWakeLock();
35   virtual ~ScopedWakeLock();
36 };
37 
38 }  // namespace openscreen
39 
40 #endif  // PLATFORM_API_SCOPED_WAKE_LOCK_H_
41