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_RUNTIME_DART_SERVICE_ISOLATE_H_ 6 #define FLUTTER_RUNTIME_DART_SERVICE_ISOLATE_H_ 7 8 #include <functional> 9 #include <mutex> 10 #include <set> 11 #include <string> 12 13 #include "flutter/fml/compiler_specific.h" 14 #include "flutter/fml/synchronization/thread_annotations.h" 15 16 #include "third_party/dart/runtime/include/dart_api.h" 17 18 namespace flutter { 19 20 class DartServiceIsolate { 21 public: 22 using ObservatoryServerStateCallback = 23 std::function<void(const std::string&)>; 24 25 static bool Startup(std::string server_ip, 26 intptr_t server_port, 27 Dart_LibraryTagHandler embedder_tag_handler, 28 bool disable_origin_check, 29 bool disable_service_auth_codes, 30 char** error); 31 32 using CallbackHandle = ptrdiff_t; 33 34 // Returns a handle for the callback that can be used in 35 // RemoveServerStatusCallback 36 FML_WARN_UNUSED_RESULT 37 static CallbackHandle AddServerStatusCallback( 38 ObservatoryServerStateCallback callback); 39 40 // Accepts the handle returned by AddServerStatusCallback 41 static bool RemoveServerStatusCallback(CallbackHandle handle); 42 43 private: 44 // Native entries. 45 static void NotifyServerState(Dart_NativeArguments args); 46 static void Shutdown(Dart_NativeArguments args); 47 48 static std::mutex callbacks_mutex_; 49 static std::set<std::unique_ptr<ObservatoryServerStateCallback>> callbacks_ 50 FML_GUARDED_BY(callbacks_mutex_); 51 }; 52 53 } // namespace flutter 54 55 #endif // FLUTTER_RUNTIME_DART_SERVICE_ISOLATE_H_ 56