Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Selectable.hxx
Go to the documentation of this file.
1
35#ifndef _EXECUTOR_SELECTABLE_HXX_
36#define _EXECUTOR_SELECTABLE_HXX_
37
40class Selectable : public QMember
41{
42public:
46 {
47 READ = 1,
48 WRITE = 2,
49 EXCEPT = 3,
50 };
51
53 enum Limits
54 {
56 MAX_FD = (1 << 14) - 1,
58 MAX_PRIO = (1 << 16) - 1,
59 };
60
66
73 void reset(SelectType type, int fd, unsigned priority)
74 {
76 HASSERT(fd <= MAX_FD);
77 fd_ = fd;
78 priority_ = std::min((unsigned)priority, (unsigned)MAX_PRIO);
79 }
80
82 bool is_empty() {
83 return selectType_ == 0;
84 }
85
88 unsigned priority()
89 {
90 return priority_;
91 }
92
95 {
96 return static_cast<SelectType>(selectType_);
97 }
98
101 {
102 return wakeup_;
103 }
104
106 int fd()
107 {
108 return fd_;
109 }
110
114 {
115 wakeup_ = e;
116 }
117
118private:
119 friend class ExecutorBase;
120
122 unsigned selectType_ : 2;
124 unsigned fd_ : 14;
127 unsigned priority_ : 16;
131};
132
133#endif // _EXECUTOR_SELECTABLE_HXX_
An object that can be scheduled on an executor to run.
This class implements an execution of tasks pulled off an input queue.
Definition Executor.hxx:64
Essentially a "next" pointer container.
Definition QMember.hxx:42
Handler structure that ExecutorBase knows about each entry to the select call.
Limits
Helper declarations for the certain fields' maximums.
@ MAX_PRIO
Largest priority we accept (otherwise we clip).
@ MAX_FD
Largest FD we accept (otherwise crash with error).
Executable * parent()
Selectable(Executable *parent)
Constructor.
SelectType type()
void reset(SelectType type, int fd, unsigned priority)
Re-initialize a Selectable preparing to add it to select().
void set_wakeup(Executable *e)
Can be used to override the executable to wake up.
unsigned priority_
When the select condition is met, the Executable will be scheduled at this priority.
unsigned selectType_
What to watch the file for. See SelectType.
unsigned fd_
File descriptor to watch.
unsigned priority()
Executable * wakeup_
This executable will be scheduled on the executor when the select condition is met.
SelectType
Which operation this file should be selected upon.
bool is_empty()
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
Definition macros.h:138