Skip to content

Commit 9c7f943

Browse files
committed
Update sensor model. Add IPC async module.
1 parent 0c2aa77 commit 9c7f943

27 files changed

+787
-283
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ dist/
55
doc/
66
dump/
77
env/
8-
guide/html/
8+
guide/dist/
99
include/
1010
lib/
1111

@@ -19,12 +19,14 @@ lib/
1919
*.html
2020
*.json
2121
*.mod
22+
*.ms
2223
*.o
2324
*.pdf
2425
*.so
2526
*.sql
2627
*.sqlite
2728
*.swp
29+
*.troff
2830
config/*.conf
2931
config/*.config
3032
favicon.png

CHANGELOG.md

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

99
* `Added` error codes
10-
* `Added` interface bindings to NNG
10+
* `Added` _fortran-nng_ interface bindings to NNG to `vendor/`
1111
* `Added` module `dm_arg_parser` (outsourced from `dm_arg`)
1212
* `Added` module `dm_group` for observation groups
13-
* `Added` module `dm_ipc` for NNG socket access
14-
* `Added` module `dm_ipc_message` for NNG message handling
15-
* `Added` module `dm_ipc_mutex` for NNG mutex access
16-
* `Added` module `dm_ipc_thread` for NNG thread access
13+
* `Added` module `dm_ipc` for socket access
14+
* `Added` module `dm_ipc_async` for asynchronous I/O
15+
* `Added` module `dm_ipc_disco` for service discovery
16+
* `Added` module `dm_ipc_message` for message handling
17+
* `Added` module `dm_ipc_mutex` for mutex access
18+
* `Added` module `dm_ipc_thread` for thread access
19+
* `Added` module `dm_ipc_type` of IPC enumerators
1720
* `Added` module `dm_job_list` (outsourced from `dm_job`)
1821
* `Changed` names of modules `dm_fifo`, `dm_mqueue`, `dm_mqueue_util`, `dm_pipe`,
1922
`dm_sem`, `dm_signal`, `dm_thread`, `dm_tty` to include `posix` prefix
2023
* `Changed` name of module `dm_system` to `dm_posix`
21-
* `Changed` database schema
24+
* `Changed` database schema due to new data models
2225
* `Changed` default database suffix from `.sqlite` to `.db`
2326
* `Changed` GeoCOM API for Lua to accept prototype observation as first argument
2427
* `Changed` model of observation data structure `dm_observ`

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ SRC = $(SRCDIR)/dm_ansi.f90 \
291291
$(SRCDIR)/dm_im.f90 \
292292
$(SRCDIR)/dm_image.f90 \
293293
$(SRCDIR)/dm_ipc.f90 \
294+
$(SRCDIR)/dm_ipc_async.f90 \
294295
$(SRCDIR)/dm_ipc_disco.f90 \
295296
$(SRCDIR)/dm_ipc_message.f90 \
296297
$(SRCDIR)/dm_ipc_mutex.f90 \
@@ -419,6 +420,7 @@ OBJ = dm_ansi.o \
419420
dm_im.o \
420421
dm_image.o \
421422
dm_ipc.o \
423+
dm_ipc_async.o \
422424
dm_ipc_disco.o \
423425
dm_ipc_message.o \
424426
dm_ipc_mutex.o \
@@ -577,6 +579,7 @@ test: dmtestapi \
577579
dmtesthtml \
578580
dmtestid \
579581
dmtestipc \
582+
dmtestipcasync \
580583
dmtestipcmutex \
581584
dmtestipcthread \
582585
dmtestjob \
@@ -884,6 +887,9 @@ dm_image.o: $(SRCDIR)/dm_image.f90
884887
dm_ipc.o: $(SRCDIR)/dm_ipc.f90
885888
$(FC) $(FFLAGS) $(LIBFLAGS) $(MODFLAGS) -c $(SRCDIR)/dm_ipc.f90
886889

890+
dm_ipc_async.o: $(SRCDIR)/dm_ipc_async.f90
891+
$(FC) $(FFLAGS) $(LIBFLAGS) $(MODFLAGS) -c $(SRCDIR)/dm_ipc_async.f90
892+
887893
dm_ipc_disco.o: $(SRCDIR)/dm_ipc_disco.f90
888894
$(FC) $(FFLAGS) $(LIBFLAGS) $(MODFLAGS) -c $(SRCDIR)/dm_ipc_disco.f90
889895

@@ -1228,6 +1234,7 @@ $(TARGET): $(SRC)
12281234
@$(MAKE) dm_ipc.o
12291235
@$(MAKE) dm_ipc_disco.o
12301236
@$(MAKE) dm_ipc_message.o
1237+
@$(MAKE) dm_ipc_async.o
12311238
@$(MAKE) dm_ipc_mutex.o
12321239
@$(MAKE) dm_ipc_thread.o
12331240
@$(MAKE) dmpack.o
@@ -1322,6 +1329,9 @@ dmtestid: test/dmtestid.f90 $(TARGET)
13221329
dmtestipc: test/dmtestipc.f90 $(TARGET)
13231330
$(FC) $(FFLAGS) $(MODFLAGS) $(LDFLAGS) -o dmtestipc test/dmtestipc.f90 $(TARGET) $(LIBNNG) $(LDLIBS)
13241331

1332+
dmtestipcasync: test/dmtestipcasync.f90 $(TARGET)
1333+
$(FC) $(FFLAGS) $(MODFLAGS) $(LDFLAGS) -o dmtestipcasync test/dmtestipcasync.f90 $(TARGET) $(LIBNNG) $(LDLIBS)
1334+
13251335
dmtestipcmutex: test/dmtestipcmutex.f90 $(TARGET)
13261336
$(FC) $(FFLAGS) $(MODFLAGS) $(LDFLAGS) -o dmtestipcmutex test/dmtestipcmutex.f90 $(TARGET) $(LIBNNG) $(LDLIBS)
13271337

fpm.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ name = "dmtestipc"
288288
main = "dmtestipc.f90"
289289
link = [ "nng" ]
290290

291+
[[test]]
292+
name = "dmtestipcasync"
293+
main = "dmtestipcasync.f90"
294+
link = [ "nng" ]
295+
291296
[[test]]
292297
name = "dmtestipcmutex"
293298
main = "dmtestipcmutex.f90"

guide/guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9479,6 +9479,7 @@ DMPACK Makefile.
94799479
| 37 | `E_AUTH` | Authentication failed. |
94809480
| 38 | `E_CONNECT` | Connection failed. |
94819481
| 39 | `E_IGNORED` | Result ignored. |
9482+
| 40 | `E_STATE` | Invalid state. |
94829483
| 50 | `E_ARG` | Generic command-line error. |
94839484
| 51 | `E_ARG_NOT_FOUND` | Argument not passed. |
94849485
| 52 | `E_ARG_INVALID` | Argument invalid or missing. |

src/dm_c.f90

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module dm_c
3737
public :: dm_c_f_logical
3838
public :: dm_c_f_string_characters
3939
public :: dm_c_f_string_pointer
40+
public :: dm_c_nullify
4041
public :: dm_f_c_logical
4142
public :: dm_f_c_string
4243

@@ -181,4 +182,23 @@ subroutine dm_c_f_string_pointer(c, f)
181182

182183
if (.not. allocated(f)) f = ''
183184
end subroutine dm_c_f_string_pointer
185+
186+
pure elemental subroutine dm_c_nullify(ptr, error)
187+
!! Nullifies the passed C pointer `ptr`. If the argument could not be
188+
!! set to `c_null_ptr`, argument `error` will be set to `E_COMPILER`.
189+
use :: dm_error, only: E_COMPILER, E_NONE
190+
191+
type(c_ptr), intent(inout) :: ptr !! C pointer.
192+
integer, intent(out), optional :: error !! Error code.
193+
194+
ptr = c_null_ptr
195+
196+
if (.not. present(error)) return
197+
198+
if (c_associated(ptr)) then
199+
error = E_COMPILER
200+
else
201+
error = E_NONE
202+
end if
203+
end subroutine dm_c_nullify
184204
end module dm_c

src/dm_csv.f90

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,10 @@ function dm_csv_header_sensor(separator) result(header)
301301

302302
header = '#id' // s // &
303303
'node_id' // s // &
304-
'type' // s // &
305304
'name' // s // &
306305
'sn' // s // &
307306
'meta' // s // &
307+
'type' // s // &
308308
'x' // s // &
309309
'y' // s // &
310310
'z' // s // &
@@ -674,10 +674,10 @@ function csv_from_sensor(sensor, separator) result(csv)
674674

675675
csv = trim(sensor%id) // s // &
676676
trim(sensor%node_id) // s // &
677-
dm_itoa(sensor%type) // s // &
678677
trim(sensor%name) // s // &
679678
trim(sensor%sn) // s // &
680679
'"' // trim(sensor%meta) // '"' // s // &
680+
dm_itoa(sensor%type) // s // &
681681
dm_ftoa(sensor%x) // s // &
682682
dm_ftoa(sensor%y) // s // &
683683
dm_ftoa(sensor%z) // s // &
@@ -1110,10 +1110,10 @@ integer function csv_read_sensor(sensor, unit, separator, quote) result(rc)
11101110

11111111
rc = csv_next(buffer, sensor%id, s, n, p, q); if (rc /= E_NONE) return
11121112
rc = csv_next(buffer, sensor%node_id, s, n, p, q); if (rc /= E_NONE) return
1113-
rc = csv_next(buffer, sensor%type, s, n, p, q); if (rc /= E_NONE) return
11141113
rc = csv_next(buffer, sensor%name, s, n, p, q); if (rc /= E_NONE) return
11151114
rc = csv_next(buffer, sensor%sn, s, n, p, q); if (rc /= E_NONE) return
11161115
rc = csv_next(buffer, sensor%meta, s, n, p, q); if (rc /= E_NONE) return
1116+
rc = csv_next(buffer, sensor%type, s, n, p, q); if (rc /= E_NONE) return
11171117
rc = csv_next(buffer, sensor%x, s, n, p, q); if (rc /= E_NONE) return
11181118
rc = csv_next(buffer, sensor%y, s, n, p, q); if (rc /= E_NONE) return
11191119
rc = csv_next(buffer, sensor%z, s, n, p, q); if (rc /= E_NONE) return
@@ -1547,13 +1547,13 @@ integer function csv_write_sensor(sensor, unit, header, separator) result(rc)
15471547
if (stat /= 0) return
15481548
end if
15491549

1550-
write (unit_, '(4a, i0, 8a, 6(a, ' // FMT_REAL // '))', iostat=stat) &
1550+
write (unit_, '(12a, i0, 6(a, ' // FMT_REAL // '))', iostat=stat) &
15511551
trim(sensor%id), s, &
15521552
trim(sensor%node_id), s, &
1553-
sensor%type, s, &
15541553
trim(sensor%name), s, &
15551554
trim(sensor%sn), s, &
15561555
'"', trim(sensor%meta), '"', s, &
1556+
sensor%type, s, &
15571557
sensor%x, s, &
15581558
sensor%y, s, &
15591559
sensor%z, s, &

src/dm_db_api.f90

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,10 +1455,10 @@ integer function dm_db_insert_sensor(db, sensor, validate) result(rc)
14551455

14561456
rc = dm_db_bind(dbs, 1, sensor%id); if (dm_is_error(rc)) exit sql_block
14571457
rc = dm_db_bind(dbs, 2, sensor%node_id); if (dm_is_error(rc)) exit sql_block
1458-
rc = dm_db_bind(dbs, 3, sensor%type); if (dm_is_error(rc)) exit sql_block
1459-
rc = dm_db_bind(dbs, 4, sensor%name); if (dm_is_error(rc)) exit sql_block
1460-
rc = dm_db_bind(dbs, 5, sensor%sn); if (dm_is_error(rc)) exit sql_block
1461-
rc = dm_db_bind(dbs, 6, sensor%meta); if (dm_is_error(rc)) exit sql_block
1458+
rc = dm_db_bind(dbs, 3, sensor%name); if (dm_is_error(rc)) exit sql_block
1459+
rc = dm_db_bind(dbs, 4, sensor%sn); if (dm_is_error(rc)) exit sql_block
1460+
rc = dm_db_bind(dbs, 5, sensor%meta); if (dm_is_error(rc)) exit sql_block
1461+
rc = dm_db_bind(dbs, 6, sensor%type); if (dm_is_error(rc)) exit sql_block
14621462
rc = dm_db_bind(dbs, 7, sensor%x); if (dm_is_error(rc)) exit sql_block
14631463
rc = dm_db_bind(dbs, 8, sensor%y); if (dm_is_error(rc)) exit sql_block
14641464
rc = dm_db_bind(dbs, 9, sensor%z); if (dm_is_error(rc)) exit sql_block
@@ -3323,10 +3323,10 @@ integer function dm_db_update_sensor(db, sensor, validate) result(rc)
33233323

33243324
! Sensor id must be last argument!
33253325
rc = dm_db_bind(dbs, 1, sensor%node_id); if (dm_is_error(rc)) exit sql_block
3326-
rc = dm_db_bind(dbs, 2, sensor%type); if (dm_is_error(rc)) exit sql_block
3327-
rc = dm_db_bind(dbs, 3, sensor%name); if (dm_is_error(rc)) exit sql_block
3328-
rc = dm_db_bind(dbs, 4, sensor%sn); if (dm_is_error(rc)) exit sql_block
3329-
rc = dm_db_bind(dbs, 5, sensor%meta); if (dm_is_error(rc)) exit sql_block
3326+
rc = dm_db_bind(dbs, 2, sensor%name); if (dm_is_error(rc)) exit sql_block
3327+
rc = dm_db_bind(dbs, 3, sensor%sn); if (dm_is_error(rc)) exit sql_block
3328+
rc = dm_db_bind(dbs, 4, sensor%meta); if (dm_is_error(rc)) exit sql_block
3329+
rc = dm_db_bind(dbs, 5, sensor%type); if (dm_is_error(rc)) exit sql_block
33303330
rc = dm_db_bind(dbs, 6, sensor%x); if (dm_is_error(rc)) exit sql_block
33313331
rc = dm_db_bind(dbs, 7, sensor%y); if (dm_is_error(rc)) exit sql_block
33323332
rc = dm_db_bind(dbs, 8, sensor%z); if (dm_is_error(rc)) exit sql_block

src/dm_db_row.f90

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,10 @@ integer function db_row_next_sensor(dbs, sensor, validate) result(rc)
387387
rc = E_DB_TYPE
388388
if (.not. dm_db_column_is_text (dbs, 0)) return
389389
if (.not. dm_db_column_is_text (dbs, 1)) return
390-
if (.not. dm_db_column_is_integer(dbs, 2)) return
390+
if (.not. dm_db_column_is_text (dbs, 2)) return
391391
if (.not. dm_db_column_is_text (dbs, 3)) return
392392
if (.not. dm_db_column_is_text (dbs, 4)) return
393-
if (.not. dm_db_column_is_text (dbs, 5)) return
393+
if (.not. dm_db_column_is_integer(dbs, 5)) return
394394
if (.not. dm_db_column_is_float (dbs, 6)) return
395395
if (.not. dm_db_column_is_float (dbs, 7)) return
396396
if (.not. dm_db_column_is_float (dbs, 8)) return
@@ -401,10 +401,10 @@ integer function db_row_next_sensor(dbs, sensor, validate) result(rc)
401401

402402
call dm_db_column(dbs, 0, sensor%id, n)
403403
call dm_db_column(dbs, 1, sensor%node_id, n)
404-
call dm_db_column(dbs, 2, sensor%type)
405-
call dm_db_column(dbs, 3, sensor%name, n)
406-
call dm_db_column(dbs, 4, sensor%sn, n)
407-
call dm_db_column(dbs, 5, sensor%meta, n)
404+
call dm_db_column(dbs, 2, sensor%name, n)
405+
call dm_db_column(dbs, 3, sensor%sn, n)
406+
call dm_db_column(dbs, 4, sensor%meta, n)
407+
call dm_db_column(dbs, 5, sensor%type)
408408
call dm_db_column(dbs, 6, sensor%x)
409409
call dm_db_column(dbs, 7, sensor%y)
410410
call dm_db_column(dbs, 8, sensor%z)

src/dm_error.f90

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ module dm_error
5757
integer, parameter, public :: E_AUTH = 37 !! Authentication failed.
5858
integer, parameter, public :: E_CONNECT = 38 !! Connection failed.
5959
integer, parameter, public :: E_IGNORED = 39 !! Result ignored.
60+
integer, parameter, public :: E_STATE = 40 !! Invalid state.
6061
! Command-line argument errors.
6162
integer, parameter, public :: E_ARG = 50 !! Generic argument error.
6263
integer, parameter, public :: E_ARG_NOT_FOUND = 51 !! Option not passed.
@@ -205,6 +206,7 @@ pure function dm_error_message(error) result(message)
205206
case (E_AUTH); message = 'authentication failed'
206207
case (E_CONNECT); message = 'connection failed'
207208
case (E_IGNORED); message = 'result ignored'
209+
case (E_STATE); message = 'invalid state'
208210
! Options.
209211
case (E_ARG); message = 'argument error'
210212
case (E_ARG_NOT_FOUND); message = 'argument not found'
@@ -308,7 +310,7 @@ pure elemental logical function dm_is_ok(error) result(is)
308310
error == E_LUA_YIELD)
309311
end function dm_is_ok
310312

311-
subroutine dm_error_out(error, message, verbose, extra, fatal)
313+
recursive subroutine dm_error_out(error, message, verbose, extra, fatal)
312314
!! Prints error description to `stderr`. If `verbose` is `.true.`, the
313315
!! routine outputs even if no error occured (`E_NONE`).
314316
!!

0 commit comments

Comments
 (0)