Flutter Engine
mock_engine.cc File Reference
#include <cstring>
#include "flutter/shell/platform/embedder/embedder.h"
#include "flutter/shell/platform/linux/fl_method_codec_private.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_response.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h"
#include "gtest/gtest.h"

Go to the source code of this file.

Classes

struct  _FlutterEngine
 
struct  _FlutterPlatformMessageResponseHandle
 
struct  _FlutterTaskRunner
 

Functions

static void send_response (FLUTTER_API_SYMBOL(FlutterEngine) engine, const std::string &channel, const FlutterPlatformMessageResponseHandle *response_handle, const uint8_t *message, size_t message_size)
 
static void send_message (FLUTTER_API_SYMBOL(FlutterEngine) engine, const std::string &channel, const uint8_t *message, size_t message_size)
 
static void invoke_method (FLUTTER_API_SYMBOL(FlutterEngine) engine, const std::string &channel, const gchar *name, FlValue *args)
 
FlutterEngineResult FlutterEngineCreateAOTData (const FlutterEngineAOTDataSource *source, FlutterEngineAOTData *data_out)
 Creates the necessary data structures to launch a Flutter Dart application in AOT mode. The data may only be collected after all FlutterEngine instances launched using this data have been terminated. More...
 
FlutterEngineResult FlutterEngineCollectAOTData (FlutterEngineAOTData data)
 Collects the AOT data. More...
 
FlutterEngineResult FlutterEngineRun (size_t version, const FlutterRendererConfig *config, const FlutterProjectArgs *args, void *user_data, FLUTTER_API_SYMBOL(FlutterEngine) *engine_out)
 Initialize and run a Flutter engine instance and return a handle to it. This is a convenience method for the pair of calls to FlutterEngineInitialize and FlutterEngineRunInitialized. More...
 
FlutterEngineResult FlutterEngineShutdown (FLUTTER_API_SYMBOL(FlutterEngine) engine)
 Shuts down a Flutter engine instance. The engine handle is no longer valid for any calls in the embedder API after this point. Making additional calls with this handle is undefined behavior. More...
 
FlutterEngineResult FlutterEngineInitialize (size_t version, const FlutterRendererConfig *config, const FlutterProjectArgs *args, void *user_data, FLUTTER_API_SYMBOL(FlutterEngine) *engine_out)
 Initialize a Flutter engine instance. This does not run the Flutter application code till the FlutterEngineRunInitialized call is made. Besides Flutter application code, no tasks are scheduled on embedder managed task runners either. This allows embedders providing custom task runners to the Flutter engine to obtain a handle to the Flutter engine before the engine can post tasks on these task runners. More...
 
FlutterEngineResult FlutterEngineDeinitialize (FLUTTER_API_SYMBOL(FlutterEngine) engine)
 Stops running the Flutter engine instance. After this call, the embedder is also guaranteed that no more calls to post tasks onto custom task runners specified by the embedder are made. The Flutter engine handle still needs to be collected via a call to FlutterEngineShutdown. More...
 
FlutterEngineResult FlutterEngineRunInitialized (FLUTTER_API_SYMBOL(FlutterEngine) engine)
 Runs an initialized engine instance. An engine can be initialized via FlutterEngineInitialize. An initialized instance can only be run once. During and after this call, custom task runners supplied by the embedder are expected to start servicing tasks. More...
 
FlutterEngineResult FlutterEngineSendWindowMetricsEvent (FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterWindowMetricsEvent *event)
 
FlutterEngineResult FlutterEngineSendPointerEvent (FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPointerEvent *events, size_t events_count)
 
FLUTTER_EXPORT FlutterEngineResult FlutterEngineSendPlatformMessage (FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPlatformMessage *message)
 
FlutterEngineResult FlutterPlatformMessageCreateResponseHandle (FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterDataCallback data_callback, void *user_data, FlutterPlatformMessageResponseHandle **response_out)
 Creates a platform message response handle that allows the embedder to set a native callback for a response to a message. This handle may be set on the response_handle field of any FlutterPlatformMessage sent to the engine. More...
 
FlutterEngineResult FlutterPlatformMessageReleaseResponseHandle (FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterPlatformMessageResponseHandle *response)
 Collects the handle created using FlutterPlatformMessageCreateResponseHandle. More...
 
FlutterEngineResult FlutterEngineSendPlatformMessageResponse (FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPlatformMessageResponseHandle *handle, const uint8_t *data, size_t data_length)
 Send a response from the native side to a platform message from the Dart Flutter application. More...
 
FlutterEngineResult FlutterEngineRunTask (FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterTask *task)
 Inform the engine to run the specified task. This task has been given to the engine via the FlutterTaskRunnerDescription.post_task_callback. This call must only be made at the target time specified in that callback. Running the task before that time is undefined behavior. More...
 
bool FlutterEngineRunsAOTCompiledDartCode ()
 Returns if the Flutter engine instance will run AOT compiled Dart code. This call has no threading restrictions. More...
 
FlutterEngineResult FlutterEngineUpdateLocales (FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterLocale **locales, size_t locales_count)
 Notify a running engine instance that the locale has been updated. The preferred locale must be the first item in the list of locales supplied. The other entries will be used as a fallback. More...
 

Function Documentation

◆ FlutterEngineCollectAOTData()

FlutterEngineResult FlutterEngineCollectAOTData ( FlutterEngineAOTData  data)

Collects the AOT data.

Warning
The embedder must ensure that this call is made only after all FlutterEngine instances launched using this data have been terminated, and that all of those instances were launched with the FlutterProjectArgs::shutdown_dart_vm_when_done flag set to true.
Parameters
[in]dataThe data to collect.
Returns
Returns if the AOT data was successfully collected.

Definition at line 137 of file mock_engine.cc.

References kSuccess.

137  {
138  return kSuccess;
139 }

◆ FlutterEngineCreateAOTData()

FlutterEngineResult FlutterEngineCreateAOTData ( const FlutterEngineAOTDataSource source,
FlutterEngineAOTData data_out 
)

Creates the necessary data structures to launch a Flutter Dart application in AOT mode. The data may only be collected after all FlutterEngine instances launched using this data have been terminated.

Parameters
[in]sourceThe source of the AOT data.
[out]data_outThe AOT data on success. Unchanged on failure.
Returns
Returns if the AOT data could be successfully resolved.

Definition at line 130 of file mock_engine.cc.

References FlutterEngineAOTDataSource::elf_path, error, fml::IsFile(), flutter::DartVM::IsRunningPrecompiledCode(), kFlutterEngineAOTDataSourceTypeElfPath, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, and FlutterEngineAOTDataSource::type.

132  {
133  *data_out = nullptr;
134  return kSuccess;
135 }

◆ FlutterEngineDeinitialize()

FlutterEngineResult FlutterEngineDeinitialize ( FLUTTER_API_SYMBOL(FlutterEngine engine)

Stops running the Flutter engine instance. After this call, the embedder is also guaranteed that no more calls to post tasks onto custom task runners specified by the embedder are made. The Flutter engine handle still needs to be collected via a call to FlutterEngineShutdown.

Parameters
[in]engineThe running engine instance to de-initialize.
Returns
The result of the call to de-initialize the Flutter engine.

Definition at line 192 of file mock_engine.cc.

References engine, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, and flutter::EmbedderEngine::NotifyDestroyed().

193  {
194  return kSuccess;
195 }

◆ FlutterEngineInitialize()

FlutterEngineResult FlutterEngineInitialize ( size_t  version,
const FlutterRendererConfig config,
const FlutterProjectArgs args,
void *  user_data,
FLUTTER_API_SYMBOL(FlutterEngine) *  engine_out 
)

Initialize a Flutter engine instance. This does not run the Flutter application code till the FlutterEngineRunInitialized call is made. Besides Flutter application code, no tasks are scheduled on embedder managed task runners either. This allows embedders providing custom task runners to the Flutter engine to obtain a handle to the Flutter engine before the engine can post tasks on these task runners.

Parameters
[in]versionThe Flutter embedder API version. Must be FLUTTER_ENGINE_VERSION.
[in]configThe renderer configuration.
[in]argsThe Flutter project arguments.
user_dataA user data baton passed back to embedders in callbacks.
[out]engine_outThe engine handle on successful engine creation.
Returns
The result of the call to initialize the Flutter engine.

Definition at line 166 of file mock_engine.cc.

References _FlutterEngine::_FlutterEngine(), action, fml::MessageLoop::AddTaskObserver(), flutter::Settings::application_kernel_asset, flutter::Settings::assets_path, FlutterProjectArgs::assets_path, FlutterPlatformMessage::channel, fml::CommandLineFromArgcArgv(), FlutterProjectArgs::compute_platform_resolved_locale_callback, flutter::EmbedderThreadHost::CreateEmbedderOrEngineManagedThreadHost(), FlutterProjectArgs::custom_dart_entrypoint, FlutterProjectArgs::custom_task_runners, FlutterProjectArgs::dart_entrypoint_argc, flutter::Settings::dart_entrypoint_args, FlutterProjectArgs::dart_entrypoint_argv, FlutterOpenGLTexture::destruction_callback, FLUTTER_ENGINE_VERSION, FML_LOG, FlutterOpenGLTexture::format, fml::MessageLoop::GetCurrent(), flutter::PersistentCache::gIsReadOnly, FlutterOpenGLRendererConfig::gl_external_texture_frame_callback, height, FlutterOpenGLTexture::height, flutter::Settings::icu_data_path, FlutterSemanticsNode::id, InferExternalViewEmbedderFromArgs(), flutter::RunConfiguration::InferFromSettings(), InferPlatformViewCreationCallback(), fml::IsFile(), IsRendererValid(), flutter::DartVM::IsRunningPrecompiledCode(), fml::paths::JoinPaths(), kApplicationKernelSnapshotFileName, kFlutterSemanticsCustomActionIdBatchEnd, kFlutterSemanticsNodeIdBatchEnd, kInternalInconsistency, kInvalidArguments, kInvalidLibraryVersion, kOpenGL, kSuccess, flutter::Settings::leak_vm, LOG_EMBEDDER_ERROR, FlutterOpenGLTexture::name, flutter::Settings::old_gen_heap_size, FlutterRendererConfig::open_gl, FlutterProjectArgs::platform_message_callback, FlutterCustomTaskRunners::platform_task_runner, PopulateSnapshotMappingCallbacks(), FlutterTaskRunnerDescription::post_task_callback, fml::MessageLoop::RemoveTaskObserver(), flutter::Settings::root_isolate_create_callback, SAFE_ACCESS, flutter::PersistentCache::SetCacheDirectoryPath(), flutter::SettingsFromCommandLine(), fml::size(), FlutterOpenGLTexture::target, flutter::Settings::task_observer_add, flutter::Settings::task_observer_remove, flutter::transform, FlutterRendererConfig::type, FlutterProjectArgs::update_semantics_custom_action_callback, FlutterProjectArgs::update_semantics_node_callback, user_data, FlutterOpenGLTexture::user_data, value, FlutterProjectArgs::vsync_callback, width, and FlutterOpenGLTexture::width.

Referenced by FlutterEngineRun().

171  {
172  EXPECT_NE(config, nullptr);
173 
174  EXPECT_NE(args, nullptr);
175  EXPECT_NE(args->platform_message_callback, nullptr);
176  EXPECT_NE(args->custom_task_runners, nullptr);
177  EXPECT_NE(args->custom_task_runners->platform_task_runner, nullptr);
179  nullptr);
180 
181  EXPECT_NE(user_data, nullptr);
182 
183  EXPECT_EQ(config->type, kOpenGL);
184 
185  *engine_out = new _FlutterEngine(
188  user_data);
189  return kSuccess;
190 }
const FlutterCustomTaskRunners * custom_task_runners
Definition: embedder.h:1265
FlutterPlatformMessageCallback platform_message_callback
Definition: embedder.h:1174
G_BEGIN_DECLS FlValue gpointer user_data
FlutterRendererType type
Definition: embedder.h:448
const FlutterTaskRunnerDescription * platform_task_runner
Definition: embedder.h:752
FlutterTaskRunnerPostTaskCallback post_task_callback
Definition: embedder.h:739

◆ FlutterEngineRun()

FlutterEngineResult FlutterEngineRun ( size_t  version,
const FlutterRendererConfig config,
const FlutterProjectArgs args,
void *  user_data,
FLUTTER_API_SYMBOL(FlutterEngine) *  engine_out 
)

Initialize and run a Flutter engine instance and return a handle to it. This is a convenience method for the pair of calls to FlutterEngineInitialize and FlutterEngineRunInitialized.

Note
This method of running a Flutter engine works well except in cases where the embedder specifies custom task runners via FlutterProjectArgs::custom_task_runners. In such cases, the engine may need the embedder to post tasks back to it before FlutterEngineRun has returned. Embedders can only post tasks to the engine if they have a handle to the engine. In such cases, embedders are advised to get the engine handle via the FlutterInitializeCall. Then they can call FlutterEngineRunInitialized knowing that they will be able to service custom tasks on other threads with the engine handle.
Parameters
[in]versionThe Flutter embedder API version. Must be FLUTTER_ENGINE_VERSION.
[in]configThe renderer configuration.
[in]argsThe Flutter project arguments.
user_dataA user data baton passed back to embedders in callbacks.
[out]engine_outThe engine handle on successful engine creation.
Returns
The result of the call to run the Flutter engine.

Definition at line 141 of file mock_engine.cc.

References FlutterEngineInitialize(), FlutterEngineRunInitialized(), and kSuccess.

146  {
147  EXPECT_NE(config, nullptr);
148  EXPECT_NE(args, nullptr);
149  EXPECT_NE(user_data, nullptr);
150  EXPECT_NE(engine_out, nullptr);
151 
152  FlutterEngineResult result =
153  FlutterEngineInitialize(version, config, args, user_data, engine_out);
154  if (result != kSuccess) {
155  return result;
156  }
157  return FlutterEngineRunInitialized(*engine_out);
158 }
FlutterEngineResult FlutterEngineRunInitialized(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Runs an initialized engine instance. An engine can be initialized via FlutterEngineInitialize. An initialized instance can only be run once. During and after this call, custom task runners supplied by the embedder are expected to start servicing tasks.
Definition: mock_engine.cc:197
G_BEGIN_DECLS FlValue gpointer user_data
FlutterEngineResult
Definition: embedder.h:65
FlutterEngineResult FlutterEngineInitialize(size_t version, const FlutterRendererConfig *config, const FlutterProjectArgs *args, void *user_data, FLUTTER_API_SYMBOL(FlutterEngine) *engine_out)
Initialize a Flutter engine instance. This does not run the Flutter application code till the Flutter...
Definition: mock_engine.cc:166

◆ FlutterEngineRunInitialized()

FlutterEngineResult FlutterEngineRunInitialized ( FLUTTER_API_SYMBOL(FlutterEngine engine)

Runs an initialized engine instance. An engine can be initialized via FlutterEngineInitialize. An initialized instance can only be run once. During and after this call, custom task runners supplied by the embedder are expected to start servicing tasks.

Parameters
[in]engineAn initialized engine instance that has not previously been run.
Returns
The result of the call to run the initialized Flutter engine instance.

Definition at line 197 of file mock_engine.cc.

References engine, FLUTTER_EXPORT, kInternalInconsistency, kInvalidArguments, kSuccess, and LOG_EMBEDDER_ERROR.

Referenced by FlutterEngineRun().

198  {
199  engine->running = true;
200  return kSuccess;
201 }

◆ FlutterEngineRunsAOTCompiledDartCode()

bool FlutterEngineRunsAOTCompiledDartCode ( void  )

Returns if the Flutter engine instance will run AOT compiled Dart code. This call has no threading restrictions.

For embedder code that is configured for both AOT and JIT mode Dart execution based on the Flutter engine being linked to, this runtime check may be used to appropriately configure the FlutterProjectArgs. In JIT mode execution, the kernel snapshots must be present in the Flutter assets directory specified in the FlutterProjectArgs. For AOT execution, the fields vm_snapshot_data, vm_snapshot_instructions, isolate_snapshot_data and isolate_snapshot_instructions (along with their size fields) must be specified in FlutterProjectArgs.

Returns
True, if AOT Dart code is run. JIT otherwise.

Definition at line 394 of file mock_engine.cc.

References flutter::DartVM::IsRunningPrecompiledCode().

394  {
395  return false;
396 }

◆ FlutterEngineRunTask()

FlutterEngineResult FlutterEngineRunTask ( FLUTTER_API_SYMBOL(FlutterEngine engine,
const FlutterTask task 
)

Inform the engine to run the specified task. This task has been given to the engine via the FlutterTaskRunnerDescription.post_task_callback. This call must only be made at the target time specified in that callback. Running the task before that time is undefined behavior.

Parameters
[in]engineA running engine instance.
[in]taskthe task handle.
Returns
The result of the call.

Definition at line 361 of file mock_engine.cc.

References _FlutterTaskRunner::channel, FlutterPlatformMessage::channel, _FlutterPlatformMessageResponseHandle::data_callback, engine, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, _FlutterTaskRunner::message, FlutterPlatformMessage::message, _FlutterTaskRunner::message_size, FlutterPlatformMessage::message_size, _FlutterTaskRunner::response_handle, FlutterPlatformMessage::response_handle, FlutterTask::runner, FlutterPlatformMessage::struct_size, and _FlutterPlatformMessageResponseHandle::user_data.

363  {
364  EXPECT_NE(engine, nullptr);
365  EXPECT_NE(task, nullptr);
366  EXPECT_NE(task->runner, nullptr);
367 
368  FlutterTaskRunner runner = task->runner;
369  EXPECT_NE(runner, nullptr);
370  const FlutterPlatformMessageResponseHandle* response_handle =
371  runner->response_handle;
372  if (response_handle != nullptr) {
373  EXPECT_NE(response_handle->data_callback, nullptr);
374  response_handle->data_callback(runner->message, runner->message_size,
375  response_handle->user_data);
376  } else {
379 
380  FlutterPlatformMessage message;
381  message.struct_size = sizeof(FlutterPlatformMessage);
382  message.channel = runner->channel.c_str();
383  message.message = runner->message;
384  message.message_size = runner->message_size;
385  message.response_handle = handle;
386  engine->platform_message_callback(&message, engine->user_data);
387  }
388 
389  delete runner;
390 
391  return kSuccess;
392 }
const char * channel
Definition: embedder.h:567
const FlutterPlatformMessageResponseHandle * response_handle
Definition: embedder.h:576
FlutterTaskRunner runner
Definition: embedder.h:707
const FlutterPlatformMessageResponseHandle * response_handle
Definition: mock_engine.cc:50
const uint8_t * message
Definition: embedder.h:568
size_t struct_size
The size of this struct. Must be sizeof(FlutterPlatformMessage).
Definition: embedder.h:566
std::string channel
Definition: mock_engine.cc:49

◆ FlutterEngineSendPlatformMessage()

FLUTTER_EXPORT FlutterEngineResult FlutterEngineSendPlatformMessage ( FLUTTER_API_SYMBOL(FlutterEngine engine,
const FlutterPlatformMessage message 
)

Definition at line 218 of file mock_engine.cc.

References FlutterPlatformMessage::channel, engine, error, fl_method_codec_decode_method_call(), fl_method_codec_encode_error_envelope(), fl_method_codec_encode_success_envelope(), fl_standard_method_codec_new(), fl_value_get_length(), fl_value_get_list_value(), fl_value_get_string(), fl_value_get_type(), FL_VALUE_TYPE_STRING, invoke_method(), kInternalInconsistency, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, FlutterPlatformMessage::message, _FlutterPlatformMessageResponseHandle::message, FlutterPlatformMessage::message_size, name, flutter::PlatformMessage::response(), FlutterPlatformMessage::response_handle, SAFE_ACCESS, send_message(), and send_response().

220  {
221  EXPECT_TRUE(engine->running);
222 
223  if (strcmp(message->channel, "test/echo") == 0) {
224  // Responds with the same message received.
225  send_response(engine, message->channel, message->response_handle,
226  message->message, message->message_size);
227  } else if (strcmp(message->channel, "test/send-message") == 0) {
228  // Triggers the engine to send a message.
229  send_response(engine, message->channel, message->response_handle, nullptr,
230  0);
231  send_message(engine, "test/messages", message->message,
232  message->message_size);
233  } else if (strcmp(message->channel, "test/standard-method") == 0) {
234  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
235  g_autoptr(GBytes) m = g_bytes_new(message->message, message->message_size);
236  g_autofree gchar* name = nullptr;
237  g_autoptr(FlValue) args = nullptr;
238  g_autoptr(GError) error = nullptr;
239  EXPECT_TRUE(fl_method_codec_decode_method_call(FL_METHOD_CODEC(codec), m,
240  &name, &args, &error));
241  EXPECT_EQ(error, nullptr);
242 
243  g_autoptr(GBytes) response = nullptr;
244  if (strcmp(name, "Echo") == 0) {
245  // Returns args as a success result.
246  response = fl_method_codec_encode_success_envelope(FL_METHOD_CODEC(codec),
247  args, &error);
248  EXPECT_EQ(error, nullptr);
249  } else if (strcmp(name, "Error") == 0) {
250  // Returns an error result.
251  const gchar* code = nullptr;
252  const gchar* message = nullptr;
253  FlValue* details = nullptr;
254  if (fl_value_get_length(args) >= 2) {
255  FlValue* code_value = fl_value_get_list_value(args, 0);
256  EXPECT_EQ(fl_value_get_type(code_value), FL_VALUE_TYPE_STRING);
257  code = fl_value_get_string(code_value);
258  FlValue* message_value = fl_value_get_list_value(args, 1);
259  message = fl_value_get_type(message_value) == FL_VALUE_TYPE_STRING
260  ? fl_value_get_string(message_value)
261  : nullptr;
262  }
263  if (fl_value_get_length(args) >= 3) {
264  details = fl_value_get_list_value(args, 2);
265  }
267  FL_METHOD_CODEC(codec), code, message, details, &error);
268  EXPECT_EQ(error, nullptr);
269  } else if (strcmp(name, "InvokeMethod") == 0) {
270  // Gets the engine to call the shell.
271  if (fl_value_get_length(args) == 3) {
272  FlValue* channel_value = fl_value_get_list_value(args, 0);
273  EXPECT_EQ(fl_value_get_type(channel_value), FL_VALUE_TYPE_STRING);
274  const gchar* channel = fl_value_get_string(channel_value);
275  FlValue* name_value = fl_value_get_list_value(args, 1);
276  EXPECT_EQ(fl_value_get_type(name_value), FL_VALUE_TYPE_STRING);
277  const gchar* name = fl_value_get_string(name_value);
278  FlValue* method_args = fl_value_get_list_value(args, 2);
279  invoke_method(engine, channel, name, method_args);
280  }
281  response = fl_method_codec_encode_success_envelope(FL_METHOD_CODEC(codec),
282  nullptr, &error);
283  EXPECT_EQ(error, nullptr);
284  } else {
285  // Returns "not implemented".
286  response = g_bytes_new(nullptr, 0);
287  }
288 
290  engine, message->channel, message->response_handle,
291  static_cast<const uint8_t*>(g_bytes_get_data(response, nullptr)),
292  g_bytes_get_size(response));
293  } else if (strcmp(message->channel, "test/nullptr-response") == 0) {
294  // Sends a null response.
295  send_response(engine, message->channel, message->response_handle, nullptr,
296  0);
297  } else if (strcmp(message->channel, "test/standard-event") == 0) {
298  // Send a message so the shell can check the events sent.
299  send_message(engine, "test/events", message->message,
300  message->message_size);
301  } else if (strcmp(message->channel, "test/failure") == 0) {
302  // Generates an internal error.
303  return kInternalInconsistency;
304  }
305 
306  return kSuccess;
307 }
G_BEGIN_DECLS FlValue * args
const char * channel
Definition: embedder.h:567
static void invoke_method(FLUTTER_API_SYMBOL(FlutterEngine) engine, const std::string &channel, const gchar *name, FlValue *args)
Definition: mock_engine.cc:110
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:395
static void send_response(FLUTTER_API_SYMBOL(FlutterEngine) engine, const std::string &channel, const FlutterPlatformMessageResponseHandle *response_handle, const uint8_t *message, size_t message_size)
Definition: mock_engine.cc:81
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
FlMethodResponse GError ** error
const FlutterPlatformMessageResponseHandle * response_handle
Definition: embedder.h:576
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
const uint8_t * message
Definition: embedder.h:568
G_MODULE_EXPORT FlValue * fl_value_get_list_value(FlValue *self, size_t index)
Definition: fl_value.cc:677
const char * name
Definition: fuchsia.cc:50
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:596
GBytes * fl_method_codec_encode_error_envelope(FlMethodCodec *self, const gchar *code, const gchar *message, FlValue *details, GError **error)
static void send_message(FLUTTER_API_SYMBOL(FlutterEngine) engine, const std::string &channel, const uint8_t *message, size_t message_size)
Definition: mock_engine.cc:99
GBytes * fl_method_codec_encode_success_envelope(FlMethodCodec *self, FlValue *result, GError **error)
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
Definition: fl_value.cc:631
gboolean fl_method_codec_decode_method_call(FlMethodCodec *self, GBytes *message, gchar **name, FlValue **args, GError **error)

◆ FlutterEngineSendPlatformMessageResponse()

FlutterEngineResult FlutterEngineSendPlatformMessageResponse ( FLUTTER_API_SYMBOL(FlutterEngine engine,
const FlutterPlatformMessageResponseHandle handle,
const uint8_t *  data,
size_t  data_length 
)

Send a response from the native side to a platform message from the Dart Flutter application.

Parameters
[in]engineThe running engine instance.
[in]handleThe platform message response handle.
[in]dataThe data to associate with the platform message response.
[in]data_lengthThe length of the platform message response data.
Returns
The result of the call.

Definition at line 339 of file mock_engine.cc.

References _FlutterPlatformMessageResponseHandle::channel, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, _FlutterPlatformMessageResponseHandle::message, _FlutterPlatformMessageResponseHandle::released, flutter::PlatformMessage::response(), and send_message().

343  {
344  EXPECT_NE(engine, nullptr);
345  EXPECT_NE(handle, nullptr);
346 
347  EXPECT_TRUE(engine->running);
348 
349  // Send a message so the shell can check the responses received.
350  if (handle->channel != "test/responses") {
351  send_message(engine, "test/responses", data, data_length);
352  }
353 
354  EXPECT_FALSE(handle->released);
355 
356  delete handle;
357 
358  return kSuccess;
359 }
static void send_message(FLUTTER_API_SYMBOL(FlutterEngine) engine, const std::string &channel, const uint8_t *message, size_t message_size)
Definition: mock_engine.cc:99

◆ FlutterEngineSendPointerEvent()

◆ FlutterEngineSendWindowMetricsEvent()

◆ FlutterEngineShutdown()

FlutterEngineResult FlutterEngineShutdown ( FLUTTER_API_SYMBOL(FlutterEngine engine)

Shuts down a Flutter engine instance. The engine handle is no longer valid for any calls in the embedder API after this point. Making additional calls with this handle is undefined behavior.

Note
This de-initializes the Flutter engine instance (via an implicit call to FlutterEngineDeinitialize) if necessary.
Parameters
[in]engineThe Flutter engine instance to collect.
Returns
The result of the call to shutdown the Flutter engine instance.

Definition at line 160 of file mock_engine.cc.

References engine, FlutterEngineDeinitialize(), and kSuccess.

161  {
162  delete engine;
163  return kSuccess;
164 }

◆ FlutterEngineUpdateLocales()

FlutterEngineResult FlutterEngineUpdateLocales ( FLUTTER_API_SYMBOL(FlutterEngine engine,
const FlutterLocale **  locales,
size_t  locales_count 
)

Notify a running engine instance that the locale has been updated. The preferred locale must be the first item in the list of locales supplied. The other entries will be used as a fallback.

Parameters
[in]engineA running engine instance.
[in]localesThe updated locales in the order of preference.
[in]locales_countThe count of locales supplied.
Returns
Whether the locale updates were applied.

Definition at line 398 of file mock_engine.cc.

References args, DispatchJSONPlatformMessage(), kInternalInconsistency, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, and SAFE_ACCESS.

401  {
402  return kSuccess;
403 }

◆ FlutterPlatformMessageCreateResponseHandle()

FlutterEngineResult FlutterPlatformMessageCreateResponseHandle ( FLUTTER_API_SYMBOL(FlutterEngine engine,
FlutterDataCallback  data_callback,
void *  user_data,
FlutterPlatformMessageResponseHandle **  response_out 
)

Creates a platform message response handle that allows the embedder to set a native callback for a response to a message. This handle may be set on the response_handle field of any FlutterPlatformMessage sent to the engine.

The handle must be collected via a call to FlutterPlatformMessageReleaseResponseHandle. This may be done immediately after a call to FlutterEngineSendPlatformMessage with a platform message whose response handle contains the handle created using this call. In case a handle is created but never sent in a message, the release call must still be made. Not calling release on the handle results in a small memory leak.

The user data baton passed to the data callback is the one specified in this call as the third argument.

See also
FlutterPlatformMessageReleaseResponseHandle()
Parameters
[in]engineA running engine instance.
[in]data_callbackThe callback invoked by the engine when the Flutter application send a response on the handle.
[in]user_dataThe user data associated with the data callback.
[out]response_outThe response handle created when this call is successful.
Returns
The result of the call.

Definition at line 309 of file mock_engine.cc.

References engine, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, fml::size(), and user_data.

313  {
314  EXPECT_TRUE(engine->running);
315  EXPECT_NE(data_callback, nullptr);
316  EXPECT_NE(user_data, nullptr);
317 
320 
321  *response_out = handle;
322  return kSuccess;
323 }
G_BEGIN_DECLS FlValue gpointer user_data

◆ FlutterPlatformMessageReleaseResponseHandle()

FlutterEngineResult FlutterPlatformMessageReleaseResponseHandle ( FLUTTER_API_SYMBOL(FlutterEngine engine,
FlutterPlatformMessageResponseHandle response 
)

Collects the handle created using FlutterPlatformMessageCreateResponseHandle.

See also
FlutterPlatformMessageCreateResponseHandle()
Parameters
[in]engineA running engine instance.
[in]responseThe platform message response handle to collect. These handles are created using FlutterPlatformMessageCreateResponseHandle().
Returns
The result of the call.

Definition at line 325 of file mock_engine.cc.

References kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, and _FlutterPlatformMessageResponseHandle::released.

327  {
328  EXPECT_NE(engine, nullptr);
329  EXPECT_NE(response, nullptr);
330 
331  EXPECT_TRUE(engine->running);
332 
333  EXPECT_FALSE(response->released);
334  response->released = true;
335 
336  return kSuccess;
337 }

◆ invoke_method()

static void invoke_method ( FLUTTER_API_SYMBOL(FlutterEngine engine,
const std::string &  channel,
const gchar *  name,
FlValue args 
)
static

Definition at line 110 of file mock_engine.cc.

References error, fl_method_codec_encode_method_call(), fl_standard_method_codec_new(), FlutterTask::runner, _FlutterTaskRunner::task, and FlutterTask::task.

Referenced by FlutterEngineSendPlatformMessage().

113  {
114  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
115  g_autoptr(GError) error = nullptr;
116  g_autoptr(GBytes) message = fl_method_codec_encode_method_call(
117  FL_METHOD_CODEC(codec), name, args, &error);
118  EXPECT_NE(message, nullptr);
119  EXPECT_EQ(error, nullptr);
120 
121  FlutterTask task;
122  task.runner = new _FlutterTaskRunner(
123  1234, channel, nullptr,
124  static_cast<const uint8_t*>(g_bytes_get_data(message, nullptr)),
125  g_bytes_get_size(message));
126  task.task = task.runner->task;
127  engine->platform_post_task_callback(task, 0, engine->user_data);
128 }
G_BEGIN_DECLS FlValue * args
GBytes * fl_method_codec_encode_method_call(FlMethodCodec *self, const gchar *name, FlValue *args, GError **error)
FlMethodResponse GError ** error
FlutterTaskRunner runner
Definition: embedder.h:707
uint64_t task
Definition: embedder.h:708
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
const char * name
Definition: fuchsia.cc:50

◆ send_message()

static void send_message ( FLUTTER_API_SYMBOL(FlutterEngine engine,
const std::string &  channel,
const uint8_t *  message,
size_t  message_size 
)
static

Definition at line 99 of file mock_engine.cc.

References FlutterTask::runner, _FlutterTaskRunner::task, and FlutterTask::task.

Referenced by FlutterEngineSendPlatformMessage(), and FlutterEngineSendPlatformMessageResponse().

102  {
103  FlutterTask task;
104  task.runner =
105  new _FlutterTaskRunner(1234, channel, nullptr, message, message_size);
106  task.task = task.runner->task;
107  engine->platform_post_task_callback(task, 0, engine->user_data);
108 }
FlutterTaskRunner runner
Definition: embedder.h:707
uint64_t task
Definition: embedder.h:708

◆ send_response()

static void send_response ( FLUTTER_API_SYMBOL(FlutterEngine engine,
const std::string &  channel,
const FlutterPlatformMessageResponseHandle response_handle,
const uint8_t *  message,
size_t  message_size 
)
static

Definition at line 81 of file mock_engine.cc.

References FlutterTask::runner, _FlutterTaskRunner::task, and FlutterTask::task.

Referenced by FlutterEngineSendPlatformMessage().

86  {
87  if (response_handle == nullptr) {
88  return;
89  }
90 
91  FlutterTask task;
92  task.runner = new _FlutterTaskRunner(1234, channel, response_handle, message,
93  message_size);
94  task.task = task.runner->task;
95  engine->platform_post_task_callback(task, 0, engine->user_data);
96 }
FlutterTaskRunner runner
Definition: embedder.h:707
uint64_t task
Definition: embedder.h:708