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 THIRD_PARTY_MOJO_SRC_MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ | 5 #ifndef MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ |
6 #define THIRD_PARTY_MOJO_SRC_MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ | 6 #define MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ |
7 | 7 |
8 #include <assert.h> | 8 #include <assert.h> |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
11 #include "third_party/mojo/src/mojo/public/c/system/functions.h" | 11 #include "mojo/public/c/system/functions.h" |
12 #include "third_party/mojo/src/mojo/public/c/system/types.h" | 12 #include "mojo/public/c/system/types.h" |
13 #include "third_party/mojo/src/mojo/public/cpp/system/macros.h" | 13 #include "mojo/public/cpp/system/macros.h" |
14 | 14 |
15 namespace mojo { | 15 namespace mojo { |
16 | 16 |
17 // OVERVIEW | 17 // OVERVIEW |
18 // | 18 // |
19 // |Handle| and |...Handle|: | 19 // |Handle| and |...Handle|: |
20 // | 20 // |
21 // |Handle| is a simple, copyable wrapper for the C type |MojoHandle| (which is | 21 // |Handle| is a simple, copyable wrapper for the C type |MojoHandle| (which is |
22 // just an integer). Its purpose is to increase type-safety, not provide | 22 // just an integer). Its purpose is to increase type-safety, not provide |
23 // lifetime management. For the same purpose, we have trivial *subclasses* of | 23 // lifetime management. For the same purpose, we have trivial *subclasses* of |
(...skipping 17 matching lines...) Expand all Loading... |
41 // |scoped_ptr|). | 41 // |scoped_ptr|). |
42 // | 42 // |
43 // |ScopedHandle| is just (a typedef of) a |ScopedHandleBase<Handle>|. | 43 // |ScopedHandle| is just (a typedef of) a |ScopedHandleBase<Handle>|. |
44 // Similarly, |ScopedMessagePipeHandle| is just a | 44 // Similarly, |ScopedMessagePipeHandle| is just a |
45 // |ScopedHandleBase<MessagePipeHandle>|. Etc. Note that a | 45 // |ScopedHandleBase<MessagePipeHandle>|. Etc. Note that a |
46 // |ScopedMessagePipeHandle| is *not* a (subclass of) |ScopedHandle|. | 46 // |ScopedMessagePipeHandle| is *not* a (subclass of) |ScopedHandle|. |
47 // | 47 // |
48 // Wrapper functions: | 48 // Wrapper functions: |
49 // | 49 // |
50 // We provide simple wrappers for the |Mojo...()| functions (in | 50 // We provide simple wrappers for the |Mojo...()| functions (in |
51 // third_party/mojo/src/mojo/public/c/system/core.h -- see that file for details
on individual | 51 // mojo/public/c/system/core.h -- see that file for details on individual |
52 // functions). | 52 // functions). |
53 // | 53 // |
54 // The general guideline is functions that imply ownership transfer of a handle | 54 // The general guideline is functions that imply ownership transfer of a handle |
55 // should take (or produce) an appropriate |Scoped...Handle|, while those that | 55 // should take (or produce) an appropriate |Scoped...Handle|, while those that |
56 // don't take a |...Handle|. For example, |CreateMessagePipe()| has two | 56 // don't take a |...Handle|. For example, |CreateMessagePipe()| has two |
57 // |ScopedMessagePipe| "out" parameters, whereas |Wait()| and |WaitMany()| take | 57 // |ScopedMessagePipe| "out" parameters, whereas |Wait()| and |WaitMany()| take |
58 // |Handle| parameters. Some, have both: e.g., |DuplicatedBuffer()| takes a | 58 // |Handle| parameters. Some, have both: e.g., |DuplicatedBuffer()| takes a |
59 // suitable (unscoped) handle (e.g., |SharedBufferHandle|) "in" parameter and | 59 // suitable (unscoped) handle (e.g., |SharedBufferHandle|) "in" parameter and |
60 // produces a suitable scoped handle (e.g., |ScopedSharedBufferHandle| a.k.a. | 60 // produces a suitable scoped handle (e.g., |ScopedSharedBufferHandle| a.k.a. |
61 // |ScopedHandleBase<SharedBufferHandle>|) as an "out" parameter. | 61 // |ScopedHandleBase<SharedBufferHandle>|) as an "out" parameter. |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 return MojoClose(handle.value()); | 280 return MojoClose(handle.value()); |
281 } | 281 } |
282 | 282 |
283 // Strict weak ordering, so that |Handle|s can be used as keys in |std::map|s, | 283 // Strict weak ordering, so that |Handle|s can be used as keys in |std::map|s, |
284 inline bool operator<(const Handle a, const Handle b) { | 284 inline bool operator<(const Handle a, const Handle b) { |
285 return a.value() < b.value(); | 285 return a.value() < b.value(); |
286 } | 286 } |
287 | 287 |
288 } // namespace mojo | 288 } // namespace mojo |
289 | 289 |
290 #endif // THIRD_PARTY_MOJO_SRC_MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ | 290 #endif // MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ |
OLD | NEW |