00001 #include "Event.h"
00002 #include <sstream>
00003
00004 namespace FCam {
00005
00006
00007
00008 bool getNextEvent(Event *e) {
00009 pthread_mutex_lock(&EventGenerator::_eventQueueMutex);
00010 if (!EventGenerator::_eventQueue.size()) {
00011 pthread_mutex_unlock(&EventGenerator::_eventQueueMutex);
00012 return false;
00013 }
00014 *e = EventGenerator::_eventQueue.front();
00015 EventGenerator::_eventQueue.pop();
00016 pthread_mutex_unlock(&EventGenerator::_eventQueueMutex);
00017 return true;
00018 }
00019
00020 void EventGenerator::postEvent(Event e) {
00021 e.creator = this;
00022 pthread_mutex_lock(&_eventQueueMutex);
00023 _eventQueue.push(e);
00024 pthread_mutex_unlock(&_eventQueueMutex);
00025 }
00026
00027 std::string Event::description() const {
00028 return creator->getEventString(*this);
00029 }
00030
00031 std::string EventGenerator::getEventString(const Event &e) const {
00032 std::stringstream str;
00033 str << "Unknown event of type " << e.type;
00034 str << " with data " << e.iData;
00035 str << " generated by " << std::hex << ((unsigned)(e.creator));
00036 return str.str();
00037 }
00038
00039 std::queue<Event> EventGenerator::_eventQueue;
00040 pthread_mutex_t EventGenerator::_eventQueueMutex = PTHREAD_MUTEX_INITIALIZER;
00041 }
00042