Skip to content

Commit

Permalink
Use connect-info to mark services as available/unavailable.
Browse files Browse the repository at this point in the history
  • Loading branch information
lutzbichler committed Jul 9, 2014
1 parent 10e80ca commit 3e8509d
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 7 deletions.
4 changes: 4 additions & 0 deletions implementation/endpoints/include/endpoint_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#ifndef VSOMEIP_ENDPOINT_HOST_HPP
#define VSOMEIP_ENDPOINT_HOST_HPP

#include <memory>

#include <vsomeip/primitive_types.hpp>

namespace vsomeip {
Expand All @@ -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;
};

Expand Down
16 changes: 13 additions & 3 deletions implementation/endpoints/src/client_endpoint_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
}
Expand Down
3 changes: 3 additions & 0 deletions implementation/endpoints/src/udp_client_endpoint_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <boost/asio/ip/multicast.hpp>

#include <vsomeip/logger.hpp>

#include "../include/udp_client_endpoint_impl.hpp"

namespace vsomeip {
Expand Down Expand Up @@ -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],
Expand Down
9 changes: 8 additions & 1 deletion implementation/endpoints/src/udp_server_endpoint_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 0 additions & 2 deletions implementation/examples/client-sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
6 changes: 5 additions & 1 deletion implementation/routing/include/routing_manager_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions implementation/routing/include/routing_manager_proxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions implementation/routing/include/routing_manager_stub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
32 changes: 32 additions & 0 deletions implementation/routing/src/routing_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: ";
Expand Down
6 changes: 6 additions & 0 deletions implementation/routing/src/routing_manager_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions implementation/routing/src/routing_manager_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: ";
Expand Down

0 comments on commit 3e8509d

Please sign in to comment.