| 1004 | } |
| 1005 | |
| 1006 | void application_impl::on_subscription(service_t _service, instance_t _instance, eventgroup_t _eventgroup, client_t _client, |
| 1007 | const vsomeip_sec_client_t* _sec_client, const std::string& _env, bool _subscribed, |
| 1008 | const std::function<void(bool)>& _accepted_cb) { |
| 1009 | |
| 1010 | // A sync_handler needs to be created to guarantee order of callback invocations, |
| 1011 | // irrespective of (un)registration of any handler |
| 1012 | auto its_sync_handler = |
| 1013 | std::make_shared<sync_handler>([this, _service, _instance, _eventgroup, _client, _subscribed, sec_client = *_sec_client, |
| 1014 | env = _env, continuation = _accepted_cb, weak_self = weak_from_this()] { |
| 1015 | if (auto self = weak_self.lock(); self) { |
| 1016 | subscription_handler_sec_t handler; |
| 1017 | async_subscription_handler_sec_t async_handler; |
| 1018 | { |
| 1019 | std::scoped_lock its_lock{subscription_mutex_}; |
| 1020 | if (auto found_si = subscription_.find({_service, _instance}); found_si != subscription_.end()) { |
| 1021 | if (auto found_eventgroup = found_si->second.find(_eventgroup); found_eventgroup != found_si->second.end()) { |
| 1022 | std::tie(handler, async_handler) = found_eventgroup->second; |
| 1023 | } |
| 1024 | } |
| 1025 | } |
| 1026 | if (handler) { |
| 1027 | continuation(handler(_client, &sec_client, env, _subscribed)); |
| 1028 | } else if (async_handler) { |
| 1029 | async_handler(_client, &sec_client, env, _subscribed, continuation); |
| 1030 | } else { |
| 1031 | continuation(true); |
| 1032 | } |
| 1033 | } |
| 1034 | }); |
| 1035 | its_sync_handler->service_id_ = _service; |
| 1036 | its_sync_handler->instance_id_ = _instance; |
| 1037 | its_sync_handler->eventgroup_id_ = _eventgroup; |
| 1038 | its_sync_handler->client_id_ = _client; |
| 1039 | its_sync_handler->handler_type_ = handler_type_e::SUBSCRIPTION; |
| 1040 | std::scoped_lock handlers_lock(handlers_mutex_); |
| 1041 | handlers_.push_back(its_sync_handler); |
| 1042 | dispatcher_condition_.notify_all(); |
| 1043 | } |
| 1044 | |
| 1045 | void application_impl::register_subscription_handler(service_t _service, instance_t _instance, eventgroup_t _eventgroup, |
| 1046 | const subscription_handler_t& _handler) { |
no test coverage detected