OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef BIN_EVENTHANDLER_FUCHSIA_H_ | 5 #ifndef BIN_EVENTHANDLER_FUCHSIA_H_ |
6 #define BIN_EVENTHANDLER_FUCHSIA_H_ | 6 #define BIN_EVENTHANDLER_FUCHSIA_H_ |
7 | 7 |
8 #if !defined(BIN_EVENTHANDLER_H_) | 8 #if !defined(BIN_EVENTHANDLER_H_) |
9 #error Do not include eventhandler_fuchsia.h directly; use eventhandler.h instea
d. | 9 #error Do not include eventhandler_fuchsia.h directly; use eventhandler.h instea
d. |
10 #endif | 10 #endif |
11 | 11 |
| 12 #include <errno.h> |
12 #include <magenta/syscalls.h> | 13 #include <magenta/syscalls.h> |
13 | 14 |
| 15 #include "platform/signal_blocker.h" |
| 16 |
14 namespace dart { | 17 namespace dart { |
15 namespace bin { | 18 namespace bin { |
16 | 19 |
| 20 class DescriptorInfo : public DescriptorInfoBase { |
| 21 public: |
| 22 explicit DescriptorInfo(intptr_t fd) : DescriptorInfoBase(fd) { } |
| 23 |
| 24 virtual ~DescriptorInfo() { } |
| 25 |
| 26 virtual void Close() { |
| 27 VOID_TEMP_FAILURE_RETRY(close(fd_)); |
| 28 fd_ = -1; |
| 29 } |
| 30 |
| 31 private: |
| 32 DISALLOW_COPY_AND_ASSIGN(DescriptorInfo); |
| 33 }; |
| 34 |
| 35 class DescriptorInfoSingle |
| 36 : public DescriptorInfoSingleMixin<DescriptorInfo> { |
| 37 public: |
| 38 explicit DescriptorInfoSingle(intptr_t fd) |
| 39 : DescriptorInfoSingleMixin(fd, false) {} |
| 40 virtual ~DescriptorInfoSingle() {} |
| 41 |
| 42 private: |
| 43 DISALLOW_COPY_AND_ASSIGN(DescriptorInfoSingle); |
| 44 }; |
| 45 |
| 46 class DescriptorInfoMultiple |
| 47 : public DescriptorInfoMultipleMixin<DescriptorInfo> { |
| 48 public: |
| 49 explicit DescriptorInfoMultiple(intptr_t fd) |
| 50 : DescriptorInfoMultipleMixin(fd, false) {} |
| 51 virtual ~DescriptorInfoMultiple() {} |
| 52 |
| 53 private: |
| 54 DISALLOW_COPY_AND_ASSIGN(DescriptorInfoMultiple); |
| 55 }; |
| 56 |
| 57 // Information needed to call mx_handle_wait_many(), and to handle events. |
| 58 class MagentaWaitManyInfo { |
| 59 public: |
| 60 MagentaWaitManyInfo(); |
| 61 ~MagentaWaitManyInfo(); |
| 62 |
| 63 intptr_t capacity() const { return capacity_; } |
| 64 intptr_t size() const { return size_; } |
| 65 DescriptorInfo** descriptor_infos() const { return descriptor_infos_; } |
| 66 mx_handle_t* handles() const { return handles_; } |
| 67 mx_signals_t* signals() const { return signals_; } |
| 68 mx_signals_state_t* signals_states() const { return signals_states_; } |
| 69 |
| 70 void AddHandle(mx_handle_t handle, mx_signals_t signals, DescriptorInfo* di); |
| 71 void RemoveHandle(mx_handle_t handle); |
| 72 |
| 73 private: |
| 74 static const intptr_t kInitialCapacity = 32; |
| 75 |
| 76 void GrowArraysIfNeeded(intptr_t desired_size); |
| 77 |
| 78 intptr_t capacity_; |
| 79 intptr_t size_; |
| 80 DescriptorInfo** descriptor_infos_; |
| 81 mx_handle_t* handles_; |
| 82 mx_signals_t* signals_; |
| 83 mx_signals_state_t* signals_states_; |
| 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(MagentaWaitManyInfo); |
| 86 }; |
| 87 |
17 class EventHandlerImplementation { | 88 class EventHandlerImplementation { |
18 public: | 89 public: |
19 EventHandlerImplementation(); | 90 EventHandlerImplementation(); |
20 ~EventHandlerImplementation(); | 91 ~EventHandlerImplementation(); |
21 | 92 |
22 void SendData(intptr_t id, Dart_Port dart_port, int64_t data); | 93 void SendData(intptr_t id, Dart_Port dart_port, int64_t data); |
23 void Start(EventHandler* handler); | 94 void Start(EventHandler* handler); |
24 void Shutdown(); | 95 void Shutdown(); |
25 | 96 |
| 97 const MagentaWaitManyInfo& info() const { return info_; } |
| 98 |
26 private: | 99 private: |
27 int64_t GetTimeout() const; | 100 int64_t GetTimeout() const; |
28 void HandleEvents(); | 101 void HandleEvents(); |
29 void HandleTimeout(); | 102 void HandleTimeout(); |
30 void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data); | 103 void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data); |
31 void HandleInterruptFd(); | 104 void HandleInterruptFd(); |
32 static void Poll(uword args); | 105 static void Poll(uword args); |
33 | 106 |
34 TimeoutQueue timeout_queue_; | 107 TimeoutQueue timeout_queue_; |
35 bool shutdown_; | 108 bool shutdown_; |
36 mx_handle_t interrupt_handles_[2]; | 109 mx_handle_t interrupt_handles_[2]; |
37 | 110 |
| 111 MagentaWaitManyInfo info_; |
| 112 |
38 DISALLOW_COPY_AND_ASSIGN(EventHandlerImplementation); | 113 DISALLOW_COPY_AND_ASSIGN(EventHandlerImplementation); |
39 }; | 114 }; |
40 | 115 |
41 } // namespace bin | 116 } // namespace bin |
42 } // namespace dart | 117 } // namespace dart |
43 | 118 |
44 #endif // BIN_EVENTHANDLER_FUCHSIA_H_ | 119 #endif // BIN_EVENTHANDLER_FUCHSIA_H_ |
OLD | NEW |