summaryrefslogtreecommitdiff
path: root/implementation/routing/include/routing_manager_stub.hpp
blob: aef89921a4d61ae46c62c57d189fd3487730156b (plain)
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
// Copyright (C) 2014-2015 BMW Group
// Author: Lutz Bichler (lutz.bichler@bmw.de)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef VSOMEIP_ROUTING_MANAGER_STUB
#define VSOMEIP_ROUTING_MANAGER_STUB

#include <list>
#include <map>
#include <memory>
#include <mutex>
#include <set>

#include <boost/asio/io_service.hpp>
#include <boost/asio/system_timer.hpp>

#include "../../endpoints/include/endpoint_host.hpp"

namespace vsomeip {

class routing_manager_stub_host;

class routing_manager_stub:
		public endpoint_host,
		public std::enable_shared_from_this< routing_manager_stub > {
public:
	routing_manager_stub(routing_manager_stub_host *_host);
	virtual ~routing_manager_stub();

	void init();
	void start();
	void stop();

	void on_connect(std::shared_ptr< endpoint > _endpoint);
	void on_disconnect(std::shared_ptr< endpoint > _endpoint);
	void on_message(const byte_t *_data, const length_t _length, endpoint *_receiver);

	void on_offer_service(client_t _client, service_t _service, instance_t _instance);
	void on_stop_offer_service(client_t _client, service_t _service, instance_t _instance);

private:
	void broadcast(std::vector< byte_t > &_command) const;

	void on_register_application(client_t _client);
	void on_deregister_application(client_t _client);

	void broadcast_routing_info();
	void send_routing_info(client_t _client);

	void broadcast_ping() const;
	void on_pong(client_t _client);
	void start_watchdog();
	void check_watchdog();
	void send_application_lost(std::list< client_t > &_lost);

private:
	boost::asio::io_service &io_;
	boost::asio::system_timer watchdog_timer_;

	routing_manager_stub_host *host_;

	std::string endpoint_path_;
	std::shared_ptr< endpoint > endpoint_;

	std::map< client_t,
			  std::pair< uint8_t,
			     	     std::map< service_t,
			     	     	 	   std::set< instance_t > > > > routing_info_;
	mutable std::mutex routing_info_mutex_;
};

} // namespace vsomeip

#endif // VSOMEIP_ROUTING_MANAGER_STUB