Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 77e266e0d8ac0ee3b15c0eb03e7e9105a1e5ccd7 (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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
 * @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();
	}
}


Back to the top