Changeset 2761 for trunk/synergy/lib/platform/CPMEventQueueBuffer.cpp
- Timestamp:
- Aug 13, 2006, 1:41:05 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/synergy/lib/platform/CPMEventQueueBuffer.cpp
r2755 r2761 16 16 #include "CPMEventQueueBuffer.h" 17 17 #include "CThread.h" 18 #include "CLog.h" 18 19 #include "IEventQueue.h" 20 #include "CPMUtil.h" 21 #include <unistd.h> 19 22 20 23 // … … 31 34 CPMEventQueueBuffer::CPMEventQueueBuffer() 32 35 { 33 // remember the queue (/ thread / hab). we'll be posting messages to it. 34 m_hab = WinInitialize(0); 35 m_hmq = WinCreateMsgQueue(m_hab, 0); 36 assert(m_hmq != NULLHANDLE); 36 // the anchor block. Remeber it for use when waiting, peeking, and getting events. 37 m_hab = NULLHANDLE; 38 PTIB pTib; 39 PPIB pPib; 40 DosGetInfoBlocks(&pTib, &pPib); 41 LOG((CLOG_DEBUG2 "CPMEventQueueBuffer: ultype=%lx tid=%lx", pPib->pib_ultype, pTib->tib_ptib2->tib2_ultid)); 42 if (pPib->pib_ultype != 3) { 43 pPib->pib_ultype = 3; 44 m_shallTerminate = true; 45 m_hab = WinInitialize(0); 46 } 47 if (m_hab == NULLHANDLE) { 48 m_hab = CPMUtil::getHAB(); 49 if (m_hab == NULLHANDLE) { 50 m_shallTerminate = true; 51 m_hab = WinInitialize(0); 52 } 53 } 54 55 // the message queue. remember it so we can post and get messages. 56 m_hmq = CPMUtil::getHMQ(m_hab); 57 if (m_hmq == NULLHANDLE) { 58 m_shallDestroyMsgQueue = true; 59 m_hmq = WinCreateMsgQueue(m_hab, 0); 60 } 61 62 // check that we succeeded the two previous steps. 63 if (m_hab == NULLHANDLE || m_hmq == NULLHANDLE) { 64 LOG((CLOG_CRIT "couldn't get the hab(%lx)/hmq(%lx) of the current thread!", m_hab, m_hmq)); 65 assert(m_hab != NULLHANDLE && m_hmq != NULLHANDLE); 66 } 67 assert(CPMUtil::getHAB() == m_hab); 37 68 38 69 // create a message type for custom events … … 46 77 APIRET rc = DosCreateEventSem(NULL, &m_hev, 0, FALSE); 47 78 assert(rc == NO_ERROR); 79 LOG((CLOG_DEBUG2 "CPMEventQueueBuffer: m_userEvent=%#lx m_daemonQuit=%#lx m_hev=%#lx m_hab=%#lx m_hmq=%#lx m_shallTermiate=%d m_shallDestroyMsgQueue=%d", 80 m_userEvent, m_daemonQuit, m_hev, m_hab, m_hmq, m_shallTerminate, m_shallDestroyMsgQueue)); 48 81 } 49 82 … … 52 85 // do nothing 53 86 DosCloseEventSem(m_hev); 54 WinDestroyMsgQueue(m_hmq); 55 WinTerminate(m_hab); 87 if (m_shallDestroyMsgQueue) { 88 WinDestroyMsgQueue(m_hmq); 89 } 90 if (m_shallTerminate) { 91 WinTerminate(m_hab); 92 } 56 93 } 57 94 … … 62 99 ULONG fStatus = WinQueryQueueStatus(HWND_DESKTOP); 63 100 if (!fStatus) { 101 ULONG cPosts; 102 DosResetEventSem(m_hev, &cPosts); 103 fStatus = WinQueryQueueStatus(HWND_DESKTOP); 104 } 105 LOG((CLOG_DEBUG2 "waitForEvent: %#lx", fStatus)); 106 if (!fStatus) { 64 107 // convert timeout and wait. 65 108 ULONG ulPMTimeout = timeout < 0.0 … … 67 110 : (ULONG)(1000.0 * timeout); 68 111 WinWaitEventSem(m_hev, ulPMTimeout); 112 LOG((CLOG_DEBUG2 "waitForEvent: ulPMTimeout=%ld", ulPMTimeout)); 69 113 } 70 114 } … … 76 120 QMSG qmsg; 77 121 if (!WinPeekMsg(m_hab, &qmsg, NULLHANDLE, 0, 0, PM_NOREMOVE)) { 122 LOG((CLOG_DEBUG2 "getEvent: kNone")); 78 123 return kNone; 79 124 } … … 88 133 if (m_event.msg == m_userEvent) { 89 134 dataID = (UInt32)(uintptr_t)m_event.mp1; 135 LOG((CLOG_DEBUG2 "getEvent: dataID=%#x", dataID)); 90 136 return kUser; 91 137 } 92 138 93 139 event = CEvent(CEvent::kSystem, IEventQueue::getSystemTarget(), &m_event); 140 LOG((CLOG_DEBUG2 "getEvent: kSystem")); 94 141 return kSystem; 95 142 } … … 98 145 CPMEventQueueBuffer::addEvent(UInt32 dataID) 99 146 { 100 return WinPostQueueMsg(m_hmq, m_userEvent, (MPARAM)dataID, 0) != FALSE; 147 LOG((CLOG_DEBUG2 "addEvent: dataID=%#x", dataID)); 148 BOOL fRc = WinPostQueueMsg(m_hmq, m_userEvent, (MPARAM)dataID, 0) != FALSE; 149 if (fRc) { 150 DosPostEventSem(m_hev); 151 } else { 152 LOG((CLOG_CRIT "addEvent: dataID=%#x fRc=%d lasterr=%d", dataID, WinGetLastError(CPMUtil::getHAB()))); 153 } 154 return fRc; 101 155 } 102 156 … … 105 159 { 106 160 ULONG fStatus = WinQueryQueueStatus(HWND_DESKTOP); 107 return fStatus != 0; 161 LOG((CLOG_DEBUG2 "isEmpty: %#lx", fStatus)); 162 return fStatus == 0; 108 163 } 109 164
Note:
See TracChangeset
for help on using the changeset viewer.