19SerialPollThread::SerialPollThread(
const char_t *_name)
25SerialPollThread::~SerialPollThread()
27 CloseHandle(__pollInterrupt);
30bool SerialPollThread::add(
PollAble* _pPollAble,
short _events)
46 if (!SetCommMask(_pPollAble->
handle(), (DWORD)_events)) {
47 CloseHandle(((
SerialPort*)_pPollAble)->__overlapped.hEvent);
51 __updateList.add(Update(_pPollAble,
true));
55 SetEvent(__pollInterrupt);
60bool SerialPollThread::remove(
PollAble* _pPollAble)
67 __updateList.add(Update(_pPollAble,
false));
71 SetEvent(__pollInterrupt);
76void SerialPollThread::terminate()
80 SetEvent(__pollInterrupt);
83int SerialPollThread::run()
89 fds.
add(__pollInterrupt);
91 while (!__terminate) {
94 if (!__updateList.isEmpty()) {
95 ResetEvent(__pollInterrupt);
96 for (UpdateList::Iterator itUpdate = __updateList.begin();
97 itUpdate != __updateList.end(); itUpdate++) {
98 Update& update = *itUpdate;
101 if (((
SerialPort*) update.pPollAble)->waitCommEvent()) {
103 update.pPollAble->toString().data());
105 fds.
add(((
SerialPort*) update.pPollAble)->__overlapped.hEvent);
108 onRemoved(update.pPollAble);
111 Array<SerialPort*>::Iterator itPollAble =
113 if (itPollAble != pollAbles.
end()) {
115 update.pPollAble->toString().data());
116 onRemoved(*itPollAble);
117 pollAbles.
erase(itPollAble);
122 __updateList.clear();
128 DWORD
r = WaitForMultipleObjects(
146 ResetEvent(__pollInterrupt);
149 size_t index =
r - WAIT_OBJECT_0;
165 if (pSerialPort->
onEvent((
short)(pSerialPort->__revents),
this))
166 pSerialPort->waitCommEvent();
189 for (Array<SerialPort*>::Iterator itPollAble = pollAbles.
begin();
190 itPollAble != pollAbles.
end(); itPollAble++) {
192 if (*itPollAble !=
NULL) {
194 (*itPollAble)->toString().data());
195 onRemoved(*itPollAble);
200 for (UpdateList::Iterator itUpdate = __updateList.begin();
201 itUpdate != __updateList.end(); itUpdate++) {
202 Update& update = *itUpdate;
205 update.pPollAble->toString().data());
206 onRemoved(update.pPollAble);
#define __DCL_TRACE1(fmt, arg1)
#define CLASSINFO(class_name)
#define __DCL_ASSERT(expr)
#define IMPLEMENT_CLASSINFO(class_name, base_class_name)
__DCL_BEGIN_NAMESPACE typedef PollThread SerialPollThread
Iterator erase(Iterator _pos)
ConstIterator end() const
Iterator find(const ELEMENT &_element)
Array< ELEMENT > & add(const ELEMENT &_element)
ConstIterator begin() const
size_t index(Iterator _pos) const
HandleType handle() const
virtual String toString() const
virtual String toString() const
virtual bool onEvent(short _revents, PollThread *_pPollThread) __DCL_THROWS1(IOException *)
static void sleep(unsigned int _mills)
static Thread * getCurrentThread()
SingleLock< Mutex > SingleLockMutex