diff options
Diffstat (limited to 'cast/sender/public/cast_app_discovery_service.cc')
-rw-r--r-- | cast/sender/public/cast_app_discovery_service.cc | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/cast/sender/public/cast_app_discovery_service.cc b/cast/sender/public/cast_app_discovery_service.cc new file mode 100644 index 00000000..c561b386 --- /dev/null +++ b/cast/sender/public/cast_app_discovery_service.cc @@ -0,0 +1,48 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "cast/sender/public/cast_app_discovery_service.h" + +namespace openscreen { +namespace cast { + +CastAppDiscoveryService::Subscription::Subscription( + CastAppDiscoveryService* discovery_service, + uint32_t id) + : discovery_service_(discovery_service), id_(id) {} + +CastAppDiscoveryService::Subscription::Subscription(Subscription&& other) + : discovery_service_(other.discovery_service_), id_(other.id_) { + other.discovery_service_ = nullptr; +} + +CastAppDiscoveryService::Subscription::~Subscription() { + Reset(); +} + +CastAppDiscoveryService::Subscription& CastAppDiscoveryService::Subscription:: +operator=(Subscription other) { + Swap(other); + return *this; +} + +void CastAppDiscoveryService::Subscription::Reset() { + if (discovery_service_) { + discovery_service_->RemoveAvailabilityCallback(id_); + } + discovery_service_ = nullptr; +} + +void CastAppDiscoveryService::Subscription::Swap(Subscription& other) { + CastAppDiscoveryService* service = other.discovery_service_; + other.discovery_service_ = discovery_service_; + discovery_service_ = service; + + uint32_t id = other.id_; + other.id_ = id_; + id_ = id; +} + +} // namespace cast +} // namespace openscreen |