00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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>
00041 #include <CNCL/SimTime.h>
00042
00043 #include <stddef.h>
00044
00045 extern CNClassDesc CN_EVENT;
00046
00047
00048
00049 class CNEventHandler;
00050
00051
00052 typedef unsigned long CNEventID;
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;
00195
00197 void issued(const CNSimTime t) { ev_issued=t; }
00199 void set_issued(const CNSimTime t) { ev_issued=t; }
00200
00201
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
00239 public:
00240 virtual CNClassDesc class_desc() const
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
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