- add sources.
[platform/framework/web/crosswalk.git] / src / mojo / system / message_pipe_endpoint.h
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.
4
5 #ifndef MOJO_SYSTEM_MESSAGE_PIPE_ENDPOINT_H_
6 #define MOJO_SYSTEM_MESSAGE_PIPE_ENDPOINT_H_
7
8 #include "base/basictypes.h"
9 #include "mojo/public/system/core.h"
10
11 namespace mojo {
12 namespace system {
13
14 class Waiter;
15
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 {
25  public:
26   virtual ~MessagePipeEndpoint() {}
27
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;
34
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.
39   //
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();
44   virtual void Close();
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,
49                                MojoWaitFlags flags,
50                                MojoResult wake_result);
51   virtual void RemoveWaiter(Waiter* waiter);
52
53  protected:
54   MessagePipeEndpoint() {}
55
56  private:
57   DISALLOW_COPY_AND_ASSIGN(MessagePipeEndpoint);
58 };
59
60 }  // namespace system
61 }  // namespace mojo
62
63 #endif  // MOJO_SYSTEM_MESSAGE_PIPE_ENDPOINT_H_