00001 #ifndef DirectEventSender_H_
00002 #define DirectEventSender_H_
00003
00004 #include <cstdlib>
00005
00006 #include "globals.h"
00007 #include "SimContext.h"
00008
00009 #include "EvSimObject.h"
00010 #include "evesim_hash.h"
00011 #include "EvSimEngine.h"
00012
00013 class DirectEventSender
00014 {
00015 public:
00016
00017 virtual ~DirectEventSender() {};
00018
00019 void outputEvent(SimContext & sim_context, port_id_t port, Time evtime);
00020
00021 void setFirstOutPortGlobalID(global_out_port_id_t port_id);
00022
00023 global_out_port_id_t getFirstOutPortGlobalID() const;
00024
00025 global_out_port_id_t getOutPortGlobalID(port_id_t port) const;
00026 protected:
00027 global_out_port_id_t first_out_port_global_id;
00028 };
00029
00030 inline void DirectEventSender::outputEvent(SimContext & sim_context, port_id_t port, Time evtime)
00031 {
00032 sim_context.eng->scheduleEvent(first_out_port_global_id + port, evtime);
00033 }
00034
00035 inline void DirectEventSender::setFirstOutPortGlobalID(global_proj_out_port_id_t port_id)
00036 {
00037 first_out_port_global_id = port_id;
00038 }
00039
00040 inline global_out_port_id_t DirectEventSender::getFirstOutPortGlobalID() const
00041 {
00042 return first_out_port_global_id;
00043 }
00044
00045 inline global_out_port_id_t DirectEventSender::getOutPortGlobalID(port_id_t port) const
00046 {
00047 EvSimObject *obj = dynamic_cast<EvSimObject *>(const_cast<DirectEventSender *>(this));
00048 if (port < obj->numOutputPorts())
00049 return first_out_port_global_id + port;
00050 else
00051 return PORT_NOT_DEFINED;
00052 }
00053
00054 #endif