Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1205c2a334156ee77364230228408d837cecbd96 (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
/*
 * RTSystemServicesProtocol.cpp
 *
 *  Created on: 29.08.2012
 *      Author: karlitsc
 */

#include "RTSystemServicesProtocol.h"

namespace etRuntime {

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

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

//------------------------------------------------------------------
// RTSystemServicesProtocol: surrounding class
//------------------------------------------------------------------


RTSystemServicesProtocol::RTSystemServicesProtocol() {
}

RTSystemServicesProtocol::~RTSystemServicesProtocol() {
}


//------------------------------------------------------------------
// 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 msg) {
	if (! Events::isValidIncomingEvtID(msg.getEvtId())) {
		std::cout << "unknown" << std::endl;
	}
	else {
		if (msg.hasDebugFlagSet()) {			// TODO: model switch for activation of this flag
			DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), Events::getMessageString(msg.getEvtId()));
		}
		getActor().receiveEvent(*this, msg.getEvtId(),	msg.getData());
	}
};

// sent messages

void RTSystemServicesProtocol::RTSystemServicesProtocolPort::dummy() {
	DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
		Events::getMessageString(Events::OUT_dummy));
	PortBase::send(Events::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]));
	}
};

// 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 msg) {
	if (! Events::isValidOutgoingEvtID(msg.getEvtId())) {  //conjugated port receives out-messages
		std::cout << "unknown" << std::endl;
	}
	else {
		if (msg.hasDebugFlagSet()) {			// TODO: model switch for activation of this flag
			DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), Events::getMessageString(msg.getEvtId()));
		}
		getActor().receiveEvent(*this, msg.getEvtId(),	msg.getData());
	}
}

// sent messages

void RTSystemServicesProtocol::RTSystemServicesProtocolConjPort::executeInitialTransition() {
	DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
		Events::getMessageString(Events::IN_executeInitialTransition));
	PortBase::send(Events::IN_executeInitialTransition);
}

void RTSystemServicesProtocol::RTSystemServicesProtocolConjPort::startDebugging() {
	DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
		Events::getMessageString(Events::IN_startDebugging));
	PortBase::send(Events::IN_startDebugging);
}

void RTSystemServicesProtocol::RTSystemServicesProtocolConjPort::stopDebugging() {
	DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
		Events::getMessageString(Events::IN_stopDebugging));
	PortBase::send(Events::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]));
	}
};

// sent 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