diff options
Diffstat (limited to 'mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.cc')
-rw-r--r-- | mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.cc | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.cc b/mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.cc new file mode 100644 index 0000000..f54c3f7 --- /dev/null +++ b/mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.cc @@ -0,0 +1,72 @@ +// Copyright 2015 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 "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" + +#include "base/logging.h" +#include "mojo/public/cpp/bindings/associated_group_controller.h" + +namespace mojo { + +ScopedInterfaceEndpointHandle::ScopedInterfaceEndpointHandle() + : ScopedInterfaceEndpointHandle(kInvalidInterfaceId, true, nullptr) {} + +ScopedInterfaceEndpointHandle::ScopedInterfaceEndpointHandle( + ScopedInterfaceEndpointHandle&& other) + : id_(other.id_), is_local_(other.is_local_) { + group_controller_.swap(other.group_controller_); + other.id_ = kInvalidInterfaceId; +} + +ScopedInterfaceEndpointHandle::~ScopedInterfaceEndpointHandle() { + reset(); +} + +ScopedInterfaceEndpointHandle& ScopedInterfaceEndpointHandle::operator=( + ScopedInterfaceEndpointHandle&& other) { + reset(); + swap(other); + + return *this; +} + +void ScopedInterfaceEndpointHandle::reset() { + if (!IsValidInterfaceId(id_)) + return; + + group_controller_->CloseEndpointHandle(id_, is_local_); + + id_ = kInvalidInterfaceId; + is_local_ = true; + group_controller_ = nullptr; +} + +void ScopedInterfaceEndpointHandle::swap(ScopedInterfaceEndpointHandle& other) { + using std::swap; + swap(other.id_, id_); + swap(other.is_local_, is_local_); + swap(other.group_controller_, group_controller_); +} + +InterfaceId ScopedInterfaceEndpointHandle::release() { + InterfaceId result = id_; + + id_ = kInvalidInterfaceId; + is_local_ = true; + group_controller_ = nullptr; + + return result; +} + +ScopedInterfaceEndpointHandle::ScopedInterfaceEndpointHandle( + InterfaceId id, + bool is_local, + scoped_refptr<AssociatedGroupController> group_controller) + : id_(id), + is_local_(is_local), + group_controller_(std::move(group_controller)) { + DCHECK(!IsValidInterfaceId(id) || group_controller_); +} + +} // namespace mojo |