Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9f5e2b759a410b01893a31a068069d667eeac7f4 (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
/*******************************************************************************
 * Copyright (c) 2012 Draeger Medical GmbH (http://www.draeger.com).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * CONTRIBUTORS:
 * 		Peter Karlitschek (initial contribution)
 *
 *******************************************************************************/

#include "MessageDispatcher.h"

namespace etRuntime {


MessageDispatcher::~MessageDispatcher() {
}

MessageDispatcher::MessageDispatcher(IRTObject* parent, Address addr, std::string name)
: RTObject(parent, name) ,
  IMessageReceiver(),
  m_local_map(),
  m_thread_map(),
  m_node_map(),
  m_address(addr)
{};

void MessageDispatcher::addMessageReceiver(IMessageReceiver& receiver){
if (! receiver.getAddress().isValid() )
	return;

// TODO: does only work same thread (else)
if (receiver.getAddress().m_nodeID != m_address.m_nodeID){
	m_node_map[receiver.getAddress().m_objectID] = &receiver;
}
else if(receiver.getAddress().m_threadID != m_address.m_threadID){
	m_thread_map[receiver.getAddress().m_threadID] = &receiver;
}
else {
	m_local_map[receiver.getAddress().m_objectID] = &receiver;
}
};

void MessageDispatcher::receive(Message* msg) {
// TODO: does only work same thread (else)
	//TODO: assert msg != 0
IMessageReceiver* receiver = 0;
std::map<int, IMessageReceiver*>::iterator it;
if (msg->getAddress().m_nodeID != m_address.m_nodeID){
	it = m_node_map.find(msg->getAddress().m_objectID);
	if (it != m_node_map.end() ) {
		receiver = (*it).second;
	}
}
else if(msg->getAddress().m_threadID != m_address.m_threadID){
	it = m_thread_map.find(msg->getAddress().m_objectID);
	if (it != m_thread_map.end() ) {
		receiver = (*it).second;
	}
}
else {
	// Same node, same thread -> local call Dispatch Map
	it = m_local_map.find(msg->getAddress().m_objectID);
	if (it != m_local_map.end() ) {
		receiver = (*it).second;
	}
}
if (receiver!=0)
{
	receiver->receive(msg);
	// TODO: error handling for not found addresses
}
}

} /* namespace etRuntime */

Back to the top