00001 #ifndef MTANALOGMESSAGECREATOR_H_
00002 #define MTANALOGMESSAGECREATOR_H_
00003
00004 #include "MultiThreadAnalogMsgDispatcher.h"
00005 #include "MultiThreadSimEngine.h"
00006 #include "AnalogDelayObjectMap.h"
00007
00008 class MTAnalogMessageCreator
00009 {
00010 public:
00011 MTAnalogMessageCreator(vector<MultiThreadAnalogMsgDispatcher*> & mtAnalogMsgDispatchers,
00012 MultiThreadSimEngine &mtSimEngine,
00013 AnalogDelayObjectMap &analogDelayObjectsMap,
00014 delay_t minDelay) :
00015 dispatchers(mtAnalogMsgDispatchers),
00016 simEngine(mtSimEngine),
00017 analog_delay_objects_map(analogDelayObjectsMap),
00018 min_delay(minDelay)
00019 {};
00020 virtual ~MTAnalogMessageCreator();
00021
00022 template<typename srcType, typename destType>
00023 inline int addAnalogMessage(
00024 const SimObject::ID &sender,
00025 srcType senderPortOrField,
00026 const SimObject::ID &receiver,
00027 destType recvPortOrField,
00028 delay_t delay);
00029
00030
00031 protected:
00032 vector< MultiThreadAnalogMsgDispatcher*> &dispatchers;
00033
00034 MultiThreadSimEngine &simEngine;
00035
00036 AnalogDelayObjectMap & analog_delay_objects_map;
00037
00038 delay_t min_delay;
00039 };
00040
00041
00042 template<typename srcType, typename destType>
00043 inline int MTAnalogMessageCreator::addAnalogMessage(
00044 const SimObject::ID &sender,
00045 srcType senderPortOrField,
00046 const SimObject::ID &receiver,
00047 destType recvPortOrField,
00048 delay_t delay )
00049 {
00050 if (delay == 0) {
00051 dispatchers[receiver.eng]->mTImmediateDispatcher().addAnalogMessage( simEngine.getObject(sender), senderPortOrField,
00052 simEngine.getObject(receiver), recvPortOrField);
00053 } else {
00054 SimObject *sender_ptr = dynamic_cast<SimObject*> (simEngine.getObject(sender));
00055 AnalogDelayObject *delay_object;
00056 SimObject::ID delayer_id = sender;
00057 if ((delay_object = analog_delay_objects_map.find(sender_ptr, senderPortOrField)) == NULL) {
00058 AnalogDelayObject delay_object_model(min_delay);
00059 simEngine.addObject(delay_object_model, delayer_id);
00060 delay_object = (AnalogDelayObject *)simEngine.getObject( delayer_id );
00061 delayer_id.type = delay_object->getObjectTypeID();
00062 analog_delay_objects_map.insert(sender_ptr, senderPortOrField, delay_object);
00063
00064 dispatchers[sender.eng]->sTLocalDispatcher().addAnalogMessage(sender_ptr, senderPortOrField, delay_object, 0);
00065 }
00066 if (!delay_object->isScheduledForAdvanceCycle())
00067 simEngine.addForAdvanceCycle(delay_object, delayer_id);
00068 delay_object->announceDelayedRead(delay);
00069
00070
00071 dispatchers[receiver.eng]->mTDelayedDispatcher().addAnalogMessage(delay_object, delay-1, simEngine.getObject(receiver), recvPortOrField);
00072 }
00073
00074 return 0;
00075 }
00076
00077 #endif