00001 #ifndef DISTRIBUTEDANALOGMESSAGECREATOR_H_
00002 #define DISTRIBUTEDANALOGMESSAGECREATOR_H_
00003
00004 #include "SimObject.h"
00005 #include "SingleThreadSimEngine.h"
00006 #include "AnalogDelayObject.h"
00007 #include "DistributedAnalogMessageDispatcher.h"
00008
00009
00010 class DistributedAnalogMessageCreator
00011 {
00012 public:
00013 DistributedAnalogMessageCreator(
00014 SingleThreadSimEngine & singleThreadEngine,
00015 DistributedAnalogMessageDispatcher &distAnalogMsgDispatcher,
00016 delay_t minAnalogDelay) :
00017 dispatcher(distAnalogMsgDispatcher),
00018 stEngine(singleThreadEngine),
00019 min_analog_delay(minAnalogDelay)
00020 {};
00021
00022 virtual ~DistributedAnalogMessageCreator();
00023
00024 template <class AnalogSrcType>
00025 inline void addOutgoingAnalogMessage(const SimObject::ID &src, AnalogSrcType srcFieldOrPort, nodeid_t dest_node);
00026
00027 template <class AnalogSrcType, class AnalogDestType>
00028 inline void addIncomingAnalogMessage(const SimObject::ID &src, AnalogSrcType srcFieldOrPort,
00029 const SimObject::ID &receiver, AnalogDestType destFieldOrPort, delay_t delay);
00030
00031 protected:
00032 DistributedAnalogMessageDispatcher & dispatcher;
00033 SingleThreadSimEngine &stEngine;
00034 delay_t min_analog_delay;
00035 };
00036
00037 template <class AnalogSrcType>
00038 inline void DistributedAnalogMessageCreator::addOutgoingAnalogMessage(const SimObject::ID &src, AnalogSrcType srcFieldOrPort, nodeid_t dest_node)
00039 {
00040 dispatcher.outgoing()[dest_node]->addOutgoingAnalogMessage((SimObject *)stEngine.getObject(src), srcFieldOrPort);
00041 }
00042
00043 template <class AnalogSrcType, class AnalogDestType>
00044 inline void DistributedAnalogMessageCreator::addIncomingAnalogMessage(const SimObject::ID &src, AnalogSrcType srcFieldOrPort, const SimObject::ID &receiver, AnalogDestType destFieldOrPort, delay_t delay)
00045 {
00046
00047 IncomingAnalogDelayObject * delayObj = dispatcher.incoming()[src.node]->addDelayerCycledIncomingAnalogMessage(src, srcFieldOrPort);
00048 delayObj->announceDelayedRead(delay);
00049
00050 dispatcher.cycledLocal().addAnalogMessage(delayObj, delay - 1, (SimObject *)stEngine.getObject(receiver), destFieldOrPort);
00051 }
00052
00053
00054 #endif