Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

COSXEventQueueBuffer.cpp

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2004 Chris Schoeneman
00004  * 
00005  * This package is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * found in the file COPYING that should have accompanied this file.
00008  * 
00009  * This package is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #include "COSXEventQueueBuffer.h"
00016 #include "CEvent.h"
00017 #include "IEventQueue.h"
00018 
00019 //
00020 // CEventQueueTimer
00021 //
00022 
00023 class CEventQueueTimer { };
00024 
00025 //
00026 // COSXEventQueueBuffer
00027 //
00028 
00029 COSXEventQueueBuffer::COSXEventQueueBuffer() :
00030     m_event(NULL)
00031 {
00032     // do nothing
00033 }
00034 
00035 COSXEventQueueBuffer::~COSXEventQueueBuffer()
00036 {
00037     // release the last event
00038     if (m_event != NULL) {
00039         ReleaseEvent(m_event);
00040     }
00041 }
00042 
00043 void
00044 COSXEventQueueBuffer::waitForEvent(double timeout)
00045 {
00046     EventRef event;
00047     ReceiveNextEvent(0, NULL, timeout, false, &event);
00048 }
00049 
00050 IEventQueueBuffer::Type
00051 COSXEventQueueBuffer::getEvent(CEvent& event, UInt32& dataID)
00052 {
00053     // release the previous event
00054     if (m_event != NULL) {
00055         ReleaseEvent(m_event);
00056         m_event = NULL;
00057     }
00058 
00059     // get the next event
00060     OSStatus error = ReceiveNextEvent(0, NULL, 0.0, true, &m_event);
00061 
00062     // handle the event
00063     if (error == eventLoopQuitErr) {
00064         event = CEvent(CEvent::kQuit);
00065         return kSystem;
00066     }
00067     else if (error != noErr) {
00068         return kNone;
00069     }
00070     else {
00071         UInt32 eventClass = GetEventClass(m_event);
00072         switch (eventClass) {
00073         case 'Syne': 
00074             dataID = GetEventKind(m_event);
00075             return kUser;
00076 
00077         default: 
00078             event = CEvent(CEvent::kSystem,
00079                         IEventQueue::getSystemTarget(), &m_event);
00080             return kSystem;
00081         }
00082     }
00083 }
00084 
00085 bool
00086 COSXEventQueueBuffer::addEvent(UInt32 dataID)
00087 {
00088     EventRef event;
00089     OSStatus error = CreateEvent( 
00090                             kCFAllocatorDefault,
00091                             'Syne', 
00092                             dataID,
00093                             0,
00094                             kEventAttributeNone,
00095                             &event);
00096 
00097     if (error == noErr) {
00098         error = PostEventToQueue(GetMainEventQueue(), event, 
00099                             kEventPriorityStandard);
00100         ReleaseEvent(event);
00101     }
00102     
00103     return (error == noErr);
00104 }
00105 
00106 bool
00107 COSXEventQueueBuffer::isEmpty() const
00108 {
00109     EventRef event;
00110     OSStatus status = ReceiveNextEvent(0, NULL, 0.0, false, &event);
00111     return (status == eventLoopTimedOutErr);
00112 }
00113 
00114 CEventQueueTimer*
00115 COSXEventQueueBuffer::newTimer(double, bool) const
00116 {
00117     return new CEventQueueTimer;
00118 }
00119 
00120 void
00121 COSXEventQueueBuffer::deleteTimer(CEventQueueTimer* timer) const
00122 {
00123     delete timer;
00124 }

Generated on Fri Nov 6 00:21:14 2009 for synergy-plus by  doxygen 1.3.9.1