Browse Source

recreate linux plugin folder with new template

master
Herbert Poul 4 years ago
parent
commit
2620399d1b
  1. 23
      linux/CMakeLists.txt
  2. 110
      linux/argon2_ffi_plugin.cc
  3. 26
      linux/include/argon2_ffi/argon2_ffi_plugin.h
  4. 23
      linux/include/argon2_ffi_plugin.h

23
linux/CMakeLists.txt

@ -1,21 +1,11 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
set(PROJECT_NAME "argon2_ffi") set(PROJECT_NAME "argon2_ffi")
project(${PROJECT_NAME} LANGUAGES C CXX) project(${PROJECT_NAME} LANGUAGES CXX)
set(PLUGIN_NAME "${PROJECT_NAME}_plugin") set(PLUGIN_NAME "${PROJECT_NAME}_plugin")
add_library(${PLUGIN_NAME} SHARED add_library(${PLUGIN_NAME} SHARED
${PLUGIN_NAME}.cc "${PLUGIN_NAME}.cc"
../ios/Classes/argon2_ffi.c
../ios/Classes/argon2src/argon2.c
../ios/Classes/argon2src/core.c
../ios/Classes/argon2src/encoding.c
../ios/Classes/argon2src/genkat.c
../ios/Classes/argon2src/ref.c
../ios/Classes/argon2src/thread.c
../ios/Classes/argon2src/blake2/blake2b.c
) )
apply_standard_settings(${PLUGIN_NAME}) apply_standard_settings(${PLUGIN_NAME})
set_target_properties(${PLUGIN_NAME} PROPERTIES set_target_properties(${PLUGIN_NAME} PROPERTIES
@ -23,4 +13,11 @@ set_target_properties(${PLUGIN_NAME} PROPERTIES
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
target_include_directories(${PLUGIN_NAME} INTERFACE target_include_directories(${PLUGIN_NAME} INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}/include") "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) target_link_libraries(${PLUGIN_NAME} PRIVATE flutter)
target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK)
# List of absolute paths to libraries that should be bundled with the plugin
set(argon2_ffi_bundled_libraries
""
PARENT_SCOPE
)

110
linux/argon2_ffi_plugin.cc

@ -1,78 +1,68 @@
#include "include/argon2_ffi_plugin.h" #include "include/argon2_ffi/argon2_ffi_plugin.h"
#include <flutter/method_channel.h> #include <flutter_linux/flutter_linux.h>
#include <flutter/plugin_registrar_glfw.h> #include <gtk/gtk.h>
#include <flutter/standard_method_codec.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include <map> #define ARGON2_FFI_PLUGIN(obj) \
#include <memory> (G_TYPE_CHECK_INSTANCE_CAST((obj), argon2_ffi_plugin_get_type(), \
#include <sstream> Argon2FfiPlugin))
namespace { struct _Argon2FfiPlugin {
GObject parent_instance;
class Argon2FfiPlugin : public flutter::Plugin { };
public:
static void RegisterWithRegistrar(flutter::PluginRegistrarGlfw *registrar);
Argon2FfiPlugin(); G_DEFINE_TYPE(Argon2FfiPlugin, argon2_ffi_plugin, g_object_get_type())
virtual ~Argon2FfiPlugin(); // Called when a method call is received from Flutter.
static void argon2_ffi_plugin_handle_method_call(
Argon2FfiPlugin* self,
FlMethodCall* method_call) {
g_autoptr(FlMethodResponse) response = nullptr;
private: const gchar* method = fl_method_call_get_name(method_call);
// Called when a method is called on this plugin's channel from Dart.
void HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue> &method_call,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
};
// static if (strcmp(method, "getPlatformVersion") == 0) {
void Argon2FfiPlugin::RegisterWithRegistrar( struct utsname uname_data = {};
flutter::PluginRegistrarGlfw *registrar) { uname(&uname_data);
auto channel = g_autofree gchar *version = g_strdup_printf("Linux %s", uname_data.version);
std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>( g_autoptr(FlValue) result = fl_value_new_string(version);
registrar->messenger(), "argon2_ffi", response = FL_METHOD_RESPONSE(fl_method_success_response_new(result));
&flutter::StandardMethodCodec::GetInstance()); } else {
auto plugin = std::make_unique<Argon2FfiPlugin>(); response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new());
}
channel->SetMethodCallHandler( fl_method_call_respond(method_call, response, nullptr);
[plugin_pointer = plugin.get()](const auto &call, auto result) { }
plugin_pointer->HandleMethodCall(call, std::move(result));
});
registrar->AddPlugin(std::move(plugin)); static void argon2_ffi_plugin_dispose(GObject* object) {
G_OBJECT_CLASS(argon2_ffi_plugin_parent_class)->dispose(object);
} }
Argon2FfiPlugin::Argon2FfiPlugin() {} static void argon2_ffi_plugin_class_init(Argon2FfiPluginClass* klass) {
G_OBJECT_CLASS(klass)->dispose = argon2_ffi_plugin_dispose;
}
Argon2FfiPlugin::~Argon2FfiPlugin() {} static void argon2_ffi_plugin_init(Argon2FfiPlugin* self) {}
void Argon2FfiPlugin::HandleMethodCall( static void method_call_cb(FlMethodChannel* channel, FlMethodCall* method_call,
const flutter::MethodCall<flutter::EncodableValue> &method_call, gpointer user_data) {
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) { Argon2FfiPlugin* plugin = ARGON2_FFI_PLUGIN(user_data);
// Replace "getPlatformVersion" check with your plugin's method. argon2_ffi_plugin_handle_method_call(plugin, method_call);
// See:
// https://github.com/flutter/engine/tree/master/shell/platform/common/cpp/client_wrapper/include/flutter
// and
// https://github.com/flutter/engine/tree/master/shell/platform/glfw/client_wrapper/include/flutter
// for the relevant Flutter APIs.
if (method_call.method_name().compare("getPlatformVersion") == 0) {
struct utsname uname_data = {};
uname(&uname_data);
std::ostringstream version_stream;
version_stream << "Linux " << uname_data.version;
flutter::EncodableValue response(version_stream.str());
result->Success(&response);
} else {
result->NotImplemented();
}
} }
} // namespace void argon2_ffi_plugin_register_with_registrar(FlPluginRegistrar* registrar) {
Argon2FfiPlugin* plugin = ARGON2_FFI_PLUGIN(
g_object_new(argon2_ffi_plugin_get_type(), nullptr));
g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
g_autoptr(FlMethodChannel) channel =
fl_method_channel_new(fl_plugin_registrar_get_messenger(registrar),
"argon2_ffi",
FL_METHOD_CODEC(codec));
fl_method_channel_set_method_call_handler(channel, method_call_cb,
g_object_ref(plugin),
g_object_unref);
void Argon2FfiPluginRegisterWithRegistrar( g_object_unref(plugin);
FlutterDesktopPluginRegistrarRef registrar) {
Argon2FfiPlugin::RegisterWithRegistrar(
flutter::PluginRegistrarManager::GetInstance()
->GetRegistrar<flutter::PluginRegistrarGlfw>(registrar));
} }

26
linux/include/argon2_ffi/argon2_ffi_plugin.h

@ -0,0 +1,26 @@
#ifndef FLUTTER_PLUGIN_ARGON2_FFI_PLUGIN_H_
#define FLUTTER_PLUGIN_ARGON2_FFI_PLUGIN_H_
#include <flutter_linux/flutter_linux.h>
G_BEGIN_DECLS
#ifdef FLUTTER_PLUGIN_IMPL
#define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default")))
#else
#define FLUTTER_PLUGIN_EXPORT
#endif
typedef struct _Argon2FfiPlugin Argon2FfiPlugin;
typedef struct {
GObjectClass parent_class;
} Argon2FfiPluginClass;
FLUTTER_PLUGIN_EXPORT GType argon2_ffi_plugin_get_type();
FLUTTER_PLUGIN_EXPORT void argon2_ffi_plugin_register_with_registrar(
FlPluginRegistrar* registrar);
G_END_DECLS
#endif // FLUTTER_PLUGIN_ARGON2_FFI_PLUGIN_H_

23
linux/include/argon2_ffi_plugin.h

@ -1,23 +0,0 @@
#ifndef FLUTTER_PLUGIN_ARGON2_FFI_PLUGIN_H_
#define FLUTTER_PLUGIN_ARGON2_FFI_PLUGIN_H_
#include <flutter_plugin_registrar.h>
#ifdef FLUTTER_PLUGIN_IMPL
#define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default")))
#else
#define FLUTTER_PLUGIN_EXPORT
#endif
#if defined(__cplusplus)
extern "C" {
#endif
FLUTTER_PLUGIN_EXPORT void Argon2FfiPluginRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar);
#if defined(__cplusplus)
} // extern "C"
#endif
#endif // FLUTTER_PLUGIN_ARGON2_FFI_PLUGIN_H_
Loading…
Cancel
Save