OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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_ASSOCIATED_GROUP_CONTROLLER_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_GROUP_CONTROLLER_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/ref_counted_delete_on_message_loop.h" |
| 13 #include "base/single_thread_task_runner.h" |
| 14 #include "mojo/public/cpp/bindings/interface_id.h" |
| 15 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
| 16 |
| 17 namespace mojo { |
| 18 |
| 19 class AssociatedGroup; |
| 20 class InterfaceEndpointClient; |
| 21 class InterfaceEndpointController; |
| 22 |
| 23 // An internal interface used to manage endpoints within an associated group. |
| 24 class AssociatedGroupController : |
| 25 public base::RefCountedDeleteOnMessageLoop<AssociatedGroupController> { |
| 26 public: |
| 27 explicit AssociatedGroupController( |
| 28 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 29 |
| 30 // Creates a pair of interface endpoint handles. The method generates a new |
| 31 // interface ID and assigns it to the two handles. |local_endpoint| is used |
| 32 // locally; while |remote_endpoint| is sent over the message pipe. |
| 33 virtual void CreateEndpointHandlePair( |
| 34 ScopedInterfaceEndpointHandle* local_endpoint, |
| 35 ScopedInterfaceEndpointHandle* remote_endpoint) = 0; |
| 36 |
| 37 // Creates an interface endpoint handle from a given interface ID. The handle |
| 38 // is used locally. |
| 39 // Typically, this method is used to (1) create an endpoint handle for the |
| 40 // master interface; or (2) create an endpoint handle on receiving an |
| 41 // interface ID from the message pipe. |
| 42 virtual ScopedInterfaceEndpointHandle CreateLocalEndpointHandle( |
| 43 InterfaceId id) = 0; |
| 44 |
| 45 // Closes an interface endpoint handle. |
| 46 virtual void CloseEndpointHandle(InterfaceId id, bool is_local) = 0; |
| 47 |
| 48 // Attaches a client to the specified endpoint to send and receive messages. |
| 49 // The returned object is still owned by the controller. It must only be used |
| 50 // on the same thread as this call, and only before the client is detached |
| 51 // using DetachEndpointClient(). |
| 52 virtual InterfaceEndpointController* AttachEndpointClient( |
| 53 const ScopedInterfaceEndpointHandle& handle, |
| 54 InterfaceEndpointClient* endpoint_client, |
| 55 scoped_refptr<base::SingleThreadTaskRunner> runner) = 0; |
| 56 |
| 57 // Detaches the client attached to the specified endpoint. It must be called |
| 58 // on the same thread as the corresponding AttachEndpointClient() call. |
| 59 virtual void DetachEndpointClient( |
| 60 const ScopedInterfaceEndpointHandle& handle) = 0; |
| 61 |
| 62 // Raises an error on the underlying message pipe. It disconnects the pipe |
| 63 // and notifies all interfaces running on this pipe. |
| 64 virtual void RaiseError() = 0; |
| 65 |
| 66 std::unique_ptr<AssociatedGroup> CreateAssociatedGroup(); |
| 67 |
| 68 protected: |
| 69 friend class base::RefCountedDeleteOnMessageLoop<AssociatedGroupController>; |
| 70 friend class base::DeleteHelper<AssociatedGroupController>; |
| 71 |
| 72 // Creates a new ScopedInterfaceEndpointHandle associated with this |
| 73 // controller. |
| 74 ScopedInterfaceEndpointHandle CreateScopedInterfaceEndpointHandle( |
| 75 InterfaceId id, |
| 76 bool is_local); |
| 77 |
| 78 virtual ~AssociatedGroupController(); |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(AssociatedGroupController); |
| 81 }; |
| 82 |
| 83 } // namespace mojo |
| 84 |
| 85 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_GROUP_CONTROLLER_H_ |
OLD | NEW |