Skip to content

Commit

Permalink
Refactoring and minor updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
interkosmos committed Mar 26, 2024
1 parent f56632d commit 247786d
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 71 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ The following programs are based on the DMPACK library.
| [dmfs](adoc/dmfs.adoc) | Reads sensor values from file system (file, named pipe, OWFS). |
| [dmgrc](adoc/dmgrc.adoc) | Generates log messages from GeoCOM return codes. |
| [dmimport](adoc/dmimport.adoc) | Imports CSV file into database. |
| [dminfo](adoc/dminfo.adoc) | Prints system and database information as key-value pairs. |
| [dminfo](adoc/dminfo.adoc) | Prints system and database information as keyvalue pairs. |
| [dminit](adoc/dminit.adoc) | Creates and initialises DMPACK databases. |
| [dmlog](adoc/dmlog.adoc) | Sends log messages to logger via message queue. |
| [dmlogger](adoc/dmlogger.adoc) | Stores log messages received from message queue in database. |
Expand Down
14 changes: 8 additions & 6 deletions app/dmgrc.f90
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ program dmgrc
integer function read_args(app) result(rc)
!! Reads command-line arguments and settings from configuration file.
type(app_type), intent(out) :: app
type(arg_type) :: args(8)

integer :: i
type(arg_type) :: args(8)

rc = E_NONE

Expand Down Expand Up @@ -141,11 +143,11 @@ integer function read_args(app) result(rc)
end if

! Allocate return code arrays.
if (.not. allocated(app%levels(LVL_DEBUG )%codes)) allocate (app%levels(LVL_DEBUG )%codes(0))
if (.not. allocated(app%levels(LVL_INFO )%codes)) allocate (app%levels(LVL_INFO )%codes(0))
if (.not. allocated(app%levels(LVL_WARNING )%codes)) allocate (app%levels(LVL_WARNING )%codes(0))
if (.not. allocated(app%levels(LVL_ERROR )%codes)) allocate (app%levels(LVL_ERROR )%codes(0))
if (.not. allocated(app%levels(LVL_CRITICAL)%codes)) allocate (app%levels(LVL_CRITICAL)%codes(0))
do i = LVL_DEBUG, LVL_LAST
if (.not. allocated(app%levels(i)%codes)) then
allocate (app%levels(i)%codes(0))
end if
end do

rc = E_NONE
end function read_args
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions guide/guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5452,12 +5452,12 @@ performed observations are forwarded to <<dmdb>>.

The following utility functions are exported to convert units:

* `deg2gon(deg)` – Converts degrees to gon.
* `deg2gon(deg)` – Converts degrees to gradians.
* `deg2rad(deg)` – Converts degrees to radiants.
* `gon2deg(gon)` – Converts gon to degrees.
* `gon2rad(gon)` – Converts gon to radiants.
* `gon2deg(gon)` – Converts gradians to degrees.
* `gon2rad(gon)` – Converts gradians to radiants.
* `rad2deg(rad)` – Converts radiants to degrees.
* `rad2gon(rad)` – Converts radiants to gon.
* `rad2gon(rad)` – Converts radiants to gradians.

The Lua functions may be called inside of configuration files. For testing, load
the shared library `libdmpack.so` first, for example:
Expand Down
90 changes: 45 additions & 45 deletions src/dm_db.f90
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,8 @@ integer function dm_db_create_logs(db, sync) result(rc)
!! * `E_INVALID` if the database is not connected.
!! * `E_READ_ONLY` if database is opened read-only.
!!
type(db_type), intent(inout) :: db !! Database type.
logical, intent(in), optional :: sync !! Create synchronisation tables.
type(db_type), intent(inout) :: db !! Database type.
logical, intent(in), optional :: sync !! Create synchronisation tables.

integer :: i
logical :: sync_
Expand Down Expand Up @@ -5193,10 +5193,10 @@ integer function db_select_beats_iter(db, db_stmt, beat, limit) result(rc)
!!
use :: dm_beat

type(db_type), intent(inout) :: db !! Database type.
type(db_stmt_type), intent(inout) :: db_stmt !! Database statement type.
type(beat_type), intent(out) :: beat !! Returned beat type.
integer(kind=i8), intent(in), optional :: limit !! Max. number of beats.
type(db_type), intent(inout) :: db !! Database type.
type(db_stmt_type), intent(inout) :: db_stmt !! Database statement type.
type(beat_type), intent(out) :: beat !! Returned beat type.
integer(kind=i8), intent(in), optional :: limit !! Max. number of beats.

if (.not. dm_db_prepared(db_stmt)) then
if (present(limit)) then
Expand Down Expand Up @@ -5749,20 +5749,20 @@ integer function db_select_json_logs_iter(db, db_stmt, json, node_id, sensor_id,
!! * `E_DB_PREPARE` if statement preparation failed.
!! * `E_DB_TYPE` if returned columns are unexpected.
!!
type(db_type), intent(inout) :: db !! Database type.
type(db_stmt_type), intent(inout) :: db_stmt !! Database statement type.
character(len=:), allocatable, intent(out) :: json !! Returned JSON.
character(len=*), intent(in), optional :: node_id !! Node id.
character(len=*), intent(in), optional :: sensor_id !! Sensor id.
character(len=*), intent(in), optional :: target_id !! Target id.
character(len=*), intent(in), optional :: source !! Source name.
character(len=*), intent(in), optional :: from !! Begin of time range.
character(len=*), intent(in), optional :: to !! End of time range.
integer, intent(in), optional :: min_level !! Minimum log level.
integer, intent(in), optional :: max_level !! Maximum log level.
integer, intent(in), optional :: error !! Error code.
logical, intent(in), optional :: desc !! Descending order.
integer(kind=i8), intent(in), optional :: limit !! Max. numbers of logs.
type(db_type), intent(inout) :: db !! Database type.
type(db_stmt_type), intent(inout) :: db_stmt !! Database statement type.
character(len=:), allocatable, intent(out) :: json !! Returned JSON.
character(len=*), intent(in), optional :: node_id !! Node id.
character(len=*), intent(in), optional :: sensor_id !! Sensor id.
character(len=*), intent(in), optional :: target_id !! Target id.
character(len=*), intent(in), optional :: source !! Source name.
character(len=*), intent(in), optional :: from !! Begin of time range.
character(len=*), intent(in), optional :: to !! End of time range.
integer, intent(in), optional :: min_level !! Minimum log level.
integer, intent(in), optional :: max_level !! Maximum log level.
integer, intent(in), optional :: error !! Error code.
logical, intent(in), optional :: desc !! Descending order.
integer(kind=i8), intent(in), optional :: limit !! Max. numbers of logs.

character(len=:), allocatable :: query
integer :: k
Expand Down Expand Up @@ -6303,20 +6303,20 @@ integer function db_select_logs_iter(db, db_stmt, log, node_id, sensor_id, targe
!!
use :: dm_log

type(db_type), intent(inout) :: db !! Database type.
type(db_stmt_type), intent(inout) :: db_stmt !! Database statement type.
type(log_type), intent(out) :: log !! Returned log type.
character(len=*), intent(in), optional :: node_id !! Node id.
character(len=*), intent(in), optional :: sensor_id !! Sensor id.
character(len=*), intent(in), optional :: target_id !! Target id.
character(len=*), intent(in), optional :: source !! Source name.
character(len=*), intent(in), optional :: from !! Begin of time range.
character(len=*), intent(in), optional :: to !! End of time range.
integer, intent(in), optional :: min_level !! Minimum log level.
integer, intent(in), optional :: max_level !! Maximum log level.
integer, intent(in), optional :: error !! Error code.
logical, intent(in), optional :: desc !! Descending order.
integer(kind=i8), intent(in), optional :: limit !! Max. numbers of logs.
type(db_type), intent(inout) :: db !! Database type.
type(db_stmt_type), intent(inout) :: db_stmt !! Database statement type.
type(log_type), intent(out) :: log !! Returned log type.
character(len=*), intent(in), optional :: node_id !! Node id.
character(len=*), intent(in), optional :: sensor_id !! Sensor id.
character(len=*), intent(in), optional :: target_id !! Target id.
character(len=*), intent(in), optional :: source !! Source name.
character(len=*), intent(in), optional :: from !! Begin of time range.
character(len=*), intent(in), optional :: to !! End of time range.
integer, intent(in), optional :: min_level !! Minimum log level.
integer, intent(in), optional :: max_level !! Maximum log level.
integer, intent(in), optional :: error !! Error code.
logical, intent(in), optional :: desc !! Descending order.
integer(kind=i8), intent(in), optional :: limit !! Max. numbers of logs.

character(len=:), allocatable :: query
integer :: k
Expand Down Expand Up @@ -6832,17 +6832,17 @@ integer function db_select_observs_iter(db, db_stmt, observ, node_id, sensor_id,
!!
use :: dm_observ

type(db_type), intent(inout) :: db !! Database type.
type(db_stmt_type), intent(inout) :: db_stmt !! Database statement type.
type(observ_type), intent(out) :: observ !! Returned observation type.
character(len=*), intent(in), optional :: node_id !! Node id.
character(len=*), intent(in), optional :: sensor_id !! Sensor id.
character(len=*), intent(in), optional :: target_id !! Target id.
character(len=*), intent(in), optional :: from !! Beginning of time span.
character(len=*), intent(in), optional :: to !! End of time span.
logical, intent(in), optional :: desc !! Descending order.
integer(kind=i8), intent(in), optional :: limit !! Max. number of observations.
logical, intent(in), optional :: stub !! Without receivers, requests, responses.
type(db_type), intent(inout) :: db !! Database type.
type(db_stmt_type), intent(inout) :: db_stmt !! Database statement type.
type(observ_type), intent(out) :: observ !! Returned observation type.
character(len=*), intent(in), optional :: node_id !! Node id.
character(len=*), intent(in), optional :: sensor_id !! Sensor id.
character(len=*), intent(in), optional :: target_id !! Target id.
character(len=*), intent(in), optional :: from !! Beginning of time span.
character(len=*), intent(in), optional :: to !! End of time span.
logical, intent(in), optional :: desc !! Descending order.
integer(kind=i8), intent(in), optional :: limit !! Max. number of observations.
logical, intent(in), optional :: stub !! Without receivers, requests, responses.

character(len=:), allocatable :: query
integer :: i, k, n
Expand Down
6 changes: 3 additions & 3 deletions src/dm_node.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ module dm_node
implicit none (type, external)
private

integer, parameter, public :: NODE_ID_LEN = ID_LEN
integer, parameter, public :: NODE_NAME_LEN = 32
integer, parameter, public :: NODE_META_LEN = 32
integer, parameter, public :: NODE_ID_LEN = ID_LEN !! Max. node id length.
integer, parameter, public :: NODE_NAME_LEN = 32 !! Max. node name length.
integer, parameter, public :: NODE_META_LEN = 32 !! Max. node meta description length.

type, public :: node_type
!! Node type.
Expand Down
1 change: 1 addition & 0 deletions src/dm_regex.f90
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ integer function dm_regex_response_string(request, name, string, pattern) result
!! * `E_REGEX_NO_GROUP` if `name` does not match any group.
!! * `E_REGEX_NO_MATCH` if the pattern does not match.
!!
!! On error, the group string is allocated, but may be empty.
use :: dm_request

type(request_type), intent(inout) :: request !! Request type.
Expand Down
2 changes: 1 addition & 1 deletion src/dm_rpc.f90
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module dm_rpc
!! type(rpc_response_type) :: response
!!
!! rc = dm_rpc_init()
!! if (dm_is_error(rc)) error stop
!! if (dm_is_error(rc)) call dm_stop(1)
!!
!! url = dm_rpc_url('localhost', port=80, endpoint=RPC_ROUTE_OBSERV)
!! rc = dm_rpc_send(request, response, observ, url)
Expand Down
11 changes: 6 additions & 5 deletions src/dm_sensor.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ module dm_sensor
implicit none (type, external)
private

integer, parameter, public :: SENSOR_ID_LEN = ID_LEN
integer, parameter, public :: SENSOR_NAME_LEN = 32
integer, parameter, public :: SENSOR_SN_LEN = 32
integer, parameter, public :: SENSOR_META_LEN = 32
integer, parameter, public :: SENSOR_ID_LEN = ID_LEN !! Max. sensor id length.
integer, parameter, public :: SENSOR_NAME_LEN = 32 !! Max. sensor name length.
integer, parameter, public :: SENSOR_SN_LEN = 32 !! Max. sensor serial number length.
integer, parameter, public :: SENSOR_META_LEN = 32 !! Max. sensor meta description length.

! Sensor types.
integer, parameter, public :: SENSOR_TYPE_NONE = 0 !! Unknown sensor type.
Expand All @@ -25,7 +25,7 @@ module dm_sensor
integer, parameter, public :: SENSOR_TYPE_MEMS = 8 !! MEMS sensor.
integer, parameter, public :: SENSOR_TYPE_LAST = 8 !! Never use this.

integer, parameter, public :: SENSOR_TYPE_NAME_LEN = 7
integer, parameter, public :: SENSOR_TYPE_NAME_LEN = 7 !! Max. length of sensor type name.

character(len=*), parameter, public :: SENSOR_TYPE_NAMES(SENSOR_TYPE_NONE:SENSOR_TYPE_LAST) = [ &
character(len=SENSOR_TYPE_NAME_LEN) :: &
Expand Down Expand Up @@ -151,6 +151,7 @@ subroutine dm_sensor_out(sensor, unit)

write (unit_, '("sensor.id: ", a)') trim(sensor%id)
write (unit_, '("sensor.node_id: ", a)') trim(sensor%node_id)

write (unit_, '("sensor.type: ")', advance='no')

if (dm_sensor_type_valid(sensor%type)) then
Expand Down
8 changes: 4 additions & 4 deletions src/dm_target.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ module dm_target
implicit none (type, external)
private

integer, parameter, public :: TARGET_ID_LEN = ID_LEN
integer, parameter, public :: TARGET_NAME_LEN = 32
integer, parameter, public :: TARGET_META_LEN = 32
integer, parameter, public :: TARGET_ID_LEN = ID_LEN !! Max. target id length.
integer, parameter, public :: TARGET_NAME_LEN = 32 !! Max. target name length.
integer, parameter, public :: TARGET_META_LEN = 32 !! Max. target meta description length.

! Target states.
integer, parameter, public :: TARGET_STATE_NONE = 0 !! Default state.
Expand All @@ -22,7 +22,7 @@ module dm_target
integer, parameter, public :: TARGET_STATE_USER = 6 !! User-defined state.
integer, parameter, public :: TARGET_STATE_LAST = 6 !! Never use this.

integer, parameter, public :: TARGET_STATE_NAME_LEN = 8 !! Length of target state name.
integer, parameter, public :: TARGET_STATE_NAME_LEN = 8 !! Max. target state name length.

character(len=*), parameter, public :: TARGET_STATE_NAMES(TARGET_STATE_NONE:TARGET_STATE_LAST) = [ &
character(len=TARGET_STATE_NAME_LEN) :: &
Expand Down
4 changes: 2 additions & 2 deletions src/dm_thread.f90
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ subroutine dm_thread_routine(arg) bind(c)
!! C-interoperable POSIX thread routine.
import :: c_ptr
implicit none
type(c_ptr), intent(in), value :: arg
type(c_ptr), intent(in), value :: arg !! Client data as C pointer.
end subroutine dm_thread_routine
end interface

type, public :: thread_type
!! Opaque POSIX thread type.
private
type(c_pthread_t) :: state
type(c_pthread_t) :: state !! POSIX thread handle.
end type thread_type

public :: dm_thread_create
Expand Down

0 comments on commit 247786d

Please sign in to comment.