Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
interkosmos committed Jul 14, 2024
1 parent d0302d1 commit 35767c3
Show file tree
Hide file tree
Showing 33 changed files with 861 additions and 729 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ $ make [freebsd|linux|linux_aarch64]
$ make install PREFIX=/opt
```

On 64-bit Raspberry Pi single-board computers, target `linux_aarch64` must be
chosen.
On 64-bit Raspberry Pi single-board computers, select target `linux_aarch64`.

## Library

Expand Down
12 changes: 6 additions & 6 deletions app/dmapi.f90
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ subroutine route_beat(env)
end if

! Uncompress payload.
rc = dm_z_uncompress(content, beat, encoding)
rc = dm_z_uncompress(content, encoding, beat)

if (dm_is_error(rc)) then
call api_error(HTTP_BAD_REQUEST, 'corrupted payload', rc)
Expand Down Expand Up @@ -445,7 +445,7 @@ subroutine route_log(env)
end if

! Uncompress payload.
rc = dm_z_uncompress(content, log, encoding)
rc = dm_z_uncompress(content, encoding, log)

if (dm_is_error(rc)) then
call api_error(HTTP_BAD_REQUEST, 'corrupted payload', rc)
Expand Down Expand Up @@ -778,7 +778,7 @@ subroutine route_node(env)
end if

! Uncompress payload.
rc = dm_z_uncompress(content, node, encoding)
rc = dm_z_uncompress(content, encoding, node)

if (dm_is_error(rc)) then
call api_error(HTTP_BAD_REQUEST, 'corrupted payload', rc)
Expand Down Expand Up @@ -1035,7 +1035,7 @@ subroutine route_observ(env)
end if

! Uncompress payload.
rc = dm_z_uncompress(content, observ, encoding)
rc = dm_z_uncompress(content, encoding, observ)

if (dm_is_error(rc)) then
call api_error(HTTP_BAD_REQUEST, 'corrupted payload', rc)
Expand Down Expand Up @@ -1444,7 +1444,7 @@ subroutine route_sensor(env)
end if

! Uncompress payload.
rc = dm_z_uncompress(content, sensor, encoding)
rc = dm_z_uncompress(content, encoding, sensor)

if (dm_is_error(rc)) then
call api_error(HTTP_BAD_REQUEST, 'corrupted payload', rc)
Expand Down Expand Up @@ -1702,7 +1702,7 @@ subroutine route_target(env)
end if

! Uncompress payload.
rc = dm_z_uncompress(content, target, encoding)
rc = dm_z_uncompress(content, encoding, target)

if (dm_is_error(rc)) then
call api_error(HTTP_BAD_REQUEST, 'corrupted payload', rc)
Expand Down
4 changes: 2 additions & 2 deletions app/dmbeat.f90
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ integer function read_args(app) result(rc)
]

! Read all command-line arguments.
version = dm_rpc_version() // ' ' // dm_lua_version(.true.)
version = dm_rpc_version() // ' ' // dm_lua_version(.true.) // ' ' // dm_zstd_version(.true.)
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, version)
if (dm_is_error(rc)) return

Expand Down Expand Up @@ -294,7 +294,7 @@ subroutine run(app, error)
last_error = rc

if (app%count > 0) then
niter = niter + 1
niter = dm_inc(niter)
if (niter >= app%count) exit emit_loop
end if

Expand Down
2 changes: 1 addition & 1 deletion app/dmdb.f90
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ subroutine run(app, db, mqueue, sem)
end if

! Increase optimise step counter.
steps = modulo(steps + 1, APP_DB_NSTEPS)
steps = modulo(dm_inc(steps), APP_DB_NSTEPS)
end do ipc_loop
end subroutine run

Expand Down
96 changes: 39 additions & 57 deletions app/dminfo.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ program dminfo
character(len=*), parameter :: APP_NAME = 'dminfo'
integer, parameter :: APP_MAJOR = 0
integer, parameter :: APP_MINOR = 9
integer, parameter :: APP_PATCH = 1
integer, parameter :: APP_PATCH = 2

type :: app_type
!! Command-line arguments.
Expand Down Expand Up @@ -52,9 +52,9 @@ integer function output_info(app) result(rc)
type(app_type), intent(inout) :: app

character(len=:), allocatable :: mode_name
integer :: app_id, mode
integer :: app_id, mode, user_version
integer(kind=i8) :: n, sz
logical :: exists, has_db
logical :: exists, foreign_keys, has_db
type(db_type) :: db
type(uname_type) :: uname

Expand All @@ -78,85 +78,67 @@ integer function output_info(app) result(rc)
! Database information.
if (has_db) then
rc = dm_db_get_application_id(db, app_id)
print '("db.application_id: ", z0)', app_id

rc = dm_db_get_foreign_keys(db, exists)
print '("db.foreign_keys: ", l)', exists

rc = dm_db_get_user_version(db, user_version)
rc = dm_db_get_foreign_keys(db, foreign_keys)
rc = dm_db_get_journal_mode(db, mode, mode_name)
print '("db.journal_mode: ", a)', mode_name

print '("db.path: ", a)', trim(app%database)
print '("db.size: ", i0)', sz
print '("db.application_id: ", z0)', app_id
print '("db.foreign_keys: ", l1)', foreign_keys
print '("db.journal_mode: ", a)', mode_name
print '("db.library: ", a)', dm_db_version(.true.)
print '("db.path: ", a)', trim(app%database)
print '("db.schema.version: ", i0)', user_version
print '("db.size: ", i0)', sz

rc = dm_db_table_exists(db, SQL_TABLE_BEATS, exists)
rc = dm_db_count_beats(db, n)
print '("db.table.beats: ", l)', exists
print '("db.table.beats.rows: ", i0)', n
if (exists) rc = dm_db_count_beats(db, n)
if (exists) print '("db.table.beats.rows: ", i0)', n

rc = dm_db_table_exists(db, SQL_TABLE_LOGS, exists)
rc = dm_db_count_logs(db, n)
print '("db.table.logs: ", l)', exists
print '("db.table.logs.rows: ", i0)', n
if (exists) rc = dm_db_count_logs(db, n)
if (exists) print '("db.table.logs.rows: ", i0)', n

rc = dm_db_table_exists(db, SQL_TABLE_NODES, exists)
rc = dm_db_count_nodes(db, n)
print '("db.table.nodes: ", l)', exists
print '("db.table.nodes.rows: ", i0)', n
if (exists) rc = dm_db_count_nodes(db, n)
if (exists) print '("db.table.nodes.rows: ", i0)', n

rc = dm_db_table_exists(db, SQL_TABLE_OBSERVS, exists)
rc = dm_db_count_observs(db, n)
print '("db.table.observs: ", l)', exists
print '("db.table.observs.rows: ", i0)', n
if (exists) rc = dm_db_count_observs(db, n)
if (exists) print '("db.table.observs.rows: ", i0)', n

rc = dm_db_table_exists(db, SQL_TABLE_RECEIVERS, exists)
rc = dm_db_count_receivers(db, n)
print '("db.table.receivers: ", l)', exists
print '("db.table.receivers.rows: ", i0)', n
if (exists) rc = dm_db_count_receivers(db, n)
if (exists) print '("db.table.receivers.rows: ", i0)', n

rc = dm_db_table_exists(db, SQL_TABLE_REQUESTS, exists)
rc = dm_db_count_requests(db, n)
print '("db.table.requests: ", l)', exists
print '("db.table.requests.rows: ", i0)', n
if (exists) rc = dm_db_count_requests(db, n)
if (exists) print '("db.table.requests.rows: ", i0)', n

rc = dm_db_table_exists(db, SQL_TABLE_RESPONSES, exists)
rc = dm_db_count_responses(db, n)
print '("db.table.responses: ", l)', exists
print '("db.table.responses.rows: ", i0)', n
if (exists) rc = dm_db_count_responses(db, n)
if (exists) print '("db.table.responses.rows: ", i0)', n

rc = dm_db_table_exists(db, SQL_TABLE_SENSORS, exists)
rc = dm_db_count_sensors(db, n)
print '("db.table.sensors: ", l)', exists
print '("db.table.sensors.rows: ", i0)', n
if (exists) rc = dm_db_count_sensors(db, n)
if (exists) print '("db.table.sensors.rows: ", i0)', n

rc = dm_db_table_exists(db, SQL_TABLE_TARGETS, exists)
rc = dm_db_count_targets(db, n)
print '("db.table.targets: ", l)', exists
print '("db.table.targets.rows: ", i0)', n
if (exists) rc = dm_db_count_targets(db, n)
if (exists) print '("db.table.targets.rows: ", i0)', n

rc = dm_db_close(db)
end if

! DMPACK information.
print '("dmpack.version: ", a)', DM_VERSION_STRING

! System information.
write (*, '("system.byte_order: ")', advance='no')

if (LITTLE_ENDIAN) then
print '("little-endian")'
else
print '("big-endian")'
end if

call dm_system_uname(uname)

print '("system.host: ", a)', trim(uname%node_name)
print '("system.machine: ", a)', trim(uname%machine)
print '("system.name: ", a)', trim(uname%system_name)
print '("system.release: ", a)', trim(uname%release)
print '("system.time.now: ", a)', dm_time_now()
print '("system.time.zone: ", a)', dm_time_zone()
print '("system.version: ", a)', trim(uname%version)
print '("dmpack.version: ", a)', DM_VERSION_STRING
print '("system.byte_order: ", a)', dm_btoa(LITTLE_ENDIAN, 'little-endian', 'big-endian')
print '("system.host: ", a)', trim(uname%node_name)
print '("system.name: ", a)', trim(uname%system_name)
print '("system.platform: ", a)', trim(uname%machine)
print '("system.release: ", a)', trim(uname%release)
print '("system.time.now: ", a)', dm_time_now()
print '("system.time.zone: ", a)', dm_time_zone()
print '("system.version: ", a)', trim(uname%version)
end function output_info
end program dminfo
2 changes: 1 addition & 1 deletion app/dmlogger.f90
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ subroutine run(app, db, mqueue, sem)
end if

! Increase optimise step counter.
steps = modulo(steps + 1, APP_DB_NSTEPS)
steps = modulo(dm_inc(steps), APP_DB_NSTEPS)
end do ipc_loop
end subroutine run

Expand Down
2 changes: 1 addition & 1 deletion app/dmplot.f90
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ integer function read_args(app) result(rc)
]

! Read all command-line arguments.
version = dm_plot_version() // ' ' // dm_lua_version(.true.) // ' ' // dm_db_version(.true.)
version = dm_plot_version(.true.) // ' ' // dm_lua_version(.true.) // ' ' // dm_db_version(.true.)
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, version)
if (dm_is_error(rc)) return

Expand Down
2 changes: 1 addition & 1 deletion app/dmreport.f90
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ integer function read_args(app) result(rc)
]

! Read all command-line arguments.
version = dm_plot_version() // ' ' // dm_lua_version(.true.) // ' ' // dm_db_version(.true.)
version = dm_plot_version(.true.) // ' ' // dm_lua_version(.true.) // ' ' // dm_db_version(.true.)
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, version)
if (dm_is_error(rc)) return

Expand Down
9 changes: 5 additions & 4 deletions app/dmsync.f90
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ integer function read_args(app) result(rc)
]

! Read all command-line arguments.
version = dm_rpc_version() // ' ' // dm_lua_version(.true.) // ' ' // dm_db_version(.true.)
version = dm_rpc_version() // ' ' // dm_lua_version(.true.) // ' ' // &
dm_db_version(.true.) // ' ' // dm_zstd_version(.true.)
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, version)
if (dm_is_error(rc)) return

Expand Down Expand Up @@ -510,9 +511,9 @@ integer function run(app, db, sem) result(rc)
last_error = max(last_error, rc)

! Update sync data.
syncs(i)%timestamp = dm_time_now() ! Time of sync attempt.
syncs(i)%code = responses(i)%code ! Server status code.
syncs(i)%attempts = syncs(i)%attempts + 1 ! Number of sync attempts.
syncs(i)%timestamp = dm_time_now() ! Time of sync attempt.
syncs(i)%code = responses(i)%code ! Server status code.
syncs(i)%attempts = dm_inc(syncs(i)%attempts) ! Number of sync attempts.

! Insert or replace the sync data in database. If the database
! is busy, try up to `APP_DB_NATTEMPTS` times, then abort.
Expand Down
2 changes: 2 additions & 0 deletions app/dmweb.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,8 @@ subroutine route_status(env)
H_TD // dm_version_to_string(APP_MAJOR, APP_MINOR, APP_PATCH) // H_TD_END // H_TR_END // &
H_TR // H_TH // 'DMPACK Version' // H_TH_END // &
H_TD // DM_VERSION_STRING // H_TD_END // H_TR_END // &
H_TR // H_TH // 'SQLite Version' // H_TH_END // &
H_TD // dm_db_version() // H_TD_END // H_TR_END // &
H_TR // H_TH // 'Compiler' // H_TH_END // &
H_TD // dm_html_encode(compiler_version()) // H_TD_END // H_TR_END // &
H_TR // H_TH // 'Compiler Options' // H_TH_END // &
Expand Down
2 changes: 1 addition & 1 deletion runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ for TEST in ${TESTS}; do
if [ $? -ne 0 ]; then
NFAIL=`expr ${NFAIL} + 1`
printf "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
printf "TEST ${TEST} FAILED!\n"
printf "TEST %s FAILED!\n" ${TEST}
printf "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
fi
done
Expand Down
3 changes: 3 additions & 0 deletions src/dm_arg.f90
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ integer function dm_arg_read(args, app, major, minor, patch, version) result(rc)
!! arguments. If one of these arguments is passed, `dm_stop(0)` is
!! called afterwards.
!!
!! Optional argument `version` may be a string of third-party library
!! names and version numbers.
!!
!! The function returns the following error codes:
!!
!! * `E_EMPTY` if array of arguments is empty.
Expand Down
4 changes: 2 additions & 2 deletions src/dm_db.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4208,7 +4208,7 @@ end function dm_db_valid

function dm_db_version(name) result(version)
!! Returns SQLite 3 library version as allocatable string.
logical, intent(in), optional :: name !! Add string `libsqlite/' as prefix.
logical, intent(in), optional :: name !! Add prefix `libsqlite/'.
character(len=:), allocatable :: version

logical :: name_
Expand All @@ -4217,7 +4217,7 @@ function dm_db_version(name) result(version)
if (present(name)) name_ = name

if (name_) then
version = 'libsqlite/' // sqlite3_libversion()
version = 'libsqlite3/' // sqlite3_libversion()
else
version = sqlite3_libversion()
end if
Expand Down
28 changes: 26 additions & 2 deletions src/dm_hdf5.f90
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ module dm_hdf5
public :: dm_hdf5_open
public :: dm_hdf5_read
public :: dm_hdf5_version
public :: dm_hdf5_version_number
public :: dm_hdf5_write

! Private procedures.
Expand Down Expand Up @@ -321,7 +322,30 @@ integer function dm_hdf5_init() result(rc)
rc = E_NONE
end function dm_hdf5_init

integer function dm_hdf5_version(major, minor, release) result(rc)
function dm_hdf5_version(name) result(version)
!! Returns HDF5 library version as allocatable string.
logical, intent(in), optional :: name !! Add prefix `libhdf5/`.
character(len=:), allocatable :: version

character(len=8) :: v
integer :: major, minor, release
integer :: rc
logical :: name_

name_ = .false.
if (present(name)) name_ = name

rc = dm_hdf5_version_number(major, minor, release)
write (v, '(2(i0, "."), i0)') major, minor, release

if (name_) then
version = 'libhdf5/' // trim(v)
else
version = trim(v)
end if
end function dm_hdf5_version

integer function dm_hdf5_version_number(major, minor, release) result(rc)
!! Returns version numbers of HDF5 library. The function returns
!! `E_HDF5` on error.
use :: h5lib, only: h5get_libversion_f
Expand All @@ -342,7 +366,7 @@ integer function dm_hdf5_version(major, minor, release) result(rc)

if (stat < 0) return
rc = E_NONE
end function dm_hdf5_version
end function dm_hdf5_version_number

! ******************************************************************
! PRIVATE PROCEDURES.
Expand Down
Loading

0 comments on commit 35767c3

Please sign in to comment.