2004-04-11 14:58:08 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2004 Chris Schoeneman
|
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "COSXEventQueueBuffer.h"
|
2004-05-15 19:41:46 +00:00
|
|
|
#include "CEvent.h"
|
|
|
|
#include "IEventQueue.h"
|
|
|
|
|
|
|
|
//
|
|
|
|
// CEventQueueTimer
|
|
|
|
//
|
|
|
|
|
|
|
|
class CEventQueueTimer { };
|
2004-04-11 14:58:08 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// COSXEventQueueBuffer
|
|
|
|
//
|
|
|
|
|
2004-05-15 19:41:46 +00:00
|
|
|
COSXEventQueueBuffer::COSXEventQueueBuffer() :
|
|
|
|
m_event(NULL)
|
2004-04-11 14:58:08 +00:00
|
|
|
{
|
2004-05-15 19:41:46 +00:00
|
|
|
// do nothing
|
2004-04-11 14:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
COSXEventQueueBuffer::~COSXEventQueueBuffer()
|
|
|
|
{
|
2004-05-15 19:41:46 +00:00
|
|
|
setOSXEvent(NULL);
|
2004-04-11 14:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
COSXEventQueueBuffer::waitForEvent(double timeout)
|
|
|
|
{
|
|
|
|
EventRef event;
|
|
|
|
ReceiveNextEvent(0, NULL, timeout, false, &event);
|
|
|
|
}
|
|
|
|
|
|
|
|
IEventQueueBuffer::Type
|
|
|
|
COSXEventQueueBuffer::getEvent(CEvent& event, UInt32& dataID)
|
|
|
|
{
|
2004-05-15 19:41:46 +00:00
|
|
|
EventRef carbonEvent = NULL;
|
|
|
|
OSStatus error = ReceiveNextEvent(0, NULL, 0.0, true, &carbonEvent);
|
|
|
|
setOSXEvent(carbonEvent);
|
|
|
|
|
|
|
|
if (error == eventLoopQuitErr) {
|
|
|
|
event = CEvent(CEvent::kQuit);
|
|
|
|
return kSystem;
|
|
|
|
}
|
|
|
|
else if (error != noErr) {
|
|
|
|
return kNone;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
UInt32 eventClass = GetEventClass(m_event);
|
|
|
|
switch (eventClass) {
|
|
|
|
case 'Syne':
|
|
|
|
dataID = GetEventKind(m_event);
|
|
|
|
return kUser;
|
|
|
|
|
|
|
|
default:
|
|
|
|
event = CEvent(CEvent::kSystem,
|
|
|
|
IEventQueue::getSystemTarget(), &m_event);
|
|
|
|
return kNone;
|
|
|
|
}
|
|
|
|
}
|
2004-04-11 14:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
COSXEventQueueBuffer::addEvent(UInt32 dataID)
|
|
|
|
{
|
2004-05-15 19:41:46 +00:00
|
|
|
EventRef event;
|
|
|
|
OSStatus error = CreateEvent(
|
|
|
|
kCFAllocatorDefault,
|
|
|
|
'Syne',
|
|
|
|
dataID,
|
|
|
|
0,
|
|
|
|
kEventAttributeNone,
|
|
|
|
&event);
|
|
|
|
|
|
|
|
if (error == noErr) {
|
|
|
|
error = PostEventToQueue(GetMainEventQueue(), event,
|
|
|
|
kEventPriorityStandard);
|
|
|
|
ReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error == noErr);
|
2004-04-11 14:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
COSXEventQueueBuffer::isEmpty() const
|
|
|
|
{
|
|
|
|
EventRef event;
|
|
|
|
OSStatus status = ReceiveNextEvent(0, NULL, 0.0, false, &event);
|
2004-05-15 19:41:46 +00:00
|
|
|
return (status == eventLoopTimedOutErr);
|
2004-04-11 14:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CEventQueueTimer*
|
2004-05-15 19:41:46 +00:00
|
|
|
COSXEventQueueBuffer::newTimer(double, bool) const
|
2004-04-11 14:58:08 +00:00
|
|
|
{
|
2004-05-15 19:41:46 +00:00
|
|
|
return new CEventQueueTimer;
|
2004-04-11 14:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-05-15 19:41:46 +00:00
|
|
|
COSXEventQueueBuffer::deleteTimer(CEventQueueTimer* timer) const
|
|
|
|
{
|
|
|
|
delete timer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
COSXEventQueueBuffer::setOSXEvent(EventRef event)
|
2004-04-11 14:58:08 +00:00
|
|
|
{
|
2004-05-15 19:41:46 +00:00
|
|
|
if (m_event != NULL) {
|
|
|
|
ReleaseEvent(m_event);
|
|
|
|
}
|
|
|
|
m_event = RetainEvent(event);
|
2004-04-11 14:58:08 +00:00
|
|
|
}
|