Flutter Engine
The Flutter Engine
eventhandler.cc
Go to the documentation of this file.
1// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
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.
4
5#include "bin/eventhandler.h"
6
7#include "bin/builtin.h"
8#include "bin/dartutils.h"
9#include "bin/lockers.h"
10#include "bin/socket.h"
11#include "bin/thread.h"
12
13#include "include/dart_api.h"
14
15namespace dart {
16namespace bin {
17
18static EventHandler* event_handler = nullptr;
19static Monitor* shutdown_monitor = nullptr;
20
22 // Initialize global socket registry.
24
25 ASSERT(event_handler == nullptr);
29
31 FATAL("Failed to initialize sockets");
32 }
33}
34
37 ml.Notify();
38}
39
41 if (event_handler == nullptr) {
42 return;
43 }
44
45 // Wait until it has stopped.
46 {
48
49 // Signal to event handler that we want it to stop.
50 event_handler->delegate_.Shutdown();
52 }
53
54 // Cleanup
55 delete event_handler;
56 event_handler = nullptr;
57 delete shutdown_monitor;
58 shutdown_monitor = nullptr;
59
60 // Destroy the global socket registry.
62}
63
65 if (event_handler == nullptr) {
66 return nullptr;
67 }
68 return &event_handler->delegate_;
69}
70
71void EventHandler::SendFromNative(intptr_t id, Dart_Port port, int64_t data) {
73}
74
75/*
76 * Send data to the EventHandler thread to register for a given instance
77 * args[0] a ReceivePort args[1] with a notification event args[2].
78 */
80 // Get the id out of the send port. If the handle is not a send port
81 // we will get an error and propagate that out.
83 Dart_Port dart_port;
84 handle = Dart_SendPortGetId(handle, &dart_port);
85 if (Dart_IsError(handle)) {
86 Dart_PropagateError(handle);
88 }
90 intptr_t id;
91 if (Dart_IsNull(sender)) {
92 id = kTimerId;
93 } else {
94 Socket* socket = Socket::GetSocketIdNativeField(sender);
95 ASSERT(dart_port != ILLEGAL_PORT);
96 socket->set_port(dart_port);
97 socket->Retain(); // inc refcount before sending to the eventhandler.
98 id = reinterpret_cast<intptr_t>(socket);
99 }
101 event_handler->SendData(id, dart_port, data);
102}
103
108}
109
110} // namespace bin
111} // namespace dart
#define UNREACHABLE()
Definition: assert.h:248
#define FUNCTION_NAME(name)
Definition: builtin.h:19
static int64_t GetIntegerValue(Dart_Handle value_obj)
Definition: dartutils.cc:81
void Start(EventHandler *handler)
static EventHandlerImplementation * delegate()
Definition: eventhandler.cc:64
static void SendFromNative(intptr_t id, Dart_Port port, int64_t data)
Definition: eventhandler.cc:71
void SendData(intptr_t id, Dart_Port dart_port, int64_t data)
Definition: eventhandler.h:606
Monitor::WaitResult Wait(int64_t millis=Monitor::kNoTimeout)
Definition: lockers.h:38
static constexpr int64_t kNoTimeout
Definition: thread.h:79
static bool Initialize()
static Socket * GetSocketIdNativeField(Dart_Handle socket)
Definition: socket.cc:1496
void set_port(Dart_Port port)
Definition: socket.h:64
static int64_t GetCurrentMonotonicMillis()
#define ILLEGAL_PORT
Definition: dart_api.h:1535
int64_t Dart_Port
Definition: dart_api.h:1525
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
struct _Dart_NativeArguments * Dart_NativeArguments
Definition: dart_api.h:3019
#define ASSERT(E)
#define FATAL(error)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static constexpr intptr_t kTimerId
Definition: eventhandler.h:109
void FUNCTION_NAME() EventHandler_TimerMillisecondClock(Dart_NativeArguments args)
void FUNCTION_NAME() EventHandler_SendData(Dart_NativeArguments args)
Definition: eventhandler.cc:79
static Monitor * shutdown_monitor
Definition: eventhandler.cc:19
static EventHandler * event_handler
Definition: eventhandler.cc:18
Definition: dart_vm.cc:33
DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value)
DART_EXPORT void Dart_PropagateError(Dart_Handle handle)
DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, Dart_Handle retval)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, int index)
DART_EXPORT bool Dart_IsNull(Dart_Handle object)
static int8_t data[kExtLength]
DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port, Dart_Port *port_id)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service port
Definition: switches.h:87
const uintptr_t id