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

panda/src/event/eventQueue.cxx

Go to the documentation of this file.
00001 // Filename: eventQueue.cxx
00002 // Created by:  drose (08Feb99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "eventQueue.h"
00020 #include "config_event.h"
00021 
00022 EventQueue *EventQueue::_global_event_queue = NULL;
00023 
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //     Function: EventQueue::Constructor
00027 //       Access: Public
00028 //  Description:
00029 ////////////////////////////////////////////////////////////////////
00030 EventQueue::
00031 EventQueue() {
00032 }
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //     Function: EventQueue::Destructor
00036 //       Access: Public
00037 //  Description:
00038 ////////////////////////////////////////////////////////////////////
00039 EventQueue::
00040 ~EventQueue() {
00041 }
00042 
00043 ////////////////////////////////////////////////////////////////////
00044 //     Function: EventQueue::queue_event
00045 //       Access: Public
00046 //  Description:
00047 ////////////////////////////////////////////////////////////////////
00048 void EventQueue::
00049 queue_event(CPT_Event event) {
00050 #ifdef OLD_HAVE_IPC
00051   mutex_lock lock(_lock);
00052 #endif
00053   if (_queue.full()) {
00054     event_cat.error()
00055       << "Ignoring event " << *event << "; event queue full.\n";
00056   } else {
00057     _queue.push_back(event);
00058     if (event_cat.is_spam() || event_cat.is_debug()) {
00059       if (event->get_name() == "NewFrame") {
00060         // Don't bother us with this particularly spammy event.
00061         event_cat.spam()
00062           << "Throwing event " << *event << "\n";
00063       } else {
00064         event_cat.debug()
00065           << "Throwing event " << *event << "\n";
00066       }
00067     }
00068   }
00069 }
00070 
00071 ////////////////////////////////////////////////////////////////////
00072 //     Function: EventQueue::clear
00073 //       Access: Public
00074 //  Description: Empties all events on the queue, throwing them on the
00075 //               floor.
00076 ////////////////////////////////////////////////////////////////////
00077 void EventQueue::
00078 clear() {
00079   while (!_queue.empty()) {
00080     _queue.pop_front();
00081   }
00082 }
00083 
00084 
00085 ////////////////////////////////////////////////////////////////////
00086 //     Function: EventQueue::is_queue_empty
00087 //       Access: Public
00088 //  Description:
00089 ////////////////////////////////////////////////////////////////////
00090 bool EventQueue::
00091 is_queue_empty() const {
00092   return _queue.empty();
00093 }
00094 
00095 bool EventQueue::
00096 is_queue_full() const {
00097   return _queue.full();
00098 }
00099 
00100 
00101 ////////////////////////////////////////////////////////////////////
00102 //     Function: EventQueue::dequeue_event
00103 //       Access: Public
00104 //  Description:
00105 ////////////////////////////////////////////////////////////////////
00106 CPT_Event EventQueue::
00107 dequeue_event() {
00108   // We need no mutex protection here, as long as there is only one
00109   // thread extracting events.  The magic of circular buffers.
00110   CPT_Event result = _queue.front();
00111   _queue.pop_front();
00112   return result;
00113 }
00114 
00115 ////////////////////////////////////////////////////////////////////
00116 //     Function: EventQueue::make_global_event_queue
00117 //       Access: Protected, Static
00118 //  Description:
00119 ////////////////////////////////////////////////////////////////////
00120 void EventQueue::
00121 make_global_event_queue() {
00122   _global_event_queue = new EventQueue;
00123 }

Generated on Fri May 2 00:38:17 2003 for Panda by doxygen1.3