Flutter Engine
isolate_name_server_natives.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 "flutter/lib/ui/isolate_name_server/isolate_name_server_natives.h"
6 
7 #include <string>
8 
9 #include "flutter/lib/ui/isolate_name_server/isolate_name_server.h"
10 #include "flutter/lib/ui/ui_dart_state.h"
13 
14 namespace flutter {
15 
17  const std::string& name) {
18  auto name_server = UIDartState::Current()->GetIsolateNameServer();
19  if (!name_server) {
20  return Dart_Null();
21  }
22  Dart_Port port = name_server->LookupIsolatePortByName(name);
23  if (port == ILLEGAL_PORT) {
24  return Dart_Null();
25  }
26  return Dart_NewSendPort(port);
27 }
28 
30  Dart_Handle port_handle,
31  const std::string& name) {
32  auto name_server = UIDartState::Current()->GetIsolateNameServer();
33  if (!name_server) {
34  return Dart_False();
35  }
36  Dart_Port port = ILLEGAL_PORT;
37  Dart_SendPortGetId(port_handle, &port);
38  if (!name_server->RegisterIsolatePortWithName(port, name)) {
39  return Dart_False();
40  }
41  return Dart_True();
42 }
43 
45  const std::string& name) {
46  auto name_server = UIDartState::Current()->GetIsolateNameServer();
47  if (!name_server) {
48  return Dart_False();
49  }
50  if (!name_server->RemoveIsolateNameMapping(name)) {
51  return Dart_False();
52  }
53  return Dart_True();
54 }
55 
56 #define FOR_EACH_BINDING(V) \
57  V(IsolateNameServerNatives, LookupPortByName) \
58  V(IsolateNameServerNatives, RegisterPortWithName) \
59  V(IsolateNameServerNatives, RemovePortNameMapping)
60 
62 
63 #define DART_REGISTER_NATIVE_STATIC_(CLASS, METHOD) \
64  DART_REGISTER_NATIVE_STATIC(CLASS, METHOD),
65 
67  tonic::DartLibraryNatives* natives) {
69 }
70 
71 } // namespace flutter
#define DART_REGISTER_NATIVE_STATIC_(CLASS, METHOD)
DEF_SWITCHES_START snapshot asset Path to the directory containing the four files specified by VmSnapshotInstructions and IsolateSnapshotInstructions vm snapshot The VM instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present isolate snapshot The isolate instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present icu symbol Prefix for the symbols representing ICU data linked into the Flutter library dart Flags passed directly to the Dart VM without being interpreted by the Flutter shell observatory port
Definition: switches.h:75
static Dart_Handle RegisterPortWithName(Dart_Handle port_handle, const std::string &name)
void Register(std::initializer_list< Entry > entries)
#define DART_NATIVE_CALLBACK_STATIC(CLASS, METHOD)
#define FOR_EACH_BINDING(V)
const char * name
Definition: fuchsia.cc:50
std::shared_ptr< IsolateNameServer > GetIsolateNameServer() const
static Dart_Handle LookupPortByName(const std::string &name)
static void RegisterNatives(tonic::DartLibraryNatives *natives)
static UIDartState * Current()
static Dart_Handle RemovePortNameMapping(const std::string &name)