• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DISPATCHER_H_
6 #define MOJO_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_
7 
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h"
11 #include "mojo/system/dispatcher.h"
12 #include "mojo/system/system_impl_export.h"
13 
14 namespace mojo {
15 namespace system {
16 
17 class MessagePipe;
18 
19 // This is the |Dispatcher| implementation for message pipes (created by the
20 // Mojo primitive |MojoCreateMessagePipe()|). This class is thread-safe.
21 class MOJO_SYSTEM_IMPL_EXPORT MessagePipeDispatcher : public Dispatcher {
22  public:
23   MessagePipeDispatcher();
24 
25   // Must be called before any other methods. (This method is not thread-safe.)
26   void Init(scoped_refptr<MessagePipe> message_pipe, unsigned port);
27 
28  private:
29   friend class base::RefCountedThreadSafe<MessagePipeDispatcher>;
30   virtual ~MessagePipeDispatcher();
31 
32   // |Dispatcher| implementation/overrides:
33   virtual void CancelAllWaitersNoLock() OVERRIDE;
34   virtual MojoResult CloseImplNoLock() OVERRIDE;
35   virtual MojoResult WriteMessageImplNoLock(
36       const void* bytes, uint32_t num_bytes,
37       const std::vector<Dispatcher*>* dispatchers,
38       MojoWriteMessageFlags flags) OVERRIDE;
39   virtual MojoResult ReadMessageImplNoLock(
40       void* bytes, uint32_t* num_bytes,
41       std::vector<scoped_refptr<Dispatcher> >* dispatchers,
42       uint32_t* num_dispatchers,
43       MojoReadMessageFlags flags) OVERRIDE;
44   virtual MojoResult AddWaiterImplNoLock(Waiter* waiter,
45                                          MojoWaitFlags flags,
46                                          MojoResult wake_result) OVERRIDE;
47   virtual void RemoveWaiterImplNoLock(Waiter* waiter) OVERRIDE;
48   virtual scoped_refptr<Dispatcher>
49       CreateEquivalentDispatcherAndCloseImplNoLock() OVERRIDE;
50 
51   // Protected by |lock()|:
52   scoped_refptr<MessagePipe> message_pipe_;  // This will be null if closed.
53   unsigned port_;
54 
55   DISALLOW_COPY_AND_ASSIGN(MessagePipeDispatcher);
56 };
57 
58 }  // namespace system
59 }  // namespace mojo
60 
61 #endif  // MOJO_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_
62