blob: 7f681940d97015eca00e8951bd72ded0b1627b39 [file]
#include "Ponger.hh"
#include "DataType1.hh"
#include "PingPongProtocol.hh"
#include "umlrtcapsuleclass.hh"
#include "umlrtcommsport.hh"
#include "umlrtcommsportfarend.hh"
#include "umlrtcommsportrole.hh"
#include "umlrtframeservice.hh"
#include "umlrtmessage.hh"
#include "umlrtsignal.hh"
#include "umlrtslot.hh"
#include <cstddef>
class UMLRTRtsInterface;
#include <iostream>
Capsule_Ponger::Capsule_Ponger( UMLRTSlot * st, const UMLRTCommsPort * * border, const UMLRTCommsPort * internal, bool isStat )
: UMLRTCapsule( NULL, &Ponger, st, border, internal, isStat )
{
}
PingPongProtocol_conjrole Capsule_Ponger::PongPort() const
{
return PingPongProtocol_conjrole( borderPorts[borderport_PongPort] );
}
void Capsule_Ponger::bindPort( bool isBorder, int portId, int index )
{
if( isBorder )
switch( portId )
{
case borderport_PongPort:
UMLRTFrameService::sendBoundUnbound( borderPorts[borderport_PongPort], index, borderPorts[borderport_PongPort]->farEnds[index].port, borderPorts[borderport_PongPort]->farEnds[index].farEndIndex, true );
UMLRTFrameService::sendBoundUnbound( borderPorts[borderport_PongPort]->farEnds[index].port, borderPorts[borderport_PongPort]->farEnds[index].farEndIndex, borderPorts[borderport_PongPort], index, true );
break;
case borderport__bind:
UMLRTFrameService::sendBoundUnbound( borderPorts[borderport__bind], index, borderPorts[borderport__bind]->farEnds[index].port, borderPorts[borderport__bind]->farEnds[index].farEndIndex, true );
UMLRTFrameService::sendBoundUnbound( borderPorts[borderport__bind]->farEnds[index].port, borderPorts[borderport__bind]->farEnds[index].farEndIndex, borderPorts[borderport__bind], index, true );
break;
}
else
{
}
}
void Capsule_Ponger::unbindPort( bool isBorder, int portId, int index )
{
if( isBorder )
switch( portId )
{
case borderport_PongPort:
UMLRTFrameService::sendBoundUnbound( borderPorts[borderport_PongPort], index, borderPorts[borderport_PongPort]->farEnds[index].port, borderPorts[borderport_PongPort]->farEnds[index].farEndIndex, true );
UMLRTFrameService::sendBoundUnbound( borderPorts[borderport_PongPort]->farEnds[index].port, borderPorts[borderport_PongPort]->farEnds[index].farEndIndex, borderPorts[borderport_PongPort], index, true );
UMLRTFrameService::disconnectPort( borderPorts[borderport_PongPort], index );
break;
case borderport__bind:
UMLRTFrameService::sendBoundUnbound( borderPorts[borderport__bind], index, borderPorts[borderport__bind]->farEnds[index].port, borderPorts[borderport__bind]->farEnds[index].farEndIndex, true );
UMLRTFrameService::sendBoundUnbound( borderPorts[borderport__bind]->farEnds[index].port, borderPorts[borderport__bind]->farEnds[index].farEndIndex, borderPorts[borderport__bind], index, true );
UMLRTFrameService::disconnectPort( borderPorts[borderport__bind], index );
break;
}
else
{
}
}
void Capsule_Ponger::inject( const UMLRTMessage & msg )
{
switch( currentState )
{
case top__Running:
currentState = state_____top__Running( msg );
break;
}
}
void Capsule_Ponger::initialize( const UMLRTMessage & msg )
{
actionchain_____top__initial__ActionChain3( msg );
currentState = top__Running;
}
void Capsule_Ponger::transitionaction_____top__initial__ActionChain3__onInit( const UMLRTMessage & msg )
{
void * rtdata = *(void * *)msg.signal.getPayload();
std::cout << "Ponger initialised" << std::endl;
}
void Capsule_Ponger::transitionaction_____top__onBound__ActionChain6__onBound( const UMLRTMessage & msg )
{
void * rtdata = *(void * *)msg.signal.getPayload();
printf( "%s onBound\n", getName() );
}
void Capsule_Ponger::transitionaction_____top__onPing__ActionChain5__onPing( const UMLRTMessage & msg )
{
const DataType1 & rtdata = *(DataType1 * )msg.signal.getPayload();
std::cout << "Ping received"
<< " field1:" << rtdata.field1_int
<< " field2:" << rtdata.field2_bool
<< " field3:" << rtdata.field3_double
<< std::endl;
std::cout << "Sending Pong" << std::endl;
PongPort().pong().send();
}
void Capsule_Ponger::actionchain_____top__initial__ActionChain3( const UMLRTMessage & msg )
{
transitionaction_____top__initial__ActionChain3__onInit( msg );
}
void Capsule_Ponger::actionchain_____top__onBound__ActionChain6( const UMLRTMessage & msg )
{
transitionaction_____top__onBound__ActionChain6__onBound( msg );
}
void Capsule_Ponger::actionchain_____top__onPing__ActionChain5( const UMLRTMessage & msg )
{
transitionaction_____top__onPing__ActionChain5__onPing( msg );
}
Capsule_Ponger::State Capsule_Ponger::state_____top__Running( const UMLRTMessage & msg )
{
switch( msg.destPort->role()->id )
{
case port_PongPort:
switch( msg.signal.getId() )
{
case UMLRTSignal::rtBound:
actionchain_____top__onBound__ActionChain6( msg );
return top__Running;
case PingPongProtocol::signal_ping:
actionchain_____top__onPing__ActionChain5( msg );
return top__Running;
}
return currentState;
}
return currentState;
}
static const UMLRTCommsPortRole portroles_border[] =
{
{
Capsule_Ponger::port_PongPort,
"PingPongProtocol",
"PongPort",
NULL,
1,
true,
true,
false,
true,
false,
false,
true
},
{
Capsule_Ponger::port__bind,
"UMLRTBaseCommProtocol",
"_bind",
NULL,
1,
true,
false,
false,
false,
false,
false,
true
}
};
static void instantiate_Ponger( const UMLRTRtsInterface * rts, UMLRTSlot * slot, const UMLRTCommsPort * * borderPorts )
{
slot->capsule = new Capsule_Ponger( slot, borderPorts, NULL, false );
}
const UMLRTCapsuleClass Ponger =
{
"Ponger",
NULL,
instantiate_Ponger,
0,
NULL,
2,
portroles_border,
0,
NULL
};