From 3e8509da17d1914d2bfa3030f83c6aeddd9ee04e Mon Sep 17 00:00:00 2001 From: Lutz Bichler Date: Wed, 9 Jul 2014 11:49:57 +0200 Subject: [PATCH] Use connect-info to mark services as available/unavailable. --- .../endpoints/include/endpoint_host.hpp | 4 +++ .../endpoints/src/client_endpoint_impl.cpp | 16 ++++++++-- .../src/udp_client_endpoint_impl.cpp | 3 ++ .../src/udp_server_endpoint_impl.cpp | 9 +++++- implementation/examples/client-sample.cpp | 2 -- .../routing/include/routing_manager_impl.hpp | 6 +++- .../routing/include/routing_manager_proxy.hpp | 3 ++ .../routing/include/routing_manager_stub.hpp | 3 ++ .../routing/src/routing_manager_impl.cpp | 32 +++++++++++++++++++ .../routing/src/routing_manager_proxy.cpp | 6 ++++ .../routing/src/routing_manager_stub.cpp | 8 +++++ 11 files changed, 85 insertions(+), 7 deletions(-) diff --git a/implementation/endpoints/include/endpoint_host.hpp b/implementation/endpoints/include/endpoint_host.hpp index b98675209..4700a7e77 100644 --- a/implementation/endpoints/include/endpoint_host.hpp +++ b/implementation/endpoints/include/endpoint_host.hpp @@ -7,6 +7,8 @@ #ifndef VSOMEIP_ENDPOINT_HOST_HPP #define VSOMEIP_ENDPOINT_HOST_HPP +#include + #include namespace vsomeip { @@ -17,6 +19,8 @@ class endpoint_host { public: virtual ~endpoint_host() {}; + virtual void on_connect(std::shared_ptr< endpoint > _endpoint) = 0; + virtual void on_disconnect(std::shared_ptr< endpoint > _endpoint) = 0; virtual void on_message(const byte_t *_data, length_t _length, endpoint *_receiver) = 0; }; diff --git a/implementation/endpoints/src/client_endpoint_impl.cpp b/implementation/endpoints/src/client_endpoint_impl.cpp index 73934cffa..5369bc64d 100644 --- a/implementation/endpoints/src/client_endpoint_impl.cpp +++ b/implementation/endpoints/src/client_endpoint_impl.cpp @@ -13,6 +13,7 @@ #include #include +#include #include "../include/client_endpoint_impl.hpp" #include "../include/endpoint_host.hpp" @@ -132,12 +133,21 @@ void client_endpoint_impl< Protocol, MaxBufferSize >::connect_cbk( // next time we wait longer connect_timeout_ <<= 1; + + if (is_connected_) { + is_connected_ = false; + this->host_->on_disconnect(this->shared_from_this()); + } } else { connect_timer_.cancel(); connect_timeout_ = VSOMEIP_DEFAULT_CONNECT_TIMEOUT; // TODO: use config variable - is_connected_ = true; - if (!packet_queue_.empty()) { - send_queued(); + + if (!is_connected_) { + is_connected_ = true; + this->host_->on_connect(this->shared_from_this()); + if (!packet_queue_.empty()) { + send_queued(); + } } receive(); } diff --git a/implementation/endpoints/src/udp_client_endpoint_impl.cpp b/implementation/endpoints/src/udp_client_endpoint_impl.cpp index 4f3bc64ec..0c882c63c 100644 --- a/implementation/endpoints/src/udp_client_endpoint_impl.cpp +++ b/implementation/endpoints/src/udp_client_endpoint_impl.cpp @@ -6,6 +6,8 @@ #include +#include + #include "../include/udp_client_endpoint_impl.hpp" namespace vsomeip { @@ -44,6 +46,7 @@ void udp_client_endpoint_impl::start() { } void udp_client_endpoint_impl::send_queued() { + VSOMEIP_DEBUG << "UDP CLIENT SENDING"; socket_.async_send( boost::asio::buffer( &packet_queue_.front()[0], diff --git a/implementation/endpoints/src/udp_server_endpoint_impl.cpp b/implementation/endpoints/src/udp_server_endpoint_impl.cpp index 5a2bca21c..a1ef866ae 100644 --- a/implementation/endpoints/src/udp_server_endpoint_impl.cpp +++ b/implementation/endpoints/src/udp_server_endpoint_impl.cpp @@ -4,6 +4,8 @@ // 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/. +#include + #include #include @@ -134,7 +136,12 @@ bool udp_server_endpoint_impl::is_udp() const { // TODO: find a better way to structure the receive functions void udp_server_endpoint_impl::receive_cbk(boost::system::error_code const &_error, std::size_t _bytes) { - if (!_error && 0 < _bytes) { + if (!_error && 0 < _bytes) { +#if 1 + for (std::size_t i = 0; i < _bytes; ++i) + std::cout << std::setw(2) << std::setfill('0') << (int)get_buffer()[i] << " "; + std::cout << std::endl; +#endif const uint8_t *buffer = get_buffer(); message_.insert(message_.end(), buffer, buffer + _bytes); diff --git a/implementation/examples/client-sample.cpp b/implementation/examples/client-sample.cpp index b17369056..9d43f1f12 100644 --- a/implementation/examples/client-sample.cpp +++ b/implementation/examples/client-sample.cpp @@ -47,8 +47,6 @@ class client_sample { } void start() { - if (app_->is_available(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID)) - on_availability(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, true); app_->start(); } diff --git a/implementation/routing/include/routing_manager_impl.hpp b/implementation/routing/include/routing_manager_impl.hpp index 3d5e62f5e..f947c97e0 100644 --- a/implementation/routing/include/routing_manager_impl.hpp +++ b/implementation/routing/include/routing_manager_impl.hpp @@ -102,7 +102,6 @@ class routing_manager_impl: service_t _service, instance_t _instance, event_t _event, const std::vector< byte_t > &_value); - void on_message(const byte_t *_data, length_t _length, endpoint *_receiver); bool is_available(service_t _service, instance_t _instance) const; @@ -113,6 +112,11 @@ class routing_manager_impl: void remove_local(client_t _client); std::shared_ptr< endpoint > find_local(service_t _service, instance_t _instance); + // interface "endpoint_host" + void on_connect(std::shared_ptr< endpoint > _endpoint); + void on_disconnect(std::shared_ptr< endpoint > _endpoint); + void on_message(const byte_t *_data, length_t _length, endpoint *_receiver); + // interface "service_discovery_host" const std::map< std::string, std::shared_ptr< servicegroup > > & get_servicegroups() const; service_map_t get_offered_services(const std::string &_name) const; diff --git a/implementation/routing/include/routing_manager_proxy.hpp b/implementation/routing/include/routing_manager_proxy.hpp index 9986b6a83..32e4f72a0 100644 --- a/implementation/routing/include/routing_manager_proxy.hpp +++ b/implementation/routing/include/routing_manager_proxy.hpp @@ -83,7 +83,10 @@ class routing_manager_proxy: service_t _service, instance_t _instance, event_t _event, const std::vector< byte_t > &_value); + void on_connect(std::shared_ptr< endpoint > _endpoint); + void on_disconnect(std::shared_ptr< endpoint > _endpoint); void on_message(const byte_t *_data, length_t _length, endpoint *_receiver); + void on_routing_info(const byte_t *_data, uint32_t _size); bool is_available(service_t _service, instance_t _instance) const; diff --git a/implementation/routing/include/routing_manager_stub.hpp b/implementation/routing/include/routing_manager_stub.hpp index 3a59b4b57..83bd1e998 100644 --- a/implementation/routing/include/routing_manager_stub.hpp +++ b/implementation/routing/include/routing_manager_stub.hpp @@ -31,6 +31,9 @@ class routing_manager_stub: 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); private: diff --git a/implementation/routing/src/routing_manager_impl.cpp b/implementation/routing/src/routing_manager_impl.cpp index f13a58048..3c49294ba 100644 --- a/implementation/routing/src/routing_manager_impl.cpp +++ b/implementation/routing/src/routing_manager_impl.cpp @@ -296,6 +296,38 @@ void routing_manager_impl::on_message(const byte_t *_data, length_t _size, endpo } } +void routing_manager_impl::on_connect(std::shared_ptr< endpoint > _endpoint) { + for (auto &its_service : remote_services_) { + for (auto &its_instance : its_service.second) { + auto found_endpoint = its_instance.second.find(false); + if (found_endpoint != its_instance.second.end()) { + host_->on_availability(its_service.first, its_instance.first, true); + } else { + found_endpoint = its_instance.second.find(true); + if (found_endpoint != its_instance.second.end()) { + host_->on_availability(its_service.first, its_instance.first, true); + } + } + } + } +} + +void routing_manager_impl::on_disconnect(std::shared_ptr< endpoint > _endpoint) { + for (auto &its_service : remote_services_) { + for (auto &its_instance : its_service.second) { + auto found_endpoint = its_instance.second.find(false); + if (found_endpoint != its_instance.second.end()) { + host_->on_availability(its_service.first, its_instance.first, false); + } else { + found_endpoint = its_instance.second.find(true); + if (found_endpoint != its_instance.second.end()) { + host_->on_availability(its_service.first, its_instance.first, false); + } + } + } + } +} + void routing_manager_impl::on_message(const byte_t *_data, length_t _size, instance_t _instance) { #if 0 std::cout << "rmi::on_message: "; diff --git a/implementation/routing/src/routing_manager_proxy.cpp b/implementation/routing/src/routing_manager_proxy.cpp index e52466233..601f6bf7e 100644 --- a/implementation/routing/src/routing_manager_proxy.cpp +++ b/implementation/routing/src/routing_manager_proxy.cpp @@ -260,6 +260,12 @@ void routing_manager_proxy::set(client_t _client, event_t _event, const std::vector< byte_t > &_value) { } +void routing_manager_proxy::on_connect(std::shared_ptr< endpoint > _endpoint) { +} + +void routing_manager_proxy::on_disconnect(std::shared_ptr< endpoint > _endpoint) { +} + void routing_manager_proxy::on_message( const byte_t *_data, length_t _size, endpoint *_receiver) { #if 0 diff --git a/implementation/routing/src/routing_manager_stub.cpp b/implementation/routing/src/routing_manager_stub.cpp index 69d1835ee..74fd2869e 100644 --- a/implementation/routing/src/routing_manager_stub.cpp +++ b/implementation/routing/src/routing_manager_stub.cpp @@ -58,6 +58,14 @@ routing_manager * routing_manager_stub::get_manager() { return routing_; } +void routing_manager_stub::on_connect(std::shared_ptr< endpoint > _endpoint) { + +} + +void routing_manager_stub::on_disconnect(std::shared_ptr< endpoint > _endpoint) { + +} + void routing_manager_stub::on_message(const byte_t *_data, length_t _size, endpoint *_receiver) { #if 0 std::cout << "rms::on_message: ";