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