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

Event.h

00001 //   -*- C++ -*-
00002 /*****************************************************************************
00003  *
00004  *   |_|_|_  |_|_    |_    |_|_|_  |_                C O M M U N I C A T I O N
00005  * |_        |_  |_  |_  |_        |_                          N E T W O R K S
00006  * |_        |_  |_  |_  |_        |_                                C L A S S
00007  *   |_|_|_  |_    |_|_    |_|_|_  |_|_|_|_                      L I B R A R Y
00008  *
00009  * $Id: Event.h,v 1.5 2002/02/01 08:46:04 spee Exp $
00010  *
00011  * CNClass: CNEvent --- Generic event
00012  *
00013  *****************************************************************************
00014  * Copyright (C) 1992-2002   Communication Networks
00015  *                           Aachen University of Technology
00016  *                           D-52056 Aachen
00017  *                           Germany
00018  *                           Email: cncl-adm@comnets.rwth-aachen.de
00019  *****************************************************************************
00020  * This file is part of the CN class library. All files marked with
00021  * this header are free software; you can redistribute it and/or modify
00022  * it under the terms of the GNU Library General Public License as
00023  * published by the Free Software Foundation; either version 2 of the
00024  * License, or (at your option) any later version.  This library is
00025  * distributed in the hope that it will be useful, but WITHOUT ANY
00026  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
00027  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00028  * License for more details.  You should have received a copy of the GNU
00029  * Library General Public License along with this library; if not, write
00030  * to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
00031  * USA.
00032  *****************************************************************************/
00033 
00034 #ifndef __Event_h
00035 #define __Event_h
00036 
00037 
00038 #include <CNCL/Class.h>
00039 #include <CNCL/Param.h>
00040 #include <CNCL/DLObject.h>              // Base class
00041 #include <CNCL/SimTime.h>
00042 
00043 #include <stddef.h>
00044 
00045 extern CNClassDesc CN_EVENT;            // CNClass CNEvent description
00046 
00047 
00048 
00049 class CNEventHandler;
00050 
00051 
00052 typedef unsigned long CNEventID;                // Type of CNEvent::ev_id
00053 
00054 
00055 
00063 class CNEvent : public CNDLObject
00064 {
00065     friend class CNEventList;
00066     friend class CNEventBaseSched;
00067     friend class CNEventScheduler;
00068     friend class CNEventHeapSched;
00069     friend class CNEventHIterator;
00070     
00071   private:
00072 
00073     enum { default_max_events=100 };
00074 
00075   public:
00081     unsigned long get_max_events();
00087     static void set_max_events(unsigned long n);
00088 
00089   public:
00091     int priority()             const        { return ev_prio; }
00093     int get_priority()         const        { return ev_prio; }
00095     void priority(int prio)                 { ev_prio=prio;   }
00097     void set_priority(int prio)             { ev_prio=prio;   }
00098 
00100     int type()                 const        { return ev_type;   }
00102     int get_type()             const        { return ev_type;   }
00104     void type(int new_type)                 { ev_type=new_type; }  
00106     void set_type(int new_type)             { ev_type=new_type; }
00107 
00109     CNSimTime scheduled()      const        { return ev_scheduled; }
00111     CNSimTime get_scheduled()  const        { return ev_scheduled; }
00113     void scheduled(const CNSimTime new_scheduled)
00114                                             { ev_scheduled = new_scheduled; }
00116     void set_scheduled(const CNSimTime new_scheduled)
00117                                             { ev_scheduled = new_scheduled; }
00118 
00120     CNSimTime issued()         const        { return ev_issued; }
00122     CNSimTime get_issued()     const        { return ev_issued; }
00123 
00125     CNEventHandler *to()       const        { return ev_to; }
00127     CNEventHandler *get_to()   const        { return ev_to; }
00129     void to(CNEventHandler *new_to)         { ev_to=new_to; }
00131     void set_to(CNEventHandler *new_to)     { ev_to=new_to; }
00132 
00134     CNEventHandler *from()     const        { return ev_from; }
00136     CNEventHandler *get_from() const        { return ev_from; }
00138     void from(CNEventHandler *new_from)     { ev_from=new_from; }
00140     void set_from(CNEventHandler *new_from) { ev_from=new_from; }
00141 
00143     CNObject *object()         const        { return ev_obj; }
00145     CNObject *get_object()     const        { return ev_obj; }
00147     void object(CNObject *obj)              { ev_obj=obj; }
00149     void set_object(CNObject *obj)          { ev_obj=obj; }
00150 
00152     CNEventID id()             const        { return ev_id; }
00154     CNEventID get_id()         const        { return ev_id; }
00155 
00157     static void *operator new(size_t);
00159     static void  operator delete(void *);
00160 
00162     static void reset_pool();
00163     
00165     inline bool after(CNEvent* ev);
00166 
00168   private:
00170     static CNEvent *pool;
00172     static unsigned long pool_size;
00174     static unsigned long next_free;     
00175 
00178     CNEventID ev_id;                    
00180     int ev_prio;
00182     int ev_type;
00184     CNSimTime ev_issued;        
00186     CNSimTime ev_scheduled;
00188     CNEventHandler *ev_to;
00190     CNEventHandler *ev_from;
00192     CNObject *ev_obj;           
00193 
00194     static CNEventID id_sequencer;      // Sequencer for event IDs
00195 
00197     void issued(const CNSimTime t)     { ev_issued=t; }
00199     void set_issued(const CNSimTime t) { ev_issued=t; }
00200 
00201     /****** Constructors ******************************************************/
00202   public:
00204     CNEvent();
00206     CNEvent(CNParam *param);
00210     CNEvent(int new_type);
00214     CNEvent(int new_type, const CNSimTime t, int new_prio=0);
00218     CNEvent(int new_type, CNEventHandler *new_to, const CNSimTime t,
00219             CNObject *new_object=NIL, int new_prio=0);
00223     CNEvent(int new_type, CNEventHandler *new_from, CNEventHandler *new_to,
00224             const CNSimTime t, CNObject *new_object=NIL, int new_prio=0);
00228     CNEvent(int new_type, CNEventHandler *new_to,
00229             CNObject *new_object=NIL, int new_prio=0);
00230 
00231 protected:
00236     ~CNEvent() {}
00237 
00238     /****** Member functions required by CNCL *********************************/
00239 public:
00240     virtual CNClassDesc class_desc() const      // CNClass description
00241     {
00242         return CN_EVENT;
00243     };
00244             
00246     virtual bool is_a(CNClassDesc desc) const
00247     {
00248         return desc == CN_EVENT ? TRUE : CNDLObject::is_a(desc);
00249     };
00250         
00252     static CNEvent *cast_from_object(CNObject *obj)
00253     {
00254 #   ifdef NO_TYPE_CHECK
00255         return (CNEvent *)obj;
00256 #   else
00257         return (CNEvent *)( !obj || obj->is_a(CN_EVENT)
00258                ? obj : fatal_type(obj->class_desc(), CN_EVENT) );
00259 #   endif
00260     }
00261     
00263     static CNObject *new_object(CNParam *param = NIL)
00264     { return param ? new CNEvent(param) : new CNEvent; }
00265     
00267     virtual void print(ostream &strm = cout) const;
00269     virtual void dump (ostream &strm = cout) const;
00270 };
00271 
00272 
00273 /* Comparison used by HeapEventScheduler */
00274 inline bool CNEvent::after(CNEvent* e2)
00275 {
00276     bool flag = FALSE;
00277     
00278     if      (ev_scheduled > e2->ev_scheduled) flag = TRUE;
00279     else if (ev_scheduled < e2->ev_scheduled) ;
00280     else if (ev_prio      > e2->ev_prio     ) flag = TRUE;
00281     else if (ev_prio      < e2->ev_prio     ) ;
00282     else if (ev_id        > e2->ev_id       ) flag = TRUE;
00283     return flag;
00284 };
00285 
00286 #endif 

Generated on Fri Feb 1 19:53:48 2002 for CNCL by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001