OLD | NEW |
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 #ifndef MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ | 5 #ifndef MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ |
6 #define MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ | 6 #define MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "mojo/public/c/system/functions.h" | 14 #include "mojo/public/c/system/functions.h" |
15 #include "mojo/public/c/system/types.h" | 15 #include "mojo/public/c/system/types.h" |
16 #include "mojo/public/cpp/system/handle_signals_state.h" | |
17 | 16 |
18 namespace mojo { | 17 namespace mojo { |
19 | 18 |
20 // OVERVIEW | 19 // OVERVIEW |
21 // | 20 // |
22 // |Handle| and |...Handle|: | 21 // |Handle| and |...Handle|: |
23 // | 22 // |
24 // |Handle| is a simple, copyable wrapper for the C type |MojoHandle| (which is | 23 // |Handle| is a simple, copyable wrapper for the C type |MojoHandle| (which is |
25 // just an integer). Its purpose is to increase type-safety, not provide | 24 // just an integer). Its purpose is to increase type-safety, not provide |
26 // lifetime management. For the same purpose, we have trivial *subclasses* of | 25 // lifetime management. For the same purpose, we have trivial *subclasses* of |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 MojoHandle* mutable_value() { return &value_; } | 163 MojoHandle* mutable_value() { return &value_; } |
165 void set_value(MojoHandle value) { value_ = value; } | 164 void set_value(MojoHandle value) { value_ = value; } |
166 | 165 |
167 void Close() { | 166 void Close() { |
168 DCHECK(is_valid()); | 167 DCHECK(is_valid()); |
169 MojoResult result = MojoClose(value_); | 168 MojoResult result = MojoClose(value_); |
170 ALLOW_UNUSED_LOCAL(result); | 169 ALLOW_UNUSED_LOCAL(result); |
171 DCHECK_EQ(MOJO_RESULT_OK, result); | 170 DCHECK_EQ(MOJO_RESULT_OK, result); |
172 } | 171 } |
173 | 172 |
174 HandleSignalsState QuerySignalsState() const { | |
175 HandleSignalsState signals_state; | |
176 MojoResult result = MojoQueryHandleSignalsState( | |
177 value_, static_cast<MojoHandleSignalsState*>(&signals_state)); | |
178 DCHECK_EQ(MOJO_RESULT_OK, result); | |
179 return signals_state; | |
180 } | |
181 | |
182 private: | 173 private: |
183 MojoHandle value_; | 174 MojoHandle value_; |
184 | 175 |
185 // Copying and assignment allowed. | 176 // Copying and assignment allowed. |
186 }; | 177 }; |
187 | 178 |
188 // Should have zero overhead. | 179 // Should have zero overhead. |
189 static_assert(sizeof(Handle) == sizeof(MojoHandle), "Bad size for C++ Handle"); | 180 static_assert(sizeof(Handle) == sizeof(MojoHandle), "Bad size for C++ Handle"); |
190 | 181 |
191 // The scoper should also impose no more overhead. | 182 // The scoper should also impose no more overhead. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 } | 299 } |
309 | 300 |
310 // Comparison, so that |Handle|s can be used as keys in hash maps. | 301 // Comparison, so that |Handle|s can be used as keys in hash maps. |
311 inline bool operator==(const Handle a, const Handle b) { | 302 inline bool operator==(const Handle a, const Handle b) { |
312 return a.value() == b.value(); | 303 return a.value() == b.value(); |
313 } | 304 } |
314 | 305 |
315 } // namespace mojo | 306 } // namespace mojo |
316 | 307 |
317 #endif // MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ | 308 #endif // MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ |
OLD | NEW |