| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_SYSTEM_RAW_CHANNEL_H_ | 5 #ifndef MOJO_SYSTEM_RAW_CHANNEL_H_ |
| 6 #define MOJO_SYSTEM_RAW_CHANNEL_H_ | 6 #define MOJO_SYSTEM_RAW_CHANNEL_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "mojo/system/constants.h" | 11 #include "mojo/system/constants.h" |
| 12 #include "mojo/system/scoped_platform_handle.h" |
| 12 #include "mojo/system/system_impl_export.h" | 13 #include "mojo/system/system_impl_export.h" |
| 13 | 14 |
| 14 namespace base { | 15 namespace base { |
| 15 class MessageLoop; | 16 class MessageLoop; |
| 16 } | 17 } |
| 17 | 18 |
| 18 namespace mojo { | 19 namespace mojo { |
| 19 namespace system { | 20 namespace system { |
| 20 | 21 |
| 21 class MessageInTransit; | 22 class MessageInTransit; |
| 22 | 23 |
| 23 // This simply wraps an |int| file descriptor on POSIX and a |HANDLE| on | 24 // This simply wraps an |int| file descriptor on POSIX and a |HANDLE| on |
| 24 // Windows, but we don't want to impose, e.g., the inclusion of windows.h on | 25 // Windows, but we don't want to impose, e.g., the inclusion of windows.h on |
| 25 // everyone. | 26 // everyone. |
| 26 struct PlatformChannelHandle; | 27 struct PlatformHandle; |
| 27 | 28 |
| 28 // |RawChannel| is an interface to objects that wrap an OS "pipe". It presents | 29 // |RawChannel| is an interface to objects that wrap an OS "pipe". It presents |
| 29 // the following interface to users: | 30 // the following interface to users: |
| 30 // - Receives and dispatches messages on a thread (running a |MessageLoop|; it | 31 // - Receives and dispatches messages on a thread (running a |MessageLoop|; it |
| 31 // must be a |MessageLoopForIO| in the case of the POSIX libevent | 32 // must be a |MessageLoopForIO| in the case of the POSIX libevent |
| 32 // implementation). | 33 // implementation). |
| 33 // - Provides a thread-safe way of writing messages (|WriteMessage()|); | 34 // - Provides a thread-safe way of writing messages (|WriteMessage()|); |
| 34 // writing/queueing messages will not block and is atomic from the point of | 35 // writing/queueing messages will not block and is atomic from the point of |
| 35 // view of the caller. If necessary, messages are queued (to be written on | 36 // view of the caller. If necessary, messages are queued (to be written on |
| 36 // the aforementioned thread). | 37 // the aforementioned thread). |
| (...skipping 22 matching lines...) Expand all Loading... |
| 59 virtual void OnReadMessage(const MessageInTransit& message) = 0; | 60 virtual void OnReadMessage(const MessageInTransit& message) = 0; |
| 60 | 61 |
| 61 // Called when there's a fatal error, which leads to the channel no longer | 62 // Called when there's a fatal error, which leads to the channel no longer |
| 62 // being viable. | 63 // being viable. |
| 63 virtual void OnFatalError(FatalError fatal_error) = 0; | 64 virtual void OnFatalError(FatalError fatal_error) = 0; |
| 64 | 65 |
| 65 protected: | 66 protected: |
| 66 virtual ~Delegate() {} | 67 virtual ~Delegate() {} |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 // Static factory method. Takes ownership of |handle| (i.e., will close it). | 70 // Static factory method. |handle| should be a handle to a |
| 70 // Does *not* take ownership of |delegate| and |message_loop|, which must | 71 // (platform-appropriate) bidirectional communication channel (e.g., a socket |
| 71 // remain alive while this object does. | 72 // on POSIX, a named pipe on Windows). Does *not* take ownership of |delegate| |
| 72 static RawChannel* Create(const PlatformChannelHandle& handle, | 73 // and |message_loop|, which must remain alive while this object does. |
| 74 static RawChannel* Create(ScopedPlatformHandle handle, |
| 73 Delegate* delegate, | 75 Delegate* delegate, |
| 74 base::MessageLoop* message_loop); | 76 base::MessageLoop* message_loop); |
| 75 | 77 |
| 76 // This must be called (on the I/O thread) before this object is used. Returns | 78 // This must be called (on the I/O thread) before this object is used. Returns |
| 77 // true on success. On failure, |Shutdown()| should *not* be called. | 79 // true on success. On failure, |Shutdown()| should *not* be called. |
| 78 virtual bool Init() = 0; | 80 virtual bool Init() = 0; |
| 79 | 81 |
| 80 // This must be called (on the I/O thread) before this object is destroyed. | 82 // This must be called (on the I/O thread) before this object is destroyed. |
| 81 virtual void Shutdown() = 0; | 83 virtual void Shutdown() = 0; |
| 82 | 84 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 95 Delegate* const delegate_; | 97 Delegate* const delegate_; |
| 96 base::MessageLoop* const message_loop_; | 98 base::MessageLoop* const message_loop_; |
| 97 | 99 |
| 98 DISALLOW_COPY_AND_ASSIGN(RawChannel); | 100 DISALLOW_COPY_AND_ASSIGN(RawChannel); |
| 99 }; | 101 }; |
| 100 | 102 |
| 101 } // namespace system | 103 } // namespace system |
| 102 } // namespace mojo | 104 } // namespace mojo |
| 103 | 105 |
| 104 #endif // MOJO_SYSTEM_RAW_CHANNEL_H_ | 106 #endif // MOJO_SYSTEM_RAW_CHANNEL_H_ |
| OLD | NEW |