Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
zircon::dart::Handle Class Reference

#include <handle.h>

Inheritance diagram for zircon::dart::Handle:
fml::RefCountedThreadSafe< Handle > tonic::DartWrappable fml::internal::RefCountedThreadSafeBase

Public Member Functions

 ~Handle ()
 
zx_handle_t ReleaseHandle ()
 
bool is_valid () const
 
zx_handle_t handle () const
 
zx_koid_t koid () const
 
zx_status_t Close ()
 
fml::RefPtr< HandleWaiterAsyncWait (zx_signals_t signals, Dart_Handle callback)
 
void ReleaseWaiter (HandleWaiter *waiter)
 
Dart_Handle Duplicate (uint32_t rights)
 
Dart_Handle Replace (uint32_t rights)
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< Handle >
void Release () const
 
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 
- Public Member Functions inherited from tonic::DartWrappable
 DartWrappable ()
 
virtual const DartWrapperInfoGetDartWrapperInfo () const =0
 
virtual void RetainDartWrappableReference () const =0
 
virtual void ReleaseDartWrappableReference () const =0
 
Dart_Handle CreateDartWrapper (DartState *dart_state)
 
void AssociateWithDartWrapper (Dart_Handle wrappable)
 
void ClearDartWrapper ()
 
Dart_WeakPersistentHandle dart_wrapper () const
 

Static Public Member Functions

static void RegisterNatives (tonic::DartLibraryNatives *natives)
 
static fml::RefPtr< HandleCreate (zx_handle_t handle)
 
static fml::RefPtr< HandleCreate (zx::handle handle)
 
static fml::RefPtr< HandleUnwrap (Dart_Handle handle)
 
static Dart_Handle CreateInvalid ()
 

Additional Inherited Members

- Public Types inherited from tonic::DartWrappable
enum  DartNativeFields { kPeerIndex , kNumberOfNativeFields }
 
- Protected Member Functions inherited from fml::RefCountedThreadSafe< Handle >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 
- Protected Member Functions inherited from tonic::DartWrappable
virtual ~DartWrappable ()
 
- Static Protected Member Functions inherited from tonic::DartWrappable
static Dart_PersistentHandle GetTypeForWrapper (tonic::DartState *dart_state, const tonic::DartWrapperInfo &wrapper_info)
 

Detailed Description

Handle is the native peer of a Dart object (Handle in dart:zircon) that holds an zx_handle_t. It tracks active waiters on handle too.

Definition at line 26 of file handle.h.

Constructor & Destructor Documentation

◆ ~Handle()

zircon::dart::Handle::~Handle ( )

Definition at line 21 of file handle.cc.

21 {
22 if (is_valid()) {
23 zx_status_t status = Close();
24 FML_DCHECK(status == ZX_OK);
25 }
26}
zx_status_t Close()
Definition: handle.cc:54
bool is_valid() const
Definition: handle.h:51
#define FML_DCHECK(condition)
Definition: logging.h:103

Member Function Documentation

◆ AsyncWait()

fml::RefPtr< HandleWaiter > zircon::dart::Handle::AsyncWait ( zx_signals_t  signals,
Dart_Handle  callback 
)

Definition at line 62 of file handle.cc.

63 {
64 if (!is_valid()) {
65 FML_LOG(WARNING) << "Attempt to wait on an invalid handle.";
66 return nullptr;
67 }
68
71 waiters_.push_back(waiter.get());
72
73 return waiter;
74}
T * get() const
Definition: ref_ptr.h:116
static fml::RefPtr< HandleWaiter > Create(Handle *handle, zx_signals_t signals, Dart_Handle callback)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
static guint signals[kSignalLastSignal]
Definition: fl_settings.cc:16
#define FML_LOG(severity)
Definition: logging.h:82

◆ Close()

zx_status_t zircon::dart::Handle::Close ( )

Definition at line 54 of file handle.cc.

54 {
55 if (is_valid()) {
56 zx_handle_t handle = ReleaseHandle();
57 return zx_handle_close(handle);
58 }
59 return ZX_ERR_BAD_HANDLE;
60}
zx_handle_t ReleaseHandle()
Definition: handle.cc:36
zx_handle_t handle() const
Definition: handle.h:53

◆ Create() [1/2]

static fml::RefPtr< Handle > zircon::dart::Handle::Create ( zx::handle  handle)
inlinestatic

Definition at line 38 of file handle.h.

38 {
39 return Create(handle.release());
40 }
static fml::RefPtr< Handle > Create(zx_handle_t handle)
Definition: handle.cc:28

◆ Create() [2/2]

fml::RefPtr< Handle > zircon::dart::Handle::Create ( zx_handle_t  handle)
static

Definition at line 28 of file handle.cc.

28 {
29 return fml::MakeRefCounted<Handle>(handle);
30}

◆ CreateInvalid()

Dart_Handle zircon::dart::Handle::CreateInvalid ( )
static

Definition at line 32 of file handle.cc.

32 {
33 return ToDart(Create(ZX_HANDLE_INVALID));
34}
Dart_Handle ToDart(const T &object)

◆ Duplicate()

Dart_Handle zircon::dart::Handle::Duplicate ( uint32_t  rights)

Definition at line 84 of file handle.cc.

84 {
85 if (!is_valid()) {
86 return ToDart(Create(ZX_HANDLE_INVALID));
87 }
88
89 zx_handle_t out_handle;
90 zx_status_t status = zx_handle_duplicate(handle_, rights, &out_handle);
91 if (status != ZX_OK) {
92 return ToDart(Create(ZX_HANDLE_INVALID));
93 }
94 return ToDart(Create(out_handle));
95}

◆ handle()

zx_handle_t zircon::dart::Handle::handle ( ) const
inline

Definition at line 53 of file handle.h.

53{ return handle_; }

◆ is_valid()

bool zircon::dart::Handle::is_valid ( ) const
inline

Definition at line 51 of file handle.h.

51{ return handle_ != ZX_HANDLE_INVALID; }

◆ koid()

zx_koid_t zircon::dart::Handle::koid ( ) const
inline

Definition at line 55 of file handle.h.

55 {
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 }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213

◆ RegisterNatives()

void zircon::dart::Handle::RegisterNatives ( tonic::DartLibraryNatives natives)
static

Definition at line 132 of file handle.cc.

132 {
135}
void Register(std::initializer_list< Entry > entries)
#define DART_REGISTER_NATIVE(CLASS, METHOD)
#define FOR_EACH_STATIC_BINDING(V)
Definition: handle.cc:112
#define FOR_EACH_BINDING(V)
Definition: handle.cc:114
#define DART_REGISTER_NATIVE_STATIC_(CLASS, METHOD)
Definition: handle.cc:126

◆ ReleaseHandle()

zx_handle_t zircon::dart::Handle::ReleaseHandle ( )

Definition at line 36 of file handle.cc.

36 {
38
39 zx_handle_t handle = handle_;
40 handle_ = ZX_HANDLE_INVALID;
41 cached_koid_ = std::nullopt;
42 while (waiters_.size()) {
43 // HandleWaiter::Cancel calls Handle::ReleaseWaiter which removes the
44 // HandleWaiter from waiters_.
45 FML_DCHECK(waiters_.back()->is_pending());
46 waiters_.back()->Cancel();
47 }
48
50
51 return handle;
52}

◆ ReleaseWaiter()

void zircon::dart::Handle::ReleaseWaiter ( HandleWaiter waiter)

Definition at line 76 of file handle.cc.

76 {
77 FML_DCHECK(waiter);
78 auto iter = std::find(waiters_.cbegin(), waiters_.cend(), waiter);
79 FML_DCHECK(iter != waiters_.cend());
80 FML_DCHECK(*iter == waiter);
81 waiters_.erase(iter);
82}
int find(T *array, int N, T item)

◆ Replace()

Dart_Handle zircon::dart::Handle::Replace ( uint32_t  rights)

Definition at line 97 of file handle.cc.

97 {
98 if (!is_valid()) {
99 return ToDart(Create(ZX_HANDLE_INVALID));
100 }
101
102 zx_handle_t out_handle;
103 zx_status_t status = zx_handle_replace(ReleaseHandle(), rights, &out_handle);
104 if (status != ZX_OK) {
105 return ToDart(Create(ZX_HANDLE_INVALID));
106 }
107 return ToDart(Create(out_handle));
108}

◆ Unwrap()

static fml::RefPtr< Handle > zircon::dart::Handle::Unwrap ( Dart_Handle  handle)
inlinestatic

The documentation for this class was generated from the following files: