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_LOCAL_MESSAGE_PIPE_ENDPOINT_H_
6 #define MOJO_SYSTEM_LOCAL_MESSAGE_PIPE_ENDPOINT_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "mojo/public/system/core.h"
14 #include "mojo/system/message_pipe_endpoint.h"
15 #include "mojo/system/system_impl_export.h"
16 #include "mojo/system/waiter_list.h"
21 class MOJO_SYSTEM_IMPL_EXPORT LocalMessagePipeEndpoint
22 : public MessagePipeEndpoint {
24 LocalMessagePipeEndpoint();
25 virtual ~LocalMessagePipeEndpoint();
27 // |MessagePipeEndpoint| implementation:
28 virtual void Close() OVERRIDE;
29 virtual void OnPeerClose() OVERRIDE;
30 virtual MojoResult EnqueueMessage(
31 MessageInTransit* message,
32 std::vector<DispatcherTransport>* transports) OVERRIDE;
34 // There's a dispatcher for |LocalMessagePipeEndpoint|s, so we have to
35 // implement/override these:
36 virtual void CancelAllWaiters() OVERRIDE;
37 virtual MojoResult ReadMessage(
38 void* bytes, uint32_t* num_bytes,
39 std::vector<scoped_refptr<Dispatcher> >* dispatchers,
40 uint32_t* num_dispatchers,
41 MojoReadMessageFlags flags) OVERRIDE;
42 virtual MojoResult AddWaiter(Waiter* waiter,
44 MojoResult wake_result) OVERRIDE;
45 virtual void RemoveWaiter(Waiter* waiter) OVERRIDE;
48 class MessageQueueEntry {
51 // Provide an explicit copy constructor, so that we can use this directly in
52 // a (C++03) STL container. However, we only allow the case where |other| is
53 // empty. (We don't provide a nontrivial constructor, because it wouldn't be
54 // useful with these constraints. This will change with C++11.)
55 MessageQueueEntry(const MessageQueueEntry& other);
58 // Initialize, taking ownership of |message| and creating equivalent
59 // "duplicate" dispatchers. |transports| should be non-null only if
61 // TODO(vtl): This would simply be a constructor, but we don't have C++11's
62 // emplace operations yet, and I don't want to copy |dispatchers_|.
63 void Init(MessageInTransit* message,
64 std::vector<DispatcherTransport>* transports);
66 MessageInTransit* message() {
69 std::vector<scoped_refptr<Dispatcher> >* dispatchers() {
74 MessageInTransit* message_;
75 std::vector<scoped_refptr<Dispatcher> > dispatchers_;
77 // We don't need assignment, however.
78 DISALLOW_ASSIGN(MessageQueueEntry);
81 MojoWaitFlags SatisfiedFlags();
82 MojoWaitFlags SatisfiableFlags();
87 std::deque<MessageQueueEntry> message_queue_;
88 WaiterList waiter_list_;
90 DISALLOW_COPY_AND_ASSIGN(LocalMessagePipeEndpoint);
96 #endif // MOJO_SYSTEM_LOCAL_MESSAGE_PIPE_ENDPOINT_H_