00001 #ifndef STANALOGMESSAGECREATOR_H_
00002 #define STANALOGMESSAGECREATOR_H_
00003
00004
00005 #include "SingleThreadSimEngine.h"
00006 #include "SingleThreadAnalogMsgDispatcher.h"
00007 #include "AnalogDelayObjectMap.h"
00008
00009 class STAnalogMessageCreator
00010 {
00011 public:
00012 STAnalogMessageCreator(SingleThreadAnalogMsgDispatcher & analogMsgDispatcher,
00013 SingleThreadSimEngine &simulationEngine,
00014 AnalogDelayObjectMap &delayObjectMap ,
00015 delay_t minDelay);
00016
00017 virtual ~STAnalogMessageCreator();
00018
00019
00020 template<typename srcType, typename destType>
00021 inline int addAnalogMessage(
00022 const SimObject::ID &sender,
00023 srcType senderPortOrField,
00024 const SimObject::ID &receiver,
00025 destType recvPortOrField, delay_t delay);
00026
00027 protected:
00028 SingleThreadAnalogMsgDispatcher & dispatcher;
00029
00030 SingleThreadSimEngine & simEngine;
00031
00032 AnalogDelayObjectMap & delay_objects_map;
00033
00034 delay_t min_delay;
00035
00036 };
00037
00038 template<typename srcType, typename destType>
00039 inline int STAnalogMessageCreator::addAnalogMessage(
00040 const SimObject::ID &sender,
00041 srcType senderPortOrField,
00042 const SimObject::ID &receiver,
00043 destType recvPortOrField, delay_t delay)
00044 {
00045 if (delay == 0) {
00046 dispatcher.addAnalogMessage( simEngine.getObject( sender ),
00047 senderPortOrField, simEngine.getObject( receiver ), recvPortOrField);
00048 } else {
00049 SimObject *src_obj = dynamic_cast<SimObject*> (simEngine.getObject( sender ) );
00050 AnalogDelayObject *delay_object;
00051 if ((delay_object = delay_objects_map.find(src_obj, senderPortOrField)) == NULL) {
00052 AnalogDelayObject delay_object_model(min_delay);
00053 SimObject::ID id;
00054 simEngine.addObject( delay_object_model, id );
00055 delay_object = (AnalogDelayObject *)simEngine.getObject( id );
00056 delay_objects_map.insert(src_obj, senderPortOrField, delay_object );
00057 }
00058 delay_object->announceDelayedRead(delay);
00059
00060
00061 dispatcher.addAnalogMessage(src_obj, senderPortOrField, delay_object, 0);
00062
00063 dispatcher.addAnalogMessage(delay_object, delay, simEngine.getObject( receiver ), recvPortOrField );
00064 }
00065 return 0;
00066 }
00067
00068 #endif