Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial version #1

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig <http://EditorConfig.org>
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
33 changes: 33 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*~
build
34 changes: 34 additions & 0 deletions lib/Action.vala
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*/

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
);
}
}
82 changes: 82 additions & 0 deletions lib/Dispatcher.vala
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*/

public class Flux.Dispatcher : GLib.Object {
private static GLib.Once<Dispatcher> instance;

private GLib.List<Flux.Middleware> middlewares;
private GLib.List<Flux.Store> stores;
private GLib.Queue<Flux.Action> actions;
private GLib.Mutex mutex;

private signal void new_action_added ();

private Dispatcher () {
middlewares = new GLib.List<Flux.Middleware> ();
stores = new GLib.List<Flux.Store> ();
actions = new GLib.Queue<Flux.Action> ();
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 ();
}
}
24 changes: 24 additions & 0 deletions lib/Middleware.vala
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*/

public abstract class Flux.Middleware : GLib.Object {
public abstract void process (Flux.Action action);
}
22 changes: 22 additions & 0 deletions lib/Payload.vala
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*/

public class Flux.Payload : GLib.Object {}
24 changes: 24 additions & 0 deletions lib/Store.vala
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*/

public abstract class Flux.Store : GLib.Object {
public abstract void process (Flux.Action action);
}
3 changes: 3 additions & 0 deletions lib/flux.deps
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gio-2.0
glib-2.0
json-glib-1.0
83 changes: 83 additions & 0 deletions lib/meson.build
Original file line number Diff line number Diff line change
@@ -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',
)
10 changes: 10 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -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')
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
option('introspection', type: 'boolean', value: true, description: 'Whether to build introspection files')