summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLutz Bichler <Lutz.Bichler@bmw.de>2014-07-09 11:49:57 +0200
committerLutz Bichler <Lutz.Bichler@bmw.de>2014-07-09 11:49:57 +0200
commit3e8509da17d1914d2bfa3030f83c6aeddd9ee04e (patch)
treec7838129fef60479106ab06df88f7cee465841c7
parent10e80cac055911230514e447b40777ac9440f456 (diff)
downloadvSomeIP-3e8509da17d1914d2bfa3030f83c6aeddd9ee04e.tar.gz
Use connect-info to mark services as available/unavailable.
-rw-r--r--implementation/endpoints/include/endpoint_host.hpp4
-rw-r--r--implementation/endpoints/src/client_endpoint_impl.cpp16
-rw-r--r--implementation/endpoints/src/udp_client_endpoint_impl.cpp3
-rw-r--r--implementation/endpoints/src/udp_server_endpoint_impl.cpp9
-rw-r--r--implementation/examples/client-sample.cpp2
-rw-r--r--implementation/routing/include/routing_manager_impl.hpp6
-rw-r--r--implementation/routing/include/routing_manager_proxy.hpp3
-rw-r--r--implementation/routing/include/routing_manager_stub.hpp3
-rw-r--r--implementation/routing/src/routing_manager_impl.cpp32
-rw-r--r--implementation/routing/src/routing_manager_proxy.cpp6
-rw-r--r--implementation/routing/src/routing_manager_stub.cpp8
11 files changed, 85 insertions, 7 deletions
diff --git a/implementation/endpoints/include/endpoint_host.hpp b/implementation/endpoints/include/endpoint_host.hpp
index b986752..4700a7e 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 <memory>
+
#include <vsomeip/primitive_types.hpp>
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 73934cf..5369bc6 100644
--- a/implementation/endpoints/src/client_endpoint_impl.cpp
+++ b/implementation/endpoints/src/client_endpoint_impl.cpp
@@ -13,6 +13,7 @@
#include <boost/asio/local/stream_protocol.hpp>
#include <vsomeip/defines.hpp>
+#include <vsomeip/logger.hpp>
#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 4f3bc64..0c882c6 100644
--- a/implementation/endpoints/src/udp_client_endpoint_impl.cpp
+++ b/implementation/endpoints/src/udp_client_endpoint_impl.cpp
@@ -6,6 +6,8 @@
#include <boost/asio/ip/multicast.hpp>
+#include <vsomeip/logger.hpp>
+
#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 5a2bca2..a1ef866 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 <iomanip>
+
#include <boost/asio/ip/address.hpp>
#include <boost/asio/ip/multicast.hpp>
@@ -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 b173690..9d43f1f 100644
--- a/implementation/examples/client-sample.cpp
+++ b/implementation/examples/client-sample.cpp
@@ -47,8 +47,6 @@ public:
}
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 3d5e62f..f947c97 100644
--- a/implementation/routing/include/routing_manager_impl.hpp
+++ b/implementation/routing/include/routing_manager_impl.hpp
@@ -102,7 +102,6 @@ public:
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 @@ public:
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 9986b6a..32e4f72 100644
--- a/implementation/routing/include/routing_manager_proxy.hpp
+++ b/implementation/routing/include/routing_manager_proxy.hpp
@@ -83,7 +83,10 @@ public:
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 3a59b4b..83bd1e9 100644
--- a/implementation/routing/include/routing_manager_stub.hpp
+++ b/implementation/routing/include/routing_manager_stub.hpp
@@ -31,6 +31,9 @@ public:
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 f13a580..3c49294 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 e524662..601f6bf 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 69d1835..74fd286 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: ";