Flutter Engine
flutter::PlatformMessageResponseDart Class Reference

#include <platform_message_response_dart.h>

Inheritance diagram for flutter::PlatformMessageResponseDart:
flutter::PlatformMessageResponse fml::RefCountedThreadSafe< PlatformMessageResponse > fml::internal::RefCountedThreadSafeBase

Public Member Functions

void Complete (std::unique_ptr< fml::Mapping > data) override
 
void CompleteEmpty () override
 
- Public Member Functions inherited from flutter::PlatformMessageResponse
bool is_complete () const
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< PlatformMessageResponse >
void Release () const
 
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 

Protected Member Functions

 PlatformMessageResponseDart (tonic::DartPersistentValue callback, fml::RefPtr< fml::TaskRunner > ui_task_runner)
 
 ~PlatformMessageResponseDart () override
 
- Protected Member Functions inherited from flutter::PlatformMessageResponse
 PlatformMessageResponse ()
 
virtual ~PlatformMessageResponse ()
 
- Protected Member Functions inherited from fml::RefCountedThreadSafe< PlatformMessageResponse >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 

Protected Attributes

tonic::DartPersistentValue callback_
 
fml::RefPtr< fml::TaskRunnerui_task_runner_
 
- Protected Attributes inherited from flutter::PlatformMessageResponse
bool is_complete_ = false
 

Detailed Description

Definition at line 14 of file platform_message_response_dart.h.

Constructor & Destructor Documentation

◆ PlatformMessageResponseDart()

flutter::PlatformMessageResponseDart::PlatformMessageResponseDart ( tonic::DartPersistentValue  callback,
fml::RefPtr< fml::TaskRunner ui_task_runner 
)
explicitprotected

Definition at line 17 of file platform_message_response_dart.cc.

20  : callback_(std::move(callback)),
21  ui_task_runner_(std::move(ui_task_runner)) {}

◆ ~PlatformMessageResponseDart()

flutter::PlatformMessageResponseDart::~PlatformMessageResponseDart ( )
overrideprotected

Definition at line 23 of file platform_message_response_dart.cc.

References callback_, tonic::DartPersistentValue::is_empty(), fml::MakeCopyable(), fml::TaskRunner::PostTask(), and ui_task_runner_.

23  {
24  if (!callback_.is_empty()) {
26  [callback = std::move(callback_)]() mutable { callback.Clear(); }));
27  }
28 }
virtual void PostTask(const fml::closure &task)
Definition: task_runner.cc:24
internal::CopyableLambda< T > MakeCopyable(T lambda)
Definition: make_copyable.h:57

Member Function Documentation

◆ Complete()

void flutter::PlatformMessageResponseDart::Complete ( std::unique_ptr< fml::Mapping data)
overridevirtual

Implements flutter::PlatformMessageResponse.

Definition at line 30 of file platform_message_response_dart.cc.

References callback_, tonic::DartByteData::Create(), tonic::DartInvoke(), FML_DCHECK, flutter::PlatformMessageResponse::is_complete_, tonic::DartPersistentValue::is_empty(), fml::MakeCopyable(), fml::TaskRunner::PostTask(), and ui_task_runner_.

30  {
31  if (callback_.is_empty()) {
32  return;
33  }
35  is_complete_ = true;
37  [callback = std::move(callback_), data = std::move(data)]() mutable {
38  std::shared_ptr<tonic::DartState> dart_state =
39  callback.dart_state().lock();
40  if (!dart_state) {
41  return;
42  }
43  tonic::DartState::Scope scope(dart_state);
44 
45  Dart_Handle byte_buffer =
46  tonic::DartByteData::Create(data->GetMapping(), data->GetSize());
47  tonic::DartInvoke(callback.Release(), {byte_buffer});
48  }));
49 }
#define FML_DCHECK(condition)
Definition: logging.h:86
virtual void PostTask(const fml::closure &task)
Definition: task_runner.cc:24
Dart_Handle DartInvoke(Dart_Handle closure, std::initializer_list< Dart_Handle > args)
Definition: dart_invoke.cc:20
internal::CopyableLambda< T > MakeCopyable(T lambda)
Definition: make_copyable.h:57
static Dart_Handle Create(const void *data, size_t length)

◆ CompleteEmpty()

void flutter::PlatformMessageResponseDart::CompleteEmpty ( )
overridevirtual

Implements flutter::PlatformMessageResponse.

Definition at line 51 of file platform_message_response_dart.cc.

References callback_, tonic::DartInvoke(), FML_DCHECK, flutter::PlatformMessageResponse::is_complete_, tonic::DartPersistentValue::is_empty(), fml::MakeCopyable(), fml::TaskRunner::PostTask(), and ui_task_runner_.

51  {
52  if (callback_.is_empty()) {
53  return;
54  }
56  is_complete_ = true;
58  fml::MakeCopyable([callback = std::move(callback_)]() mutable {
59  std::shared_ptr<tonic::DartState> dart_state =
60  callback.dart_state().lock();
61  if (!dart_state) {
62  return;
63  }
64  tonic::DartState::Scope scope(dart_state);
65  tonic::DartInvoke(callback.Release(), {Dart_Null()});
66  }));
67 }
#define FML_DCHECK(condition)
Definition: logging.h:86
virtual void PostTask(const fml::closure &task)
Definition: task_runner.cc:24
Dart_Handle DartInvoke(Dart_Handle closure, std::initializer_list< Dart_Handle > args)
Definition: dart_invoke.cc:20
internal::CopyableLambda< T > MakeCopyable(T lambda)
Definition: make_copyable.h:57

Member Data Documentation

◆ callback_

tonic::DartPersistentValue flutter::PlatformMessageResponseDart::callback_
protected

◆ ui_task_runner_

fml::RefPtr<fml::TaskRunner> flutter::PlatformMessageResponseDart::ui_task_runner_
protected

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