| 278 | } |
| 279 | |
| 280 | void service_discovery_impl::subscribe(service_t _service, instance_t _instance, eventgroup_t _eventgroup, major_version_t _major, |
| 281 | ttl_t _ttl, client_t _client, const std::shared_ptr<eventgroupinfo>& _info) { |
| 282 | |
| 283 | if (is_suspended_) { |
| 284 | VSOMEIP_WARNING_P << "Ignoring subscription as we are suspended"; |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | std::scoped_lock its_lock(subscribed_mutex_); |
| 289 | if (auto found_si = subscribed_.find({_service, _instance}); found_si != subscribed_.end()) { |
| 290 | if (auto found_eventgroup = found_si->second.find(_eventgroup); found_eventgroup != found_si->second.end()) { |
| 291 | if (auto its_subscription = found_eventgroup->second; its_subscription->get_major() != _major) { |
| 292 | VSOMEIP_ERROR << "Subscriptions to different versions of the same service instance are not supported!"; |
| 293 | } else if (its_subscription->is_selective()) { |
| 294 | if (its_subscription->add_client(_client)) { |
| 295 | its_subscription->set_state(_client, subscription_state_e::ST_NOT_ACKNOWLEDGED); |
| 296 | send_subscription(its_subscription, _service, _instance, _eventgroup, _client); |
| 297 | } |
| 298 | } |
| 299 | return; |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | std::shared_ptr<boardnet_endpoint> its_reliable, its_unreliable; |
| 304 | get_subscription_endpoints(_service, _instance, its_reliable, its_unreliable); |
| 305 | |
| 306 | // New subscription |
| 307 | std::shared_ptr<subscription> its_subscription = create_subscription(_major, _ttl, its_reliable, its_unreliable, _info); |
| 308 | |
| 309 | if (!its_subscription) { |
| 310 | VSOMEIP_ERROR_P << "Creating subscription failed!"; |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | subscribed_[{_service, _instance}][_eventgroup] = its_subscription; |
| 315 | |
| 316 | its_subscription->add_client(_client); |
| 317 | its_subscription->set_state(_client, subscription_state_e::ST_NOT_ACKNOWLEDGED); |
| 318 | |
| 319 | send_subscription(its_subscription, _service, _instance, _eventgroup, _client); |
| 320 | } |
| 321 | |
| 322 | void service_discovery_impl::send_subscription(const std::shared_ptr<subscription>& _subscription, const service_t _service, |
| 323 | const instance_t _instance, const eventgroup_t _eventgroup, const client_t _client) { |
nothing calls this directly
no test coverage detected