Initial plugin system

This commit is contained in:
Marvin W 2017-03-10 19:34:56 +01:00
parent cf51e1dee2
commit 29ca70a6d5
No known key found for this signature in database
GPG key ID: 072E9235DB996F2A
101 changed files with 275 additions and 122 deletions

View file

@ -18,9 +18,11 @@ endif()
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set (VALA_CFLAGS -Wno-deprecated-declarations -Wno-incompatible-pointer-types -Wno-int-conversion) set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
set (VALA_CFLAGS -Wno-deprecated-declarations -Wno-incompatible-pointer-types -Wno-int-conversion -Wno-discarded-qualifiers)
add_subdirectory(gpgme-vala) add_subdirectory(gpgme-vala)
add_subdirectory(qlite) add_subdirectory(qlite)
add_subdirectory(xmpp-vala) add_subdirectory(xmpp-vala)
add_subdirectory(client) add_subdirectory(libdino)
add_subdirectory(main)

View file

@ -1,12 +0,0 @@
using Dino.Entities;
using Dino.Ui;
namespace Dino {
void main(string[] args) {
Notify.init("dino");
Gtk.init(ref args);
Dino.Ui.Application app = new Dino.Ui.Application();
app.run(args);
}
}

View file

@ -115,9 +115,11 @@ function(_vala_mkdir_for_file file)
endfunction() endfunction()
function(vala_precompile output) function(vala_precompile output)
cmake_parse_arguments(ARGS "" "DIRECTORY;GENERATE_HEADER;GENERATE_VAPI" cmake_parse_arguments(ARGS "FAST_VAPI" "DIRECTORY;GENERATE_HEADER;GENERATE_VAPI"
"SOURCES;PACKAGES;OPTIONS;DEFINITIONS;CUSTOM_VAPIS;GRESOURCES" ${ARGN}) "SOURCES;PACKAGES;OPTIONS;DEFINITIONS;CUSTOM_VAPIS;GRESOURCES" ${ARGN})
set(ARGS_FAST_VAPI true)
if(ARGS_DIRECTORY) if(ARGS_DIRECTORY)
get_filename_component(DIRECTORY ${ARGS_DIRECTORY} ABSOLUTE) get_filename_component(DIRECTORY ${ARGS_DIRECTORY} ABSOLUTE)
else(ARGS_DIRECTORY) else(ARGS_DIRECTORY)
@ -159,7 +161,8 @@ function(vala_precompile output)
set(vapi_arguments "") set(vapi_arguments "")
if(ARGS_GENERATE_VAPI) if(ARGS_GENERATE_VAPI)
list(APPEND out_extra_files "${DIRECTORY}/${ARGS_GENERATE_VAPI}.vapi") list(APPEND out_extra_files "${DIRECTORY}/${ARGS_GENERATE_VAPI}.vapi")
set(vapi_arguments "--vapi=${ARGS_GENERATE_VAPI}.vapi") list(APPEND out_extra_files "${DIRECTORY}/${ARGS_GENERATE_VAPI}-internal.vapi")
set(vapi_arguments "--vapi=${ARGS_GENERATE_VAPI}.vapi" "--internal-vapi=${ARGS_GENERATE_VAPI}-internal.vapi")
# Header and internal header is needed to generate internal vapi # Header and internal header is needed to generate internal vapi
if (NOT ARGS_GENERATE_HEADER) if (NOT ARGS_GENERATE_HEADER)
@ -175,6 +178,7 @@ function(vala_precompile output)
list(APPEND header_arguments "--internal-header=${DIRECTORY}/${ARGS_GENERATE_HEADER}_internal.h") list(APPEND header_arguments "--internal-header=${DIRECTORY}/${ARGS_GENERATE_HEADER}_internal.h")
endif(ARGS_GENERATE_HEADER) endif(ARGS_GENERATE_HEADER)
if(ARGS_FAST_VAPI)
foreach(src ${ARGS_SOURCES} ${ARGS_UNPARSED_ARGUMENTS}) foreach(src ${ARGS_SOURCES} ${ARGS_UNPARSED_ARGUMENTS})
set(in_file "${CMAKE_CURRENT_SOURCE_DIR}/${src}") set(in_file "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
list(APPEND in_files "${in_file}") list(APPEND in_files "${in_file}")
@ -267,5 +271,39 @@ function(vala_precompile output)
"Generating VAPI and headers for linking" "Generating VAPI and headers for linking"
) )
endif() endif()
else(ARGS_FAST_VAPI)
foreach(src ${ARGS_SOURCES} ${ARGS_UNPARSED_ARGUMENTS})
set(in_file "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
list(APPEND in_files "${in_file}")
string(REPLACE ".vala" ".c" src ${src})
string(REPLACE ".gs" ".c" src ${src})
list(APPEND out_files "${DIRECTORY}/${src}")
_vala_mkdir_for_file("${fast_vapi_file}")
endforeach(src ${ARGS_SOURCES} ${ARGS_UNPARSED_ARGUMENTS})
add_custom_command(OUTPUT ${out_files} ${out_extra_files}
COMMAND
${VALA_EXECUTABLE}
ARGS
-C
${header_arguments}
${vapi_arguments}
"-b" ${CMAKE_CURRENT_SOURCE_DIR}
"-d" ${DIRECTORY}
${vala_pkg_opts}
${vala_define_opts}
${gresources_args}
${ARGS_OPTIONS}
${in_files}
${custom_vapi_arguments}
DEPENDS
${in_files}
${ARGS_CUSTOM_VAPIS}
${ARGS_GRESOURCES}
COMMENT
"Generating C code for target ${output}"
)
endif(ARGS_FAST_VAPI)
set(${output} ${out_files} PARENT_SCOPE) set(${output} ${out_files} PARENT_SCOPE)
endfunction(vala_precompile) endfunction(vala_precompile)

18
configure vendored
View file

@ -15,27 +15,27 @@ then
fi fi
if [ -x "$(which ninja 2>/dev/null)" ]; then if [ -x "$(which ninja 2>/dev/null)" ]; then
echo "Using Ninja ($(which ninja))" echo "-- Found Ninja: $(which ninja)"
cmake_type="Ninja" cmake_type="Ninja"
exec_bin="ninja" exec_bin="ninja"
elif [ -x "$(which ninja-build 2>/dev/null)" ]; then elif [ -x "$(which ninja-build 2>/dev/null)" ]; then
echo "Using Ninja ($(which ninja-build))" echo "-- Found Ninja: $(which ninja-build)"
cmake_type="Ninja" cmake_type="Ninja"
exec_bin="ninja-build" exec_bin="ninja-build"
elif [ -x "$(which make 2>/dev/null)" ]; then elif [ -x "$(which make 2>/dev/null)" ]; then
echo "Using Make ($(which make))" echo "-- Found Make: $(which make)"
cmake_type="Unix Makefiles" cmake_type="Unix Makefiles"
exec_bin="make" exec_bin="make -j4"
printf "Using Ninja improves build experience, continue with Make? [y/N] " echo "-- Using Ninja might improve build experience."
cont cont
else else
echo "No compatible build system (Ninja, Make) found." echo "-!- No compatible build system (Ninja, Make) found."
exit 4 exit 4
fi fi
if [ -f ./build ] if [ -f ./build ]
then then
echo "./build file exists. ./configure can't continue" echo "-!- ./build file exists. ./configure can't continue"
exit 2 exit 2
fi fi
@ -43,13 +43,13 @@ if [ -d build ]
then then
if [ ! -f "build/.cmake_type" ] if [ ! -f "build/.cmake_type" ]
then then
printf "./build exists but was not created by ./configure script, continue? [y/N] " printf "-!- ./build exists but was not created by ./configure script, continue? [y/N] "
cont cont
fi fi
last_type=`cat build/.cmake_type` last_type=`cat build/.cmake_type`
if [ "$cmake_type" != "$last_type" ] if [ "$cmake_type" != "$last_type" ]
then then
echo "Using different build system, cleaning build system files" echo "-- Using different build system, cleaning build system files"
cd build cd build
rm -r CMakeCache.txt CMakeFiles rm -r CMakeCache.txt CMakeFiles
cd .. cd ..

View file

@ -28,7 +28,7 @@ OPTIONS
--thread --thread
) )
set(CFLAGS ${GPGME_VALA_CFLAGS} ${GPGME_CFLAGS} -g ${VALA_CFLAGS} -I${CMAKE_CURRENT_SOURCE_DIR}/src) set(CFLAGS ${VALA_CFLAGS} ${GPGME_VALA_CFLAGS} ${GPGME_CFLAGS} -I${CMAKE_CURRENT_SOURCE_DIR}/src)
add_definitions(${CFLAGS}) add_definitions(${CFLAGS})
add_library(gpgme-vala SHARED ${GPGME_VALA_C} src/fix.c) add_library(gpgme-vala SHARED ${GPGME_VALA_C} src/fix.c)
target_link_libraries(gpgme-vala ${GPGME_VALA_LIBRARIES} ${GPGME_LIBRARIES}) target_link_libraries(gpgme-vala ${GPGME_VALA_LIBRARIES} ${GPGME_LIBRARIES})

View file

@ -1,20 +1,19 @@
find_package(Vala REQUIRED) find_package(Vala REQUIRED)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
find_package(GPGME REQUIRED)
find_package(LIBUUID REQUIRED)
include(${VALA_USE_FILE}) include(${VALA_USE_FILE})
include(GlibCompileResourcesSupport) include(GlibCompileResourcesSupport)
set(CLIENT_PACKAGES set(LIBDINO_PACKAGES
gee-0.8 gee-0.8
gio-2.0 gio-2.0
glib-2.0 glib-2.0
gtk+-3.0 gtk+-3.0
gmodule-2.0
libnotify libnotify
sqlite3 sqlite3
) )
pkg_check_modules(CLIENT REQUIRED ${CLIENT_PACKAGES}) pkg_check_modules(LIBDINO REQUIRED ${LIBDINO_PACKAGES})
set(RESOURCE_LIST set(RESOURCE_LIST
img/double_tick.svg img/double_tick.svg
@ -52,8 +51,8 @@ set(RESOURCE_LIST
) )
compile_gresources( compile_gresources(
CLIENT_GRESOURCES_TARGET LIBDINO_GRESOURCES_TARGET
CLIENT_GRESOURCES_XML LIBDINO_GRESOURCES_XML
TARGET ${CMAKE_BINARY_DIR}/resources/resources.c TARGET ${CMAKE_BINARY_DIR}/resources/resources.c
TYPE EMBED_C TYPE EMBED_C
RESOURCES ${RESOURCE_LIST} RESOURCES ${RESOURCE_LIST}
@ -61,9 +60,9 @@ compile_gresources(
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data
) )
vala_precompile(CLIENT_VALA_C vala_precompile(LIBDINO_VALA_C
SOURCES SOURCES
src/main.vala src/plugin.vala
src/dbus/login1.vala src/dbus/login1.vala
src/dbus/networkmanager.vala src/dbus/networkmanager.vala
@ -124,25 +123,31 @@ SOURCES
src/ui/settings_dialog.vala src/ui/settings_dialog.vala
src/ui/unified_window.vala src/ui/unified_window.vala
src/ui/util.vala src/ui/util.vala
CUSTOM_VAPIS
${CMAKE_BINARY_DIR}/xmpp-vala/xmpp-vala.vapi
${CMAKE_BINARY_DIR}/qlite/qlite.vapi
PACKAGES PACKAGES
${CLIENT_PACKAGES} ${LIBDINO_PACKAGES}
xmpp-vala GENERATE_VAPI
qlite dino
GENERATE_HEADER
dino
GRESOURCES GRESOURCES
${CLIENT_GRESOURCES_XML} ${LIBDINO_GRESOURCES_XML}
OPTIONS OPTIONS
--target-glib=2.38 --target-glib=2.38
-g -g
--thread --thread
--vapidir=${CMAKE_BINARY_DIR}/xmpp-vala
--vapidir=${CMAKE_BINARY_DIR}/qlite
--vapidir=${CMAKE_SOURCE_DIR}/vapi
) )
set(CFLAGS ${CLIENT_CFLAGS} -g -I${CMAKE_BINARY_DIR}/xmpp-vala -I${CMAKE_BINARY_DIR}/qlite ${VALA_CFLAGS}) set(CFLAGS ${VALA_CFLAGS} ${LIBDINO_CFLAGS} -I${CMAKE_BINARY_DIR}/xmpp-vala -I${CMAKE_BINARY_DIR}/qlite)
add_definitions(${CFLAGS}) add_definitions(${CFLAGS})
add_executable(dino ${CLIENT_VALA_C} ${CLIENT_GRESOURCES_TARGET}) add_library(libdino SHARED ${LIBDINO_VALA_C} ${LIBDINO_GRESOURCES_TARGET})
add_dependencies(dino xmpp-vala-vapi qlite-vapi) add_dependencies(libdino xmpp-vala-vapi qlite-vapi)
target_link_libraries(dino xmpp-vala qlite ${CLIENT_LIBRARIES} -lm) target_link_libraries(libdino xmpp-vala qlite ${LIBDINO_LIBRARIES} -lm)
set_target_properties(libdino PROPERTIES PREFIX "")
add_custom_target(dino-vapi
DEPENDS
${CMAKE_BINARY_DIR}/libdino/dino.vapi
)

View file

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

View file

Before

Width:  |  Height:  |  Size: 344 B

After

Width:  |  Height:  |  Size: 344 B

View file

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View file

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 3 KiB

View file

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View file

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 2 KiB

View file

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

64
libdino/src/plugin.vala Normal file
View file

@ -0,0 +1,64 @@
namespace Dino {
public errordomain PluginError {
NOT_SUPPORTED,
UNEXPECTED_TYPE,
NO_REGISTRATION_FUNCTION,
FAILED
}
public interface PluginIface : Object {
public abstract void registered(Dino.Ui.Application app);
}
private class PluginInfo : Object {
public Module module;
public Type gtype;
public PluginInfo(Type type, owned Module module) {
this.module = (owned) module;
this.gtype = type;
}
}
public class PluginLoader : Object {
[CCode (has_target = false)]
private delegate Type RegisterPluginFunction (Module module);
private PluginIface[] plugins = new PluginIface[0];
private PluginInfo[] infos = new PluginInfo[0];
public PluginIface load(string name, Dino.Ui.Application app) throws PluginError {
if (Module.supported () == false) {
throw new PluginError.NOT_SUPPORTED ("Plugins are not supported");
}
Module module = Module.open ("plugins/" + name, ModuleFlags.BIND_LAZY);
if (module == null) {
throw new PluginError.FAILED (Module.error ());
}
void* function;
module.symbol ("register_plugin", out function);
if (function == null) {
throw new PluginError.NO_REGISTRATION_FUNCTION ("register_plugin () not found");
}
RegisterPluginFunction register_plugin = (RegisterPluginFunction) function;
Type type = register_plugin (module);
if (type.is_a (typeof (PluginIface)) == false) {
throw new PluginError.UNEXPECTED_TYPE ("Unexpected type");
}
PluginInfo info = new PluginInfo (type, (owned) module);
infos += info;
PluginIface plugin = (PluginIface) Object.new (type);
plugins += plugin;
plugin.registered (app);
return plugin;
}
}
}

View file

@ -28,6 +28,7 @@ public class Dino.Ui.Application : Gtk.Application {
ConversationManager.start(stream_interaction, db); ConversationManager.start(stream_interaction, db);
ChatInteraction.start(stream_interaction); ChatInteraction.start(stream_interaction);
Notify.init("dino");
notifications = new Notifications(stream_interaction); notifications = new Notifications(stream_interaction);
notifications.start(); notifications.start();

35
main/CMakeLists.txt Normal file
View file

@ -0,0 +1,35 @@
find_package(Vala REQUIRED)
find_package(PkgConfig REQUIRED)
include(${VALA_USE_FILE})
set(MAIN_PACKAGES
gee-0.8
gio-2.0
glib-2.0
gtk+-3.0
gmodule-2.0
sqlite3
)
pkg_check_modules(MAIN REQUIRED ${MAIN_PACKAGES})
vala_precompile(MAIN_VALA_C
SOURCES
src/main.vala
CUSTOM_VAPIS
${CMAKE_BINARY_DIR}/xmpp-vala/xmpp-vala.vapi
${CMAKE_BINARY_DIR}/qlite/qlite.vapi
${CMAKE_BINARY_DIR}/libdino/dino.vapi
PACKAGES
${MAIN_PACKAGES}
OPTIONS
--target-glib=2.38
-g
--thread
)
set(CFLAGS ${VALA_CFLAGS} ${MAIN_CFLAGS} -I${CMAKE_BINARY_DIR}/xmpp-vala -I${CMAKE_BINARY_DIR}/qlite -I${CMAKE_BINARY_DIR}/libdino)
add_definitions(${CFLAGS})
add_executable(dino ${MAIN_VALA_C})
add_dependencies(dino dino-vapi)
target_link_libraries(dino libdino)

20
main/src/main.vala Normal file
View file

@ -0,0 +1,20 @@
using Dino.Entities;
using Dino.Ui;
namespace Dino {
void main(string[] args) {
Gtk.init(ref args);
Dino.Ui.Application app = new Dino.Ui.Application();
PluginLoader loader = new PluginLoader();
foreach(string plugin in new string[]{}) {
try {
loader.load(plugin, app);
} catch (Dino.PluginError e) {
print(@"Error loading plugin $plugin: $(e.message)\n");
}
}
app.run(args);
}
}

View file

@ -34,7 +34,7 @@ OPTIONS
--vapidir=${CMAKE_SOURCE_DIR}/vapi --vapidir=${CMAKE_SOURCE_DIR}/vapi
) )
set(CFLAGS ${QLITE_CFLAGS} -g ${VALA_CFLAGS}) set(CFLAGS ${VALA_CFLAGS} ${QLITE_CFLAGS})
add_definitions(${CFLAGS}) add_definitions(${CFLAGS})
add_library(qlite SHARED ${QLITE_VALA_C}) add_library(qlite SHARED ${QLITE_VALA_C})
target_link_libraries(qlite ${QLITE_LIBRARIES}) target_link_libraries(qlite ${QLITE_LIBRARIES})

View file

@ -9,7 +9,7 @@ set(ENGINE_PACKAGES
gee-0.8 gee-0.8
gio-2.0 gio-2.0
glib-2.0 glib-2.0
gtk+-3.0 gdk-3.0
) )
pkg_check_modules(ENGINE REQUIRED ${ENGINE_PACKAGES}) pkg_check_modules(ENGINE REQUIRED ${ENGINE_PACKAGES})
@ -80,10 +80,10 @@ OPTIONS
--vapidir=${CMAKE_SOURCE_DIR}/vapi --vapidir=${CMAKE_SOURCE_DIR}/vapi
) )
set(CFLAGS ${ENGINE_CFLAGS} ${GPGME_CFLAGS} ${LIBUUID_CFLAGS} -g ${VALA_CFLAGS} -I${CMAKE_BINARY_DIR}/gpgme-vala) set(CFLAGS ${VALA_CFLAGS} ${ENGINE_CFLAGS} ${GPGME_CFLAGS} ${LIBUUID_CFLAGS} -I${CMAKE_BINARY_DIR}/gpgme-vala)
add_definitions(${CFLAGS}) add_definitions(${CFLAGS})
add_library(xmpp-vala SHARED ${ENGINE_VALA_C}) add_library(xmpp-vala SHARED ${ENGINE_VALA_C})
add_dependencies(xmpp-vala gpgme-vala gpgme-vapi) add_dependencies(xmpp-vala gpgme-vapi)
target_link_libraries(xmpp-vala gpgme-vala ${ENGINE_LIBRARIES} ${GPGME_LIBRARIES} ${LIBUUID_LIBRARIES}) target_link_libraries(xmpp-vala gpgme-vala ${ENGINE_LIBRARIES} ${GPGME_LIBRARIES} ${LIBUUID_LIBRARIES})
add_custom_target(xmpp-vala-vapi add_custom_target(xmpp-vala-vapi

Some files were not shown because too many files have changed in this diff Show more