#include <vpr/IO/Selector.h>
Inheritance diagram for vpr::SelectorImplSIM:


Public Member Functions | |
| bool | addHandle (vpr::IOSys::Handle handle, vpr::Uint16 mask=0) |
| Adds the given handle to the selector. | |
| bool | removeHandle (vpr::IOSys::Handle handle) |
| Removes a handle from the selector. | |
| bool | setIn (vpr::IOSys::Handle handle, vpr::Uint16 mask) |
| Sets the event flags going in to the select to mask. | |
| vpr::Uint16 | getIn (vpr::IOSys::Handle handle) |
| Gets the current in-flag mask. | |
| vpr::Uint16 | getOut (vpr::IOSys::Handle handle) |
| Gets the current "out flag" mask after a call to select. | |
| vpr::ReturnStatus | select (vpr::Uint16 &numWithEvents, const vpr::Interval timeout=vpr::Interval::NoTimeout) |
| Poll for any ready events among the registered handles using their in flags. | |
| vpr::Uint16 | getNumHandles () |
| For iteration over the registered handles. | |
| vpr::IOSys::Handle | getHandle (vpr::Uint16 index) |
| Gets the handle at the given index within the collection of registered handles. | |
| bool | containsHandle (vpr::IOSys::Handle handle) |
| Tests if the selector contain the given handle. | |
Protected Member Functions | |
| std::vector< SimPollDesc >::iterator | getHandle (vpr::IOSys::Handle handle) |
| Gets the index of the handle given. | |
Protected Attributes | |
| std::vector< SimPollDesc > | mPollDescs |
| List of poll descriptors to pass to select. | |
Classes | |
| struct | SimPollDesc |
| Simple type used for the vector of poll descriptors. More... | |
This is typedef'd to vpr::Selector.
Implementation site of the vpr::Selector_t bridge.
Definition at line 65 of file SelectorImplSIM.h.
| bool vpr::SelectorImplSIM::addHandle | ( | vpr::IOSys::Handle | handle, | |
| vpr::Uint16 | mask = 0 | |||
| ) |
Adds the given handle to the selector.
handle is a valid handle.
handle is added to the handle set, and its mask is initialized using the given value.
| handle | The handle to be added to the selector's handle set. | |
| mask | The mask used when checking for ready events on the given handle. This argument is optional and defaults to 0 (no events). |
true is returned if the given handle is added successfully; false otherwise. Definition at line 51 of file SelectorImplSIM.cpp.
References getHandle(), and mPollDescs.
00052 { 00053 bool status; 00054 00055 if ( getHandle(handle) == mPollDescs.end() ) 00056 { 00057 SimPollDesc new_desc; 00058 new_desc.fd = handle; 00059 new_desc.in_flags = mask; 00060 new_desc.out_flags = 0; 00061 00062 mPollDescs.push_back(new_desc); 00063 status = true; 00064 } 00065 else 00066 { 00067 status = false; 00068 } 00069 00070 return status; 00071 }
| bool vpr::SelectorImplSIM::removeHandle | ( | vpr::IOSys::Handle | handle | ) |
Removes a handle from the selector.
handle is in the selector. handle is removed from the set of valid handles.| handle | The handle to be removed from the selector's handle set. |
true is returned if the given handle is removed successfully; false otherwise. Definition at line 73 of file SelectorImplSIM.cpp.
References getHandle(), and mPollDescs.
00074 { 00075 bool status; 00076 std::vector<SimPollDesc>::iterator i = getHandle(handle); 00077 00078 if ( mPollDescs.end() == i ) 00079 { 00080 status = false; 00081 } 00082 else 00083 { 00084 mPollDescs.erase(i); 00085 status = true; 00086 } 00087 00088 return status; 00089 }
| bool vpr::SelectorImplSIM::setIn | ( | vpr::IOSys::Handle | handle, | |
| vpr::Uint16 | mask | |||
| ) |
Sets the event flags going in to the select to mask.
handle has already been registered with this selector. handle has its mask updated to use the given value.| handle | The handle whose mask will be set. | |
| mask | The mask used when checking for ready events on the given handle. |
Definition at line 91 of file SelectorImplSIM.cpp.
References getHandle(), and mPollDescs.
00092 { 00093 bool status; 00094 std::vector<SimPollDesc>::iterator i = getHandle(handle); 00095 00096 if ( mPollDescs.end() == i ) 00097 { 00098 status = false; 00099 } 00100 else 00101 { 00102 (*i).in_flags = mask; 00103 status = true; 00104 } 00105 00106 return status; 00107 }
| vpr::Uint16 vpr::SelectorImplSIM::getIn | ( | vpr::IOSys::Handle | handle | ) |
Gets the current in-flag mask.
handle has already been added to the selector using addHandle.| handle | The handle whose "in" event flags will be returned. |
handle. Definition at line 109 of file SelectorImplSIM.cpp.
References getHandle(), and mPollDescs.
00110 { 00111 vpr::Uint16 flags; 00112 std::vector<SimPollDesc>::iterator i = getHandle(handle); 00113 00114 if ( mPollDescs.end() == i ) 00115 { 00116 // XXX: This is VERY bad thing to do. Need to have an error code instead 00117 flags = 0; 00118 } 00119 else 00120 { 00121 flags = (*i).in_flags; 00122 } 00123 00124 return flags; 00125 }
| vpr::Uint16 vpr::SelectorImplSIM::getOut | ( | vpr::IOSys::Handle | handle | ) |
Gets the current "out flag" mask after a call to select.
The value returned will be the bitwise OR of the "out flags". These state which of the operations named "in flags" were found to be ready.
| handle | The handle whose "out" event flags will be returned. |
handle. These flags state which requested events were detected for handle. Definition at line 127 of file SelectorImplSIM.cpp.
References getHandle(), and mPollDescs.
00128 { 00129 vpr::Uint16 flags; 00130 std::vector<SimPollDesc>::iterator i = getHandle(handle); 00131 00132 if ( mPollDescs.end() == i ) 00133 { 00134 // XXX: This is VERY bad thing to do. Need to have an error code instead 00135 flags = 0; 00136 } 00137 else 00138 { 00139 flags = (*i).out_flags; 00140 } 00141 00142 return flags; 00143 }
| vpr::ReturnStatus vpr::SelectorImplSIM::select | ( | vpr::Uint16 & | numWithEvents, | |
| const vpr::Interval | timeout = vpr::Interval::NoTimeout | |||
| ) |
Poll for any ready events among the registered handles using their in flags.
| numWithEvents | Upon completion, this holds the number of items that have events. | |
| timeout | The interval to wait for an event to be raised. This argument is optional and defaults to vpr::Interval::NoTimeout (wait until an event is detected withotu timing out). Passing vpr::Interval::NoWait effects a poll on the registered handles and returns immediately. |
vpr::ReturnStatus::Timeout is returned if no events were detected before the timeout expired or if vpr::Interval::NoWait was passed. In this case, numWithEvents should be checked for a value greater than 0.
vpr::ReturnStatus::Failure is returned if the select failed.
Definition at line 145 of file SelectorImplSIM.cpp.
References vpr::SelectorBase::Accept, vpr::SelectorBase::Except, mPollDescs, vpr::SelectorBase::Read, vpr::ReturnStatus::setCode(), vpr::ReturnStatus::Timeout, and vpr::SelectorBase::Write.
00147 { 00148 vpr::ReturnStatus status; 00149 std::vector<SimPollDesc>::iterator i; 00150 bool has_event; 00151 00152 numWithEvents = 0; 00153 00154 for ( i = mPollDescs.begin(); i != mPollDescs.end(); ++i ) 00155 { 00156 // We have to do this every time to insure that a previous event is not 00157 // "reselected". 00158 (*i).out_flags = 0; 00159 00160 has_event = false; 00161 00162 if ( (*i).in_flags & vpr::SelectorBase::Read || 00163 (*i).in_flags & vpr::SelectorBase::Accept) 00164 { 00165 if ( (*i).fd->isReadReady().success() ) 00166 { 00167 has_event = true; 00168 (*i).out_flags |= vpr::SelectorBase::Read; 00169 } 00170 } 00171 00172 if ( (*i).in_flags & vpr::SelectorBase::Write ) 00173 { 00174 if ( (*i).fd->isWriteReady().success() ) 00175 { 00176 has_event = true; 00177 (*i).out_flags |= vpr::SelectorBase::Write; 00178 } 00179 } 00180 00181 if ( (*i).in_flags & vpr::SelectorBase::Except ) 00182 { 00183 if ( (*i).fd->inExceptState().success() ) 00184 { 00185 has_event = true; 00186 (*i).out_flags |= vpr::SelectorBase::Except; 00187 } 00188 } 00189 00190 if ( has_event ) 00191 { 00192 numWithEvents++; 00193 } 00194 } 00195 00196 if ( numWithEvents == 0 ) 00197 { 00198 status.setCode(vpr::ReturnStatus::Timeout); 00199 } 00200 00201 return status; 00202 }
| vpr::Uint16 vpr::SelectorImplSIM::getNumHandles | ( | ) | [inline] |
For iteration over the registered handles.
Definition at line 166 of file SelectorImplSIM.h.
00167 { 00168 return mPollDescs.size(); 00169 }
| vpr::IOSys::Handle vpr::SelectorImplSIM::getHandle | ( | vpr::Uint16 | index | ) | [inline] |
Gets the handle at the given index within the collection of registered handles.
The index is determined by the order of handle addition using addHandle().
| index | The index of the desired handle. |
Definition at line 181 of file SelectorImplSIM.h.
Referenced by addHandle(), getIn(), getOut(), removeHandle(), and setIn().
00182 { 00183 return mPollDescs[index].fd; 00184 }
| bool vpr::SelectorImplSIM::containsHandle | ( | vpr::IOSys::Handle | handle | ) | [inline] |
Tests if the selector contain the given handle.
| handle | The handle of interest. |
true is returned if handle was previously registered with this selector.
false is returned if the handle has not been registered.
Definition at line 195 of file SelectorImplSIM.h.
00196 { 00197 return (getHandle(handle) != mPollDescs.end()); 00198 }
| std::vector< SelectorImplSIM::SimPollDesc >::iterator vpr::SelectorImplSIM::getHandle | ( | vpr::IOSys::Handle | handle | ) | [protected] |
Gets the index of the handle given.
Otherwise, the index to the handle in mPollDescs is returned.
Definition at line 205 of file SelectorImplSIM.cpp.
References mPollDescs.
00206 { 00207 // XXX: Should probably be replaced by a map in the future for speed. 00208 00209 for ( std::vector<SimPollDesc>::iterator i=mPollDescs.begin(); 00210 i != mPollDescs.end(); 00211 ++i ) 00212 { 00213 if ( (*i).fd == handle ) 00214 { 00215 return i; 00216 } 00217 } 00218 00219 return mPollDescs.end(); 00220 }
std::vector<SimPollDesc> vpr::SelectorImplSIM::mPollDescs [protected] |
List of poll descriptors to pass to select.
Definition at line 218 of file SelectorImplSIM.h.
Referenced by addHandle(), getHandle(), getIn(), getOut(), removeHandle(), select(), and setIn().
1.5.1