summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLutz Bichler <Lutz.Bichler@bmw.de>2015-02-16 12:40:20 +0100
committerLutz Bichler <Lutz.Bichler@bmw.de>2015-02-16 12:40:20 +0100
commit36d51624b0971dd87026184596e5abf2d8a71ae1 (patch)
treef37e2bc60cafb326dc17d998f2b613c7a09a190e
parent2d0dad7f5520264e11fb9d2aaccd4a64ead1fd8b (diff)
downloadvSomeIP-36d51624b0971dd87026184596e5abf2d8a71ae1.tar.gz
Make routing manager/proxy/stub correctly handle the case of a lost
local service.
-rw-r--r--implementation/routing/include/routing_manager_impl.hpp1
-rw-r--r--implementation/routing/include/routing_manager_stub.hpp11
-rw-r--r--implementation/routing/include/routing_manager_stub_host.hpp3
-rw-r--r--implementation/routing/src/routing_manager_impl.cpp42
-rw-r--r--implementation/routing/src/routing_manager_proxy.cpp6
-rw-r--r--implementation/routing/src/routing_manager_stub.cpp29
6 files changed, 53 insertions, 39 deletions
diff --git a/implementation/routing/include/routing_manager_impl.hpp b/implementation/routing/include/routing_manager_impl.hpp
index 46542f0..d9c0ed4 100644
--- a/implementation/routing/include/routing_manager_impl.hpp
+++ b/implementation/routing/include/routing_manager_impl.hpp
@@ -106,6 +106,7 @@ public:
void remove_local(client_t _client);
std::shared_ptr<endpoint> find_local(service_t _service,
instance_t _instance);
+ void on_stop_offer_service(service_t _service, instance_t _instance);
// interface "endpoint_host"
std::shared_ptr<endpoint> find_remote_client(service_t _service,
diff --git a/implementation/routing/include/routing_manager_stub.hpp b/implementation/routing/include/routing_manager_stub.hpp
index c06891e..aef8992 100644
--- a/implementation/routing/include/routing_manager_stub.hpp
+++ b/implementation/routing/include/routing_manager_stub.hpp
@@ -1,4 +1,4 @@
-// Copyright (C) 2014 BMW Group
+// 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
@@ -10,6 +10,7 @@
#include <list>
#include <map>
#include <memory>
+#include <mutex>
#include <set>
#include <boost/asio/io_service.hpp>
@@ -26,14 +27,12 @@ class routing_manager_stub:
public std::enable_shared_from_this< routing_manager_stub > {
public:
routing_manager_stub(routing_manager_stub_host *_host);
- ~routing_manager_stub();
+ virtual ~routing_manager_stub();
void init();
void start();
void stop();
- //routing_manager * get_manager();
-
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);
@@ -61,11 +60,15 @@ private:
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
diff --git a/implementation/routing/include/routing_manager_stub_host.hpp b/implementation/routing/include/routing_manager_stub_host.hpp
index bf113ba..e214d63 100644
--- a/implementation/routing/include/routing_manager_stub_host.hpp
+++ b/implementation/routing/include/routing_manager_stub_host.hpp
@@ -39,6 +39,9 @@ public:
virtual void on_message(service_t _service, instance_t _instance,
const byte_t *_data, length_t _size) = 0;
+ virtual void on_stop_offer_service(service_t _service,
+ instance_t _instance) = 0;
+
virtual std::shared_ptr<endpoint> find_local(client_t _client) = 0;
virtual std::shared_ptr<endpoint> find_local(service_t _service,
instance_t _instance) = 0;
diff --git a/implementation/routing/src/routing_manager_impl.cpp b/implementation/routing/src/routing_manager_impl.cpp
index 0e516bb..9985e77 100644
--- a/implementation/routing/src/routing_manager_impl.cpp
+++ b/implementation/routing/src/routing_manager_impl.cpp
@@ -132,25 +132,8 @@ void routing_manager_impl::offer_service(client_t _client, service_t _service,
void routing_manager_impl::stop_offer_service(client_t _client,
service_t _service, instance_t _instance) {
-
- host_->on_availability(_service, _instance, false);
+ on_stop_offer_service(_service, _instance);
stub_->on_stop_offer_service(_client, _service, _instance);
-
- if (discovery_) {
- auto found_service = services_.find(_service);
- if (found_service != services_.end()) {
- auto found_instance = found_service->second.find(_instance);
- if (found_instance != found_service->second.end()) {
- found_instance->second->set_ttl(0);
- discovery_->on_offer_change(
- found_instance->second->get_group()->get_name());
- }
- }
- } else {
- // TODO: allow to withdraw a service on one endpoint only
- del_routing_info(_service, _instance, false);
- del_routing_info(_service, _instance, true);
- }
}
void routing_manager_impl::request_service(client_t _client, service_t _service,
@@ -546,6 +529,27 @@ void routing_manager_impl::on_disconnect(std::shared_ptr<endpoint> _endpoint) {
}
}
+void routing_manager_impl::on_stop_offer_service(service_t _service,
+ instance_t _instance) {
+ host_->on_availability(_service, _instance, false);
+
+ if (discovery_) {
+ auto found_service = services_.find(_service);
+ if (found_service != services_.end()) {
+ auto found_instance = found_service->second.find(_instance);
+ if (found_instance != found_service->second.end()) {
+ found_instance->second->set_ttl(0);
+ discovery_->on_offer_change(
+ found_instance->second->get_group()->get_name());
+ }
+ }
+ } else {
+ // TODO: allow to withdraw a service on one endpoint only
+ del_routing_info(_service, _instance, false);
+ del_routing_info(_service, _instance, true);
+ }
+}
+
bool routing_manager_impl::deliver_message(const byte_t *_data, length_t _size,
instance_t _instance) {
bool is_sent(false);
@@ -875,7 +879,7 @@ std::shared_ptr<endpoint> routing_manager_impl::create_local(client_t _client) {
std::lock_guard<std::recursive_mutex> its_lock(endpoint_mutex_);
std::stringstream its_path;
- its_path << base_path << std::hex << _client;
+ its_path << BASE_PATH << std::hex << _client;
std::shared_ptr<endpoint> its_endpoint = std::make_shared<
local_client_endpoint_impl>(shared_from_this(),
diff --git a/implementation/routing/src/routing_manager_proxy.cpp b/implementation/routing/src/routing_manager_proxy.cpp
index d874f05..94c27f6 100644
--- a/implementation/routing/src/routing_manager_proxy.cpp
+++ b/implementation/routing/src/routing_manager_proxy.cpp
@@ -57,7 +57,7 @@ void routing_manager_proxy::init() {
sender_ = create_local(VSOMEIP_ROUTING_CLIENT);
std::stringstream its_client;
- its_client << base_path << std::hex << client_;
+ its_client << BASE_PATH << std::hex << client_;
::unlink(its_client.str().c_str());
receiver_ = std::make_shared<local_server_endpoint_impl>(shared_from_this(),
@@ -88,7 +88,7 @@ void routing_manager_proxy::stop() {
receiver_->stop();
std::stringstream its_client;
- its_client << base_path << std::hex << client_;
+ its_client << BASE_PATH << std::hex << client_;
::unlink(its_client.str().c_str());
is_started_ = false;
@@ -510,7 +510,7 @@ std::shared_ptr<endpoint> routing_manager_proxy::find_local(client_t _client) {
std::shared_ptr<endpoint> routing_manager_proxy::create_local(
client_t _client) {
std::stringstream its_path;
- its_path << base_path << std::hex << _client;
+ its_path << BASE_PATH << std::hex << _client;
VSOMEIP_DEBUG<< "Connecting to ["
<< std::hex << _client << "] at " << its_path.str();
diff --git a/implementation/routing/src/routing_manager_stub.cpp b/implementation/routing/src/routing_manager_stub.cpp
index 265a9c9..839c8e7 100644
--- a/implementation/routing/src/routing_manager_stub.cpp
+++ b/implementation/routing/src/routing_manager_stub.cpp
@@ -33,14 +33,15 @@ routing_manager_stub::~routing_manager_stub() {
void routing_manager_stub::init() {
std::stringstream its_endpoint_path;
- its_endpoint_path << base_path << VSOMEIP_ROUTING_CLIENT;
- ::unlink(its_endpoint_path.str().c_str());
+ its_endpoint_path << BASE_PATH << VSOMEIP_ROUTING_CLIENT;
+ endpoint_path_ = its_endpoint_path.str();
+ ::unlink(endpoint_path_.c_str());
- VSOMEIP_DEBUG << "Routing endpoint at " << its_endpoint_path.str();
+ VSOMEIP_DEBUG << "Routing endpoint at " << endpoint_path_;
endpoint_ =
std::make_shared < local_server_endpoint_impl
> (shared_from_this(), boost::asio::local::stream_protocol::endpoint(
- its_endpoint_path.str()), io_);
+ endpoint_path_), io_);
}
void routing_manager_stub::start() {
@@ -54,9 +55,7 @@ void routing_manager_stub::stop() {
watchdog_timer_.cancel();
endpoint_->stop();
- std::stringstream its_endpoint_path;
- its_endpoint_path << base_path << VSOMEIP_ROUTING_CLIENT;
- ::unlink(its_endpoint_path.str().c_str());
+ ::unlink(endpoint_path_.c_str());
}
void routing_manager_stub::on_connect(std::shared_ptr<endpoint> _endpoint) {
@@ -105,9 +104,7 @@ void routing_manager_stub::on_message(const byte_t *_data, length_t _size,
if (its_size <= _size - VSOMEIP_COMMAND_HEADER_SIZE) {
switch (its_command) {
case VSOMEIP_REGISTER_APPLICATION:
- (void)host_->find_or_create_local(its_client);
- routing_info_[its_client].first = 0;
- broadcast_routing_info();
+ on_register_application(its_client);
VSOMEIP_DEBUG << "Application/Client "
<< std::hex << std::setw(4) << std::setfill('0')
<< its_client << " got registered!";
@@ -194,16 +191,19 @@ void routing_manager_stub::on_message(const byte_t *_data, length_t _size,
}
void routing_manager_stub::on_register_application(client_t _client) {
-
+ std::lock_guard<std::mutex> its_guard(routing_info_mutex_);
+ (void)host_->find_or_create_local(_client);
+ routing_info_[_client].first = 0;
+ broadcast_routing_info();
}
void routing_manager_stub::on_deregister_application(client_t _client) {
+ std::lock_guard<std::mutex> its_guard(routing_info_mutex_);
auto its_info = routing_info_.find(_client);
if (its_info != routing_info_.end()) {
for (auto &its_service : its_info->second.second) {
for (auto &its_instance : its_service.second) {
- host_->stop_offer_service(_client, its_service.first,
- its_instance);
+ host_->on_stop_offer_service(its_service.first, its_instance);
}
}
}
@@ -215,12 +215,14 @@ void routing_manager_stub::on_deregister_application(client_t _client) {
void routing_manager_stub::on_offer_service(client_t _client,
service_t _service, instance_t _instance) {
+ std::lock_guard<std::mutex> its_guard(routing_info_mutex_);
routing_info_[_client].second[_service].insert(_instance);
broadcast_routing_info();
}
void routing_manager_stub::on_stop_offer_service(client_t _client,
service_t _service, instance_t _instance) {
+ std::lock_guard<std::mutex> its_guard(routing_info_mutex_);
auto found_client = routing_info_.find(_client);
if (found_client != routing_info_.end()) {
auto found_service = found_client->second.second.find(_service);
@@ -308,6 +310,7 @@ void routing_manager_stub::broadcast_routing_info() {
}
void routing_manager_stub::broadcast(std::vector<byte_t> &_command) const {
+ std::lock_guard<std::mutex> its_guard(routing_info_mutex_);
for (auto a : routing_info_) {
if (a.first > 0) {
std::shared_ptr<endpoint> its_endpoint