Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fcaf8cc625ad6f67cc4c6faf649bda37b5054525 (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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*
 * RTSystemServicesProtocol.cpp
 *
 *  Created on: 29.08.2012
 *      Author: karlitsc
 */

#include "RTSystemServicesProtocol.h"
#include "common/modelbase/EventMessage.h"
#include "common/modelbase/EventWithDataMessage.h"

namespace etRuntime {

std::string RTSystemServicesProtocol::s_messageStrings[] =
	{	"MIN",
		"dummy",
		"executeInitialTransition",
		"startDebugging",
		"stopDebugging",
		"MAX"};

RTSystemServicesProtocol::RTSystemServicesProtocol() {
}

RTSystemServicesProtocol::~RTSystemServicesProtocol() {
}

std::string RTSystemServicesProtocol::getMessageString(int msg_id) {
	if (msg_id < MSG_MIN || msg_id > MSG_MAX + 1) {
		// id out of range
		return "Message ID out of range";
	} else {
		return s_messageStrings[msg_id];
	}
}

//------------------------------------------------------------------
// RTSystemServicesProtocolPort
//------------------------------------------------------------------

RTSystemServicesProtocol::RTSystemServicesProtocolPort::RTSystemServicesProtocolPort(IEventReceiver& actor, IRTObject* parent, std::string name,
		int localId, Address addr, Address peerAddress)
:PortBase(actor, parent, name, localId, 0, addr, peerAddress)
{
	DebuggingService::getInstance().addPortInstance(*this);
};

RTSystemServicesProtocol::RTSystemServicesProtocolPort::RTSystemServicesProtocolPort(IEventReceiver& actor, IRTObject* parent, std::string name,
		int localId, int idx, Address addr, Address peerAddress)
: PortBase(actor, parent, name, localId, idx, addr, peerAddress)
{
	DebuggingService::getInstance().addPortInstance(*this);
};

void RTSystemServicesProtocol::RTSystemServicesProtocolPort::receive(Message m) {
	if (!(m.isEvtMessage()))
		return;
	EventMessage& msg(static_cast<EventMessage&>(m));
	if (msg.getEvtId() <= 0 || msg.getEvtId() >= MSG_MAX)
		std::cout << "unknown" << std::endl;
	else {
		if (s_messageStrings[msg.getEvtId()] != "timerTick") {
			// TODOTS: model switch for activation
			DebuggingService::getInstance().addMessageAsyncIn(
					getPeerAddress(), getAddress(),
					s_messageStrings[msg.getEvtId()]);
		}

		if (msg.isEvtMessageWithData())
			getActor().receiveEvent(*this, msg.getEvtId(),
				(static_cast<EventWithDataMessage&>(msg)).getData());
		else
			getActor().receiveEvent(*this, msg.getEvtId(), 0);

	}
};

// sent messages

void RTSystemServicesProtocol::RTSystemServicesProtocolPort::dummy() {

	if (s_messageStrings[OUT_dummy] != "timerTick") {
		// TODOTS: model switch for activation
		DebuggingService::getInstance().addMessageAsyncOut(getAddress(),
				getPeerAddress(), s_messageStrings[OUT_dummy]);
	}
	if (getPeerAddress().isValid())
		getPeerMsgReceiver()->receive(
				new EventMessage(getPeerAddress(), OUT_dummy));

};

//------------------------------------------------------------------
// RTSystemServicesProtocolPortRepl
//------------------------------------------------------------------


RTSystemServicesProtocol::RTSystemServicesProtocolPortRepl::
RTSystemServicesProtocolPortRepl(IEventReceiver& actor, IRTObject* parent, std::string name, int localId, const std::vector<Address>& addr, const std::vector<Address> peerAddress)
: m_replication(addr.size()),
  m_ports()
{
	char numstr[10]; // enough to hold all numbers up to 32-bits

	m_ports.reserve(m_replication);
	for (int i = 0; i < m_replication; ++i) {
		snprintf(numstr, sizeof(numstr), "%d", i);
		m_ports.push_back(RTSystemServicesProtocolPort(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i]));
	}
};

int RTSystemServicesProtocol::RTSystemServicesProtocolPortRepl::getReplication() {
	return m_replication;
};

RTSystemServicesProtocol::RTSystemServicesProtocolPort& RTSystemServicesProtocol::RTSystemServicesProtocolPortRepl::get(int i) {
	return m_ports.at(i);
};

// outgoing messages

void RTSystemServicesProtocol::RTSystemServicesProtocolPortRepl::dummy() {
	for (int i = 0; i < m_replication; ++i) {
		m_ports.at(i).dummy();
	}
};

//------------------------------------------------------------------
// RTSystemServicesProtocolConjPort
//------------------------------------------------------------------

RTSystemServicesProtocol::RTSystemServicesProtocolConjPort::RTSystemServicesProtocolConjPort(IEventReceiver& actor, IRTObject* parent,
		std::string name, int localId, Address addr, Address peerAddress)
			: PortBase(actor, parent, name, localId, 0, addr, peerAddress)
{
	DebuggingService::getInstance().addPortInstance(*this);
}
RTSystemServicesProtocol::RTSystemServicesProtocolConjPort::RTSystemServicesProtocolConjPort(IEventReceiver& actor, IRTObject* parent,
		std::string name, int localId, int idx, Address addr,
		Address peerAddress)
: PortBase(actor, parent, name, localId, idx, addr, peerAddress)
{
	DebuggingService::getInstance().addPortInstance(*this);
}

void RTSystemServicesProtocol::RTSystemServicesProtocolConjPort::receive(Message m) {
	if (!(m.isEvtMessage()))
		return;
	EventMessage& msg(static_cast<EventMessage&>(m));
	if (msg.getEvtId() <= 0 || msg.getEvtId() >= MSG_MAX)
		std::cout << "unknown" << std::endl;
	else {
		if (s_messageStrings[msg.getEvtId()] != "timerTick") {
			// TODOTS: model switch for activation
			DebuggingService::getInstance().addMessageAsyncIn(
					getPeerAddress(), getAddress(),
					s_messageStrings[msg.getEvtId()]);
		}

		if (msg.isEvtMessageWithData())
			getActor().receiveEvent(*this, msg.getEvtId(),
				(static_cast<EventWithDataMessage&>(msg)).getData());
		else
			getActor().receiveEvent(*this, msg.getEvtId(), 0);


	}
}

// sent messages

void RTSystemServicesProtocol::RTSystemServicesProtocolConjPort::executeInitialTransition() {

	if (s_messageStrings[IN_executeInitialTransition] != "timerTick") {
		// TODOTS: model switch for activation
		DebuggingService::getInstance().addMessageAsyncOut(getAddress(),
				getPeerAddress(),
				s_messageStrings[IN_executeInitialTransition]);
	}
	if (getPeerAddress().isValid())
		getPeerMsgReceiver()->receive(
				new EventMessage(getPeerAddress(),
						IN_executeInitialTransition));

}

void RTSystemServicesProtocol::RTSystemServicesProtocolConjPort::startDebugging() {

	if (s_messageStrings[IN_startDebugging] != "timerTick") {
		// TODOTS: model switch for activation
		DebuggingService::getInstance().addMessageAsyncOut(getAddress(),
				getPeerAddress(), s_messageStrings[IN_startDebugging]);
	}
	if (getPeerAddress().isValid())
		getPeerMsgReceiver()->receive(
				new EventMessage(getPeerAddress(), IN_startDebugging));

}

void RTSystemServicesProtocol::RTSystemServicesProtocolConjPort::stopDebugging() {

	if (s_messageStrings[IN_stopDebugging] != "timerTick") {
		// TODOTS: model switch for activation
		DebuggingService::getInstance().addMessageAsyncOut(getAddress(),
				getPeerAddress(), s_messageStrings[IN_stopDebugging]);
	}
	if (getPeerAddress().isValid())
		getPeerMsgReceiver()->receive(
				new EventMessage(getPeerAddress(), IN_stopDebugging));

}

//------------------------------------------------------------------
// RTSystemServicesProtocolConjPortRepl
//------------------------------------------------------------------

//TODO: data type of addr and peerAddress
RTSystemServicesProtocol::RTSystemServicesProtocolConjPortRepl::
RTSystemServicesProtocolConjPortRepl(IEventReceiver& actor,	IRTObject* parent, std::string name, int localId, const std::vector<Address>& addr, const std::vector<Address> peerAddress)
: m_replication(addr.size()),
  m_ports()
{
	char numstr[10]; // enough to hold all numbers up to 32-bits

	m_ports.reserve(m_replication);
	for (int i = 0; i < m_replication; ++i) {
		snprintf(numstr, sizeof(numstr), "%d", i);
		m_ports.push_back(RTSystemServicesProtocolConjPort(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i]));
	}
};

int RTSystemServicesProtocol::RTSystemServicesProtocolConjPortRepl::getReplication() {
	return m_replication;
}

RTSystemServicesProtocol::RTSystemServicesProtocolConjPort& RTSystemServicesProtocol::RTSystemServicesProtocolConjPortRepl::get(int i) {
	return m_ports.at(i);
}

// incoming messages

void RTSystemServicesProtocol::RTSystemServicesProtocolConjPortRepl::executeInitialTransition() {
	for (int i = 0; i < m_replication; ++i) {
		m_ports.at(i).executeInitialTransition();
	}
}

void RTSystemServicesProtocol::RTSystemServicesProtocolConjPortRepl::startDebugging() {
	for (int i = 0; i < m_replication; ++i) {
		m_ports.at(i).startDebugging();
	}
}

void RTSystemServicesProtocol::RTSystemServicesProtocolConjPortRepl::stopDebugging() {
	for (int i = 0; i < m_replication; ++i) {
		m_ports.at(i).stopDebugging();
	}
}


} /* namespace etRuntime */

Back to the top