Flutter Engine
 
Loading...
Searching...
No Matches
service_protocol.h
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#ifndef FLUTTER_RUNTIME_SERVICE_PROTOCOL_H_
6#define FLUTTER_RUNTIME_SERVICE_PROTOCOL_H_
7
8#include <map>
9#include <set>
10#include <shared_mutex>
11#include <string>
12#include <string_view>
13
14#include "flutter/fml/macros.h"
17#include "rapidjson/document.h"
18
19namespace flutter {
20
22 public:
23 static const std::string_view kScreenshotExtensionName;
24 static const std::string_view kScreenshotSkpExtensionName;
25 static const std::string_view kRunInViewExtensionName;
26 static const std::string_view kFlushUIThreadTasksExtensionName;
27 static const std::string_view kSetAssetBundlePathExtensionName;
28 static const std::string_view kGetDisplayRefreshRateExtensionName;
29 static const std::string_view kGetSkSLsExtensionName;
30 static const std::string_view kEstimateRasterCacheMemoryExtensionName;
31 static const std::string_view kReloadAssetFonts;
32
33 class Handler {
34 public:
35 struct Description {
36 int64_t isolate_port = 0 /* illegal port by default. */;
37 std::string isolate_name;
38
40
41 Description(int64_t p_isolate_port, std::string p_isolate_name)
42 : isolate_port(p_isolate_port),
43 isolate_name(std::move(p_isolate_name)) {}
44
45 void Write(Handler* handler,
46 rapidjson::Value& value,
47 rapidjson::MemoryPoolAllocator<>& allocator) const;
48 };
49
50 using ServiceProtocolMap = std::map<std::string_view, std::string_view>;
51
53 std::string_view method) const = 0;
54
56
58 std::string_view method, // one if the extension names specified above.
60 rapidjson::Document* response) = 0;
61 };
62
64
66
67 void ToggleHooks(bool set);
68
69 void AddHandler(Handler* handler, const Handler::Description& description);
70
72
74 const Handler::Description& description);
75
76 private:
77 const std::set<std::string_view> endpoints_;
78 mutable std::shared_mutex handlers_mutex_;
79 std::map<Handler*, fml::AtomicObject<Handler::Description>> handlers_;
80
81 [[nodiscard]] static bool HandleMessage(const char* method,
82 const char** param_keys,
83 const char** param_values,
84 intptr_t num_params,
85 void* user_data,
86 const char** json_object);
87 [[nodiscard]] static bool HandleMessage(
88 std::string_view method,
90 ServiceProtocol* service_protocol,
91 rapidjson::Document* response);
92 [[nodiscard]] bool HandleMessage(std::string_view method,
94 rapidjson::Document* response) const;
95
96 [[nodiscard]] bool HandleListViewsMethod(rapidjson::Document* response) const;
97
99};
100
101} // namespace flutter
102
103#endif // FLUTTER_RUNTIME_SERVICE_PROTOCOL_H_
virtual bool HandleServiceProtocolMessage(std::string_view method, const ServiceProtocolMap &params, rapidjson::Document *response)=0
std::map< std::string_view, std::string_view > ServiceProtocolMap
virtual fml::RefPtr< fml::TaskRunner > GetServiceProtocolHandlerTaskRunner(std::string_view method) const =0
virtual Description GetServiceProtocolDescription() const =0
void AddHandler(Handler *handler, const Handler::Description &description)
static const std::string_view kSetAssetBundlePathExtensionName
static const std::string_view kReloadAssetFonts
static const std::string_view kScreenshotSkpExtensionName
static const std::string_view kScreenshotExtensionName
static const std::string_view kGetDisplayRefreshRateExtensionName
static const std::string_view kRunInViewExtensionName
static const std::string_view kEstimateRasterCacheMemoryExtensionName
static const std::string_view kGetSkSLsExtensionName
void RemoveHandler(Handler *handler)
void SetHandlerDescription(Handler *handler, const Handler::Description &description)
static const std::string_view kFlushUIThreadTasksExtensionName
const EmbeddedViewParams * params
const gchar FlBinaryMessengerMessageHandler handler
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
Definition ref_ptr.h:261
Description(int64_t p_isolate_port, std::string p_isolate_name)