00001 00002 /* 00003 * Copyright (C) 2004-2005 by the University of Southern California 00004 * $Id: difftimer.h,v 1.4 2005/09/13 20:47:35 johnh Exp $ 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License, 00008 * version 2, as published by the Free Software Foundation. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, write to the Free Software Foundation, Inc., 00017 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 00018 * 00019 * 00020 * The copyright of this module includes the following 00021 * linking-with-specific-other-licenses addition: 00022 * 00023 * In addition, as a special exception, the copyright holders of 00024 * this module give you permission to combine (via static or 00025 * dynamic linking) this module with free software programs or 00026 * libraries that are released under the GNU LGPL and with code 00027 * included in the standard release of ns-2 under the Apache 2.0 00028 * license or under otherwise-compatible licenses with advertising 00029 * requirements (or modified versions of such code, with unchanged 00030 * license). You may copy and distribute such a system following the 00031 * terms of the GNU GPL for this module and the licenses of the 00032 * other code concerned, provided that you include the source code of 00033 * that other code when and as the GNU GPL requires distribution of 00034 * source code. 00035 * 00036 * Note that people who make modified versions of this module 00037 * are not obligated to grant this special exception for their 00038 * modified versions; it is their choice whether to do so. The GNU 00039 * General Public License gives permission to release a modified 00040 * version without this exception; this exception also makes it 00041 * possible to release a modified version which carries forward this 00042 * exception. 00043 * 00044 */ 00045 00046 // 00047 // Diffusion-event handler object, Padma, nov 2001. 00048 00049 #ifdef NS_DIFFUSION 00050 00051 #ifndef diffevent_handler_h 00052 #define diffevent_handler_h 00053 00054 00055 #include <list> 00056 #include "scheduler.h" 00057 #include "timers.hh" 00058 00059 00060 class MapEntry; 00061 class DiffEventQueue; 00062 00063 typedef long d_handle; 00064 typedef list<MapEntry *> UIDMap_t; 00065 00066 00067 class MapEntry { 00068 public: 00069 d_handle hdl_; 00070 scheduler_uid_t uid_; 00071 }; 00072 00073 00074 00075 /* This handler class keeps track of diffusion specific events. 00076 It schedules multiple events and irrespective of the event types, 00077 always calls back the callback function of its agent. 00078 */ 00079 00080 class DiffEvent : public Event { 00081 private: 00082 struct timeval tv_; 00083 d_handle handle_; 00084 void* payload_; 00085 public: 00086 DiffEvent(d_handle hdl, void *payload, int time); 00087 ~DiffEvent() { } 00088 int gettime() { 00089 return ((tv_.tv_sec) + ((tv_.tv_usec)/1000000)); 00090 } 00091 d_handle getHandle() { return handle_; } 00092 void* payload() { return payload_; } 00093 }; 00094 00095 00096 class DiffEventHandler : public Handler { 00097 public: 00098 DiffEventHandler(TimerManager *agent, DiffEventQueue *deq) { 00099 a_ = agent; 00100 queue_ = deq; 00101 } 00102 void handle(Event *); 00103 00104 private: 00105 TimerManager *a_; 00106 DiffEventQueue *queue_; 00107 }; 00108 00109 00110 class DiffEventQueue : public EventQueue { 00111 public: 00112 DiffEventQueue(TimerManager* a) { 00113 a_ = a; 00114 timerHandler_ = new DiffEventHandler(a_, this); 00115 } 00116 ~DiffEventQueue() { delete timerHandler_; } 00117 // queue functions 00118 void eqAddAfter(d_handle hdl, void *payload, int delay_msec); 00119 DiffEvent *eqFindEvent(d_handle hdl); 00120 bool eqRemove(d_handle hdl); 00121 00122 // mapping functions 00123 void setUID(d_handle hdl, scheduler_uid_t uid); 00124 scheduler_uid_t getUID(d_handle hdl); 00125 00126 private: 00127 TimerManager *a_; 00128 DiffEventHandler *timerHandler_; 00129 00130 // map for diffusion handle and ns scheduler uid 00131 UIDMap_t uidmap_; 00132 }; 00133 00134 00135 00136 00137 00138 #endif //diffusion_timer_h 00139 #endif // NS