#include <SelectorImplNSPR.h>
Inheritance diagram for vpr::SelectorImplNSPR:


Public Methods | |
| bool | addHandle (IOSys::Handle handle, vpr::Uint16 mask=0) |
| Adds the given handle to the selector. More... | |
| bool | removeHandle (IOSys::Handle handle) |
| Removes a handle from the selector. More... | |
| bool | setIn (IOSys::Handle handle, vpr::Uint16 mask) |
| Sets the event flags going in to the select to mask. More... | |
| vpr::Uint16 | getIn (IOSys::Handle handle) |
| Gets the current in flag mask. More... | |
| vpr::Uint16 | getOut (IOSys::Handle handle) |
| Gets the current out flag mask. More... | |
| vpr::ReturnStatus | select (vpr::Uint16 &numWithEvents, const vpr::Interval timeout=vpr::Interval::NoTimeout) |
| Select. More... | |
| vpr::Uint16 | getNumHandles () |
| Gets the number of handles. More... | |
| IOSys::Handle | getHandle (vpr::Uint16 index) |
| bool | containsHandle (IOSys::Handle handle) |
Protected Methods | |
| std::vector< PRPollDesc >::iterator | getHandle (PRFileDesc const *handle) |
| Gets the index of the handle given. More... | |
| PRUint16 | convertMaskVprToNspr (vpr::Uint16 mask) |
| vpr::Uint16 | convertMaskNsprToVpr (PRUint16 mask) |
Protected Attributes | |
| std::vector< PRPollDesc > | mPollDescs |
| List of Poll Descriptions to pass to PR_Poll(). More... | |
A selector is used to wait on a set of Handles untils any of the events occur that the user is interested in.
Implementation site of the Selector_t bridge.
Definition at line 69 of file SelectorImplNSPR.h.
|
||||||||||||
|
Adds the given handle to the selector.
Definition at line 56 of file SelectorImplNSPR.cpp. References convertMaskVprToNspr, getHandle, and mPollDescs.
00057 {
00058 if(getHandle(handle) != mPollDescs.end())
00059 {
00060 return false;
00061 }
00062
00063 PRPollDesc new_desc;
00064 new_desc.fd = handle;
00065 new_desc.in_flags = convertMaskVprToNspr(mask);
00066 //new_desc.in_flags = 0;
00067 new_desc.out_flags = 0;
00068
00069 mPollDescs.push_back(new_desc);
00070
00071 return true;
00072 }
|
|
|
Removes a handle from the selector.
Definition at line 77 of file SelectorImplNSPR.cpp. References getHandle, and mPollDescs.
00078 {
00079 std::vector<PRPollDesc>::iterator i = getHandle(handle);
00080
00081 if(mPollDescs.end() == i)
00082 {
00083 return false;
00084 }
00085 else
00086 {
00087 mPollDescs.erase(i);
00088 return true;
00089 }
00090 }
|
|
||||||||||||
|
Sets the event flags going in to the select to mask.
Definition at line 95 of file SelectorImplNSPR.cpp. References convertMaskVprToNspr, getHandle, and mPollDescs.
00096 {
00097 std::vector<PRPollDesc>::iterator i = getHandle(handle);
00098
00099 if(mPollDescs.end() == i)
00100 {
00101 return false;
00102 }
00103
00104 (*i).in_flags = convertMaskVprToNspr(mask);
00105
00106 return true;
00107 }
|
|
|
Gets the current in flag mask.
Definition at line 112 of file SelectorImplNSPR.cpp. References convertMaskNsprToVpr, getHandle, and mPollDescs.
00113 {
00114 std::vector<PRPollDesc>::iterator i = getHandle(handle);
00115
00116 if(mPollDescs.end() == i)
00117 {
00118 // XXX: This is VERY bad thing to do. Need to have an error code instead
00119 return 0;
00120 }
00121
00122 return convertMaskNsprToVpr((*i).in_flags);
00123 }
|
|
|
Gets the current out flag mask.
Definition at line 128 of file SelectorImplNSPR.cpp. References convertMaskNsprToVpr, getHandle, and mPollDescs.
00129 {
00130 std::vector<PRPollDesc>::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 return 0;
00136 }
00137
00138 return convertMaskNsprToVpr((*i).out_flags);
00139 }
|
|
||||||||||||
|
Select.
Definition at line 144 of file SelectorImplNSPR.cpp. References mPollDescs, vpr::NSPR_getInterval, and vpr::ReturnStatus::setCode.
00145 {
00146 vpr::ReturnStatus ret_val;
00147
00148 PRInt32 result;
00149
00150 // Call poll - If timeout == 0, then make sure we pass 0
00151 result = PR_Poll(&(mPollDescs[0]), mPollDescs.size(), NSPR_getInterval(timeout) );
00152
00153 if( -1 == result)
00154 {
00155 //NSPR_PrintError("SelectorImplNSPR::select: Error selecting. ");
00156 vpr::Error::outputCurrentError(std::cerr, "SelectorImplNSPR::select: Error selecting.");
00157 numWithEvents = 0;
00158 ret_val.setCode(ReturnStatus::Fail);
00159 }
00160 else if(0 == result) // Timeout
00161 {
00162 numWithEvents = 0;
00163 ret_val.setCode(ReturnStatus::Timeout);
00164 }
00165 //else // Got some
00166
00167 numWithEvents = result;
00168 return ret_val;
00169 }
|
|
|
Gets the number of handles.
Definition at line 121 of file SelectorImplNSPR.h.
00122 {
00123 return mPollDescs.size();
00124 }
|
|
|
Definition at line 126 of file SelectorImplNSPR.h. Referenced by addHandle, getIn, getOut, removeHandle, and setIn.
00127 {
00128 return mPollDescs[index].fd;
00129 }
|
|
|
Definition at line 131 of file SelectorImplNSPR.h.
00132 {
00133 return (getHandle(handle) != mPollDescs.end());
00134 }
|
|
|
Gets the index of the handle given.
Definition at line 174 of file SelectorImplNSPR.cpp. References mPollDescs.
00175 {
00176 // XXX: Should probably be replaced by a map in the future for speed
00177
00178 for(std::vector<PRPollDesc>::iterator i=mPollDescs.begin();
00179 i != mPollDescs.end();++i)
00180 {
00181 if((*i).fd == handle)
00182 return i;
00183 }
00184
00185 return mPollDescs.end();
00186 }
|
|
|
Definition at line 189 of file SelectorImplNSPR.cpp. References vpr::SelectorBase::Error, vpr::SelectorBase::Except, vpr::SelectorBase::Invalid, vpr::SelectorBase::Read, and vpr::SelectorBase::Write. Referenced by addHandle, and setIn.
00190 {
00191 PRUint16 ret_mask(0);
00192 if(mask & Read)
00193 ret_mask |= PR_POLL_READ;
00194 if(mask & Write)
00195 ret_mask |= PR_POLL_WRITE;
00196 if(mask & Except)
00197 ret_mask |= PR_POLL_EXCEPT;
00198 if(mask & Error)
00199 ret_mask |= PR_POLL_ERR;
00200 if(mask & Invalid)
00201 ret_mask |= PR_POLL_NVAL;
00202
00203 return ret_mask;
00204 }
|
|
|
Definition at line 206 of file SelectorImplNSPR.cpp. References vpr::SelectorBase::Error, vpr::SelectorBase::Except, vpr::SelectorBase::Invalid, vpr::SelectorBase::Read, and vpr::SelectorBase::Write. Referenced by getIn, and getOut.
00207 {
00208 vpr::Uint16 ret_mask(0);
00209 if(mask & PR_POLL_READ)
00210 ret_mask |= Read;
00211 if(mask & PR_POLL_WRITE)
00212 ret_mask |= Write;
00213 if(mask & PR_POLL_EXCEPT)
00214 ret_mask |= Except;
00215 if(mask & PR_POLL_ERR)
00216 ret_mask |= Error;
00217 if(mask & PR_POLL_NVAL)
00218 ret_mask |= Invalid;
00219
00220 return ret_mask;
00221 }
|
|
|
List of Poll Descriptions to pass to PR_Poll().
Definition at line 150 of file SelectorImplNSPR.h. Referenced by addHandle, getHandle, getIn, getOut, removeHandle, select, and setIn. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002