00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "COSXEventQueueBuffer.h"
00016 #include "CEvent.h"
00017 #include "IEventQueue.h"
00018
00019
00020
00021
00022
00023 class CEventQueueTimer { };
00024
00025
00026
00027
00028
00029 COSXEventQueueBuffer::COSXEventQueueBuffer() :
00030 m_event(NULL)
00031 {
00032
00033 }
00034
00035 COSXEventQueueBuffer::~COSXEventQueueBuffer()
00036 {
00037
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
00054 if (m_event != NULL) {
00055 ReleaseEvent(m_event);
00056 m_event = NULL;
00057 }
00058
00059
00060 OSStatus error = ReceiveNextEvent(0, NULL, 0.0, true, &m_event);
00061
00062
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 }