Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0f201c20fb6de4262378706ca5ee93de8df51e51 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
 * @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"
#include <iterator>
#include <vector>

using namespace etRuntime;



/* message names as strings for debugging (generate MSC) */
const std::string RTSystemServicesProtocol::s_messageStrings[] = {"MIN",  "executeInitialTransition","startDebugging","stopDebugging","MAX"};

const std::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 std::string errorMsg = "Message ID out of range";
		return errorMsg;
	}
}

//------------------------------------------------------------------------------------------------------------
// port class
//------------------------------------------------------------------------------------------------------------

RTSystemServicesProtocolPort::RTSystemServicesProtocolPort(IInterfaceItemOwner* actor, const std::string& name, int localId)
	: PortBase(actor, name, localId, 0)
{
}

RTSystemServicesProtocolPort::RTSystemServicesProtocolPort(IInterfaceItemOwner* actor, const std::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()));

	getActor()->receiveEvent(this, msg->getEvtId(),	msg->getData());
}


// sent messages

//------------------------------------------------------------------------------------------------------------
// replicated port class
//------------------------------------------------------------------------------------------------------------
RTSystemServicesProtocolReplPort::RTSystemServicesProtocolReplPort(IInterfaceItemOwner* actor, const std::string& name, int localId) :
		ReplicatedPortBase(actor, name, localId)
{
}

// outgoing messages
//------------------------------------------------------------------------------------------------------------
// conjugated port class
//------------------------------------------------------------------------------------------------------------

RTSystemServicesProtocolConjPort::RTSystemServicesProtocolConjPort(IInterfaceItemOwner* actor, const std::string& name, int localId)
	: PortBase(actor, name, localId, 0)
{
}

RTSystemServicesProtocolConjPort::RTSystemServicesProtocolConjPort(IInterfaceItemOwner* actor, const std::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()));

	getActor()->receiveEvent(this, msg->getEvtId(),	msg->getData());
}


// sent messages
void RTSystemServicesProtocolConjPort::executeInitialTransition() {
	DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
		RTSystemServicesProtocol::getMessageString(RTSystemServicesProtocol::IN_executeInitialTransition));
	if (getPeerAddress().isValid()){
		getPeerMsgReceiver()->receive(new Message(getPeerAddress(), RTSystemServicesProtocol::IN_executeInitialTransition));
	}
}
void RTSystemServicesProtocolConjPort::startDebugging() {
	DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
		RTSystemServicesProtocol::getMessageString(RTSystemServicesProtocol::IN_startDebugging));
	if (getPeerAddress().isValid()){
		getPeerMsgReceiver()->receive(new Message(getPeerAddress(), RTSystemServicesProtocol::IN_startDebugging));
	}
}
void RTSystemServicesProtocolConjPort::stopDebugging() {
	DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
		RTSystemServicesProtocol::getMessageString(RTSystemServicesProtocol::IN_stopDebugging));
	if (getPeerAddress().isValid()){
		getPeerMsgReceiver()->receive(new Message(getPeerAddress(), RTSystemServicesProtocol::IN_stopDebugging));
	}
}

//------------------------------------------------------------------------------------------------------------
// conjugated replicated port class
//------------------------------------------------------------------------------------------------------------
RTSystemServicesProtocolConjReplPort::RTSystemServicesProtocolConjReplPort(IInterfaceItemOwner* actor, const std::string& name, int localId) :
		ReplicatedPortBase(actor, name, localId)
{
}

// incoming messages
void RTSystemServicesProtocolConjReplPort::executeInitialTransition(){
	for (std::vector<etRuntime::InterfaceItemBase*>::iterator it = getItems().begin(); it != getItems().end(); ++it) {
		(dynamic_cast<RTSystemServicesProtocolConjPort*>(*it))->executeInitialTransition();
	}
}
void RTSystemServicesProtocolConjReplPort::startDebugging(){
	for (std::vector<etRuntime::InterfaceItemBase*>::iterator it = getItems().begin(); it != getItems().end(); ++it) {
		(dynamic_cast<RTSystemServicesProtocolConjPort*>(*it))->startDebugging();
	}
}
void RTSystemServicesProtocolConjReplPort::stopDebugging(){
	for (std::vector<etRuntime::InterfaceItemBase*>::iterator it = getItems().begin(); it != getItems().end(); ++it) {
		(dynamic_cast<RTSystemServicesProtocolConjPort*>(*it))->stopDebugging();
	}
}


Back to the top