1 // Copyright 2015 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_SCOPED_INTERFACE_ENDPOINT_HANDLE_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_SCOPED_INTERFACE_ENDPOINT_HANDLE_H_ 7 8 #include "base/macros.h" 9 #include "base/memory/ref_counted.h" 10 #include "mojo/public/cpp/bindings/interface_id.h" 11 12 namespace mojo { 13 14 class AssociatedGroupController; 15 16 // ScopedInterfaceEndpointHandle refers to one end of an interface, either the 17 // implementation side or the client side. 18 class ScopedInterfaceEndpointHandle { 19 public: 20 // Creates an invalid endpoint handle. 21 ScopedInterfaceEndpointHandle(); 22 23 ScopedInterfaceEndpointHandle(ScopedInterfaceEndpointHandle&& other); 24 25 ~ScopedInterfaceEndpointHandle(); 26 27 ScopedInterfaceEndpointHandle& operator=( 28 ScopedInterfaceEndpointHandle&& other); 29 is_valid()30 bool is_valid() const { return IsValidInterfaceId(id_); } 31 is_local()32 bool is_local() const { return is_local_; } 33 34 void reset(); 35 void swap(ScopedInterfaceEndpointHandle& other); 36 37 // DO NOT USE METHODS BELOW THIS LINE. These are for internal use and testing. 38 id()39 InterfaceId id() const { return id_; } 40 group_controller()41 AssociatedGroupController* group_controller() const { 42 return group_controller_.get(); 43 } 44 45 // Releases the handle without closing it. 46 InterfaceId release(); 47 48 private: 49 friend class AssociatedGroupController; 50 51 // This is supposed to be used by AssociatedGroupController only. 52 // |id| is the corresponding interface ID. 53 // If |is_local| is false, this handle is meant to be passed over a message 54 // pipe the remote side of the associated group. 55 ScopedInterfaceEndpointHandle( 56 InterfaceId id, 57 bool is_local, 58 scoped_refptr<AssociatedGroupController> group_controller); 59 60 InterfaceId id_; 61 bool is_local_; 62 scoped_refptr<AssociatedGroupController> group_controller_; 63 64 DISALLOW_COPY_AND_ASSIGN(ScopedInterfaceEndpointHandle); 65 }; 66 67 } // namespace mojo 68 69 #endif // MOJO_PUBLIC_CPP_BINDINGS_SCOPED_INTERFACE_ENDPOINT_HANDLE_H_ 70