summaryrefslogtreecommitdiff
path: root/examples/subscribe-sample.cpp
diff options
context:
space:
mode:
authorLutz Bichler <Lutz.Bichler@bmw.de>2014-08-19 10:32:30 +0200
committerLutz Bichler <Lutz.Bichler@bmw.de>2014-08-19 10:32:30 +0200
commit198280b385590c06ae3d857f138e5e31d76773ff (patch)
tree54d61a2d10bd48b8064f5477a7cf1bba4ec5a11d /examples/subscribe-sample.cpp
parent94fbe7b685810b3c9de45fabc3356594893cdefa (diff)
downloadvSomeIP-198280b385590c06ae3d857f138e5e31d76773ff.tar.gz
Implemented local event/field handling.
TODO: implement application-internal event/field handling.
Diffstat (limited to 'examples/subscribe-sample.cpp')
-rw-r--r--examples/subscribe-sample.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/examples/subscribe-sample.cpp b/examples/subscribe-sample.cpp
index d9797fd..15ebba7 100644
--- a/examples/subscribe-sample.cpp
+++ b/examples/subscribe-sample.cpp
@@ -29,18 +29,32 @@ public:
<< (use_tcp_ ? "TCP" : "UDP")
<< "]";
+ app_->register_availability_handler(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID,
+ std::bind(&client_sample::on_availability,
+ this,
+ std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
+
app_->register_message_handler(vsomeip::ANY_SERVICE, SAMPLE_INSTANCE_ID,
vsomeip::ANY_METHOD,
std::bind(&client_sample::on_message, this,
std::placeholders::_1));
-
- app_->subscribe(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_EVENTGROUP_ID);
}
void start() {
app_->start();
}
+ void on_availability(vsomeip::service_t _service, vsomeip::instance_t _instance, bool _is_available) {
+ VSOMEIP_INFO << "Service ["
+ << std::setw(4) << std::setfill('0') << std::hex << _service << "." << _instance
+ << "] is "
+ << (_is_available ? "available." : "NOT available.");
+
+ if (_is_available && SAMPLE_SERVICE_ID == _service && SAMPLE_INSTANCE_ID == _instance) {
+ app_->subscribe(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_EVENTGROUP_ID);
+ }
+ }
+
void on_message(std::shared_ptr<vsomeip::message> &_response) {
std::stringstream its_message;
its_message << "Received a notification for Event [" << std::setw(4)