diff --git a/shell/platform/tizen/channels/key_event_channel.cc b/shell/platform/tizen/channels/key_event_channel.cc index ae91615b65ff4..102052589a0ed 100644 --- a/shell/platform/tizen/channels/key_event_channel.cc +++ b/shell/platform/tizen/channels/key_event_channel.cc @@ -6,6 +6,7 @@ #include +#include "flutter/shell/platform/common/json_message_codec.h" #include "flutter/shell/platform/tizen/tizen_log.h" namespace flutter { diff --git a/shell/platform/tizen/channels/key_event_channel.h b/shell/platform/tizen/channels/key_event_channel.h index 8429f1826ad1f..234dd108ab6a6 100644 --- a/shell/platform/tizen/channels/key_event_channel.h +++ b/shell/platform/tizen/channels/key_event_channel.h @@ -11,7 +11,6 @@ #include "flutter/shell/platform/common/client_wrapper/include/flutter/basic_message_channel.h" #include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h" -#include "flutter/shell/platform/common/json_message_codec.h" #include "rapidjson/document.h" namespace flutter { diff --git a/shell/platform/tizen/channels/lifecycle_channel.cc b/shell/platform/tizen/channels/lifecycle_channel.cc index f3419be6362cd..95aca8582746d 100644 --- a/shell/platform/tizen/channels/lifecycle_channel.cc +++ b/shell/platform/tizen/channels/lifecycle_channel.cc @@ -4,7 +4,7 @@ #include "lifecycle_channel.h" -#include "flutter/shell/platform/tizen/flutter_tizen_engine.h" +#include "flutter/shell/platform/tizen/channels/string_codec.h" #include "flutter/shell/platform/tizen/tizen_log.h" namespace flutter { @@ -20,35 +20,32 @@ constexpr char kDetached[] = "AppLifecycleState.detached"; } // namespace -LifecycleChannel::LifecycleChannel(FlutterTizenEngine* engine) - : engine_(engine) {} +LifecycleChannel::LifecycleChannel(BinaryMessenger* messenger) + : channel_(std::make_unique>( + messenger, + kChannelName, + &StringCodec::GetInstance())) {} LifecycleChannel::~LifecycleChannel() {} -void LifecycleChannel::SendLifecycleMessage(const char message[]) { - engine_->SendPlatformMessage(kChannelName, - reinterpret_cast(message), - strlen(message), nullptr, nullptr); -} - void LifecycleChannel::AppIsInactive() { - FT_LOGI("send app lifecycle state inactive."); - SendLifecycleMessage(kInactive); + FT_LOGI("Sending %s message.", kInactive); + channel_->Send(EncodableValue(kInactive)); } void LifecycleChannel::AppIsResumed() { - FT_LOGI("send app lifecycle state resumed."); - SendLifecycleMessage(kResumed); + FT_LOGI("Sending %s message.", kResumed); + channel_->Send(EncodableValue(kResumed)); } void LifecycleChannel::AppIsPaused() { - FT_LOGI("send app lifecycle state paused."); - SendLifecycleMessage(kPaused); + FT_LOGI("Sending %s message.", kPaused); + channel_->Send(EncodableValue(kPaused)); } void LifecycleChannel::AppIsDetached() { - FT_LOGI("send app lifecycle state detached."); - SendLifecycleMessage(kDetached); + FT_LOGI("Sending %s message.", kDetached); + channel_->Send(EncodableValue(kDetached)); } } // namespace flutter diff --git a/shell/platform/tizen/channels/lifecycle_channel.h b/shell/platform/tizen/channels/lifecycle_channel.h index 98301688e08e8..1c134eaf5a650 100644 --- a/shell/platform/tizen/channels/lifecycle_channel.h +++ b/shell/platform/tizen/channels/lifecycle_channel.h @@ -5,23 +5,25 @@ #ifndef EMBEDDER_LIFECYCLE_CHANNEL_H_ #define EMBEDDER_LIFECYCLE_CHANNEL_H_ -namespace flutter { +#include + +#include "flutter/shell/platform/common/client_wrapper/include/flutter/basic_message_channel.h" +#include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h" -class FlutterTizenEngine; +namespace flutter { class LifecycleChannel { public: - explicit LifecycleChannel(FlutterTizenEngine* engine); + explicit LifecycleChannel(BinaryMessenger* messenger); virtual ~LifecycleChannel(); void AppIsInactive(); void AppIsResumed(); void AppIsPaused(); void AppIsDetached(); - void SendLifecycleMessage(const char message[]); private: - FlutterTizenEngine* engine_{nullptr}; + std::unique_ptr> channel_; }; } // namespace flutter diff --git a/shell/platform/tizen/channels/string_codec.h b/shell/platform/tizen/channels/string_codec.h new file mode 100644 index 0000000000000..2132f26f3f631 --- /dev/null +++ b/shell/platform/tizen/channels/string_codec.h @@ -0,0 +1,58 @@ +// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved. +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef EMBEDDER_STRING_CODEC_H_ +#define EMBEDDER_STRING_CODEC_H_ + +#include +#include +#include + +#include "flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h" +#include "flutter/shell/platform/common/client_wrapper/include/flutter/message_codec.h" + +namespace flutter { + +// A string message encoding/decoding mechanism for communications to/from the +// Flutter engine via message channels. +class StringCodec : public MessageCodec { + public: + ~StringCodec() = default; + + // Returns an instance of the codec. + static const StringCodec& GetInstance() { + static StringCodec sInstance; + return sInstance; + } + + // Prevent copying. + StringCodec(StringCodec const&) = delete; + StringCodec& operator=(StringCodec const&) = delete; + + protected: + // |flutter::MessageCodec| + std::unique_ptr DecodeMessageInternal( + const uint8_t* binary_message, + const size_t message_size) const override { + return std::make_unique(std::string( + reinterpret_cast(binary_message), message_size)); + } + + // |flutter::MessageCodec| + std::unique_ptr> EncodeMessageInternal( + const EncodableValue& message) const override { + auto string_value = std::get(message); + return std::make_unique>(string_value.begin(), + string_value.end()); + } + + private: + // Instances should be obtained via GetInstance. + explicit StringCodec() = default; +}; + +} // namespace flutter + +#endif // EMBEDDER_STRING_CODEC_H_ diff --git a/shell/platform/tizen/flutter_tizen_engine.cc b/shell/platform/tizen/flutter_tizen_engine.cc index 309182e1461ab..20839242a971a 100644 --- a/shell/platform/tizen/flutter_tizen_engine.cc +++ b/shell/platform/tizen/flutter_tizen_engine.cc @@ -236,7 +236,8 @@ bool FlutterTizenEngine::RunEngine( internal_plugin_registrar_->messenger()); localization_channel = std::make_unique(this); localization_channel->SendLocales(); - lifecycle_channel = std::make_unique(this); + lifecycle_channel = std::make_unique( + internal_plugin_registrar_->messenger()); if (IsHeaded()) { texture_registrar_ = std::make_unique(this);