Ignore:
Timestamp:
Aug 13, 2006, 1:41:05 AM (19 years ago)
Author:
bird
Message:

Hacking and debugging.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/synergy/lib/platform/CPMEventQueueBuffer.cpp

    r2755 r2761  
    1616#include "CPMEventQueueBuffer.h"
    1717#include "CThread.h"
     18#include "CLog.h"
    1819#include "IEventQueue.h"
     20#include "CPMUtil.h"
     21#include <unistd.h>
    1922
    2023//
     
    3134CPMEventQueueBuffer::CPMEventQueueBuffer()
    3235{
    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);
    3768
    3869        // create a message type for custom events
     
    4677    APIRET rc = DosCreateEventSem(NULL, &m_hev, 0, FALSE);
    4778    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));
    4881}
    4982
     
    5285        // do nothing
    5386    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    }
    5693}
    5794
     
    6299    ULONG fStatus = WinQueryQueueStatus(HWND_DESKTOP);
    63100    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) {
    64107        // convert timeout and wait.
    65108        ULONG ulPMTimeout = timeout < 0.0
     
    67110                          : (ULONG)(1000.0 * timeout);
    68111        WinWaitEventSem(m_hev, ulPMTimeout);
     112        LOG((CLOG_DEBUG2 "waitForEvent: ulPMTimeout=%ld", ulPMTimeout));
    69113    }
    70114}
     
    76120    QMSG qmsg;
    77121    if (!WinPeekMsg(m_hab, &qmsg, NULLHANDLE, 0, 0, PM_NOREMOVE)) {
     122        LOG((CLOG_DEBUG2 "getEvent: kNone"));
    78123                return kNone;
    79124    }
     
    88133    if (m_event.msg == m_userEvent) {
    89134                dataID = (UInt32)(uintptr_t)m_event.mp1;
     135        LOG((CLOG_DEBUG2 "getEvent: dataID=%#x", dataID));
    90136                return kUser;
    91137        }
    92138
    93139    event = CEvent(CEvent::kSystem, IEventQueue::getSystemTarget(), &m_event);
     140    LOG((CLOG_DEBUG2 "getEvent: kSystem"));
    94141    return kSystem;
    95142}
     
    98145CPMEventQueueBuffer::addEvent(UInt32 dataID)
    99146{
    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;
    101155}
    102156
     
    105159{
    106160    ULONG fStatus = WinQueryQueueStatus(HWND_DESKTOP);
    107         return fStatus != 0;
     161    LOG((CLOG_DEBUG2 "isEmpty: %#lx", fStatus));
     162        return fStatus == 0;
    108163}
    109164
Note: See TracChangeset for help on using the changeset viewer.