diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c0d4437 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +# EditorConfig +root = true + +# elementary defaults +[*] +charset = utf-8 +end_of_line = lf +indent_size = tab +indent_style = space +insert_final_newline = true +max_line_length = 80 +tab_width = 4 +trim_trailing_whitespace = true + +[{*.xml,*.xml.in,*.yml}] +tab_width = 2 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..88cb78b --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,33 @@ +name: CI + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + + container: + image: elementary/docker:unstable + + steps: + - uses: actions/checkout@v1 + - name: Install Dependencies + run: | + apt update + apt install -y meson valac + - name: Build + env: + DESTDIR: out + run: | + meson build + ninja -C build + ninja -C build install + + lint: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - uses: elementary/actions/vala-lint@master diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bdc5af0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*~ +build diff --git a/lib/Action.vala b/lib/Action.vala new file mode 100644 index 0000000..c27569b --- /dev/null +++ b/lib/Action.vala @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021 Manexim (https://github.com/manexim) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authored by: Marius Meisenzahl + */ + +public class Flux.Action : GLib.Object { + public string action_type { get; construct set; } + public Flux.Payload payload { get; construct set; } + public bool error { get; construct set; } + + public Action (string action_type, Flux.Payload payload, bool error = false) { + GLib.Object ( + action_type: action_type, + payload: payload, + error: error + ); + } +} diff --git a/lib/Dispatcher.vala b/lib/Dispatcher.vala new file mode 100644 index 0000000..476dd89 --- /dev/null +++ b/lib/Dispatcher.vala @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2021 Manexim (https://github.com/manexim) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authored by: Marius Meisenzahl + */ + +public class Flux.Dispatcher : GLib.Object { + private static GLib.Once instance; + + private GLib.List middlewares; + private GLib.List stores; + private GLib.Queue actions; + private GLib.Mutex mutex; + + private signal void new_action_added (); + + private Dispatcher () { + middlewares = new GLib.List (); + stores = new GLib.List (); + actions = new GLib.Queue (); + mutex = GLib.Mutex (); + + new_action_added.connect (on_new_action_added); + } + + public static unowned Dispatcher get_instance () { + return instance.once (() => { + return new Dispatcher (); + }); + } + + public void dispatch (Flux.Action action) { + new GLib.MutexLocker (mutex); + actions.push_tail (action); + + new_action_added (); + } + + public void register_middleware (Flux.Middleware middleware) { + middlewares.append (middleware); + } + + public void register_store (Flux.Store store) { + stores.append (store); + } + + private void on_new_action_added () { + mutex.lock (); + + Flux.Action action = null; + while ((action = actions.pop_head ()) != null) { + mutex.unlock (); + + middlewares.foreach ((middleware) => { + middleware.process (action); + }); + + stores.foreach ((store) => { + store.process (action); + }); + + mutex.lock (); + } + + mutex.unlock (); + } +} diff --git a/lib/Middleware.vala b/lib/Middleware.vala new file mode 100644 index 0000000..eefedd0 --- /dev/null +++ b/lib/Middleware.vala @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021 Manexim (https://github.com/manexim) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authored by: Marius Meisenzahl + */ + +public abstract class Flux.Middleware : GLib.Object { + public abstract void process (Flux.Action action); +} diff --git a/lib/Payload.vala b/lib/Payload.vala new file mode 100644 index 0000000..2de44f6 --- /dev/null +++ b/lib/Payload.vala @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2021 Manexim (https://github.com/manexim) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authored by: Marius Meisenzahl + */ + +public class Flux.Payload : GLib.Object {} diff --git a/lib/Store.vala b/lib/Store.vala new file mode 100644 index 0000000..2a5fb74 --- /dev/null +++ b/lib/Store.vala @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021 Manexim (https://github.com/manexim) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authored by: Marius Meisenzahl + */ + +public abstract class Flux.Store : GLib.Object { + public abstract void process (Flux.Action action); +} diff --git a/lib/flux.deps b/lib/flux.deps new file mode 100644 index 0000000..f76fc9a --- /dev/null +++ b/lib/flux.deps @@ -0,0 +1,3 @@ +gio-2.0 +glib-2.0 +json-glib-1.0 diff --git a/lib/meson.build b/lib/meson.build new file mode 100644 index 0000000..0c984ef --- /dev/null +++ b/lib/meson.build @@ -0,0 +1,83 @@ +libflux_sources = files( + 'Action.vala', + 'Dispatcher.vala', + 'Middleware.vala', + 'Payload.vala', + 'Store.vala', +) + +# define all the names and versions +flux_gi_name = 'flux' +flux_gi_version = '1.0' + +flux_gi = flux_gi_name + '-' + flux_gi_version +flux_gir = flux_gi + '.gir' +flux_typelib = flux_gi + '.typelib' + +include_dir = join_paths( + get_option('prefix'), + get_option('includedir'), + 'flux' +) + +# compile shared library, generate GIR, header, and vapi file +libflux = library( + 'flux', + + libflux_sources, + + dependencies: [ + libflux_deps, + ], + + vala_header: 'flux.h', + vala_vapi: 'flux.vapi', + vala_gir: flux_gir, + + version: meson.project_version(), + install: true, + install_dir: [true, include_dir, true, true], +) + +install_data( + 'flux.deps', + install_dir: join_paths(get_option('datadir'), 'vala', 'vapi') +) + +if get_option('introspection') + # typelib generation isn't automated yet + g_ir_compiler = find_program('g-ir-compiler') + custom_target( + flux_typelib, + command: [ + g_ir_compiler, + '--shared-library', + '@PLAINNAME@', + '--output', + '@OUTPUT@', + join_paths(meson.current_build_dir(), flux_gir), + ], + input: libflux, + output: flux_typelib, + depends: libflux, + install: true, + install_dir: join_paths(get_option('libdir'), 'girepository-1.0'), + ) +endif + +libflux_dep = declare_dependency( + link_with: libflux, + dependencies: libflux_deps, + include_directories: [include_directories('.')], +) + +# generate pkgconfig file +flux_pc = pkgconfig.generate( + libflux, + name: 'flux', + requires: libflux_deps, + subdirs: ['flux'], + description: 'Application architecture for building user interfaces with Vala', + version: meson.project_version(), + url: 'https://github.com/manexim/flux', +) diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..e4b1836 --- /dev/null +++ b/meson.build @@ -0,0 +1,10 @@ +project('flux', 'vala', 'c', version: '1.0.0') + +libflux_deps = [ + dependency('gio-2.0'), + dependency('glib-2.0'), +] + +pkgconfig = import('pkgconfig') + +subdir('lib') diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..30e4104 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1 @@ +option('introspection', type: 'boolean', value: true, description: 'Whether to build introspection files')