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

threaded_event_handler.hh

00001 /*
00002 *  Name:      threaded_event_handler.hh
00003 *  Author:    Carlos Jimenez Moreno
00004 *             Rafael Jesus Alcantara Perez
00005 *  Summary:   Threaded Event Handler
00006 *  Date:      $Date: 2003/10/06 12:45:11 $
00007 *  Revision:  $Revision: 1.2 $
00008 *
00009 *  Copyright (C) 1999       Carlos Jimenez Moreno <carlosj@dedalo-ing.com>
00010 *  Copyright (C) 2002-2003  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00011 *
00012 *  This program is free software; you can redistribute it and/or modify
00013 *  it under the terms of the GNU General Public License as published by
00014 *  the Free Software Foundation; either version 2 of the License, or
00015 *  (at your option) any later version.
00016 *
00017 *  This program is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  You should have received a copy of the GNU General Public License
00023 *  along with this program; if not, write to the Free Software
00024 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00025 *  MA 02111-1307, USA.
00026 */
00027 
00028 
00029 #ifndef _MPCL_EVENT_THREADED_EVENT_HANDLER__
00030 #define _MPCL_EVENT_THREADED_EVENT_HANDLER__
00031 
00032 #include <mpcl/event/event_handler.hh>
00033 #include <mpcl/system/all.hh>
00034 
00035 
00037 namespace mpcl
00038 {
00039 
00041   namespace event
00042   {
00043 
00049     template <typename TEvent>
00050     class TThreadedEventHandler      :
00051         public TEventHandler<TEvent> ,
00052         public mpcl::system::TThread
00053     {
00054 
00055       private:
00056 
00061         mutable mpcl::system::TMutex   tMutex;
00062 
00063         
00064       public:
00065 
00066         //
00067         // C O N S T R U C T O R S
00068         //
00069 
00071         TThreadedEventHandler (void) :
00072           TEventHandler<TEvent> ()   ,
00073           TThread               ()   ,
00074           tMutex                ()   {}
00075 
00081         TEvent pop (void)
00082         {
00083           TEvent   tEvent;
00084 
00085           tMutex.lock();
00086           tEvent = TEventHandler<TEvent>::pop();
00087           tMutex.unlock();
00088           return tEvent;
00089         }
00090 
00096         void push (const TEvent& rktSOURCE_EVENT)
00097         {
00098           tMutex.lock();
00099           TEventHandler<TEvent>::push (rktSOURCE_EVENT);
00100           tMutex.unlock();
00101         }
00102 
00103 
00104       public:
00105 
00106         //
00107         //  S E L E C T O R S
00108         //
00109 
00115         bool isEmpty (void) const
00116         {
00117           bool   gIsEmpty;
00118   
00119           tMutex.lock();
00120           gIsEmpty = TEventHandler<TEvent>::isEmpty();
00121           tMutex.unlock();
00122           return gIsEmpty;
00123         }
00124 
00125     };  // TThreadedEventHandler
00126     
00127   }  // namespace event
00128 
00129 }  // namespace mpcl
00130 
00131 
00132 #endif  // not _MPCL_EVENT_THREADED_EVENT_HANDLER__

Generated on Mon Oct 13 02:35:24 2003 for MPCL by doxygen1.2.18