Flutter Engine
The 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 <string>
11#include <string_view>
12
13#include "flutter/fml/compiler_specific.h"
14#include "flutter/fml/macros.h"
15#include "flutter/fml/synchronization/atomic_object.h"
16#include "flutter/fml/synchronization/shared_mutex.h"
17#include "flutter/fml/task_runner.h"
18#include "rapidjson/document.h"
19
20namespace flutter {
21
23 public:
24 static const std::string_view kScreenshotExtensionName;
25 static const std::string_view kScreenshotSkpExtensionName;
26 static const std::string_view kRunInViewExtensionName;
27 static const std::string_view kFlushUIThreadTasksExtensionName;
28 static const std::string_view kSetAssetBundlePathExtensionName;
29 static const std::string_view kGetDisplayRefreshRateExtensionName;
30 static const std::string_view kGetSkSLsExtensionName;
31 static const std::string_view kEstimateRasterCacheMemoryExtensionName;
32 static const std::string_view kRenderFrameWithRasterStatsExtensionName;
33 static const std::string_view kReloadAssetFonts;
34
35 class Handler {
36 public:
37 struct Description {
38 int64_t isolate_port = 0 /* illegal port by default. */;
39 std::string isolate_name;
40
42
43 Description(int64_t p_isolate_port, std::string p_isolate_name)
44 : isolate_port(p_isolate_port),
45 isolate_name(std::move(p_isolate_name)) {}
46
47 void Write(Handler* handler,
48 rapidjson::Value& value,
49 rapidjson::MemoryPoolAllocator<>& allocator) const;
50 };
51
52 using ServiceProtocolMap = std::map<std::string_view, std::string_view>;
53
55 std::string_view method) const = 0;
56
58
60 std::string_view method, // one if the extension names specified above.
62 rapidjson::Document* response) = 0;
63 };
64
66
68
69 void ToggleHooks(bool set);
70
71 void AddHandler(Handler* handler, const Handler::Description& description);
72
73 void RemoveHandler(Handler* handler);
74
75 void SetHandlerDescription(Handler* handler,
76 const Handler::Description& description);
77
78 private:
79 const std::set<std::string_view> endpoints_;
80 std::unique_ptr<fml::SharedMutex> handlers_mutex_;
81 std::map<Handler*, fml::AtomicObject<Handler::Description>> handlers_;
82
83 [[nodiscard]] static bool HandleMessage(const char* method,
84 const char** param_keys,
85 const char** param_values,
86 intptr_t num_params,
87 void* user_data,
88 const char** json_object);
89 [[nodiscard]] static bool HandleMessage(
90 std::string_view method,
92 ServiceProtocol* service_protocol,
93 rapidjson::Document* response);
94 [[nodiscard]] bool HandleMessage(std::string_view method,
96 rapidjson::Document* response) const;
97
98 [[nodiscard]] bool HandleListViewsMethod(rapidjson::Document* response) const;
99
101};
102
103} // namespace flutter
104
105#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)
static const std::string_view kRenderFrameWithRasterStatsExtensionName
void SetHandlerDescription(Handler *handler, const Handler::Description &description)
static const std::string_view kFlushUIThreadTasksExtensionName
const EmbeddedViewParams * params
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
Definition ref_ptr.h:256
void Write(Handler *handler, rapidjson::Value &value, rapidjson::MemoryPoolAllocator<> &allocator) const
Description(int64_t p_isolate_port, std::string p_isolate_name)