| 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_EDK_EMBEDDER_PLATFORM_HANDLE_H_ | 5 #ifndef MOJO_EDK_EMBEDDER_PLATFORM_HANDLE_H_ |
| 6 #define MOJO_EDK_EMBEDDER_PLATFORM_HANDLE_H_ | 6 #define MOJO_EDK_EMBEDDER_PLATFORM_HANDLE_H_ |
| 7 | 7 |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "mojo/edk/system/system_impl_export.h" | 9 #include "mojo/edk/system/system_impl_export.h" |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 explicit PlatformHandle(int handle) : handle(handle) {} | 23 explicit PlatformHandle(int handle) : handle(handle) {} |
| 24 #if defined(OS_MACOSX) && !defined(OS_IOS) | 24 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 25 explicit PlatformHandle(mach_port_t port) | 25 explicit PlatformHandle(mach_port_t port) |
| 26 : type(Type::MACH), port(port) {} | 26 : type(Type::MACH), port(port) {} |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 void CloseIfNecessary(); | 29 void CloseIfNecessary(); |
| 30 | 30 |
| 31 bool is_valid() const { | 31 bool is_valid() const { |
| 32 #if defined(OS_MACOSX) && !defined(OS_IOS) | 32 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 33 if (type == Type::MACH) | 33 if (type == Type::MACH || type == Type::MACH_NAME) |
| 34 return port != MACH_PORT_NULL; | 34 return port != MACH_PORT_NULL; |
| 35 #endif | 35 #endif |
| 36 return handle != -1; | 36 return handle != -1; |
| 37 } | 37 } |
| 38 | 38 |
| 39 enum class Type { | 39 enum class Type { |
| 40 POSIX, | 40 POSIX, |
| 41 #if defined(OS_MACOSX) && !defined(OS_IOS) | 41 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 42 MACH, | 42 MACH, |
| 43 // MACH_NAME isn't a real Mach port. But rather the "name" of one that can |
| 44 // be resolved to a real port later. This distinction is needed so that the |
| 45 // "port" doesn't try to be closed if CloseIfNecessary() is called. Having |
| 46 // this also allows us to do checks in other places. |
| 47 MACH_NAME, |
| 43 #endif | 48 #endif |
| 44 }; | 49 }; |
| 45 Type type = Type::POSIX; | 50 Type type = Type::POSIX; |
| 46 | 51 |
| 47 int handle = -1; | 52 int handle = -1; |
| 48 | 53 |
| 49 #if defined(OS_MACOSX) && !defined(OS_IOS) | 54 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 50 mach_port_t port = MACH_PORT_NULL; | 55 mach_port_t port = MACH_PORT_NULL; |
| 51 #endif | 56 #endif |
| 52 }; | 57 }; |
| 53 #elif defined(OS_WIN) | 58 #elif defined(OS_WIN) |
| 54 struct MOJO_SYSTEM_IMPL_EXPORT PlatformHandle { | 59 struct MOJO_SYSTEM_IMPL_EXPORT PlatformHandle { |
| 55 PlatformHandle() : handle(INVALID_HANDLE_VALUE) {} | 60 PlatformHandle() : handle(INVALID_HANDLE_VALUE) {} |
| 56 explicit PlatformHandle(HANDLE handle) : handle(handle) {} | 61 explicit PlatformHandle(HANDLE handle) : handle(handle) {} |
| 57 | 62 |
| 58 void CloseIfNecessary(); | 63 void CloseIfNecessary(); |
| 59 | 64 |
| 60 bool is_valid() const { return handle != INVALID_HANDLE_VALUE; } | 65 bool is_valid() const { return handle != INVALID_HANDLE_VALUE; } |
| 61 | 66 |
| 62 HANDLE handle; | 67 HANDLE handle; |
| 63 }; | 68 }; |
| 64 #else | 69 #else |
| 65 #error "Platform not yet supported." | 70 #error "Platform not yet supported." |
| 66 #endif | 71 #endif |
| 67 | 72 |
| 68 } // namespace edk | 73 } // namespace edk |
| 69 } // namespace mojo | 74 } // namespace mojo |
| 70 | 75 |
| 71 #endif // MOJO_EDK_EMBEDDER_PLATFORM_HANDLE_H_ | 76 #endif // MOJO_EDK_EMBEDDER_PLATFORM_HANDLE_H_ |
| OLD | NEW |