Open Lighting Architecture: common/io/SelectPoller.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
SelectPoller.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 * SelectPoller.h
17 * A Poller which uses select()
18 * Copyright (C) 2013 Simon Newton
19 */
20
21#ifndef COMMON_IO_SELECTPOLLER_H_
22#define COMMON_IO_SELECTPOLLER_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#include <map>
30#include <set>
31
32#include "common/io/PollerInterface.h"
33#include "common/io/TimeoutManager.h"
34
35namespace ola {
36namespace io {
37
43 class SelectPoller : public PollerInterface {
44 public :
50 SelectPoller(ExportMap *export_map, Clock *clock);
51
52 ~SelectPoller();
53
54 bool AddReadDescriptor(class ReadFileDescriptor *descriptor);
55 bool AddReadDescriptor(class ConnectedDescriptor *descriptor,
56 bool delete_on_close);
57 bool RemoveReadDescriptor(class ReadFileDescriptor *descriptor);
58 bool RemoveReadDescriptor(class ConnectedDescriptor *descriptor);
59
60 bool AddWriteDescriptor(class WriteFileDescriptor *descriptor);
61 bool RemoveWriteDescriptor(class WriteFileDescriptor *descriptor);
62
63 const TimeStamp *WakeUpTime() const { return &m_wake_up_time; }
64
65 bool Poll(TimeoutManager *timeout_manager,
66 const TimeInterval &poll_interval);
67
68 private:
69 typedef struct {
70 ConnectedDescriptor *descriptor;
71 bool delete_on_close;
72 } connected_descriptor_t;
73
74 typedef std::map<int, ReadFileDescriptor*> ReadDescriptorMap;
75 typedef std::map<int, WriteFileDescriptor*> WriteDescriptorMap;
76 typedef std::map<int, connected_descriptor_t*> ConnectedDescriptorMap;
77
78 ExportMap *m_export_map;
79 CounterVariable *m_loop_iterations;
80 CounterVariable *m_loop_time;
81 Clock *m_clock;
82 TimeStamp m_wake_up_time;
83
84 ReadDescriptorMap m_read_descriptors;
85 WriteDescriptorMap m_write_descriptors;
86 ConnectedDescriptorMap m_connected_read_descriptors;
87
88 void CheckDescriptors(fd_set *r_set, fd_set *w_set);
89 bool AddDescriptorsToSet(fd_set *r_set, fd_set *w_set, int *max_sd);
90
91 SelectPoller(const SelectPoller &) = delete;
92 const SelectPoller &operator=(const SelectPoller &) = delete;
93};
94} // namespace io
95} // namespace ola
96#endif // COMMON_IO_SELECTPOLLER_H_
ExportMap.h
Export variables on the http server.
Macro.h
Helper macros.
ola::Clock
Used to get the current time.
Definition Clock.h:230
ola::CounterVariable
Definition ExportMap.h:176
ola::ExportMap
A container for the exported variables.
Definition ExportMap.h:324
ola::TimeInterval
Definition Clock.h:126
ola::TimeStamp
Definition Clock.h:179
ola::io::ConnectedDescriptor
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition Descriptor.h:283
ola::io::PollerInterface
The interface for the Poller classes.
Definition PollerInterface.h:70
ola::io::ReadFileDescriptor
Represents a file descriptor that supports reading data.
Definition Descriptor.h:140
ola::io::SelectPoller::RemoveReadDescriptor
bool RemoveReadDescriptor(class ReadFileDescriptor *descriptor)
Unregister a ReadFileDescriptor for read events.
Definition SelectPoller.cpp:155
ola::io::SelectPoller::SelectPoller
SelectPoller(ExportMap *export_map, Clock *clock)
Create a new SelectPoller.
Definition SelectPoller.cpp:100
ola::io::SelectPoller::AddWriteDescriptor
bool AddWriteDescriptor(class WriteFileDescriptor *descriptor)
Register a WriteFileDescriptor to receive ready-to-write events.
Definition SelectPoller.cpp:181
ola::io::SelectPoller::Poll
bool Poll(TimeoutManager *timeout_manager, const TimeInterval &poll_interval)
Poll the Descriptors for events and execute any callbacks.
Definition SelectPoller.cpp:202
ola::io::SelectPoller::RemoveWriteDescriptor
bool RemoveWriteDescriptor(class WriteFileDescriptor *descriptor)
Unregister a WriteFileDescriptor for write events.
Definition SelectPoller.cpp:191
ola::io::SelectPoller::AddReadDescriptor
bool AddReadDescriptor(class ReadFileDescriptor *descriptor)
Register a ReadFileDescriptor for read events.
Definition SelectPoller.cpp:126
ola::io::TimeoutManager
Manages timer events.
Definition TimeoutManager.h:45
ola::io::WriteFileDescriptor
Represents a file descriptor that supports writing data.
Definition Descriptor.h:170
Descriptor.h
ola::io
Classes for general I/O and event handling.
Definition Descriptor.cpp:49
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44