aboutsummaryrefslogtreecommitdiff
path: root/mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.cc
diff options
context:
space:
mode:
authorLuis Hector Chavez <lhchavez@google.com>2016-12-28 10:56:26 -0800
committerLuis Hector Chavez <lhchavez@google.com>2016-12-28 10:56:26 -0800
commit645501c2ab19a559ce82a1d5a29ced159a4c30fb (patch)
treeb3d9637e908d074f905d3dacbeb1db8361fafb8a /mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.cc
parent3d72bec9be57b7d199d2cbd7139308bb3c3c34bb (diff)
downloadlibmojo-645501c2ab19a559ce82a1d5a29ced159a4c30fb.tar.gz
Initial import of libmojo r405848
This brings libmojo in sync with libchrome. Bug: 27569341 Test: mma -j32 libmojo Change-Id: Ia7cb877e46dd3f86f18888b5d8d80bef5468b266
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.cc72
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