Skip to content

Commit e9f3a9a

Browse files
committed
Implement plugin system
This commit uses libpeas to support pluggable hardware support and splits the Arduino interface code into its own cable module.
1 parent de67664 commit e9f3a9a

16 files changed

+912
-175
lines changed

Diff for: Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ SUBDIRS = src test
55
MAINTAINERCLEANFILES = \
66
$(GITIGNORE_MAINTAINERCLEANFILES_TOPLEVEL) \
77
$(GITIGNORE_MAINTAINERCLEANFILES_MAKEFILE_IN) \
8+
$(GITIGNORE_MAINTAINERCLEANFILES_M4_LIBTOOL) \
89
m4/pkg.m4
910

1011
EXTRA_DIST = autogen.sh

Diff for: configure.ac

+34-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AC_INIT([spi-dump], [0.2])
1+
AC_INIT([spi-dump], [0.3])
22

33
AC_CONFIG_AUX_DIR([build-aux])
44
AC_CONFIG_MACRO_DIR([m4])
@@ -9,33 +9,57 @@ AM_SILENT_RULES([yes])
99
AM_PROG_VALAC([0.28])
1010
AM_PROG_CC_C_O
1111

12-
CFLAGS="$CFLAGS -w"
1312
AC_PROG_LN_S
1413

14+
LT_INIT([disable-static])
15+
16+
AC_SUBST([plugindir], ["\$(libdir)/spi-dump/plugins"])
17+
18+
AC_SUBST([AM_CFLAGS], ["\
19+
-Wall -Wextra \
20+
-Wno-unused-function \
21+
-Wno-unused-parameter \
22+
-Wno-unused-variable -Wno-unused-but-set-variable \
23+
\$(NULL)"])
1524

1625
dnl ###########################################################################
1726
dnl Dependencies
1827
dnl ###########################################################################
1928

2029
GLIB_REQUIRED=2.40.0
2130

22-
PKG_CHECK_MODULES(spi_dump_U, [
31+
PKG_CHECK_MODULES(glib_U, [
2332
glib-2.0 >= $GLIB_REQUIRED
2433
gobject-2.0 >= $GLIB_REQUIRED
2534
gio-2.0 >= $GLIB_REQUIRED
2635
gio-unix-2.0 >= $GLIB_REQUIRED
36+
])
37+
38+
PKG_CHECK_MODULES(peas_U, [libpeas-1.0])
39+
40+
PKG_CHECK_MODULES(spi_dump_U, [
2741
zlib
2842
ncurses
2943
])
3044

31-
AC_SUBST([spi_dump_U_VALAFLAGS], ["--pkg gio-2.0 \
45+
AC_SUBST([AM_VALAFLAGS], ["\
46+
--fatal-warnings \
47+
--enable-checking \
48+
--enable-experimental-non-null \
49+
\$(NULL)"])
50+
51+
AC_SUBST([glib_U_VALAFLAGS], ["\
52+
--pkg gio-2.0 \
3253
--pkg gio-unix-2.0 \
54+
--target-glib=$GLIB_REQUIRED \
55+
\$(NULL)"])
56+
57+
AC_SUBST([peas_U_VALAFLAGS], ["--pkg libpeas-1.0"])
58+
59+
AC_SUBST([spi_dump_U_VALAFLAGS], ["\
3360
--pkg posix \
3461
--pkg zlib \
35-
--target-glib=$GLIB_REQUIRED \
36-
--fatal-warnings \
37-
--enable-checking \
38-
--enable-experimental-non-null"])
62+
\$(NULL)"])
3963

4064
dnl ###########################################################################
4165
dnl Files to generate
@@ -44,6 +68,8 @@ dnl ###########################################################################
4468
AC_CONFIG_FILES([
4569
Makefile
4670
src/Makefile
71+
src/libplugin/Makefile
72+
src/plugins/Makefile
4773
test/Makefile
4874
])
4975
AC_OUTPUT

Diff for: src/Makefile.am

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
1+
SUBDIRS = libplugin plugins
2+
13
bin_PROGRAMS = spi-dump
24

35
spi_dump_SOURCES = \
6+
libplugin/libspi-dump-plugin.vapi \
47
progressbar/progressbar.c \
58
progressbar/progressbar.vapi \
6-
tty.vala \
9+
plugin-engine.vala \
710
transfer.vala \
811
spi-dump.vala
912

10-
spi_dump_VALAFLAGS = $(spi_dump_U_VALAFLAGS)
13+
spi_dump_VALAFLAGS = \
14+
$(AM_VALAFLAGS) \
15+
$(glib_U_VALAFLAGS) \
16+
$(peas_U_VALAFLAGS) \
17+
$(spi_dump_U_VALAFLAGS)
1118

12-
spi_dump_CFLAGS = $(spi_dump_U_CFLAGS)
19+
spi_dump_CFLAGS = \
20+
-Ilibplugin \
21+
-DPLUGINDIR=\"$(plugindir)\" \
22+
$(AM_CFLAGS) \
23+
$(glib_U_CFLAGS) \
24+
$(peas_U_CFLAGS) \
25+
$(spi_dump_U_CFLAGS)
1326

1427
spi_dump_LDADD = \
1528
-lm \
29+
libplugin/libspi-dump-plugin.la \
30+
$(glib_U_LIBS) \
31+
$(peas_U_LIBS) \
1632
$(spi_dump_U_LIBS)
1733

1834
-include $(top_srcdir)/git.mk

Diff for: src/libplugin/Makefile.am

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
lib_LTLIBRARIES = libspi-dump-plugin.la
2+
3+
BUILT_SOURCES = \
4+
libspi-dump-plugin.h \
5+
libspi-dump-plugin.vapi
6+
7+
libspi_dump_plugin_la_SOURCES = libspi-dump-plugin.vala
8+
9+
libspi_dump_plugin_la_VALAFLAGS = \
10+
--library libspi-dump-plugin \
11+
-H libspi-dump-plugin.h \
12+
--vapi libspi-dump-plugin.vapi \
13+
$(AM_VALAFLAGS) \
14+
$(glib_U_VALAFLAGS)
15+
16+
libspi_dump_plugin_la_CFLAGS = \
17+
$(AM_CFLAGS) \
18+
$(glib_U_CFLAGS)
19+
20+
libspi_dump_plugin_la_LIBADD = $(glib_U_LIBS)
21+
22+
-include $(top_srcdir)/git.mk

Diff for: src/libplugin/libspi-dump-plugin.vala

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
namespace SpiDump {
2+
public enum PinState {
3+
LOW, HIGH
4+
}
5+
6+
public errordomain HardwarePluginError {
7+
INVALID_ARGS
8+
}
9+
10+
public interface DeviceInputStream : InputStream {
11+
public new async void read_all (uint8[] buffer) throws Error {
12+
yield this.read_all_async (buffer, Priority.DEFAULT, null, null);
13+
}
14+
15+
public async uint8 read_byte () throws Error {
16+
var ret = new uint8[1];
17+
yield read_all (ret);
18+
return ret[0];
19+
}
20+
21+
public async void skip (ssize_t length) throws IOError {
22+
yield this.skip_async (length);
23+
}
24+
}
25+
26+
public class SimpleDeviceInputStream : InputStream, DeviceInputStream {
27+
public InputStream inner {construct; get;}
28+
29+
public override bool close (Cancellable? cancellable = null)
30+
throws IOError
31+
{
32+
return inner.close (cancellable);
33+
}
34+
35+
public override async bool close_async (
36+
int io_priority = Priority.DEFAULT,
37+
Cancellable? cancellable = null
38+
)
39+
throws IOError
40+
{
41+
return yield inner.close_async ();
42+
}
43+
44+
public override ssize_t skip (
45+
size_t count,
46+
Cancellable? cancellable = null
47+
)
48+
throws IOError
49+
{
50+
return inner.skip (count, cancellable);
51+
}
52+
53+
public override async ssize_t skip_async (
54+
size_t count,
55+
int io_priority = Priority.DEFAULT,
56+
Cancellable? cancellable = null
57+
)
58+
throws IOError
59+
{
60+
return yield inner.skip_async (count, io_priority, cancellable);
61+
}
62+
63+
public override ssize_t read (
64+
uint8[] buffer,
65+
Cancellable? cancellable = null
66+
)
67+
throws IOError
68+
{
69+
return inner.read (buffer, cancellable);
70+
}
71+
72+
public override async ssize_t read_async (
73+
uint8[]? buffer,
74+
int io_priority = Priority.DEFAULT,
75+
Cancellable? cancellable = null
76+
)
77+
throws IOError
78+
{
79+
return yield inner.read_async (buffer, io_priority, cancellable);
80+
}
81+
82+
public SimpleDeviceInputStream (InputStream inner) {
83+
Object (inner: inner);
84+
}
85+
}
86+
87+
public interface DeviceOutputStream : OutputStream {
88+
public new async void write_all (uint8[] buffer) throws Error {
89+
yield this.write_all_async (buffer, Priority.DEFAULT, null, null);
90+
}
91+
}
92+
93+
public class SimpleDeviceOutputStream : OutputStream, DeviceOutputStream {
94+
public OutputStream inner {construct; get;}
95+
96+
public override bool close (Cancellable? cancellable = null)
97+
throws IOError
98+
{
99+
return inner.close (cancellable);
100+
}
101+
102+
public override async bool close_async (
103+
int io_priority = Priority.DEFAULT,
104+
Cancellable? cancellable = null
105+
)
106+
throws IOError
107+
{
108+
return yield inner.close_async ();
109+
}
110+
111+
public override bool flush (Cancellable? cancellable = null)
112+
throws Error
113+
{
114+
return inner.flush (cancellable);
115+
}
116+
117+
public override async bool flush_async (
118+
int io_priority = Priority.DEFAULT,
119+
Cancellable? cancellable = null
120+
)
121+
throws Error
122+
{
123+
return yield inner.flush_async (io_priority, cancellable);
124+
}
125+
126+
public override ssize_t write (
127+
uint8[] buffer,
128+
Cancellable? cancellable = null
129+
)
130+
throws IOError
131+
{
132+
return inner.write (buffer, cancellable);
133+
}
134+
135+
public override async ssize_t write_async (
136+
uint8[]? buffer,
137+
int io_priority = Priority.DEFAULT,
138+
Cancellable? cancellable = null
139+
)
140+
throws IOError
141+
{
142+
return yield inner.write_async (buffer, io_priority, cancellable);
143+
}
144+
145+
public SimpleDeviceOutputStream (OutputStream inner) {
146+
Object (inner: inner);
147+
}
148+
}
149+
150+
public abstract class DeviceIOStream : Object {
151+
public DeviceInputStream @in {construct; get;}
152+
public DeviceOutputStream @out {construct; get;}
153+
154+
public abstract async void set_chip_select (PinState state)
155+
throws Error;
156+
}
157+
158+
public interface HardwarePlugin : Object {
159+
[CCode (array_length = false, array_null_terminated = true)]
160+
public abstract OptionEntry[] get_options ();
161+
public abstract DeviceIOStream open () throws Error;
162+
}
163+
}

0 commit comments

Comments
 (0)