Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 359acff438258ee8e6b8d390a04f81328421868b (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
/*******************************************************************************
 * 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)
 *
 *******************************************************************************/

#ifndef MESSAGEDISPATCHER_H_
#define MESSAGEDISPATCHER_H_

#include "common/messaging/Address.h"
#include "common/messaging/IMessageReceiver.h"
#include "common/messaging/RTObject.h"
#include <map>
#include <queue>
#include <set>
#include <string>



namespace etRuntime {

class MessageDispatcher : public RTObject, public virtual IMessageReceiver {
	public:
		MessageDispatcher(IRTObject* parent, const Address& addr, const std::string& name);
		virtual ~MessageDispatcher() {}

		Address getFreeAddress();
		void freeAddress(const Address& addr);
		void addMessageReceiver(IMessageReceiver& receiver);
		void removeMessageReceiver(IMessageReceiver& receiver);
		void addPollingMessageReceiver(IMessageReceiver& receiver);
		void removePollingMessageReceiver(IMessageReceiver& receiver);
		void receive(const Message* msg);

		const Address& getAddress() const { return m_address; };

	protected:
		std::string toString() const;

	private:
		std::map<int, IMessageReceiver*> m_local_map;
		std::queue<Address> m_freeAdresses;
		std::set<IMessageReceiver*> m_pollingMessageReceiver;
		Address m_address;
		int m_nextFreeObjId;

		MessageDispatcher();
		MessageDispatcher(MessageDispatcher const&);
		MessageDispatcher& operator=(MessageDispatcher const&);
};

} /* namespace etRuntime */
#endif /* MESSAGEDISPATCHER_H_ */


Back to the top