diff options
author | Lutz Bichler <Lutz.Bichler@bmw.de> | 2014-08-19 10:59:11 +0200 |
---|---|---|
committer | Lutz Bichler <Lutz.Bichler@bmw.de> | 2014-08-19 10:59:11 +0200 |
commit | 136d6eba9cb27be6567b34e83933f0b3eb60f0a0 (patch) | |
tree | 34c850936633c06c9add49c0cf7c8bf4652a4cf2 | |
parent | f17b2b75cbb4242853d70aba04b432ba689e528c (diff) | |
download | vSomeIP-136d6eba9cb27be6567b34e83933f0b3eb60f0a0.tar.gz |
Refined registration process (ensure services can be started after
clients).
-rw-r--r-- | implementation/routing/include/routing_manager_proxy.hpp | 3 | ||||
-rw-r--r-- | implementation/routing/src/routing_manager_proxy.cpp | 39 |
2 files changed, 26 insertions, 16 deletions
diff --git a/implementation/routing/include/routing_manager_proxy.hpp b/implementation/routing/include/routing_manager_proxy.hpp index c0d15c2..4659ccc 100644 --- a/implementation/routing/include/routing_manager_proxy.hpp +++ b/implementation/routing/include/routing_manager_proxy.hpp @@ -82,7 +82,6 @@ public: 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_message(service_t _service, instance_t _instance, const byte_t *_data, length_t _size); void on_routing_info(const byte_t *_data, uint32_t _size); @@ -106,6 +105,8 @@ private: private: boost::asio::io_service &io_; + bool is_connected_; + bool is_started_; routing_manager_host *host_; client_t client_; // store locally as it is needed in each message diff --git a/implementation/routing/src/routing_manager_proxy.cpp b/implementation/routing/src/routing_manager_proxy.cpp index a4ed3d2..a86d8fe 100644 --- a/implementation/routing/src/routing_manager_proxy.cpp +++ b/implementation/routing/src/routing_manager_proxy.cpp @@ -29,7 +29,7 @@ namespace vsomeip { routing_manager_proxy::routing_manager_proxy(routing_manager_host *_host) : io_(_host->get_io()), host_(_host), client_(_host->get_client()), sender_( 0), receiver_(0), serializer_(std::make_shared<serializer>()), deserializer_( - std::make_shared<deserializer>()) { + std::make_shared<deserializer>()), is_connected_(false), is_started_(false) { } routing_manager_proxy::~routing_manager_proxy() { @@ -73,15 +73,17 @@ void routing_manager_proxy::start() { if (receiver_) receiver_->start(); - register_application(); + if (is_connected_) { + register_application(); + host_->on_event(event_type_e::REGISTERED); + } - host_->on_event(event_type_e::REGISTERED); + is_started_ = true; } void routing_manager_proxy::stop() { - host_->on_event(event_type_e::DEREGISTERED); - deregister_application(); + host_->on_event(event_type_e::DEREGISTERED); if (receiver_) receiver_->stop(); @@ -89,6 +91,8 @@ void routing_manager_proxy::stop() { std::stringstream its_client; its_client << base_path << std::hex << client_; ::unlink(its_client.str().c_str()); + + is_started_ = false; } void routing_manager_proxy::offer_service(client_t _client, service_t _service, @@ -324,9 +328,18 @@ bool routing_manager_proxy::set(client_t _client, session_t _session, } void routing_manager_proxy::on_connect(std::shared_ptr<endpoint> _endpoint) { + is_connected_ = (_endpoint == sender_); + if (is_connected_ && is_started_) { + register_application(); + host_->on_event(event_type_e::REGISTERED); + } } void routing_manager_proxy::on_disconnect(std::shared_ptr<endpoint> _endpoint) { + is_connected_ = !(_endpoint == sender_); + if (!is_connected_) { + host_->on_event(event_type_e::DEREGISTERED); + } } void routing_manager_proxy::on_message(const byte_t *_data, length_t _size, @@ -383,10 +396,6 @@ void routing_manager_proxy::on_message(const byte_t *_data, length_t _size, } } -void routing_manager_proxy::on_message(service_t _service, instance_t _instance, const byte_t *_data, length_t _size) { - // TODO: Remove dummy implementation after creating an interface between stub and implementation. -} - void routing_manager_proxy::on_routing_info(const byte_t *_data, uint32_t _size) { #if 0 @@ -498,15 +507,15 @@ bool routing_manager_proxy::is_available(service_t _service, void routing_manager_proxy::register_application() { byte_t its_command[] = { - VSOMEIP_REGISTER_APPLICATION, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + VSOMEIP_REGISTER_APPLICATION, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; std::memcpy(&its_command[VSOMEIP_COMMAND_CLIENT_POS], &client_, sizeof(client_)); std::memset(&its_command[VSOMEIP_COMMAND_SIZE_POS_MIN], 0, sizeof(uint32_t)); - if (sender_) - sender_->send(its_command, sizeof(its_command)); + if (is_connected_) + (void)sender_->send(its_command, sizeof(its_command)); } void routing_manager_proxy::deregister_application() { @@ -518,8 +527,8 @@ void routing_manager_proxy::deregister_application() { sizeof(client_)); std::memcpy(&its_command[VSOMEIP_COMMAND_SIZE_POS_MIN], &its_size, sizeof(its_size)); - if (sender_) - sender_->send(&its_command[0], its_command.size()); + if (is_connected_) + (void)sender_->send(&its_command[0], its_command.size()); } std::shared_ptr<endpoint> routing_manager_proxy::find_local(client_t _client) { @@ -601,7 +610,7 @@ void routing_manager_proxy::send_pong() const { std::memcpy(&its_pong[VSOMEIP_COMMAND_CLIENT_POS], &client_, sizeof(client_t)); - if (sender_) + if (is_connected_) sender_->send(its_pong, sizeof(its_pong)); } |