Flutter Engine
flutter::FlutterEngine Class Reference

#include <flutter_engine.h>

Inheritance diagram for flutter::FlutterEngine:
flutter::PluginRegistry flutter::PluginRegistry

Public Member Functions

 FlutterEngine ()
 
virtual ~FlutterEngine ()
 
 FlutterEngine (FlutterEngine const &)=delete
 
FlutterEngineoperator= (FlutterEngine const &)=delete
 
bool Start (const std::string &icu_data_path, const std::string &assets_path, const std::vector< std::string > &arguments, const std::string &aot_library_path="")
 
void ShutDown ()
 
void RunEventLoopWithTimeout (std::chrono::milliseconds timeout=std::chrono::milliseconds::max())
 
FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin (const std::string &plugin_name) override
 
 FlutterEngine (const DartProject &project)
 
virtual ~FlutterEngine ()
 
 FlutterEngine (FlutterEngine const &)=delete
 
FlutterEngineoperator= (FlutterEngine const &)=delete
 
bool Run (const char *entry_point=nullptr)
 
void ShutDown ()
 
std::chrono::nanoseconds ProcessMessages ()
 
void ReloadSystemFonts ()
 
FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin (const std::string &plugin_name) override
 
BinaryMessengermessenger ()
 
- Public Member Functions inherited from flutter::PluginRegistry
 PluginRegistry ()=default
 
virtual ~PluginRegistry ()=default
 
 PluginRegistry (PluginRegistry const &)=delete
 
PluginRegistryoperator= (PluginRegistry const &)=delete
 

Friends

class FlutterViewController
 

Detailed Description

Definition at line 21 of file flutter_engine.h.

Constructor & Destructor Documentation

◆ FlutterEngine() [1/4]

FlutterEngine::FlutterEngine ( )
explicit

Definition at line 12 of file flutter_engine.cc.

12 {}

◆ ~FlutterEngine() [1/2]

FlutterEngine::~FlutterEngine ( )
virtual

Definition at line 14 of file flutter_engine.cc.

Referenced by FlutterEngine().

14 {}

◆ FlutterEngine() [2/4]

flutter::FlutterEngine::FlutterEngine ( FlutterEngine const &  )
delete

◆ FlutterEngine() [3/4]

FlutterEngine::FlutterEngine ( const DartProject project)
explicit

Definition at line 14 of file flutter_engine.cc.

References FlutterDesktopEngineProperties::aot_library_path, FlutterDesktopEngineProperties::assets_path, FlutterDesktopEngineCreate(), FlutterDesktopEngineGetMessenger(), FlutterDesktopEngineProperties::icu_data_path, ShutDown(), and ~FlutterEngine().

14  {
15  FlutterDesktopEngineProperties c_engine_properties = {};
16  c_engine_properties.assets_path = project.assets_path().c_str();
17  c_engine_properties.icu_data_path = project.icu_data_path().c_str();
18  c_engine_properties.aot_library_path = project.aot_library_path().c_str();
19 
20  engine_ = FlutterDesktopEngineCreate(c_engine_properties);
21 
22  auto core_messenger = FlutterDesktopEngineGetMessenger(engine_);
23  messenger_ = std::make_unique<BinaryMessengerImpl>(core_messenger);
24 }
FlutterDesktopMessengerRef FlutterDesktopEngineGetMessenger(FlutterDesktopEngineRef engine)
FlutterDesktopEngineRef FlutterDesktopEngineCreate(const FlutterDesktopEngineProperties &engine_properties)

◆ ~FlutterEngine() [2/2]

virtual flutter::FlutterEngine::~FlutterEngine ( )
virtual

◆ FlutterEngine() [4/4]

flutter::FlutterEngine::FlutterEngine ( FlutterEngine const &  )
delete

Member Function Documentation

◆ GetRegistrarForPlugin() [1/2]

FlutterDesktopPluginRegistrarRef FlutterEngine::GetRegistrarForPlugin ( const std::string &  plugin_name)
overridevirtual

Implements flutter::PluginRegistry.

Definition at line 53 of file flutter_engine.cc.

References FlutterDesktopGetPluginRegistrar().

Referenced by ReloadSystemFonts().

54  {
55  if (!engine_) {
56  std::cerr << "Cannot get plugin registrar on an engine that isn't running; "
57  "call Run first."
58  << std::endl;
59  return nullptr;
60  }
61  return FlutterDesktopGetPluginRegistrar(engine_.get(), plugin_name.c_str());
62 }
FlutterDesktopPluginRegistrarRef FlutterDesktopGetPluginRegistrar(FlutterDesktopEngineRef engine, const char *plugin_name)

◆ GetRegistrarForPlugin() [2/2]

FlutterDesktopPluginRegistrarRef flutter::FlutterEngine::GetRegistrarForPlugin ( const std::string &  plugin_name)
overridevirtual

◆ messenger()

BinaryMessenger* flutter::FlutterEngine::messenger ( )
inline

Definition at line 69 of file flutter_engine.h.

Referenced by flutter::TEST().

69 { return messenger_.get(); }

◆ operator=() [1/2]

FlutterEngine& flutter::FlutterEngine::operator= ( FlutterEngine const &  )
delete

◆ operator=() [2/2]

FlutterEngine& flutter::FlutterEngine::operator= ( FlutterEngine const &  )
delete

◆ ProcessMessages()

std::chrono::nanoseconds FlutterEngine::ProcessMessages ( )

Definition at line 54 of file flutter_engine.cc.

References FlutterDesktopEngineProcessMessages().

Referenced by flutter::TEST().

54  {
55  return std::chrono::nanoseconds(FlutterDesktopEngineProcessMessages(engine_));
56 }
uint64_t FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine)

◆ ReloadSystemFonts()

void FlutterEngine::ReloadSystemFonts ( )

Definition at line 58 of file flutter_engine.cc.

References FlutterDesktopEngineGetPluginRegistrar(), FlutterDesktopEngineReloadSystemFonts(), and GetRegistrarForPlugin().

Referenced by flutter::TEST().

58  {
60 }
void FlutterDesktopEngineReloadSystemFonts(FlutterDesktopEngineRef engine)

◆ Run()

bool FlutterEngine::Run ( const char *  entry_point = nullptr)

Definition at line 30 of file flutter_engine.cc.

References FlutterDesktopEngineDestroy(), FlutterDesktopEngineRun(), and ShutDown().

Referenced by flutter::TEST().

30  {
31  if (!engine_) {
32  std::cerr << "Cannot run an engine that failed creation." << std::endl;
33  return false;
34  }
35  if (has_been_run_) {
36  std::cerr << "Cannot run an engine more than once." << std::endl;
37  return false;
38  }
39  bool run_succeeded = FlutterDesktopEngineRun(engine_, entry_point);
40  if (!run_succeeded) {
41  std::cerr << "Failed to start engine." << std::endl;
42  }
43  has_been_run_ = true;
44  return run_succeeded;
45 }
bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine, const char *entry_point)

◆ RunEventLoopWithTimeout()

void FlutterEngine::RunEventLoopWithTimeout ( std::chrono::milliseconds  timeout = std::chrono::milliseconds::max())

Definition at line 64 of file flutter_engine.cc.

References FlutterDesktopRunEngineEventLoopWithTimeout().

Referenced by flutter::TEST().

64  {
65  if (!engine_) {
66  std::cerr << "Cannot run event loop without a running engine; call "
67  "Run first."
68  << std::endl;
69  return;
70  }
71  uint32_t timeout_milliseconds;
72  if (timeout == std::chrono::milliseconds::max()) {
73  // The C API uses 0 to represent no timeout, so convert |max| to 0.
74  timeout_milliseconds = 0;
75  } else if (timeout.count() > UINT32_MAX) {
76  timeout_milliseconds = UINT32_MAX;
77  } else {
78  timeout_milliseconds = static_cast<uint32_t>(timeout.count());
79  }
81  timeout_milliseconds);
82 }
void FlutterDesktopRunEngineEventLoopWithTimeout(FlutterDesktopEngineRef engine, uint32_t timeout_milliseconds)

◆ ShutDown() [1/2]

void FlutterEngine::ShutDown ( )

Definition at line 49 of file flutter_engine.cc.

Referenced by FlutterEngine(), Run(), and flutter::TEST().

49  {
50  engine_ = nullptr;
51 }

◆ ShutDown() [2/2]

void flutter::FlutterEngine::ShutDown ( )

◆ Start()

bool FlutterEngine::Start ( const std::string &  icu_data_path,
const std::string &  assets_path,
const std::vector< std::string > &  arguments,
const std::string &  aot_library_path = "" 
)

Definition at line 16 of file flutter_engine.cc.

References FlutterDesktopEngineProperties::aot_library_path, FlutterDesktopEngineProperties::assets_path, FlutterDesktopRunEngine(), FlutterDesktopShutDownEngine(), FlutterDesktopEngineProperties::icu_data_path, FlutterDesktopEngineProperties::switches, FlutterDesktopEngineProperties::switches_count, and flutter::transform.

Referenced by flutter::TEST().

19  {
20  if (engine_) {
21  std::cerr << "Cannot run an already running engine. Create a new instance "
22  "or call ShutDown first."
23  << std::endl;
24  return false;
25  }
26 
27  FlutterDesktopEngineProperties c_engine_properties = {};
28  c_engine_properties.assets_path = assets_path.c_str();
29  c_engine_properties.icu_data_path = icu_data_path.c_str();
30  c_engine_properties.aot_library_path = aot_library_path.c_str();
31  std::vector<const char*> engine_switches;
33  arguments.begin(), arguments.end(), std::back_inserter(engine_switches),
34  [](const std::string& arg) -> const char* { return arg.c_str(); });
35  if (engine_switches.size() > 0) {
36  c_engine_properties.switches = &engine_switches[0];
37  c_engine_properties.switches_count = engine_switches.size();
38  }
39 
40  engine_ = UniqueEnginePtr(FlutterDesktopRunEngine(c_engine_properties),
42  if (!engine_) {
43  std::cerr << "Failed to start engine." << std::endl;
44  return false;
45  }
46  return true;
47 }
bool FlutterDesktopShutDownEngine(FlutterDesktopEngineRef engine_ref)
FlutterDesktopEngineRef FlutterDesktopRunEngine(const FlutterDesktopEngineProperties &properties)

Friends And Related Function Documentation

◆ FlutterViewController

friend class FlutterViewController
friend

Definition at line 73 of file flutter_engine.h.


The documentation for this class was generated from the following files: