Flutter Engine
The Flutter Engine
handle.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_PKG_ZIRCON_SDK_EXT_HANDLE_H_
6#define FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_PKG_ZIRCON_SDK_EXT_HANDLE_H_
7
8#include <zircon/syscalls.h>
9
10#include <optional>
11#include <vector>
12
13#include "flutter/fml/memory/ref_counted.h"
14#include "handle_waiter.h"
15#include "third_party/dart/runtime/include/dart_api.h"
19
20namespace zircon {
21namespace dart {
22/**
23 * Handle is the native peer of a Dart object (Handle in dart:zircon)
24 * that holds an zx_handle_t. It tracks active waiters on handle too.
25 */
26class Handle : public fml::RefCountedThreadSafe<Handle>,
28 DEFINE_WRAPPERTYPEINFO();
29 FML_FRIEND_REF_COUNTED_THREAD_SAFE(Handle);
30 FML_FRIEND_MAKE_REF_COUNTED(Handle);
31
32 public:
33 ~Handle();
34
35 static void RegisterNatives(tonic::DartLibraryNatives* natives);
36
37 static fml::RefPtr<Handle> Create(zx_handle_t handle);
38 static fml::RefPtr<Handle> Create(zx::handle handle) {
39 return Create(handle.release());
40 }
41
45 }
46
48
49 zx_handle_t ReleaseHandle();
50
51 bool is_valid() const { return handle_ != ZX_HANDLE_INVALID; }
52
53 zx_handle_t handle() const { return handle_; }
54
55 zx_koid_t koid() const {
56 if (!cached_koid_.has_value()) {
57 zx_info_handle_basic_t info;
58 zx_status_t status = zx_object_get_info(
59 handle_, ZX_INFO_HANDLE_BASIC, &info, sizeof(info), nullptr, nullptr);
60 cached_koid_ = std::optional<zx_koid_t>(
61 status == ZX_OK ? info.koid : ZX_KOID_INVALID);
62 }
63 return cached_koid_.value();
64 }
65
66 zx_status_t Close();
67
70
71 void ReleaseWaiter(HandleWaiter* waiter);
72
73 Dart_Handle Duplicate(uint32_t rights);
74
75 Dart_Handle Replace(uint32_t rights);
76
77 private:
78 explicit Handle(zx_handle_t handle);
79
80 void RetainDartWrappableReference() const override { AddRef(); }
81
82 void ReleaseDartWrappableReference() const override { Release(); }
83
84 zx_handle_t handle_;
85
86 std::vector<HandleWaiter*> waiters_;
87
88 // Cache koid. To guarantee proper cache invalidation, only one `Handle`
89 // should own the `zx_handle_t` at a time and use of syscalls that invalidate
90 // the handle should use `ReleaseHandle()`.
91 mutable std::optional<zx_koid_t> cached_koid_;
92};
93
94} // namespace dart
95} // namespace zircon
96
97#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_PKG_ZIRCON_SDK_EXT_HANDLE_H_
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
Dart_Handle Duplicate(uint32_t rights)
Definition: handle.cc:84
zx_status_t Close()
Definition: handle.cc:54
bool is_valid() const
Definition: handle.h:51
static Dart_Handle CreateInvalid()
Definition: handle.cc:32
void ReleaseWaiter(HandleWaiter *waiter)
Definition: handle.cc:76
static fml::RefPtr< Handle > Unwrap(Dart_Handle handle)
Definition: handle.h:42
static fml::RefPtr< Handle > Create(zx_handle_t handle)
Definition: handle.cc:28
zx_handle_t ReleaseHandle()
Definition: handle.cc:36
static fml::RefPtr< Handle > Create(zx::handle handle)
Definition: handle.h:38
zx_handle_t handle() const
Definition: handle.h:53
zx_koid_t koid() const
Definition: handle.h:55
fml::RefPtr< HandleWaiter > AsyncWait(zx_signals_t signals, Dart_Handle callback)
Definition: handle.cc:62
static void RegisterNatives(tonic::DartLibraryNatives *natives)
Definition: handle.cc:132
Dart_Handle Replace(uint32_t rights)
Definition: handle.cc:97
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
static guint signals[kSignalLastSignal]
Definition: fl_settings.cc:16
Definition: dart_vm.cc:33
Definition: handle.cc:14