diff options
author | Diogo Pedrosa <48529452+DiogoPedrozza@users.noreply.github.com> | 2023-03-13 14:09:12 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-13 14:09:12 +0000 |
commit | 1b427801352b5dcfdc2277f6343166c01afe97d6 (patch) | |
tree | d4e984dd100f3257ce784c9e30aefb6e60a93ab5 /test/internal_routing_disabled_acceptance_test/server.cpp | |
parent | fc73f40fa1501dc53210c63cb7c0d7623d106370 (diff) | |
parent | 826ebb8d352245a36ecaec32b6af61e7abf4696e (diff) | |
download | vSomeIP-1b427801352b5dcfdc2277f6343166c01afe97d6.tar.gz |
Merge pull request #416 from COVESA/update_3.3.03.3.0
vsomeip 3.3.0
Diffstat (limited to 'test/internal_routing_disabled_acceptance_test/server.cpp')
-rw-r--r-- | test/internal_routing_disabled_acceptance_test/server.cpp | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/test/internal_routing_disabled_acceptance_test/server.cpp b/test/internal_routing_disabled_acceptance_test/server.cpp new file mode 100644 index 0000000..6e00b1e --- /dev/null +++ b/test/internal_routing_disabled_acceptance_test/server.cpp @@ -0,0 +1,132 @@ +#include "server.hpp" + +#include <chrono> +#include <iostream> +#include <thread> + +#include <vsomeip/enumeration_types.hpp> +#include <vsomeip/message.hpp> +#include <vsomeip/payload.hpp> +#include <vsomeip/runtime.hpp> + +#include "config.hpp" + +server::server() : applet{"server"}, counter_event_sent{}, counter_method_request{}, counter_method_response{} +{ + this->application->register_message_handler( + config::SERVICE_ID, + config::INSTANCE_ID, + config::METHOD_ID, + [this](const std::shared_ptr<vsomeip_v3::message>& message){ + std::shared_ptr runtime = vsomeip_v3::runtime::get(); + std::shared_ptr payload = message->get_payload(); + + switch(message->get_message_type()) + { + case vsomeip_v3::message_type_e::MT_REQUEST: + std::cout << "GOT REQUEST\n"; + this->counter_method_request++; + { + std::shared_ptr response = runtime->create_response(message); + response->set_payload(payload); + + this->application->send(response); + this->counter_method_response++; + + this->application->notify( + config::SERVICE_ID, + config::INSTANCE_ID, + config::EVENT_ID, + payload, + true + ); + this->counter_event_sent++; + } + break; + + default: + std::cout << "unhandled message type: " << unsigned(message->get_message_type()) << '\n'; + } + } + ); + + this->application->offer_event( + config::SERVICE_ID, + config::INSTANCE_ID, + config::EVENT_ID, + {config::EVENTGROUP_ID}, + vsomeip_v3::event_type_e::ET_FIELD, + {}, + false, + true, + nullptr, + vsomeip_v3::reliability_type_e::RT_UNRELIABLE + ); + + std::thread{ + [this]{ + using namespace std::chrono_literals; + std::this_thread::sleep_for(1s); + + std::shared_ptr runtime = vsomeip_v3::runtime::get(); + std::shared_ptr payload = runtime->create_payload(); + for(int i = 0; i < 10; i++) + { + int j = i | 0x30; + payload->set_data(reinterpret_cast<vsomeip_v3::byte_t*>(&j), sizeof(j)); + this->application->notify( + config::SERVICE_ID, + config::INSTANCE_ID, + config::EVENT_ID, + payload, + true + ); + this->counter_event_sent++; + + std::this_thread::sleep_for(1s); + } + } + }.detach(); +} + +server::~server() +{ + this->application->stop_offer_event( + config::SERVICE_ID, + config::INSTANCE_ID, + config::EVENT_ID + ); + + this->application->stop_offer_service( + config::SERVICE_ID, + config::INSTANCE_ID + ); +} + +std::size_t server::get_event_count() noexcept +{ + return this->counter_event_sent; +} + +std::size_t server::get_method_request_count() noexcept +{ + return this->counter_method_request; +} + +std::size_t server::get_method_response_count() noexcept +{ + return this->counter_method_response; +} + +void server::on_state_registered() +{ + this->application->offer_service( + config::SERVICE_ID, + config::INSTANCE_ID + ); +} + +void server::on_state_deregistered() +{ + std::cout << "Server is deregistered!!! Probably could not be registered!!!\n"; +} |