blob: 77e266e0d8ac0ee3b15c0eb03e7e9105a1e5ccd7 [file]
/**
* @author generated by eTrice
*
* Source File of ProtocolClass RTSystemServicesProtocol
*
*/
#include "RTSystemServicesProtocol.h"
#include "common/debugging/DebuggingService.h"
#include "common/debugging/MSCFunctionObject.h"
#include "common/messaging/AbstractMessageReceiver.h"
#include "common/messaging/Address.h"
#include "common/messaging/Message.h"
#include "common/modelbase/IEventReceiver.h"
using namespace etRuntime;
/* message names as strings for debugging (generate MSC) */
const String RTSystemServicesProtocol::s_messageStrings[] = {"MIN", "executeInitialTransition","startDebugging","stopDebugging","MAX"};
const String& RTSystemServicesProtocol::getMessageString(int msg_id) {
if ((MSG_MIN < msg_id ) && ( msg_id < MSG_MAX )) {
return s_messageStrings[msg_id];
} else {
// id out of range
static const String errorMsg = "Message ID out of range";
return errorMsg;
}
}
//------------------------------------------------------------------------------------------------------------
// port class
//------------------------------------------------------------------------------------------------------------
RTSystemServicesProtocolPort::RTSystemServicesProtocolPort(IInterfaceItemOwner* actor, const String& name, int localId)
: PortBase(actor, name, localId, 0)
{
}
RTSystemServicesProtocolPort::RTSystemServicesProtocolPort(IInterfaceItemOwner* actor, const String& name, int localId, int idx)
: PortBase(actor, name, localId, idx)
{
}
void RTSystemServicesProtocolPort::destroy() {
DebuggingService::getInstance().removePortInstance(*this);
PortBase::destroy();
}
void RTSystemServicesProtocolPort::receive(const Message* msg) {
// TODO JH further
if (! RTSystemServicesProtocol::isValidIncomingEvtID(msg->getEvtId())) {
//std::cout << "unknown" << std::endl;
}
DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), RTSystemServicesProtocol::getMessageString(msg->getEvtId()).c_str());
getActor()->receiveEvent(this, msg->getEvtId(), msg->getData());
}
// sent messages
//------------------------------------------------------------------------------------------------------------
// replicated port class
//------------------------------------------------------------------------------------------------------------
RTSystemServicesProtocolReplPort::RTSystemServicesProtocolReplPort(IInterfaceItemOwner* actor, const String& name, int localId) :
ReplicatedPortBase(actor, name, localId)
{
}
// outgoing messages
//------------------------------------------------------------------------------------------------------------
// conjugated port class
//------------------------------------------------------------------------------------------------------------
RTSystemServicesProtocolConjPort::RTSystemServicesProtocolConjPort(IInterfaceItemOwner* actor, const String& name, int localId)
: PortBase(actor, name, localId, 0)
{
}
RTSystemServicesProtocolConjPort::RTSystemServicesProtocolConjPort(IInterfaceItemOwner* actor, const String& name, int localId, int idx)
: PortBase(actor, name, localId, idx)
{
}
void RTSystemServicesProtocolConjPort::destroy() {
DebuggingService::getInstance().removePortInstance(*this);
PortBase::destroy();
}
void RTSystemServicesProtocolConjPort::receive(const Message* msg) {
// TODO JH further
if (! RTSystemServicesProtocol::isValidOutgoingEvtID(msg->getEvtId())) {
//std::cout << "unknown" << std::endl;
}
DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), RTSystemServicesProtocol::getMessageString(msg->getEvtId()).c_str());
getActor()->receiveEvent(this, msg->getEvtId(), msg->getData());
}
// sent messages
void RTSystemServicesProtocolConjPort::executeInitialTransition() {
executeInitialTransition_impl();
}
void RTSystemServicesProtocolConjPort::executeInitialTransition_impl() {
DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
RTSystemServicesProtocol::getMessageString(RTSystemServicesProtocol::IN_executeInitialTransition).c_str());
if (getPeerAddress().isValid()) {
Message* buffer = dynamic_cast<IMessageService*>(getPeerMsgReceiver())->getMessageBuffer(sizeof(Message));
if (buffer) {
getPeerMsgReceiver()->receive(new (buffer) Message(getPeerAddress(), RTSystemServicesProtocol::IN_executeInitialTransition));
}
}
}
void RTSystemServicesProtocolConjPort::startDebugging() {
startDebugging_impl();
}
void RTSystemServicesProtocolConjPort::startDebugging_impl() {
DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
RTSystemServicesProtocol::getMessageString(RTSystemServicesProtocol::IN_startDebugging).c_str());
if (getPeerAddress().isValid()) {
Message* buffer = dynamic_cast<IMessageService*>(getPeerMsgReceiver())->getMessageBuffer(sizeof(Message));
if (buffer) {
getPeerMsgReceiver()->receive(new (buffer) Message(getPeerAddress(), RTSystemServicesProtocol::IN_startDebugging));
}
}
}
void RTSystemServicesProtocolConjPort::stopDebugging() {
stopDebugging_impl();
}
void RTSystemServicesProtocolConjPort::stopDebugging_impl() {
DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
RTSystemServicesProtocol::getMessageString(RTSystemServicesProtocol::IN_stopDebugging).c_str());
if (getPeerAddress().isValid()) {
Message* buffer = dynamic_cast<IMessageService*>(getPeerMsgReceiver())->getMessageBuffer(sizeof(Message));
if (buffer) {
getPeerMsgReceiver()->receive(new (buffer) Message(getPeerAddress(), RTSystemServicesProtocol::IN_stopDebugging));
}
}
}
//------------------------------------------------------------------------------------------------------------
// conjugated replicated port class
//------------------------------------------------------------------------------------------------------------
RTSystemServicesProtocolConjReplPort::RTSystemServicesProtocolConjReplPort(IInterfaceItemOwner* actor, const String& name, int localId) :
ReplicatedPortBase(actor, name, localId)
{
}
// incoming messages
void RTSystemServicesProtocolConjReplPort::executeInitialTransition(){
for (Vector<etRuntime::InterfaceItemBase*>::iterator it = getItems().begin(); it != getItems().end(); ++it) {
(dynamic_cast<RTSystemServicesProtocolConjPort*>(*it))->executeInitialTransition();
}
}
void RTSystemServicesProtocolConjReplPort::startDebugging(){
for (Vector<etRuntime::InterfaceItemBase*>::iterator it = getItems().begin(); it != getItems().end(); ++it) {
(dynamic_cast<RTSystemServicesProtocolConjPort*>(*it))->startDebugging();
}
}
void RTSystemServicesProtocolConjReplPort::stopDebugging(){
for (Vector<etRuntime::InterfaceItemBase*>::iterator it = getItems().begin(); it != getItems().end(); ++it) {
(dynamic_cast<RTSystemServicesProtocolConjPort*>(*it))->stopDebugging();
}
}