Skip to content

Commit

Permalink
Refactor c++ onEvent (#14)
Browse files Browse the repository at this point in the history
Refactor c++ onEvent
  • Loading branch information
littleGnAl committed Nov 4, 2022
1 parent 65a7945 commit b6053bf
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 548 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ macos/iris_event_handler.framework
macos/iris_event_handler.framework.dSYM
iris_event_handler.podspec
windows/third_party/
.vscode/
.vscode/

**/pubspec.lock
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# iris_event

iris_event is a bridge of iris event handling between C/C++ and dart, which is only used internally, **NOTE** that you should not use it.
iris_event is a bridge of iris event handling between C/C++ and dart, which is used by [agora_rtc_engine](https://github.com/AgoraIO-Extensions/Agora-Flutter-SDK).

## Build
```
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ android {

dependencies {
if (!isDev(project)) {
implementation 'io.agora.rtc:iris-event-flutter:1.4.0'
implementation 'io.agora.rtc:iris-event-flutter:1.5.0-dev.1'
}
}

Expand Down
2 changes: 1 addition & 1 deletion cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ project(iris_event_handler)

set(LIBRARY_NAME iris_event_handler)

set(IRIS_EVENT_VERSION "1.4.2")
set(IRIS_EVENT_VERSION "2.0.0")

if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(IRIS_EVENT_DEBUG 1)
Expand Down
51 changes: 20 additions & 31 deletions cxx/src/iris_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,49 +38,51 @@ class DartMessageHandler
exit_flag_ = 1;
}

void Post(const char *event, const char *data,
char result[kBasicResultLength],
const void **buffer, unsigned int *length,
unsigned int buffer_count)
void Post(const EventParam *param)
{
if (!param)
{
return;
}

if (dart_send_port_ == -1)
{
return;
}

Dart_CObject c_event;
c_event.type = Dart_CObject_kString;
if (event == nullptr)
if (param->event == nullptr)
{
c_event.value.as_string = (char *)"";
}
else
{
c_event.value.as_string = const_cast<char *>(event);
c_event.value.as_string = const_cast<char *>(param->event);
}

Dart_CObject c_data;
c_data.type = Dart_CObject_kString;
if (data == nullptr)
if (param->data == nullptr)
{
c_data.value.as_string = (char *)"";
}
else
{
c_data.value.as_string = const_cast<char *>(data);
c_data.value.as_string = const_cast<char *>(param->data);
}

if (buffer_count != 0)
if (param->buffer_count != 0)
{
Dart_CObject dbuffer;
dbuffer.type = Dart_CObject_kArray;
dbuffer.value.as_array.length = buffer_count;
dbuffer.value.as_array.length = param->buffer_count;
Dart_CObject **type_data_array =
new Dart_CObject *[buffer_count];
for (int i = 0; i < buffer_count; i++)
new Dart_CObject *[param->buffer_count];
for (int i = 0; i < param->buffer_count; i++)
{
const void *obuffer = buffer[i];
unsigned int abufferLength = length[i];
const void *obuffer = param->buffer[i];
unsigned int abufferLength = param->length[i];
uint8_t *abuffer = reinterpret_cast<uint8_t *>(malloc(abufferLength));
memcpy(abuffer, obuffer, abufferLength);

Expand All @@ -106,9 +108,9 @@ class DartMessageHandler
if (exit_flag_ == 0)
Dart_PostCObject_DL(dart_send_port_, &c_on_event_data);

if (buffer_count != 0)
if (param->buffer_count != 0)
{
for (intptr_t i = 0; i < buffer_count; ++i)
for (intptr_t i = 0; i < param->buffer_count; ++i)
{
delete type_data_array[i];
}
Expand Down Expand Up @@ -167,23 +169,10 @@ EXPORT void SetDartSendPort(Dart_Port send_port)
}
}

EXPORT void OnEvent(const char *event,
const char *data,
const void **buffer,
unsigned int *length,
unsigned int buffer_count)
{

OnEventEx(event, data, nullptr, buffer, length, buffer_count);
}

EXPORT void OnEventEx(const char *event, const char *data,
char result[kBasicResultLength],
const void **buffer, unsigned int *length,
unsigned int buffer_count)
EXPORT void OnEvent(EventParam *param)
{
if (dartMessageHandler_)
{
dartMessageHandler_->Post(event, data, result, buffer, length, buffer_count);
dartMessageHandler_->Post(param);
}
}
21 changes: 11 additions & 10 deletions cxx/src/iris_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
extern "C"
{
#endif
typedef struct EventParam
{
const char *event;
const char *data;
unsigned int data_size;
char *result;
void **buffer;
unsigned int *length;
unsigned int buffer_count;
} EventParam;

// Initialize `dart_api_dl.h`
EXPORT intptr_t
Expand All @@ -24,16 +34,7 @@ extern "C"

EXPORT void SetDartSendPort(Dart_Port send_port);

EXPORT void OnEvent(const char *event,
const char *data,
const void **buffer,
unsigned int *length,
unsigned int buffer_count);

EXPORT void OnEventEx(const char *event, const char *data,
char result[kBasicResultLength],
const void **buffer, unsigned int *length,
unsigned int buffer_count);
EXPORT void OnEvent(EventParam *param);

#ifdef __cplusplus
}
Expand Down
4 changes: 0 additions & 4 deletions cxx/src/iris_life_cycle_observer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
#import <Foundation/Foundation.h>

#if TARGET_OS_IPHONE
// #import <CoreMotion/CoreMotion.h>
#import <UIKit/UIKit.h>
// #import "sdk/objc/Framework/Classes/Audio/RTEAudioSession+Private.h"
// #import "sdk/objc/Framework/Headers/WebRTC/RTEAudioSessionConfiguration.h"
// #import "sdk/objc/Framework/Headers/WebRTC/RTELogging.h"
#endif

#if TARGET_OS_MAC && !TARGET_OS_IPHONE
Expand Down
175 changes: 0 additions & 175 deletions example/pubspec.lock

This file was deleted.

2 changes: 1 addition & 1 deletion ios/iris_event.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A new flutter plugin project.
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.dependency 'AgoraIrisEventFlutter_iOS', '1.4.0'
s.dependency 'AgoraIrisEventFlutter_iOS', '1.5.0-dev.1'
# s.dependency 'iris_event_handler'
s.platform = :ios, '9.0'
s.libraries = 'stdc++'
Expand Down
Loading

0 comments on commit b6053bf

Please sign in to comment.