1 // Copyright 2023 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 15 #include "pw_bluetooth_sapphire/internal/host/l2cap/scoped_channel.h" 16 17 namespace bt::l2cap { 18 ScopedChannel(Channel::WeakPtr chan)19ScopedChannel::ScopedChannel(Channel::WeakPtr chan) : chan_(std::move(chan)) {} 20 ScopedChannel(ScopedChannel && other)21ScopedChannel::ScopedChannel(ScopedChannel&& other) 22 : chan_(std::move(other.chan_)) {} 23 ~ScopedChannel()24ScopedChannel::~ScopedChannel() { Close(); } 25 Reset(Channel::WeakPtr new_channel)26void ScopedChannel::Reset(Channel::WeakPtr new_channel) { 27 if (chan_.is_alive()) { 28 Close(); 29 } 30 chan_ = std::move(new_channel); 31 } 32 Close()33void ScopedChannel::Close() { 34 if (chan_.is_alive()) { 35 chan_->Deactivate(); 36 chan_ = Channel::WeakPtr(); 37 } 38 } 39 40 } // namespace bt::l2cap 41