summaryrefslogtreecommitdiff
path: root/test/header_factory_tests/header_factory_test_client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/header_factory_tests/header_factory_test_client.cpp')
-rw-r--r--test/header_factory_tests/header_factory_test_client.cpp45
1 files changed, 23 insertions, 22 deletions
diff --git a/test/header_factory_tests/header_factory_test_client.cpp b/test/header_factory_tests/header_factory_test_client.cpp
index 4cce67e..3f9eb4f 100644
--- a/test/header_factory_tests/header_factory_test_client.cpp
+++ b/test/header_factory_tests/header_factory_test_client.cpp
@@ -22,24 +22,20 @@ void header_factory_test_client::init()
{
app_->init();
- app_->register_event_handler(
- std::bind(&header_factory_test_client::on_event, this,
+ app_->register_state_handler(
+ std::bind(&header_factory_test_client::on_state, this,
std::placeholders::_1));
- app_->register_availability_handler(vsomeip_test::TEST_SERVICE_SERVICE_ID,
- vsomeip_test::TEST_SERVICE_INSTANCE_ID,
- std::bind(&header_factory_test_client::on_availability, this,
- std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3));
-
app_->register_message_handler(vsomeip::ANY_SERVICE,
vsomeip_test::TEST_SERVICE_INSTANCE_ID, vsomeip::ANY_METHOD,
std::bind(&header_factory_test_client::on_message, this,
std::placeholders::_1));
- request_->set_service(vsomeip_test::TEST_SERVICE_SERVICE_ID);
- request_->set_instance(vsomeip_test::TEST_SERVICE_INSTANCE_ID);
- request_->set_method(vsomeip_test::TEST_SERVICE_METHOD_ID);
+ app_->register_availability_handler(vsomeip_test::TEST_SERVICE_SERVICE_ID,
+ vsomeip_test::TEST_SERVICE_INSTANCE_ID,
+ std::bind(&header_factory_test_client::on_availability, this,
+ std::placeholders::_1, std::placeholders::_2,
+ std::placeholders::_3));
}
void header_factory_test_client::start()
@@ -53,7 +49,7 @@ void header_factory_test_client::stop()
VSOMEIP_INFO << "Stopping...";
app_->unregister_availability_handler(vsomeip_test::TEST_SERVICE_SERVICE_ID,
vsomeip_test::TEST_SERVICE_INSTANCE_ID);
- app_->unregister_event_handler();
+ app_->unregister_state_handler();
app_->unregister_message_handler(vsomeip::ANY_SERVICE,
vsomeip_test::TEST_SERVICE_INSTANCE_ID, vsomeip::ANY_METHOD);
@@ -66,9 +62,9 @@ void header_factory_test_client::join_sender_thread(){
ASSERT_EQ(number_of_sent_messages_, number_of_acknowledged_messages_);
}
-void header_factory_test_client::on_event(vsomeip::event_type_e _event)
+void header_factory_test_client::on_state(vsomeip::state_type_e _state)
{
- if(_event == vsomeip::event_type_e::ET_REGISTERED)
+ if(_state == vsomeip::state_type_e::ST_REGISTERED)
{
app_->request_service(vsomeip_test::TEST_SERVICE_SERVICE_ID,
vsomeip_test::TEST_SERVICE_INSTANCE_ID, false);
@@ -112,6 +108,11 @@ void header_factory_test_client::on_message(const std::shared_ptr<vsomeip::messa
ASSERT_EQ(_response->get_client(), vsomeip_test::TEST_CLIENT_CLIENT_ID);
ASSERT_EQ(_response->get_session(),
static_cast<vsomeip::session_t>(number_of_acknowledged_messages_));
+ if(number_of_acknowledged_messages_ == number_of_messages_to_send_) {
+ std::lock_guard<std::mutex> its_lock(mutex_);
+ blocked_ = true;
+ condition_.notify_one();
+ }
}
void header_factory_test_client::send()
@@ -128,8 +129,12 @@ void header_factory_test_client::run()
{
condition_.wait(its_lock);
}
+ blocked_ = false;
+ request_->set_service(vsomeip_test::TEST_SERVICE_SERVICE_ID);
+ request_->set_instance(vsomeip_test::TEST_SERVICE_INSTANCE_ID);
+ request_->set_method(vsomeip_test::TEST_SERVICE_METHOD_ID);
- for (int i = 0; i < number_of_messages_to_send_; i++)
+ for (uint32_t i = 0; i < number_of_messages_to_send_; i++)
{
app_->send(request_, true);
VSOMEIP_INFO << "Client/Session [" << std::setw(4) << std::setfill('0')
@@ -141,14 +146,10 @@ void header_factory_test_client::run()
<< request_->get_instance() << "]";
number_of_sent_messages_++;
}
- blocked_ = false;
- // wait until all send messages has been acknowledged, but a maximum of 5 sec.
- int cnt = 0;
- while (number_of_acknowledged_messages_ != number_of_messages_to_send_
- && cnt < 5)
+ // wait until all messages have been acknowledged
+ while (!blocked_)
{
- std::this_thread::sleep_for(std::chrono::seconds(1));
- cnt++;
+ condition_.wait(its_lock);
}
stop();
}