Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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 static const std::string_view kGetPipelineUsageExtensionName;
33
34 class Handler {
35 public:
36 struct Description {
37 int64_t isolate_port = 0 /* illegal port by default. */;
38 std::string isolate_name;
39
41
42 Description(int64_t p_isolate_port, std::string p_isolate_name)
43 : isolate_port(p_isolate_port),
44 isolate_name(std::move(p_isolate_name)) {}
45
46 void Write(Handler* handler,
47 rapidjson::Value& value,
48 rapidjson::MemoryPoolAllocator<>& allocator) const;
49 };
50
51 using ServiceProtocolMap = std::map<std::string_view, std::string_view>;
52
54 std::string_view method) const = 0;
55
57
59 std::string_view method, // one if the extension names specified above.
61 rapidjson::Document* response) = 0;
62 };
63
65
67
68 void ToggleHooks(bool set);
69
70 void AddHandler(Handler* handler, const Handler::Description& description);
71
73
75 const Handler::Description& description);
76
77 private:
78 const std::set<std::string_view> endpoints_;
79 mutable std::shared_mutex handlers_mutex_;
80 std::map<Handler*, fml::AtomicObject<Handler::Description>> handlers_;
81
82 [[nodiscard]] static bool HandleMessage(const char* method,
83 const char** param_keys,
84 const char** param_values,
85 intptr_t num_params,
86 void* user_data,
87 const char** json_object);
88 [[nodiscard]] static bool HandleMessage(
89 std::string_view method,
91 ServiceProtocol* service_protocol,
92 rapidjson::Document* response);
93 [[nodiscard]] bool HandleMessage(std::string_view method,
95 rapidjson::Document* response) const;
96
97 [[nodiscard]] bool HandleListViewsMethod(rapidjson::Document* response) const;
98
100};
101
102} // namespace flutter
103
104#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
static const std::string_view kGetPipelineUsageExtensionName
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
std::shared_ptr< ImpellerAllocator > allocator
Definition ref_ptr.h:261
Description(int64_t p_isolate_port, std::string p_isolate_name)