00001 #ifndef _UNEVT_Event_H_ // -*- mode: c++; c-file-style: "hopper"-*- 00002 00003 /* 00004 * Copyright (C) 1991-9 Eric M. Hopper <hopper@omnifarious.mn.org> 00005 * 00006 * This program is free software; you can redistribute it and/or modify it 00007 * under the terms of the GNU Lesser General Public License as published 00008 * by the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, but 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 */ 00020 00021 #ifdef __GNUG__ 00022 # pragma interface 00023 #endif 00024 00025 /* $Header: /home/hopper/src/cvs/C++/UniEvent/UniEvent/Event.h,v 1.14 2002/08/29 00:58:05 hopper Exp $ */ 00026 00027 // For log see ../ChangeLog 00028 00029 #include <LCore/Protocol.h> 00030 #include <LCore/RefCounting.h> 00031 #ifndef _UNEVT_UNEVT_ClassIdent_H_ 00032 # include <UniEvent/UNEVT_ClassIdent.h> 00033 #endif 00034 00035 #define _UNEVT_Event_H_ 00036 00037 00038 namespace strmod { 00039 namespace unievent { 00040 00041 class Dispatcher; 00042 class EventPtr; 00043 00044 /** \class Event Event.h UniEvent/Event.h 00045 * \brief An event to be queued up in a UNIDispatcher. 00046 */ 00047 class Event : virtual public lcore::Protocol, public lcore::ReferenceCounting 00048 { 00049 public: 00050 static const UNEVT_ClassIdent identifier; 00051 00052 //! Nothing exciting here. 00053 Event() : ReferenceCounting(0) { } 00054 //! This is an interface class, of course it has a virtual destructor. 00055 virtual ~Event() { } 00056 00057 inline virtual int AreYouA(const lcore::ClassIdent &cid) const; 00058 00059 /** Perform the action associated with the event. 00060 * If the event was triggered by a dispatcher, the dispatcher that triggered 00061 * it is expected to be passed in. Otherwise NULL (aka 0) can be passed in. 00062 * A dispatcher will only call ONE triggerEvent method at a time. 00063 */ 00064 virtual void triggerEvent(Dispatcher *dispatcher = 0) = 0; 00065 00066 /** Interrupt the current event if possible. 00067 * <b>MUST be thread-safe, signal-safe, and otherwise prepared to be called 00068 * in very strange contexts!</b> 00069 * 00070 * This method should cause the currently executing event to return as 00071 * quickly as possible. This may not be possible to do for all kinds of 00072 * events. This method will only be called just before, during, or just 00073 * after the triggerEvent() method is called. 00074 */ 00075 virtual void interrupt() { } 00076 00077 //! Alternate form of TriggerEvent 00078 inline void operator ()(Dispatcher *dispatcher); 00079 //! Alternate form of TriggerEvent 00080 inline void operator ()() { (*this)(0); } 00081 00082 protected: 00083 virtual const lcore::ClassIdent *i_GetIdent() const { return &identifier; } 00084 00085 private: 00086 // Purposely left undefined. 00087 Event(const Event &b); 00088 const Event &operator =(const Event &b); 00089 }; 00090 00091 //-----------------------------inline functions-------------------------------- 00092 00093 inline int Event::AreYouA(const lcore::ClassIdent &cid) const 00094 { 00095 return((identifier == cid) || Protocol::AreYouA(cid)); 00096 } 00097 00098 inline void Event::operator ()(Dispatcher *dispatcher) 00099 { 00100 triggerEvent(dispatcher); 00101 } 00102 00103 } // namespace unievent 00104 } // namespace strmod 00105 00106 #endif
1.3-rc1