Skip to content

Commit b31cb40

Browse files
committed
Update API. Add IPC trigger module.
1 parent 799aae5 commit b31cb40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2072
-1833
lines changed

CHANGELOG.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ All notable changes to the project will be documented in this file.
77
## Library
88

99
* `Added` error codes
10-
* `Added` _fortran-nng_ interface bindings to NNG to `vendor/`
10+
* `Added` _fortran-nng_ interface bindings to `vendor/`
1111
* `Added` module `dm_arg_parser` (outsourced from `dm_arg`)
1212
* `Added` module `dm_group` for observation groups
1313
* `Added` module `dm_ipc` for socket access
@@ -16,16 +16,21 @@ All notable changes to the project will be documented in this file.
1616
* `Added` module `dm_ipc_message` for message handling
1717
* `Added` module `dm_ipc_mutex` for mutex access
1818
* `Added` module `dm_ipc_thread` for thread access
19+
* `Added` module `dm_ipc_trigger` for locked triggers
1920
* `Added` module `dm_ipc_type` of IPC enumerators
2021
* `Added` module `dm_job_list` (outsourced from `dm_job`)
22+
* `Changed` location of sleep routines (moved to `dm_posix`)
2123
* `Changed` names of modules `dm_fifo`, `dm_mqueue`, `dm_mqueue_util`, `dm_pipe`,
2224
`dm_sem`, `dm_signal`, `dm_thread`, `dm_tty` to include `posix` prefix
2325
* `Changed` name of module `dm_system` to `dm_posix`
24-
* `Changed` database schema due to new data models
26+
* `Changed` database schema due to new data model
2527
* `Changed` default database suffix from `.sqlite` to `.db`
2628
* `Changed` GeoCOM API for Lua to accept prototype observation as first argument
27-
* `Changed` model of observation data structure `dm_observ`
28-
* `Deleted` model of request data strucutre `dm_request`
29+
* `Changed` log levels in `dm_log`
30+
* `Changed` model of observation data structure in `dm_observ`, removed requests
31+
and receivers
32+
* `Changed` model of sensor data structure in `dm_sensor`
33+
* `Deleted` module `dm_request`
2934

3035
## Programs
3136

Makefile

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ RELEASE = -O2 -mtune=native
156156
INCHDF5 = `pkg-config --cflags hdf5`
157157

158158
# Common build options.
159-
FFLAGS = $(RELEASE) $(INCHDF5) -ffree-line-length-0 -std=f2018
159+
FFLAGS = $(RELEASE) $(INCHDF5) -frecursive -ffree-line-length-0 -std=f2018
160160
CFLAGS = $(RELEASE) -I$(PREFIX)/include
161+
#CFLAGS = $(RELEASE) -I$(PREFIX)/include -I/opt/include
161162
LIBFLAGS = -fPIC
162163
MODFLAGS = -I$(INCDIR) -J$(INCDIR)
163164
PPFLAGS = -cpp -D__$(OS)__
@@ -174,6 +175,7 @@ LIBHDF5 = `pkg-config --libs hdf5` -lhdf5_fortran
174175
LIBLAPACK = `pkg-config --libs-only-l lapack blas`
175176
LIBLUA54 = `pkg-config --libs-only-l lua-5.4`
176177
LIBNNG = -lnng
178+
#LIBNNG = -Wl,-rpath=/opt/lib -L/opt/lib -lnng
177179
LIBMODBUS = `pkg-config --libs-only-l libmodbus`
178180
LIBPCRE2 = `pkg-config --libs-only-l libpcre2-8`
179181
LIBPTHREAD = -lpthread
@@ -208,6 +210,7 @@ DMAPI = $(DISTDIR)/dmapi
208210
DMBACKUP = $(DISTDIR)/dmbackup
209211
DMBEAT = $(DISTDIR)/dmbeat
210212
DMBOT = $(DISTDIR)/dmbot
213+
DMBROKER = $(DISTDIR)/dmbroker
211214
DMCAMERA = $(DISTDIR)/dmcamera
212215
DMDB = $(DISTDIR)/dmdb
213216
DMDBCTL = $(DISTDIR)/dmdbctl
@@ -296,6 +299,7 @@ SRC = $(SRCDIR)/dm_ansi.f90 \
296299
$(SRCDIR)/dm_ipc_message.f90 \
297300
$(SRCDIR)/dm_ipc_mutex.f90 \
298301
$(SRCDIR)/dm_ipc_thread.f90 \
302+
$(SRCDIR)/dm_ipc_trigger.f90 \
299303
$(SRCDIR)/dm_ipc_type.f90 \
300304
$(SRCDIR)/dm_job.f90 \
301305
$(SRCDIR)/dm_job_list.f90 \
@@ -425,6 +429,7 @@ OBJ = dm_ansi.o \
425429
dm_ipc_message.o \
426430
dm_ipc_mutex.o \
427431
dm_ipc_thread.o \
432+
dm_ipc_trigger.o \
428433
dm_ipc_type.o \
429434
dm_job.o \
430435
dm_job_list.o \
@@ -525,6 +530,7 @@ app: $(DMAPI) \
525530
$(DMBACKUP) \
526531
$(DMBEAT) \
527532
$(DMBOT) \
533+
$(DMBROKER) \
528534
$(DMCAMERA) \
529535
$(DMDB) \
530536
$(DMDBCTL) \
@@ -902,6 +908,9 @@ dm_ipc_mutex.o: $(SRCDIR)/dm_ipc_mutex.f90
902908
dm_ipc_thread.o: $(SRCDIR)/dm_ipc_thread.f90
903909
$(FC) $(FFLAGS) $(LIBFLAGS) $(MODFLAGS) -c $(SRCDIR)/dm_ipc_thread.f90
904910

911+
dm_ipc_trigger.o: $(SRCDIR)/dm_ipc_trigger.f90
912+
$(FC) $(FFLAGS) $(LIBFLAGS) $(MODFLAGS) -c $(SRCDIR)/dm_ipc_trigger.f90
913+
905914
dm_ipc_type.o: $(SRCDIR)/dm_ipc_type.f90
906915
$(FC) $(FFLAGS) $(LIBFLAGS) $(MODFLAGS) -c $(SRCDIR)/dm_ipc_type.f90
907916

@@ -1232,10 +1241,11 @@ $(TARGET): $(SRC)
12321241
@$(MAKE) dm_filter.o
12331242
@$(MAKE) dm_ipc_type.o
12341243
@$(MAKE) dm_ipc.o
1235-
@$(MAKE) dm_ipc_disco.o
12361244
@$(MAKE) dm_ipc_message.o
1245+
@$(MAKE) dm_ipc_disco.o
12371246
@$(MAKE) dm_ipc_async.o
12381247
@$(MAKE) dm_ipc_mutex.o
1248+
@$(MAKE) dm_ipc_trigger.o
12391249
@$(MAKE) dm_ipc_thread.o
12401250
@$(MAKE) dmpack.o
12411251
$(AR) $(ARFLAGS) $(THIN) $(OBJ)
@@ -1464,6 +1474,9 @@ $(DMBEAT): $(APPDIR)/dmbeat.f90 $(TARGET)
14641474
$(DMBOT): $(APPDIR)/dmbot.f90 $(TARGET)
14651475
$(FC) $(FFLAGS) $(MODFLAGS) $(LDFLAGS) -o $(DMBOT) $(APPDIR)/dmbot.f90 $(TARGET) $(LIBLUA54) $(LIBSQLITE3) $(LIBCURL) $(LIBSTROPHE) $(LIBRT) $(LDLIBS)
14661476

1477+
$(DMBROKER): $(APPDIR)/dmbroker.f90 $(TARGET)
1478+
$(FC) $(FFLAGS) $(MODFLAGS) $(LDFLAGS) -o $(DMBROKER) $(APPDIR)/dmbroker.f90 $(TARGET) $(LIBLUA54) $(LIBNNG) $(LIBSQLITE3) $(LIBPTHREAD) $(LIBRT) $(LDLIBS)
1479+
14671480
$(DMCAMERA): $(APPDIR)/dmcamera.f90 $(TARGET)
14681481
$(FC) $(FFLAGS) $(MODFLAGS) $(LDFLAGS) -o $(DMCAMERA) $(APPDIR)/dmcamera.f90 $(TARGET) $(LIBLUA54) $(LIBSQLITE3) $(LIBPTHREAD) $(LIBRT) $(LDLIBS)
14691482

@@ -1599,6 +1612,7 @@ install:
15991612
$(INSTALL) -m 755 $(DMBACKUP) $(IBINDIR)/
16001613
$(INSTALL) -m 755 $(DMBEAT) $(IBINDIR)/
16011614
$(INSTALL) -m 755 $(DMBOT) $(IBINDIR)/
1615+
$(INSTALL) -m 755 $(DMBROKER) $(IBINDIR)/
16021616
$(INSTALL) -m 755 $(DMCAMERA) $(IBINDIR)/
16031617
$(INSTALL) -m 755 $(DMDB) $(IBINDIR)/
16041618
$(INSTALL) -m 755 $(DMDBCTL) $(IBINDIR)/
@@ -1648,6 +1662,7 @@ install:
16481662
$(GZIP) -9 < $(MANDIR)/dmbackup.1 > $(IMANDIR)/dmbackup.1.gz
16491663
$(GZIP) -9 < $(MANDIR)/dmbeat.1 > $(IMANDIR)/dmbeat.1.gz
16501664
$(GZIP) -9 < $(MANDIR)/dmbot.1 > $(IMANDIR)/dmbot.1.gz
1665+
$(GZIP) -9 < $(MANDIR)/dmbroker.1 > $(IMANDIR)/dmbroker.1.gz
16511666
$(GZIP) -9 < $(MANDIR)/dmcamera.1 > $(IMANDIR)/dmcamera.1.gz
16521667
$(GZIP) -9 < $(MANDIR)/dmdb.1 > $(IMANDIR)/dmdb.1.gz
16531668
$(GZIP) -9 < $(MANDIR)/dmdbctl.1 > $(IMANDIR)/dmdbctl.1.gz
@@ -1688,6 +1703,7 @@ deinstall:
16881703
@$(RM) -f $(IBINDIR)/dmbackup
16891704
@$(RM) -f $(IBINDIR)/dmbeat
16901705
@$(RM) -f $(IBINDIR)/dmbot
1706+
@$(RM) -f $(IBINDIR)/dmbroker
16911707
@$(RM) -f $(IBINDIR)/dmcamera
16921708
@$(RM) -f $(IBINDIR)/dmdb
16931709
@$(RM) -f $(IBINDIR)/dmdbctl
@@ -1720,6 +1736,7 @@ deinstall:
17201736
@$(RM) -f $(IMANDIR)/dmbackup.1.gz
17211737
@$(RM) -f $(IMANDIR)/dmbeat.1.gz
17221738
@$(RM) -f $(IMANDIR)/dmbot.1.gz
1739+
@$(RM) -f $(IMANDIR)/dmbroker.1.gz
17231740
@$(RM) -f $(IMANDIR)/dmcamera.1.gz
17241741
@$(RM) -f $(IMANDIR)/dmdb.1.gz
17251742
@$(RM) -f $(IMANDIR)/dmdbctl.1.gz

app/dmapi.f90

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ subroutine route_beat(env)
179179
if (env%request_method == 'POST') then
180180
! Abort in read-only mode.
181181
if (read_only) then
182-
call api_response(HTTP_SERVICE_UNAVAILABLE, 'read-only mode', E_PERM)
182+
call api_response(HTTP_SERVICE_UNAVAILABLE, 'read-only mode', E_ACCESS)
183183
exit response_block
184184
end if
185185

@@ -431,7 +431,7 @@ subroutine route_image(env)
431431
end if
432432

433433
if (.not. dm_file_is_writeable(image_dir)) then
434-
call api_response(HTTP_SERVICE_UNAVAILABLE, 'no write permission to image directory', E_PERM)
434+
call api_response(HTTP_SERVICE_UNAVAILABLE, 'no write permission to image directory', E_ACCESS)
435435
return
436436
end if
437437

@@ -450,7 +450,7 @@ subroutine route_image(env)
450450
case ('POST')
451451
! Abort in read-only mode.
452452
if (read_only) then
453-
call api_response(HTTP_SERVICE_UNAVAILABLE, 'read-only mode', E_PERM)
453+
call api_response(HTTP_SERVICE_UNAVAILABLE, 'read-only mode', E_ACCESS)
454454
exit method_select
455455
end if
456456

@@ -568,7 +568,7 @@ subroutine route_image(env)
568568
case ('PUT')
569569
! Abort in read-only mode.
570570
if (read_only) then
571-
call api_response(HTTP_SERVICE_UNAVAILABLE, 'read-only mode', E_PERM)
571+
call api_response(HTTP_SERVICE_UNAVAILABLE, 'read-only mode', E_ACCESS)
572572
exit method_select
573573
end if
574574

@@ -751,7 +751,7 @@ subroutine route_log(env)
751751
! ------------------------------------------------------------------
752752
if (env%request_method == 'POST') then
753753
if (read_only) then
754-
call api_response(HTTP_SERVICE_UNAVAILABLE, 'read-only mode', E_PERM)
754+
call api_response(HTTP_SERVICE_UNAVAILABLE, 'read-only mode', E_ACCESS)
755755
exit response_block
756756
end if
757757

@@ -1053,7 +1053,7 @@ subroutine route_node(env)
10531053
if (env%request_method == 'POST') then
10541054
! Abort in read-only mode.
10551055
if (read_only) then
1056-
call api_response(HTTP_SERVICE_UNAVAILABLE, 'read-only mode', E_PERM)
1056+
call api_response(HTTP_SERVICE_UNAVAILABLE, 'read-only mode', E_ACCESS)
10571057
exit response_block
10581058
end if
10591059

@@ -1302,7 +1302,7 @@ subroutine route_observ(env)
13021302
if (env%request_method == 'POST') then
13031303
! Abort in read-only mode.
13041304
if (read_only) then
1305-
call api_response(HTTP_SERVICE_UNAVAILABLE, 'read-only mode', E_PERM)
1305+
call api_response(HTTP_SERVICE_UNAVAILABLE, 'read-only mode', E_ACCESS)
13061306
exit response_block
13071307
end if
13081308

@@ -1676,7 +1676,7 @@ subroutine route_sensor(env)
16761676
if (env%request_method == 'POST') then
16771677
! Abort in read-only mode.
16781678
if (read_only) then
1679-
call api_response(HTTP_SERVICE_UNAVAILABLE, 'read-only mode', E_PERM)
1679+
call api_response(HTTP_SERVICE_UNAVAILABLE, 'read-only mode', E_ACCESS)
16801680
exit response_block
16811681
end if
16821682

@@ -1926,7 +1926,7 @@ subroutine route_target(env)
19261926
if (env%request_method == 'POST') then
19271927
! Abort in read-only mode.
19281928
if (read_only) then
1929-
call api_response(HTTP_SERVICE_UNAVAILABLE, 'read-only mode', E_PERM)
1929+
call api_response(HTTP_SERVICE_UNAVAILABLE, 'read-only mode', E_ACCESS)
19301930
exit response_block
19311931
end if
19321932

app/dmbeat.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ integer function run(app) result(rc)
180180
msec = max(0, int(1000 * (app%interval - dm_timer_result(timer))))
181181
sec = dm_msec_to_sec(msec)
182182
call logger%debug('next beat in ' // dm_itoa(sec) // ' sec')
183-
call dm_msleep(msec)
183+
call dm_posix_msleep(msec)
184184
end do emit_loop
185185

186186
call dm_rpc_destroy(request)

app/dmbot.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ program dmbot
140140
call logger%error('failed to connect to ' // trim(bot%host) // ':' // dm_itoa(bot%port), error=rc)
141141
if (.not. bot%reconnect) exit
142142
call logger%debug('reconnecting in 30 sec')
143-
call dm_sleep(30)
143+
call dm_posix_sleep(30)
144144
cycle
145145
end if
146146

@@ -782,7 +782,7 @@ function message_callback(connection, stanza, user_data) bind(c)
782782
if (bot_is_authorized(bot%group, from)) then
783783
reply = bot_dispatch(bot, from, text)
784784
else
785-
call logger%warning('unauthorized access by ' // from, error=E_PERM)
785+
call logger%warning('unauthorized access by ' // from, error=E_ACCESS)
786786
reply = 'unauthorized'
787787
end if
788788

0 commit comments

Comments
 (0)