Ignore:
Timestamp:
Jul 29, 2006, 6:43:07 AM (19 years ago)
Author:
bird
Message:

Two classes (CPMScreen and CPMKeyState) + the hook dll left (and debugging of course).

File:
1 copied

Legend:

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

    r2751 r2752  
    22 * synergy -- mouse and keyboard sharing utility
    33 * Copyright (C) 2004 Chris Schoeneman
     4 * Copyright (C) 2006 Knut St. Osmundsen
    45 *
    56 * This package is free software; you can redistribute it and/or
     
    1314 */
    1415
    15 #include "CMSWindowsEventQueueBuffer.h"
     16#include "CPMEventQueueBuffer.h"
    1617#include "CThread.h"
    1718#include "IEventQueue.h"
    18 #include "CArchMiscWindows.h"
    1919
    2020//
     
    2626
    2727//
    28 // CMSWindowsEventQueueBuffer
     28// CPMEventQueueBuffer
    2929//
    3030
    31 CMSWindowsEventQueueBuffer::CMSWindowsEventQueueBuffer()
     31CPMEventQueueBuffer::CPMEventQueueBuffer()
    3232{
    33         // remember thread.  we'll be posting messages to it.
    34         m_thread     = GetCurrentThreadId();
     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);
    3537
    3638        // create a message type for custom events
    37         m_userEvent  = RegisterWindowMessage("SYNERGY_USER_EVENT");
     39        m_userEvent  = WM_USER + 42 + 42 + 42;
    3840
    3941        // get message type for daemon quit
    40         m_daemonQuit = CArchMiscWindows::getDaemonQuitMessage();
     42        m_daemonQuit = WM_USER + 666;
    4143
    42         // make sure this thread has a message queue
    43         MSG dummy;
    44         PeekMessage(&dummy, NULL, WM_USER, WM_USER, PM_NOREMOVE);
     44    // create the event semaphore we'll be waiting on when waiting for messages.
     45    m_hev = NULLHANDLE;
     46    APIRET rc = DosCreateEventSem(NULL, &m_hev, 0, FALSE);
     47    assert(rc == NO_ERROR);
    4548}
    4649
    47 CMSWindowsEventQueueBuffer::~CMSWindowsEventQueueBuffer()
     50CPMEventQueueBuffer::~CPMEventQueueBuffer()
    4851{
    4952        // do nothing
     53    DosCloseEventSem(m_hev);
     54    WinDestroyMsgQueue(m_hmq);
     55    WinTerminate(m_hab);
    5056}
    5157
    5258void
    53 CMSWindowsEventQueueBuffer::waitForEvent(double timeout)
     59CPMEventQueueBuffer::waitForEvent(double timeout)
    5460{
    55         // check if messages are available first.  if we don't do this then
    56         // MsgWaitForMultipleObjects() will block even if the queue isn't
    57         // empty if the messages in the queue were there before the last
    58         // call to GetMessage()/PeekMessage().
    59         if (HIWORD(GetQueueStatus(QS_ALLINPUT)) != 0) {
    60                 return;
    61         }
    62 
    63         // convert timeout
    64         DWORD t;
    65         if (timeout < 0.0) {
    66                 t = INFINITE;
    67         }
    68         else {
    69                 t = (DWORD)(1000.0 * timeout);
    70         }
    71 
    72         // wait for a message.  we cannot be interrupted by thread
    73         // cancellation but that's okay because we're run in the main
    74         // thread and we never cancel that thread.
    75         HANDLE dummy[1];
    76         MsgWaitForMultipleObjects(0, dummy, FALSE, t, QS_ALLINPUT);
     61        // check if messages are available first.
     62    ULONG fStatus = WinQueryQueueStatus(HWND_DESKTOP);
     63    if (!fStatus) {
     64        // convert timeout and wait.
     65        ULONG ulPMTimeout = timeout < 0.0
     66                          ? SEM_INDEFINITE_WAIT
     67                          : (ULONG)(1000.0 * timeout);
     68        WinWaitEventSem(m_hev, ulPMTimeout);
     69    }
    7770}
    7871
    7972IEventQueueBuffer::Type
    80 CMSWindowsEventQueueBuffer::getEvent(CEvent& event, UInt32& dataID)
     73CPMEventQueueBuffer::getEvent(CEvent& event, UInt32& dataID)
    8174{
    82         // peek at messages first.  waiting for QS_ALLINPUT will return
    83         // if a message has been sent to our window but GetMessage will
    84         // dispatch that message behind our backs and block.  PeekMessage
    85         // will also dispatch behind our backs but won't block.
    86         if (!PeekMessage(&m_event, NULL, 0, 0, PM_NOREMOVE) &&
    87                 !PeekMessage(&m_event, (HWND)-1, 0, 0, PM_NOREMOVE)) {
     75        // peek at messages first.
     76    QMSG qmsg;
     77    if (!WinPeekMsg(m_hab, &qmsg, NULLHANDLE, 0, 0, PM_NOREMOVE)) {
    8878                return kNone;
    89         }
     79    }
    9080
    91         // BOOL.  yeah, right.
    92         BOOL result = GetMessage(&m_event, NULL, 0, 0);
    93         if (result == -1) {
    94                 return kNone;
    95         }
    96         else if (result == 0) {
     81    // get the message
     82    if (    !WinGetMsg(m_hab, &m_event, NULLHANDLE, 0, 0)
     83        ||  (m_event.msg == m_daemonQuit && m_daemonQuit != 0)) {
    9784                event = CEvent(CEvent::kQuit);
    9885                return kSystem;
    9986        }
    100         else if (m_daemonQuit != 0 && m_event.message == m_daemonQuit) {
    101                 event = CEvent(CEvent::kQuit);
    102                 return kSystem;
    103         }
    104         else if (m_event.message == m_userEvent) {
    105                 dataID = static_cast<UInt32>(m_event.wParam);
     87       
     88    if (m_event.msg == m_userEvent) {
     89                dataID = (UInt32)(uintptr_t)m_event.mp1;
    10690                return kUser;
    10791        }
    108         else {
    109                 event = CEvent(CEvent::kSystem,
    110                                                         IEventQueue::getSystemTarget(), &m_event);
    111                 return kSystem;
    112         }
     92   
     93    event = CEvent(CEvent::kSystem, IEventQueue::getSystemTarget(), &m_event);
     94    return kSystem;
    11395}
    11496
    11597bool
    116 CMSWindowsEventQueueBuffer::addEvent(UInt32 dataID)
     98CPMEventQueueBuffer::addEvent(UInt32 dataID)
    11799{
    118         return (PostThreadMessage(m_thread, m_userEvent,
    119                                                         static_cast<WPARAM>(dataID), 0) != 0);
     100    return WinPostQueueMsg(m_hmq, m_userEvent, (MPARAM)dataID, 0) != FALSE;
    120101}
    121102
    122103bool
    123 CMSWindowsEventQueueBuffer::isEmpty() const
     104CPMEventQueueBuffer::isEmpty() const
    124105{
    125         return (HIWORD(GetQueueStatus(QS_ALLINPUT)) == 0);
     106    ULONG fStatus = WinQueryQueueStatus(HWND_DESKTOP);
     107        return fStatus != 0;
    126108}
    127109
    128110CEventQueueTimer*
    129 CMSWindowsEventQueueBuffer::newTimer(double, bool) const
     111CPMEventQueueBuffer::newTimer(double, bool) const
    130112{
    131113        return new CEventQueueTimer;
     
    133115
    134116void
    135 CMSWindowsEventQueueBuffer::deleteTimer(CEventQueueTimer* timer) const
     117CPMEventQueueBuffer::deleteTimer(CEventQueueTimer* timer) const
    136118{
    137119        delete timer;
    138120}
     121
Note: See TracChangeset for help on using the changeset viewer.