MCPcopy Create free account
hub / github.com/COVESA/vsomeip / on_message

Method on_message

examples/subscribe-sample.cpp:72–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70 }
71
72 void on_message(const std::shared_ptr<vsomeip::message>& _response) {
73 std::stringstream its_message;
74 its_message << "Received a notification for Event [" << std::hex << std::setfill('0') << std::setw(4) << _response->get_service()
75 << "." << std::setw(4) << _response->get_instance() << "." << std::setw(4) << _response->get_method()
76 << "] to Client/Session [" << std::setw(4) << _response->get_client() << "/" << std::setw(4) << _response->get_session()
77 << "] = ";
78 std::shared_ptr<vsomeip::payload> its_payload = _response->get_payload();
79 its_message << "(" << std::dec << its_payload->get_length() << ") " << std::hex;
80 for (uint32_t i = 0; i < its_payload->get_length(); ++i)
81 its_message << std::setw(2) << static_cast<int>(its_payload->get_data()[i]) << " ";
82 std::cout << its_message.str() << std::endl;
83
84 if (_response->get_client() == 0) {
85 if ((its_payload->get_length() % 5) == 0) {
86 std::shared_ptr<vsomeip::message> its_get = vsomeip::runtime::get()->create_request();
87 its_get->set_service(SAMPLE_SERVICE_ID);
88 its_get->set_instance(SAMPLE_INSTANCE_ID);
89 its_get->set_method(SAMPLE_GET_METHOD_ID);
90 its_get->set_reliable(use_tcp_);
91 app_->send(its_get);
92 }
93
94 if ((its_payload->get_length() % 8) == 0) {
95 std::shared_ptr<vsomeip::message> its_set = vsomeip::runtime::get()->create_request();
96 its_set->set_service(SAMPLE_SERVICE_ID);
97 its_set->set_instance(SAMPLE_INSTANCE_ID);
98 its_set->set_method(SAMPLE_SET_METHOD_ID);
99 its_set->set_reliable(use_tcp_);
100
101 const vsomeip::byte_t its_data[] = {0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x50, 0x51, 0x52};
102 std::shared_ptr<vsomeip::payload> its_set_payload = vsomeip::runtime::get()->create_payload();
103 its_set_payload->set_data(its_data, sizeof(its_data));
104 its_set->set_payload(its_set_payload);
105 app_->send(its_set);
106 }
107 }
108 }
109
110private:
111 std::shared_ptr<vsomeip::application> app_;

Callers

nothing calls this directly

Calls 15

get_methodMethod · 0.80
create_requestMethod · 0.80
set_methodMethod · 0.80
create_payloadMethod · 0.80
get_serviceMethod · 0.45
get_instanceMethod · 0.45
get_clientMethod · 0.45
get_sessionMethod · 0.45
get_payloadMethod · 0.45
get_lengthMethod · 0.45
get_dataMethod · 0.45
set_serviceMethod · 0.45

Tested by

no test coverage detected