Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Side by Side Diff: mojo/public/cpp/system/message_pipe.h

Issue 1773403006: [mojo-sdk] Replace assert() usage in bindings with DCHECK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/cpp/system/handle.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // This file provides a C++ wrapping around the Mojo C API for message pipes, 5 // This file provides a C++ wrapping around the Mojo C API for message pipes,
6 // replacing the prefix of "Mojo" with a "mojo" namespace, and using more 6 // replacing the prefix of "Mojo" with a "mojo" namespace, and using more
7 // strongly-typed representations of |MojoHandle|s. 7 // strongly-typed representations of |MojoHandle|s.
8 // 8 //
9 // Please see "mojo/public/c/system/message_pipe.h" for complete documentation 9 // Please see "mojo/public/c/system/message_pipe.h" for complete documentation
10 // of the API. 10 // of the API.
11 11
12 #ifndef MOJO_PUBLIC_CPP_SYSTEM_MESSAGE_PIPE_H_ 12 #ifndef MOJO_PUBLIC_CPP_SYSTEM_MESSAGE_PIPE_H_
13 #define MOJO_PUBLIC_CPP_SYSTEM_MESSAGE_PIPE_H_ 13 #define MOJO_PUBLIC_CPP_SYSTEM_MESSAGE_PIPE_H_
14 14
15 #include <assert.h>
16 #include <stdint.h> 15 #include <stdint.h>
17 16
18 #include "base/compiler_specific.h" 17 #include "base/compiler_specific.h"
18 #include "base/logging.h"
19 #include "mojo/public/c/system/message_pipe.h" 19 #include "mojo/public/c/system/message_pipe.h"
20 #include "mojo/public/cpp/system/handle.h" 20 #include "mojo/public/cpp/system/handle.h"
21 #include "mojo/public/cpp/system/macros.h" 21 #include "mojo/public/cpp/system/macros.h"
22 22
23 namespace mojo { 23 namespace mojo {
24 24
25 // A strongly-typed representation of a |MojoHandle| to one end of a message 25 // A strongly-typed representation of a |MojoHandle| to one end of a message
26 // pipe. 26 // pipe.
27 class MessagePipeHandle : public Handle { 27 class MessagePipeHandle : public Handle {
28 public: 28 public:
29 MessagePipeHandle() {} 29 MessagePipeHandle() {}
30 explicit MessagePipeHandle(MojoHandle value) : Handle(value) {} 30 explicit MessagePipeHandle(MojoHandle value) : Handle(value) {}
31 31
32 // Copying and assignment allowed. 32 // Copying and assignment allowed.
33 }; 33 };
34 34
35 static_assert(sizeof(MessagePipeHandle) == sizeof(Handle), 35 static_assert(sizeof(MessagePipeHandle) == sizeof(Handle),
36 "Bad size for C++ MessagePipeHandle"); 36 "Bad size for C++ MessagePipeHandle");
37 37
38 typedef ScopedHandleBase<MessagePipeHandle> ScopedMessagePipeHandle; 38 typedef ScopedHandleBase<MessagePipeHandle> ScopedMessagePipeHandle;
39 static_assert(sizeof(ScopedMessagePipeHandle) == sizeof(MessagePipeHandle), 39 static_assert(sizeof(ScopedMessagePipeHandle) == sizeof(MessagePipeHandle),
40 "Bad size for C++ ScopedMessagePipeHandle"); 40 "Bad size for C++ ScopedMessagePipeHandle");
41 41
42 // Creates a message pipe. See |MojoCreateMessagePipe()| for complete 42 // Creates a message pipe. See |MojoCreateMessagePipe()| for complete
43 // documentation. 43 // documentation.
44 inline MojoResult CreateMessagePipe(const MojoCreateMessagePipeOptions* options, 44 inline MojoResult CreateMessagePipe(const MojoCreateMessagePipeOptions* options,
45 ScopedMessagePipeHandle* message_pipe0, 45 ScopedMessagePipeHandle* message_pipe0,
46 ScopedMessagePipeHandle* message_pipe1) { 46 ScopedMessagePipeHandle* message_pipe1) {
47 assert(message_pipe0); 47 DCHECK(message_pipe0);
48 assert(message_pipe1); 48 DCHECK(message_pipe1);
49 MessagePipeHandle handle0; 49 MessagePipeHandle handle0;
50 MessagePipeHandle handle1; 50 MessagePipeHandle handle1;
51 MojoResult rv = MojoCreateMessagePipe( 51 MojoResult rv = MojoCreateMessagePipe(
52 options, handle0.mutable_value(), handle1.mutable_value()); 52 options, handle0.mutable_value(), handle1.mutable_value());
53 // Reset even on failure (reduces the chances that a "stale"/incorrect handle 53 // Reset even on failure (reduces the chances that a "stale"/incorrect handle
54 // will be used). 54 // will be used).
55 message_pipe0->reset(handle0); 55 message_pipe0->reset(handle0);
56 message_pipe1->reset(handle1); 56 message_pipe1->reset(handle1);
57 return rv; 57 return rv;
58 } 58 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 MessagePipe(); 96 MessagePipe();
97 explicit MessagePipe(const MojoCreateMessagePipeOptions& options); 97 explicit MessagePipe(const MojoCreateMessagePipeOptions& options);
98 ~MessagePipe(); 98 ~MessagePipe();
99 99
100 ScopedMessagePipeHandle handle0; 100 ScopedMessagePipeHandle handle0;
101 ScopedMessagePipeHandle handle1; 101 ScopedMessagePipeHandle handle1;
102 }; 102 };
103 103
104 inline MessagePipe::MessagePipe() { 104 inline MessagePipe::MessagePipe() {
105 MojoResult result = CreateMessagePipe(nullptr, &handle0, &handle1); 105 MojoResult result = CreateMessagePipe(nullptr, &handle0, &handle1);
106 ALLOW_UNUSED_LOCAL(result); 106 DCHECK_EQ(MOJO_RESULT_OK, result);
107 assert(result == MOJO_RESULT_OK);
108 } 107 }
109 108
110 inline MessagePipe::MessagePipe(const MojoCreateMessagePipeOptions& options) { 109 inline MessagePipe::MessagePipe(const MojoCreateMessagePipeOptions& options) {
111 MojoResult result = CreateMessagePipe(&options, &handle0, &handle1); 110 MojoResult result = CreateMessagePipe(&options, &handle0, &handle1);
112 ALLOW_UNUSED_LOCAL(result); 111 DCHECK_EQ(MOJO_RESULT_OK, result);
113 assert(result == MOJO_RESULT_OK);
114 } 112 }
115 113
116 inline MessagePipe::~MessagePipe() { 114 inline MessagePipe::~MessagePipe() {
117 } 115 }
118 116
119 } // namespace mojo 117 } // namespace mojo
120 118
121 #endif // MOJO_PUBLIC_CPP_SYSTEM_MESSAGE_PIPE_H_ 119 #endif // MOJO_PUBLIC_CPP_SYSTEM_MESSAGE_PIPE_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/system/handle.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698