Open Lighting Architecture  Latest Git
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 <ola/win/CleanWindows.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_
A time interval, with usecond accuracy.
Definition: Clock.h:138
Manages timer events.
Definition: TimeoutManager.h:45
A container for the exported variables.
Definition: ExportMap.h:324
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition: Descriptor.h:282
bool Poll(TimeoutManager *timeout_manager, const TimeInterval &poll_interval)
Poll the Descriptors for events and execute any callbacks.
Definition: WindowsPoller.cpp:287
Definition: ExportMap.h:176
Export variables on the http server.
Definition: WindowsPoller.cpp:223
bool RemoveWriteDescriptor(class WriteFileDescriptor *descriptor)
Unregister a WriteFileDescriptor for write events.
Definition: WindowsPoller.cpp:216
bool AddWriteDescriptor(class WriteFileDescriptor *descriptor)
Register a WriteFileDescriptor to receive ready-to-write events.
Definition: WindowsPoller.cpp:188
bool RemoveReadDescriptor(class ReadFileDescriptor *descriptor)
Unregister a ReadFileDescriptor for read events.
Definition: WindowsPoller.cpp:176
Used to get the current time.
Definition: Clock.h:242
WindowsPoller(ExportMap *export_map, Clock *clock)
Create a new WindowsPoller.
Definition: WindowsPoller.cpp:102
Represents a file descriptor that supports reading data.
Definition: Descriptor.h:140
bool AddReadDescriptor(class ReadFileDescriptor *descriptor)
Register a ReadFileDescriptor for read events.
Definition: WindowsPoller.cpp:133
Helper macros.
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
The interface for the Poller classes.
Definition: PollerInterface.h:70
An implementation of PollerInterface for Windows.
Definition: WindowsPoller.h:46
Represents a point in time with microsecond accuracy.
Definition: Clock.h:191
Represents a file descriptor that supports writing data.
Definition: Descriptor.h:170