Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
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) {
72 event_handler->SendData(id, port, 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
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:85
void Start(EventHandler *handler)
static EventHandlerImplementation * delegate()
static void SendFromNative(intptr_t id, Dart_Port port, int64_t data)
void SendData(intptr_t id, Dart_Port dart_port, int64_t data)
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:1530
int64_t Dart_Port
Definition dart_api.h:1524
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
struct _Dart_NativeArguments * Dart_NativeArguments
Definition dart_api.h:3010
#define ASSERT(E)
#define FATAL(error)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static constexpr intptr_t kTimerId
void FUNCTION_NAME() EventHandler_TimerMillisecondClock(Dart_NativeArguments args)
void FUNCTION_NAME() EventHandler_SendData(Dart_NativeArguments args)
static Monitor * shutdown_monitor
static EventHandler * event_handler
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)
const uintptr_t id