Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / mojo / system / local_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_LOCAL_MESSAGE_PIPE_ENDPOINT_H_
6 #define MOJO_SYSTEM_LOCAL_MESSAGE_PIPE_ENDPOINT_H_
7
8 #include <deque>
9 #include <vector>
10
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"
17
18 namespace mojo {
19 namespace system {
20
21 class MOJO_SYSTEM_IMPL_EXPORT LocalMessagePipeEndpoint
22     : public MessagePipeEndpoint {
23  public:
24   LocalMessagePipeEndpoint();
25   virtual ~LocalMessagePipeEndpoint();
26
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;
33
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,
43                                MojoWaitFlags flags,
44                                MojoResult wake_result) OVERRIDE;
45   virtual void RemoveWaiter(Waiter* waiter) OVERRIDE;
46
47  private:
48   class MessageQueueEntry {
49    public:
50     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);
56     ~MessageQueueEntry();
57
58     // Initialize, taking ownership of |message| and creating equivalent
59     // "duplicate" dispatchers. |transports| should be non-null only if
60     // nonempty.
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);
65
66     MessageInTransit* message() {
67       return message_;
68     }
69     std::vector<scoped_refptr<Dispatcher> >* dispatchers() {
70       return &dispatchers_;
71     }
72
73    private:
74     MessageInTransit* message_;
75     std::vector<scoped_refptr<Dispatcher> > dispatchers_;
76
77     // We don't need assignment, however.
78     DISALLOW_ASSIGN(MessageQueueEntry);
79   };
80
81   MojoWaitFlags SatisfiedFlags();
82   MojoWaitFlags SatisfiableFlags();
83
84   bool is_open_;
85   bool is_peer_open_;
86
87   std::deque<MessageQueueEntry> message_queue_;
88   WaiterList waiter_list_;
89
90   DISALLOW_COPY_AND_ASSIGN(LocalMessagePipeEndpoint);
91 };
92
93 }  // namespace system
94 }  // namespace mojo
95
96 #endif  // MOJO_SYSTEM_LOCAL_MESSAGE_PIPE_ENDPOINT_H_