Flutter Engine
The Flutter Engine
handle.cc
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#include "handle.h"
6
7#include "flutter/fml/logging.h"
8
9#include <iostream>
10#include <vector>
11
12#include <zircon/syscalls.h>
13
14static void HandleFree(void* isolate_callback_data, void* peer) {
15 FML_CHECK(peer);
16 zircon_dart_handle_t* handle = reinterpret_cast<zircon_dart_handle_t*>(peer);
18}
19
20static void HandlePairFree(void* isolate_callback_data, void* peer) {
21 FML_CHECK(peer);
22 zircon_dart_handle_pair_t* handle_pair =
23 reinterpret_cast<zircon_dart_handle_pair_t*>(peer);
24 free(handle_pair);
25}
26
28 FML_CHECK(handle);
29 if (handle->handle != ZX_HANDLE_INVALID) {
31 }
32 free(handle);
33}
34
36 FML_CHECK(handle->handle != ZX_HANDLE_INVALID);
37 zx_status_t status = zx_handle_close(handle->handle);
38 handle->handle = ZX_HANDLE_INVALID;
39 if (status == ZX_OK) {
40 return 1;
41 } else {
42 return 0;
43 }
44}
45
47 if (!handle || (handle->handle == ZX_HANDLE_INVALID)) {
48 return 0;
49 } else {
50 return 1;
51 }
52}
53
55 void* pointer,
56 intptr_t external_allocation_size) {
57 Dart_FinalizableHandle weak_handle = Dart_NewFinalizableHandle_DL(
58 object, pointer, external_allocation_size, HandleFree);
59
60 if (weak_handle == nullptr) {
61 FML_LOG(ERROR) << "Unable to attach finalizer: " << std::hex << pointer;
62 return -1;
63 }
64
65 return 1;
66}
67
69 Dart_Handle object,
70 void* pointer,
71 intptr_t external_allocation_size) {
72 Dart_FinalizableHandle weak_handle = Dart_NewFinalizableHandle_DL(
73 object, pointer, external_allocation_size, HandlePairFree);
74
75 if (weak_handle == nullptr) {
76 FML_LOG(ERROR) << "Unable to attach finalizer: " << std::hex << pointer;
77 return -1;
78 }
79
80 return 1;
81}
82
83// zircon handle list methods.
84using HandleVector = std::vector<zircon_dart_handle_t*>;
86
90 result->size = 0;
91 result->data = new HandleVector();
92 return result;
93}
94
96 zircon_dart_handle_t* handle) {
97 FML_CHECK(list);
98 FML_CHECK(handle);
99 list->size++;
100 auto data = reinterpret_cast<HandleVectorPtr>(list->data);
101 data->push_back(handle);
102}
103
105 auto data = reinterpret_cast<HandleVectorPtr>(list->data);
106 data->clear();
107 delete data;
108 free(list);
109}
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
struct _Dart_FinalizableHandle * Dart_FinalizableHandle
Definition: dart_api.h:261
int32_t zircon_dart_handle_close(zircon_dart_handle_t *handle)
Definition: handle.cc:35
void zircon_dart_handle_list_append(zircon_dart_handle_list_t *list, zircon_dart_handle_t *handle)
Definition: handle.cc:95
zircon_dart_handle_list_t * zircon_dart_handle_list_create()
Definition: handle.cc:87
HandleVector * HandleVectorPtr
Definition: handle.cc:85
static void HandlePairFree(void *isolate_callback_data, void *peer)
Definition: handle.cc:20
int32_t zircon_dart_handle_is_valid(zircon_dart_handle_t *handle)
Definition: handle.cc:46
void zircon_dart_handle_free(zircon_dart_handle_t *handle)
Definition: handle.cc:27
int zircon_dart_handle_attach_finalizer(Dart_Handle object, void *pointer, intptr_t external_allocation_size)
Definition: handle.cc:54
std::vector< zircon_dart_handle_t * > HandleVector
Definition: handle.cc:84
void zircon_dart_handle_list_free(zircon_dart_handle_list_t *list)
Definition: handle.cc:104
int zircon_dart_handle_pair_attach_finalizer(Dart_Handle object, void *pointer, intptr_t external_allocation_size)
Definition: handle.cc:68
static void HandleFree(void *isolate_callback_data, void *peer)
Definition: handle.cc:14
GAsyncResult * result
#define FML_LOG(severity)
Definition: logging.h:82
#define FML_CHECK(condition)
Definition: logging.h:85
void * malloc(size_t size)
Definition: allocation.cc:19
uint32_t handle
Definition: handle.h:19
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
#define ERROR(message)
Definition: elf_loader.cc:260