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#ifndef FLUTTER_LIB_UI_ISOLATE_NAME_SERVER_H_
6#define FLUTTER_LIB_UI_ISOLATE_NAME_SERVER_H_
7
8#include <map>
9#include <mutex>
10#include <string>
11
12#include "flutter/fml/macros.h"
13#include "third_party/dart/runtime/include/dart_api.h"
14
15namespace flutter {
16
17class IsolateNameServer {
18 public:
19 IsolateNameServer();
20
21 ~IsolateNameServer();
22
23 // Looks up the Dart_Port associated with a given name. Returns ILLEGAL_PORT
24 // if the name does not exist.
25 Dart_Port LookupIsolatePortByName(const std::string& name);
26
27 // Registers a Dart_Port with a given name. Returns true if registration is
28 // successful, false if the name entry already exists.
29 bool RegisterIsolatePortWithName(Dart_Port port, const std::string& name);
30
31 // Removes a name to Dart_Port mapping given a name. Returns true if the
32 // mapping was successfully removed, false if the mapping does not exist.
33 bool RemoveIsolateNameMapping(const std::string& name);
34
35 private:
36 Dart_Port LookupIsolatePortByNameUnprotected(const std::string& name);
37
38 mutable std::mutex mutex_;
39 std::map<std::string, Dart_Port> port_mapping_;
40
41 FML_DISALLOW_COPY_AND_ASSIGN(IsolateNameServer);
42};
43
44} // namespace flutter
45
46#endif // FLUTTER_LIB_UI_ISOLATE_NAME_SERVER_H_
47