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_
8 #include "base/basictypes.h"
9 #include "mojo/public/system/core.h"
16 // This is an interface to one of the ends of a message pipe, and is used by
17 // |MessagePipe|. Its most important role is to provide a sink for messages
18 // (i.e., a place where messages can be sent). It has a secondary role: When the
19 // endpoint is local (i.e., in the current process), there'll be a dispatcher
20 // corresponding to the endpoint. In that case, the implementation of
21 // |MessagePipeEndpoint| also implements the functionality required by the
22 // dispatcher, e.g., to read messages and to wait. Implementations of this class
23 // are not thread-safe; instances are protected by |MesssagePipe|'s lock.
24 class MessagePipeEndpoint {
26 virtual ~MessagePipeEndpoint() {}
28 // All implementations must implement these.
29 virtual void OnPeerClose() = 0;
30 virtual MojoResult EnqueueMessage(
31 const void* bytes, uint32_t num_bytes,
32 const MojoHandle* handles, uint32_t num_handles,
33 MojoWriteMessageFlags flags) = 0;
35 // Implementations must override these if they represent a local endpoint,
36 // i.e., one for which there's a |MessagePipeDispatcher| (and thus a handle).
37 // An implementation for a remote endpoint (for which there's no dispatcher)
38 // needs not override these methods, since they should never be called.
40 // These methods implement the methods of the same name in |MessagePipe|,
41 // though |MessagePipe|'s implementation may have to do a little more if the
42 // operation involves both endpoints.
43 virtual void CancelAllWaiters();
45 virtual MojoResult ReadMessage(void* bytes, uint32_t* num_bytes,
46 MojoHandle* handles, uint32_t* num_handles,
47 MojoReadMessageFlags flags);
48 virtual MojoResult AddWaiter(Waiter* waiter,
50 MojoResult wake_result);
51 virtual void RemoveWaiter(Waiter* waiter);
54 MessagePipeEndpoint() {}
57 DISALLOW_COPY_AND_ASSIGN(MessagePipeEndpoint);
63 #endif // MOJO_SYSTEM_MESSAGE_PIPE_ENDPOINT_H_