Open Lighting Architecture  0.9.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WindowsPoller.h
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15  *
16  * WindowsPoller.h
17  * A Poller for the Windows platform
18  * Copyright (C) 2014 Lukas Erlinghagen
19  */
20 
21 #ifndef COMMON_IO_WINDOWSPOLLER_H_
22 #define COMMON_IO_WINDOWSPOLLER_H_
23 
24 #include <ola/Clock.h>
25 #include <ola/ExportMap.h>
26 #include <ola/base/Macro.h>
27 #include <ola/io/Descriptor.h>
28 
29 #define WIN32_LEAN_AND_MEAN
30 #include <Windows.h>
31 
32 #include <map>
33 #include <utility>
34 #include <vector>
35 
36 #include "common/io/PollerInterface.h"
37 #include "common/io/TimeoutManager.h"
38 
39 namespace ola {
40 namespace io {
41 
47  public :
53  WindowsPoller(ExportMap *export_map, Clock *clock);
54 
55  ~WindowsPoller();
56 
57  bool AddReadDescriptor(class ReadFileDescriptor *descriptor);
58  bool AddReadDescriptor(class ConnectedDescriptor *descriptor,
59  bool delete_on_close);
60  bool RemoveReadDescriptor(class ReadFileDescriptor *descriptor);
61  bool RemoveReadDescriptor(class ConnectedDescriptor *descriptor);
62 
63  bool AddWriteDescriptor(class WriteFileDescriptor *descriptor);
64  bool RemoveWriteDescriptor(class WriteFileDescriptor *descriptor);
65 
66  const TimeStamp *WakeUpTime() const { return &m_wake_up_time; }
67 
68  bool Poll(TimeoutManager *timeout_manager,
69  const TimeInterval &poll_interval);
70 
71  private:
72  typedef std::map<void*, class WindowsPollerDescriptor*> DescriptorMap;
73  typedef std::vector<class WindowsPollerDescriptor*> OrphanedDescriptors;
74 
75  ExportMap *m_export_map;
76  CounterVariable *m_loop_iterations;
77  CounterVariable *m_loop_time;
78  Clock *m_clock;
79  TimeStamp m_wake_up_time;
80 
81  DescriptorMap m_descriptor_map;
82  OrphanedDescriptors m_orphaned_descriptors;
83 
84  std::pair<WindowsPollerDescriptor*, bool>
85  LookupOrCreateDescriptor(void* handle);
86  bool RemoveDescriptor(const DescriptorHandle &handle,
87  int flag,
88  bool warn_on_missing);
89 
90  void HandleWakeup(class PollData* data);
91  void FinalCheckIOs(std::vector<class PollData*> data);
92 
93  DISALLOW_COPY_AND_ASSIGN(WindowsPoller);
94 };
95 } // namespace io
96 } // namespace ola
97 #endif // COMMON_IO_WINDOWSPOLLER_H_