Flutter Engine
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 size_t GetAllocationSize () const
 
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.

References Close(), FML_DCHECK, and is_valid().

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

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.

References zircon::dart::HandleWaiter::Create(), FML_LOG, fml::RefPtr< T >::get(), and is_valid().

Referenced by koid().

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

◆ Close()

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

Definition at line 54 of file handle.cc.

References is_valid(), and ReleaseHandle().

Referenced by koid(), and ~Handle().

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
bool is_valid() const
Definition: handle.h:51

◆ Create() [1/2]

◆ Create() [2/2]

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

Definition at line 38 of file handle.h.

References Create().

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

◆ CreateInvalid()

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

Definition at line 32 of file handle.cc.

References Create(), and tonic::ToDart().

Referenced by Unwrap().

32  {
33  return ToDart(Create(ZX_HANDLE_INVALID));
34 }
static fml::RefPtr< Handle > Create(zx_handle_t handle)
Definition: handle.cc:28
Dart_Handle ToDart(const T &object)

◆ Duplicate()

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

Definition at line 84 of file handle.cc.

References Create(), is_valid(), and tonic::ToDart().

Referenced by koid().

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 }
bool is_valid() const
Definition: handle.h:51
static fml::RefPtr< Handle > Create(zx_handle_t handle)
Definition: handle.cc:28
Dart_Handle ToDart(const T &object)

◆ handle()

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

Definition at line 53 of file handle.h.

Referenced by zircon::dart::HandleWaiter::Create(), Create(), and ReleaseHandle().

53 { return handle_; }

◆ is_valid()

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

Definition at line 51 of file handle.h.

Referenced by AsyncWait(), Close(), zircon::dart::HandleWaiter::Create(), Duplicate(), ReleaseHandle(), Replace(), and ~Handle().

51 { return handle_ != ZX_HANDLE_INVALID; }

◆ koid()

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

Definition at line 55 of file handle.h.

References fml::internal::RefCountedThreadSafeBase::AddRef(), AsyncWait(), callback, Close(), Duplicate(), fml::RefCountedThreadSafe< Handle >::Release(), ReleaseWaiter(), and Replace().

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  }

◆ RegisterNatives()

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

Definition at line 132 of file handle.cc.

References DART_REGISTER_NATIVE, DART_REGISTER_NATIVE_STATIC_, FOR_EACH_BINDING, and FOR_EACH_STATIC_BINDING.

132  {
135 }
#define FOR_EACH_STATIC_BINDING(V)
Definition: handle.cc:112
#define FOR_EACH_BINDING(V)
Definition: handle.cc:114
void Register(std::initializer_list< Entry > entries)
#define DART_REGISTER_NATIVE(CLASS, METHOD)
#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.

References FML_DCHECK, handle(), and is_valid().

Referenced by Close(), Replace(), and Unwrap().

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 
49  FML_DCHECK(!is_valid());
50 
51  return handle;
52 }
zx_handle_t handle() const
Definition: handle.h:53
#define FML_DCHECK(condition)
Definition: logging.h:86
bool is_valid() const
Definition: handle.h:51

◆ ReleaseWaiter()

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

Definition at line 76 of file handle.cc.

References FML_DCHECK.

Referenced by zircon::dart::HandleWaiter::Cancel(), and koid().

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 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ Replace()

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

Definition at line 97 of file handle.cc.

References Create(), is_valid(), ReleaseHandle(), and tonic::ToDart().

Referenced by koid().

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 }
zx_handle_t ReleaseHandle()
Definition: handle.cc:36
bool is_valid() const
Definition: handle.h:51
static fml::RefPtr< Handle > Create(zx_handle_t handle)
Definition: handle.cc:28
Dart_Handle ToDart(const T &object)

◆ Unwrap()

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

Definition at line 42 of file handle.h.

References CreateInvalid(), and ReleaseHandle().


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