Skip to content

Commit

Permalink
Implement the forwarding logger (#203)
Browse files Browse the repository at this point in the history
* Initial implementation

* Clean up

* Clean up again

* Change switches to engine_arguments

* Do not log debug messages

* Fix x64 build
  • Loading branch information
swift-kim authored Nov 11, 2021
1 parent 11625dd commit 1aba96b
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 79 deletions.
26 changes: 22 additions & 4 deletions shell/platform/tizen/flutter_project_bundle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,34 @@ FlutterProjectBundle::FlutterProjectBundle(
}
}

switches_.insert(switches_.end(), properties.switches,
properties.switches + properties.switches_count);
engine_arguments_.insert(engine_arguments_.end(), properties.switches,
properties.switches + properties.switches_count);
}

bool FlutterProjectBundle::HasValidPaths() {
return !assets_path_.empty() && !icu_path_.empty();
}

// Attempts to load AOT data from the given path, which must be absolute and
// non-empty. Logs and returns nullptr on failure.
bool FlutterProjectBundle::HasArgument(const std::string& name) {
return std::find(engine_arguments_.begin(), engine_arguments_.end(), name) !=
engine_arguments_.end();
}

bool FlutterProjectBundle::GetArgumentValue(const std::string& name,
std::string* value) {
auto iter =
std::find(engine_arguments_.begin(), engine_arguments_.end(), name);
if (iter == engine_arguments_.end()) {
return false;
}
auto next = std::next(iter);
if (next == engine_arguments_.end()) {
return false;
}
*value = *next;
return true;
}

UniqueAotDataPtr FlutterProjectBundle::LoadAotData(
const FlutterEngineProcTable& engine_procs) {
if (aot_library_path_.empty()) {
Expand Down
14 changes: 11 additions & 3 deletions shell/platform/tizen/flutter_project_bundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@ class FlutterProjectBundle {
// Returns the path to the ICU data file.
const std::filesystem::path& icu_path() { return icu_path_; }

// Returns any switches that should be passed to the engine.
const std::vector<std::string> switches() { return switches_; }
// Returns the arguments to be passed to the engine.
const std::vector<std::string> engine_arguments() {
return engine_arguments_;
}

// Returns true if |engine_arguments| contains the argument |name|.
bool HasArgument(const std::string& name);

// Gets the value of the argument |name| from |engine_arguments|.
bool GetArgumentValue(const std::string& name, std::string* value);

// Attempts to load AOT data for this bundle. The returned data must be
// retained until any engine instance it is passed to has been shut down.
Expand All @@ -57,7 +65,7 @@ class FlutterProjectBundle {
private:
std::filesystem::path assets_path_;
std::filesystem::path icu_path_;
std::vector<std::string> switches_ = {};
std::vector<std::string> engine_arguments_ = {};

// Path to the AOT library file, if any.
std::filesystem::path aot_library_path_;
Expand Down
12 changes: 6 additions & 6 deletions shell/platform/tizen/flutter_project_bundle_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ TEST(FlutterProjectBundle, BasicPropertiesRelativePaths) {
EXPECT_EQ(project.icu_path().filename().string(), "icudtl.dat");
}

TEST(FlutterProjectBundle, SwitchesEmpty) {
TEST(FlutterProjectBundle, EmptyEngineArguments) {
FlutterDesktopEngineProperties properties = {};
properties.assets_path = "foo/flutter_assets";
properties.icu_data_path = "foo/icudtl.dat";
Expand All @@ -45,10 +45,10 @@ TEST(FlutterProjectBundle, SwitchesEmpty) {

FlutterProjectBundle project(properties);

EXPECT_EQ(project.switches().size(), 0u);
EXPECT_EQ(project.engine_arguments().size(), 0u);
}

TEST(FlutterProjectBundle, Switches) {
TEST(FlutterProjectBundle, HasEngineArguments) {
FlutterDesktopEngineProperties properties = {};
properties.assets_path = "foo/flutter_assets";
properties.icu_data_path = "foo/icudtl.dat";
Expand All @@ -62,9 +62,9 @@ TEST(FlutterProjectBundle, Switches) {

FlutterProjectBundle project(properties);

EXPECT_EQ(project.switches().size(), 2u);
EXPECT_EQ(project.switches()[0], "--abc");
EXPECT_EQ(project.switches()[1], "--foo=\"bar, baz\"");
EXPECT_EQ(project.engine_arguments().size(), 2u);
EXPECT_EQ(project.engine_arguments()[0], "--abc");
EXPECT_EQ(project.engine_arguments()[1], "--foo=\"bar, baz\"");
}

} // namespace testing
Expand Down
46 changes: 29 additions & 17 deletions shell/platform/tizen/flutter_tizen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,47 @@
#include "flutter/shell/platform/tizen/logger.h"
#include "flutter/shell/platform/tizen/public/flutter_platform_view.h"

namespace {

// Returns the engine corresponding to the given opaque API handle.
static flutter::FlutterTizenEngine* EngineFromHandle(
FlutterDesktopEngineRef ref) {
flutter::FlutterTizenEngine* EngineFromHandle(FlutterDesktopEngineRef ref) {
return reinterpret_cast<flutter::FlutterTizenEngine*>(ref);
}

// Returns the opaque API handle for the given engine instance.
static FlutterDesktopEngineRef HandleForEngine(
flutter::FlutterTizenEngine* engine) {
FlutterDesktopEngineRef HandleForEngine(flutter::FlutterTizenEngine* engine) {
return reinterpret_cast<FlutterDesktopEngineRef>(engine);
}

// Returns the texture registrar corresponding to the given opaque API handle.
flutter::FlutterTizenTextureRegistrar* TextureRegistrarFromHandle(
FlutterDesktopTextureRegistrarRef ref) {
return reinterpret_cast<flutter::FlutterTizenTextureRegistrar*>(ref);
}

// Returns the opaque API handle for the given texture registrar instance.
FlutterDesktopTextureRegistrarRef HandleForTextureRegistrar(
flutter::FlutterTizenTextureRegistrar* registrar) {
return reinterpret_cast<FlutterDesktopTextureRegistrarRef>(registrar);
}

} // namespace

FlutterDesktopEngineRef FlutterDesktopRunEngine(
const FlutterDesktopWindowProperties& window_properties,
const FlutterDesktopEngineProperties& engine_properties) {
flutter::FlutterProjectBundle project(engine_properties);
if (project.HasArgument("--verbose-logging")) {
flutter::Logger::SetLoggingLevel(flutter::kLogLevelDebug);
}
#ifndef __X64_SHELL__
std::string logging_port;
if (project.GetArgumentValue("--tizen-logging-port", &logging_port)) {
flutter::Logger::SetLoggingPort(std::stoi(logging_port));
}
flutter::Logger::Start();
#endif

flutter::FlutterProjectBundle project(engine_properties);
auto engine = std::make_unique<flutter::FlutterTizenEngine>(project);
if (window_properties.headed) {
engine->InitializeRenderer(
Expand All @@ -48,6 +69,9 @@ FlutterDesktopEngineRef FlutterDesktopRunEngine(
}

void FlutterDesktopShutdownEngine(FlutterDesktopEngineRef engine_ref) {
#ifndef __X64_SHELL__
flutter::Logger::Stop();
#endif
auto engine = EngineFromHandle(engine_ref);
engine->StopEngine();
delete engine;
Expand Down Expand Up @@ -161,18 +185,6 @@ void FlutterRegisterViewFactory(
view_type, std::move(view_factory)));
}

// Returns the texture registrar corresponding to the given opaque API handle.
static flutter::FlutterTizenTextureRegistrar* TextureRegistrarFromHandle(
FlutterDesktopTextureRegistrarRef ref) {
return reinterpret_cast<flutter::FlutterTizenTextureRegistrar*>(ref);
}

// Returns the opaque API handle for the given texture registrar instance.
static FlutterDesktopTextureRegistrarRef HandleForTextureRegistrar(
flutter::FlutterTizenTextureRegistrar* registrar) {
return reinterpret_cast<FlutterDesktopTextureRegistrarRef>(registrar);
}

FlutterDesktopTextureRegistrarRef FlutterDesktopRegistrarGetTextureRegistrar(
FlutterDesktopPluginRegistrarRef registrar) {
return HandleForTextureRegistrar(registrar->engine->texture_registrar());
Expand Down
16 changes: 6 additions & 10 deletions shell/platform/tizen/flutter_tizen_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,12 @@ bool FlutterTizenEngine::RunEngine(const char* entrypoint) {
// FlutterProjectArgs is expecting a full argv, so when processing it for
// flags the first item is treated as the executable and ignored. Add a dummy
// value so that all provided arguments are used.
std::vector<std::string> switches = project_->switches();
std::vector<const char*> argv = {"placeholder"};
std::vector<std::string> engine_args = project_->engine_arguments();
std::vector<const char*> engine_argv = {"placeholder"};
std::transform(
switches.begin(), switches.end(), std::back_inserter(argv),
engine_args.begin(), engine_args.end(), std::back_inserter(engine_argv),
[](const std::string& arg) -> const char* { return arg.c_str(); });

if (std::find(switches.begin(), switches.end(), "--verbose-logging") !=
switches.end()) {
Logger::SetLoggingLevel(kLogLevelDebug);
}

const std::vector<std::string>& entrypoint_args =
project_->dart_entrypoint_arguments();
std::vector<const char*> entrypoint_argv;
Expand Down Expand Up @@ -200,8 +195,9 @@ bool FlutterTizenEngine::RunEngine(const char* entrypoint) {
args.struct_size = sizeof(FlutterProjectArgs);
args.assets_path = assets_path_string.c_str();
args.icu_data_path = icu_path_string.c_str();
args.command_line_argc = static_cast<int>(argv.size());
args.command_line_argv = argv.size() > 0 ? argv.data() : nullptr;
args.command_line_argc = static_cast<int>(engine_argv.size());
args.command_line_argv =
engine_argv.size() > 0 ? engine_argv.data() : nullptr;
args.dart_entrypoint_argc = static_cast<int>(entrypoint_argv.size());
args.dart_entrypoint_argv =
entrypoint_argv.size() > 0 ? entrypoint_argv.data() : nullptr;
Expand Down
Loading

0 comments on commit 1aba96b

Please sign in to comment.