1 // Copyright 2013 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.
5 #ifndef MOJO_SYSTEM_MESSAGE_PIPE_ENDPOINT_H_
6 #define MOJO_SYSTEM_MESSAGE_PIPE_ENDPOINT_H_
12 #include "base/basictypes.h"
13 #include "base/memory/ref_counted.h"
14 #include "mojo/public/system/core.h"
15 #include "mojo/system/dispatcher.h"
16 #include "mojo/system/message_in_transit.h"
17 #include "mojo/system/system_impl_export.h"
25 // This is an interface to one of the ends of a message pipe, and is used by
26 // |MessagePipe|. Its most important role is to provide a sink for messages
27 // (i.e., a place where messages can be sent). It has a secondary role: When the
28 // endpoint is local (i.e., in the current process), there'll be a dispatcher
29 // corresponding to the endpoint. In that case, the implementation of
30 // |MessagePipeEndpoint| also implements the functionality required by the
31 // dispatcher, e.g., to read messages and to wait. Implementations of this class
32 // are not thread-safe; instances are protected by |MesssagePipe|'s lock.
33 class MOJO_SYSTEM_IMPL_EXPORT MessagePipeEndpoint {
35 virtual ~MessagePipeEndpoint() {}
37 // All implementations must implement these.
38 virtual void Close() = 0;
39 virtual void OnPeerClose() = 0;
40 // Implements |MessagePipe::EnqueueMessage()| (see its description for
42 virtual MojoResult EnqueueMessage(
43 MessageInTransit* message,
44 std::vector<DispatcherTransport>* transports) = 0;
46 // Implementations must override these if they represent a local endpoint,
47 // i.e., one for which there's a |MessagePipeDispatcher| (and thus a handle).
48 // An implementation for a proxy endpoint (for which there's no dispatcher)
49 // needs not override these methods, since they should never be called.
51 // These methods implement the methods of the same name in |MessagePipe|,
52 // though |MessagePipe|'s implementation may have to do a little more if the
53 // operation involves both endpoints.
54 virtual void CancelAllWaiters();
55 virtual MojoResult ReadMessage(
56 void* bytes, uint32_t* num_bytes,
57 std::vector<scoped_refptr<Dispatcher> >* dispatchers,
58 uint32_t* num_dispatchers,
59 MojoReadMessageFlags flags);
60 virtual MojoResult AddWaiter(Waiter* waiter,
62 MojoResult wake_result);
63 virtual void RemoveWaiter(Waiter* waiter);
65 // Implementations must override these if they represent a proxy endpoint. An
66 // implementation for a local endpoint needs not override these methods, since
67 // they should never be called.
68 virtual void Attach(scoped_refptr<Channel> channel,
69 MessageInTransit::EndpointId local_id);
70 virtual void Run(MessageInTransit::EndpointId remote_id);
73 MessagePipeEndpoint() {}
76 DISALLOW_COPY_AND_ASSIGN(MessagePipeEndpoint);
82 #endif // MOJO_SYSTEM_MESSAGE_PIPE_ENDPOINT_H_