Skip to content

Commit 6b556f0

Browse files
authored
Merge pull request #5 from ardera/feature-plugins
plugin registry, completely reworked platform channels, test plugin
2 parents fe06dd5 + 6c5d10f commit 6b556f0

12 files changed

+2719
-625
lines changed

src/flutter-pi.c

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
#include <flutter_embedder.h>
2929

3030
#include "flutter-pi.h"
31-
#include "methodchannel.h"
31+
#include "platformchannel.h"
32+
#include "pluginregistry.h"
3233

3334

3435
char* usage ="\
@@ -96,6 +97,7 @@ struct {
9697
int engine_argc;
9798
const char* const *engine_argv;
9899
intptr_t next_vblank_baton;
100+
struct FlutterPiPluginRegistry *registry;
99101
} flutter = {0};
100102

101103
struct {
@@ -284,7 +286,7 @@ const GLubyte* hacked_glGetString(GLenum name) {
284286
static GLubyte* extensions;
285287

286288
if (extensions == NULL) {
287-
GLubyte* orig_extensions = glGetString(GL_EXTENSIONS);
289+
GLubyte* orig_extensions = (GLubyte *) glGetString(GL_EXTENSIONS);
288290
size_t len_orig_extensions = strlen(orig_extensions);
289291

290292
extensions = malloc(len_orig_extensions+1);
@@ -380,20 +382,9 @@ void* proc_resolver(void* userdata, const char* name) {
380382
return NULL;
381383
}
382384
void on_platform_message(const FlutterPlatformMessage* message, void* userdata) {
383-
struct MethodCall* methodcall;
384-
385-
if (!MethodChannel_decode(message->message_size, (uint8_t*) (message->message), &methodcall)) {
386-
fprintf(stderr, "Decoding method call failed\n");
387-
return;
388-
}
389-
390-
printf("MethodCall: method name: %s argument type: %d\n", methodcall->method, methodcall->argument.type);
391-
392-
if (strcmp(methodcall->method, "counter") == 0) {
393-
printf("method \"counter\" was called with argument %d\n", methodcall->argument.int_value);
394-
}
395-
396-
MethodChannel_freeMethodCall(&methodcall);
385+
int ok;
386+
if ((ok = PluginRegistry_onPlatformMessage((FlutterPlatformMessage *)message)) != 0)
387+
fprintf(stderr, "PluginRegistry_onPlatformMessage failed: %s\n", strerror(ok));
397388
}
398389
void vsync_callback(void* userdata, intptr_t baton) {
399390
// not yet implemented
@@ -828,6 +819,15 @@ void destroy_display(void) {
828819
}
829820

830821
bool init_application(void) {
822+
int ok;
823+
824+
printf("Initializing Plugin Registry...\n");
825+
ok = PluginRegistry_init();
826+
if (ok != 0) {
827+
fprintf(stderr, "Could not initialize plugin registry: %s\n", strerror(ok));
828+
return false;
829+
}
830+
831831
// configure flutter rendering
832832
flutter.renderer_config.type = kOpenGL;
833833
flutter.renderer_config.open_gl.struct_size = sizeof(flutter.renderer_config.open_gl);
@@ -837,9 +837,6 @@ bool init_application(void) {
837837
flutter.renderer_config.open_gl.fbo_callback = fbo_callback;
838838
flutter.renderer_config.open_gl.gl_proc_resolver= proc_resolver;
839839

840-
for (int i=0; i<flutter.engine_argc; i++)
841-
printf("engine_argv[%i] = %s\n", i, flutter.engine_argv[i]);
842-
843840
// configure flutter
844841
flutter.args.struct_size = sizeof(FlutterProjectArgs);
845842
flutter.args.assets_path = flutter.asset_bundle_path;
@@ -868,17 +865,13 @@ bool init_application(void) {
868865

869866
// spin up the engine
870867
FlutterEngineResult _result = FlutterEngineRun(FLUTTER_ENGINE_VERSION, &flutter.renderer_config, &flutter.args, NULL, &engine);
871-
872-
for (int i=0; i<flutter.engine_argc; i++)
873-
printf("engine_argv[%i] = %s\n", i, flutter.engine_argv[i]);
874-
875868
if (_result != kSuccess) {
876869
fprintf(stderr, "Could not run the flutter engine\n");
877870
return false;
878871
}
879872

880873
// update window size
881-
bool ok = FlutterEngineSendWindowMetricsEvent(
874+
ok = FlutterEngineSendWindowMetricsEvent(
882875
engine,
883876
&(FlutterWindowMetricsEvent) {.struct_size = sizeof(FlutterWindowMetricsEvent), .width=width, .height=height, .pixel_ratio = pixel_ratio}
884877
) == kSuccess;
@@ -891,16 +884,19 @@ bool init_application(void) {
891884
return true;
892885
}
893886
void destroy_application(void) {
894-
if (engine == NULL) return;
895-
896-
FlutterEngineResult _result = FlutterEngineShutdown(engine);
897-
898-
if (_result != kSuccess) {
899-
fprintf(stderr, "Could not shutdown the flutter engine.\n");
900-
}
901-
}
887+
int ok;
902888

889+
if (engine != NULL) {
890+
if (FlutterEngineShutdown(engine) != kSuccess)
891+
fprintf(stderr, "Could not shutdown the flutter engine.\n");
903892

893+
engine = NULL;
894+
}
895+
896+
if ((ok = PluginRegistry_deinit()) != 0) {
897+
fprintf(stderr, "Could not deinitialize plugin registry: %s\n", strerror(ok));
898+
}
899+
}
904900

905901
/****************
906902
* Input-Output *
@@ -1101,7 +1097,6 @@ bool run_io_thread(void) {
11011097
}
11021098

11031099

1104-
11051100
bool parse_cmd_args(int argc, char **argv) {
11061101
int opt;
11071102
int index = 0;
@@ -1146,7 +1141,7 @@ bool parse_cmd_args(int argc, char **argv) {
11461141

11471142
argv[optind] = argv[0];
11481143
flutter.engine_argc = argc-optind;
1149-
flutter.engine_argv = &(argv[optind]);
1144+
flutter.engine_argv = (const char* const*) &(argv[optind]);
11501145

11511146
for (int i=0; i<flutter.engine_argc; i++)
11521147
printf("engine_argv[%i] = %s\n", i, flutter.engine_argv[i]);

0 commit comments

Comments
 (0)