0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SleepWakeNotifier.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
26 
27 
28 #ifndef Hypertable_Common_SleepWakeNotifier_h
29 #define Hypertable_Common_SleepWakeNotifier_h
30 
31 #include "Common/String.h"
32 
33 #include <functional>
34 #include <thread>
35 
36 #if defined(__APPLE__)
37 #include <IOKit/pwr_mgt/IOPMLib.h>
38 #endif
39 
40 
41 namespace Hypertable {
42 
45 
48 
49  public:
50 
58  SleepWakeNotifier(std::function<void()> sleep_callback,
59  std::function<void()> wakeup_callback);
60 
65 
68  void handle_sleep();
69 
72  void handle_wakeup();
73 
74 #if defined(__APPLE__)
75  io_connect_t get_root_port() { return m_root_port; }
77 #endif
78 
79  private:
80 
82  void thread_func();
83 
85  std::thread m_thread {};
86 
88  std::function<void()> m_callback_sleep {};
89 
91  std::function<void()> m_callback_wakeup {};
92 
93 #if defined(__APPLE__)
94  io_connect_t m_root_port;
96 
98  IONotificationPortRef m_notify_port_ref;
99 
101  io_object_t m_notifier_object;
102 
104  CFRunLoopRef m_run_loop;
105 #endif
106 
107  };
108 
110 
111 } // namespace Hypertable
112 
113 #endif // Hypertable_Common_SleepWakeNotifier_h
Delivers sleep and wakeup notifications.
SleepWakeNotifier(std::function< void()> sleep_callback, std::function< void()> wakeup_callback)
Constructor.
std::thread m_thread
Event notification polling thread.
~SleepWakeNotifier()
Destructor Does OS-specific deregistering of sleep/wakeup notification interest and then joins m_thre...
std::function< void()> m_callback_sleep
Registered sleep callback.
void thread_func()
Thread function for event notification polling thread (m_thread)
void handle_sleep()
Called by polling thread to deliver sleep notification Calls registered sleep callback m_callback_sle...
std::function< void()> m_callback_wakeup
Registered wakeup callback.
Hypertable definitions
A String class based on std::string.
void handle_wakeup()
Called by polling thread to deliver wakeup notification Calls registered wakeup callback m_callback_w...