Skip to content

Commit

Permalink
Use proc table for embedder APIs (flutter-tizen#97)
Browse files Browse the repository at this point in the history
* Use proc table for embedder APIs

* Use the proc table like other platform implementations
* Use FlutterEngine as private memeber of FlutterTizenEngine
* Only FlutterTizenEngine is dependent on FlutterEngine

Signed-off-by: Boram Bae <boram21.bae@samsung.com>

* Update based on review

Signed-off-by: Boram Bae <boram21.bae@samsung.com>
  • Loading branch information
bbrto21 authored and swift-kim committed Jun 7, 2021
1 parent 35d809a commit 05123d4
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 106 deletions.
16 changes: 6 additions & 10 deletions shell/platform/tizen/channels/lifecycle_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "lifecycle_channel.h"

#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
#include "flutter/shell/platform/tizen/tizen_log.h"

static constexpr char kChannelName[] = "flutter/lifecycle";
Expand All @@ -12,20 +13,15 @@ static constexpr char kResumed[] = "AppLifecycleState.resumed";
static constexpr char kPaused[] = "AppLifecycleState.paused";
static constexpr char kDetached[] = "AppLifecycleState.detached";

LifecycleChannel::LifecycleChannel(FLUTTER_API_SYMBOL(FlutterEngine)
flutter_engine)
: flutter_engine_(flutter_engine) {}
LifecycleChannel::LifecycleChannel(FlutterTizenEngine* engine)
: engine_(engine) {}

LifecycleChannel::~LifecycleChannel() {}

void LifecycleChannel::SendLifecycleMessage(const char message[]) {
FlutterPlatformMessage platformMessage = {};
platformMessage.struct_size = sizeof(FlutterPlatformMessage);
platformMessage.channel = kChannelName;
platformMessage.message = reinterpret_cast<const uint8_t*>(message);
platformMessage.message_size = strlen(message);
platformMessage.response_handle = nullptr;
FlutterEngineSendPlatformMessage(flutter_engine_, &platformMessage);
engine_->SendPlatformMessage(kChannelName,
reinterpret_cast<const uint8_t*>(message),
strlen(message), nullptr, nullptr);
}

void LifecycleChannel::AppIsInactive() {
Expand Down
6 changes: 3 additions & 3 deletions shell/platform/tizen/channels/lifecycle_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#ifndef EMBEDDER_LIFECYCLE_CHANNEL_H_
#define EMBEDDER_LIFECYCLE_CHANNEL_H_

#include "flutter/shell/platform/embedder/embedder.h"
class FlutterTizenEngine;

class LifecycleChannel {
public:
explicit LifecycleChannel(FLUTTER_API_SYMBOL(FlutterEngine) flutter_engine);
explicit LifecycleChannel(FlutterTizenEngine* engine);
virtual ~LifecycleChannel();

void AppIsInactive();
Expand All @@ -19,7 +19,7 @@ class LifecycleChannel {
void SendLifecycleMessage(const char message[]);

private:
FLUTTER_API_SYMBOL(FlutterEngine) flutter_engine_;
FlutterTizenEngine* engine_{nullptr};
};

#endif // EMBEDDER_LIFECYCLE_CHANNEL_H_
22 changes: 8 additions & 14 deletions shell/platform/tizen/channels/localization_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
#include "localization_channel.h"

#include <utils_i18n.h>

#include <vector>

#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
#include "flutter/shell/platform/tizen/tizen_log.h"
#include "rapidjson/document.h"
#include "rapidjson/writer.h"

static constexpr char kChannelName[] = "flutter/localization";

LocalizationChannel::LocalizationChannel(FLUTTER_API_SYMBOL(FlutterEngine)
flutter_engine)
: flutter_engine_(flutter_engine) {}
LocalizationChannel::LocalizationChannel(FlutterTizenEngine* engine)
: engine_(engine) {}

LocalizationChannel::~LocalizationChannel() {}

Expand Down Expand Up @@ -54,9 +53,8 @@ void LocalizationChannel::SendLocales() {
}

FT_LOGD("Send %zu available locales", flutter_locales.size());
// send locales to engine
FlutterEngineUpdateLocales(
flutter_engine_,
// Send locales to engine
engine_->UpdateLocales(
const_cast<const FlutterLocale**>(flutter_locales.data()),
flutter_locales.size());

Expand Down Expand Up @@ -111,13 +109,9 @@ void LocalizationChannel::SendPlatformResolvedLocale() {
return;
}

FlutterPlatformMessage message = {};
message.struct_size = sizeof(FlutterPlatformMessage);
message.channel = kChannelName;
message.message = reinterpret_cast<const uint8_t*>(buffer.GetString());
message.message_size = buffer.GetSize();
message.response_handle = nullptr;
FlutterEngineSendPlatformMessage(flutter_engine_, &message);
engine_->SendPlatformMessage(
kChannelName, reinterpret_cast<const uint8_t*>(buffer.GetString()),
buffer.GetSize(), nullptr, nullptr);

DestroyFlutterLocale(flutter_locale);
}
Expand Down
7 changes: 4 additions & 3 deletions shell/platform/tizen/channels/localization_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

#include "flutter/shell/platform/embedder/embedder.h"

class FlutterTizenEngine;

class LocalizationChannel {
public:
explicit LocalizationChannel(FLUTTER_API_SYMBOL(FlutterEngine)
flutter_engine);
explicit LocalizationChannel(FlutterTizenEngine* engine);
virtual ~LocalizationChannel();

void SendLocales();
Expand All @@ -20,7 +21,7 @@ class LocalizationChannel {
FlutterLocale* GetFlutterLocale(const char* locale);
void DestroyFlutterLocale(FlutterLocale* flutter_locale);

FLUTTER_API_SYMBOL(FlutterEngine) flutter_engine_;
FlutterTizenEngine* engine_;
};

#endif // EMBEDDER_LOCALIZATION_CHANNEL_H_
31 changes: 4 additions & 27 deletions shell/platform/tizen/flutter_tizen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,38 +88,16 @@ bool FlutterDesktopMessengerSendWithReply(FlutterDesktopMessengerRef messenger,
const size_t message_size,
const FlutterDesktopBinaryReply reply,
void* user_data) {
FlutterPlatformMessageResponseHandle* response_handle = nullptr;
if (reply != nullptr && user_data != nullptr) {
FlutterEngineResult result = FlutterPlatformMessageCreateResponseHandle(
messenger->engine->flutter_engine, reply, user_data, &response_handle);
if (result != kSuccess) {
FT_LOGE("Failed to create response handle");
return false;
}
}
FlutterPlatformMessage platform_message = {
sizeof(FlutterPlatformMessage),
channel,
message,
message_size,
response_handle,
};
FlutterEngineResult message_result = FlutterEngineSendPlatformMessage(
messenger->engine->flutter_engine, &platform_message);
if (response_handle != nullptr) {
FlutterPlatformMessageReleaseResponseHandle(
messenger->engine->flutter_engine, response_handle);
}
return message_result == kSuccess;
return messenger->engine->SendPlatformMessage(channel, message, message_size,
reply, user_data);
}

void FlutterDesktopMessengerSendResponse(
FlutterDesktopMessengerRef messenger,
const FlutterDesktopMessageResponseHandle* handle,
const uint8_t* data,
size_t data_length) {
FlutterEngineSendPlatformMessageResponse(messenger->engine->flutter_engine,
handle, data, data_length);
messenger->engine->SendPlatformMessageResponse(handle, data, data_length);
}

void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger,
Expand Down Expand Up @@ -151,8 +129,7 @@ void FlutterDesktopNotifyAppIsDetached(FlutterDesktopEngineRef engine) {
}

void FlutterDesktopNotifyLowMemoryWarning(FlutterDesktopEngineRef engine) {
auto flutter_engine = EngineFromHandle(engine)->flutter_engine;
FlutterEngineNotifyLowMemoryWarning(flutter_engine);
EngineFromHandle(engine)->NotifyLowMemoryWarning();
}

void FlutterRegisterViewFactory(
Expand Down
Loading

0 comments on commit 05123d4

Please sign in to comment.