Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4771b38b90658f6ab747d1c63c7441ce47f5c864 (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
/*******************************************************************************
 * 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 MESSAGESERVICECONTROLLER_H_
#define MESSAGESERVICECONTROLLER_H_

#include "common/messaging/IMessageService.h"
#include "osal/etMutex.h"
#include "osal/etSema.h"
#include <map>
#include <queue>
#include <string>

namespace etRuntime {

class MessageServiceController {
public:
	MessageServiceController();
	virtual ~MessageServiceController() {}

	int getNewID();
	void freeID(int id);
	void addMsgSvc(IMessageService& msgSvc);
	void removeMsgSvc(IMessageService& msgSvc);
	IMessageService* getMsgSvc(int threadID);
	void start();
	void stop();
	void resetAll();

	/**
	 * waitTerminate waits blocking for all MessageServices to terminate
	 * ! not thread safe !
	 */
	void waitTerminate();

	void setMsgSvcTerminated(const IMessageService& msgSvc);

protected:
	void dumpThreads(std::string msg);

private:
	void terminate();

	std::map<int, IMessageService*> m_messageServices;
	std::queue<int> m_freeIDs;
	etBool m_running;
	int m_nextFreeID;

	etMutex m_mutex;
	etSema m_terminateSema;
	std::map<int, IMessageService*> m_terminateServices;

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

} /* namespace etRuntime */
#endif /* MESSAGESERVICECONTROLLER_H_ */

Back to the top