Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
interkosmos committed Apr 12, 2024
1 parent 83c63cb commit 057c094
Show file tree
Hide file tree
Showing 22 changed files with 157 additions and 156 deletions.
18 changes: 4 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@
#
# Targets for system-wide installation:
#
# install - Install to `/usr/local` (pass `PREFIX` to overwrite).
# install_freebsd - Install to `/usr/local` (pass `PREFIX` to overwrite).
# install_linux - Install to `/usr` (pass `PREFIX` to overwrite).
# deinstall - Remove from `/usr/local` (pass `PREFIX` to overwrite).
# install - Install to `/usr/local` (pass `PREFIX` to overwrite).
# deinstall - Remove from `/usr/local` (pass `PREFIX` to overwrite).
#
# Targets related to the documentation:
#
Expand Down Expand Up @@ -390,8 +388,8 @@ OBJ = dm_ansi.o \

# Named build targets.
.PHONY: all app clean deinstall doc freebsd freebsd_debug freebsd_release guide \
help html install install_freebsd install_linux linux linux_debug \
linux_release man options pdf purge setup test
help html install linux linux_debug linux_release man options pdf purge \
setup test

# Library target.
all: $(TARGET) $(SHARED) test app
Expand Down Expand Up @@ -904,12 +902,6 @@ install:
$(GZIP) -9 < $(MANDIR)/dmuuid.1 > $(IMANDIR)/dmuuid.1.gz
$(GZIP) -9 < $(MANDIR)/dmweb.1 > $(IMANDIR)/dmweb.1.gz

install_freebsd:
$(MAKE) install PREFIX=/usr/local

install_linux:
$(MAKE) install PREFIX=/usr

deinstall:
@echo "--- Deleting DMPACK from $(PREFIX) ..."
$(RM) -r $(IINCDIR)
Expand Down Expand Up @@ -1108,8 +1100,6 @@ help:
@echo " help - Show this help."
@echo " html - Convert man pages to HTML (requires mandoc)."
@echo " install - Install DMPACK to PREFIX."
@echo " install_freebsd - Install DMPACK to /usr/local/."
@echo " install_linux - Install DMPACK to /usr/."
@echo " linux - Build Linux release version."
@echo " linux_debug - Build Linux debug version."
@echo " linux_release - Build Linux release version."
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ $ cd dmpack/
$ make linux
```

Install the library and all programs system-wide:
Install the library and all programs system-wide to `/usr/local`:

```
$ sudo make install_linux
$ sudo make install
```

To install to a custom directory, run:
Expand Down
6 changes: 3 additions & 3 deletions app/dmbackup.f90
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ program dmbackup
end type app_type

integer :: rc ! Return code.
type(app_type) :: app ! App type.
type(app_type) :: app ! App settings.

! Initialise DMPACK.
call dm_init()
Expand All @@ -48,13 +48,13 @@ integer function backup(app) result(rc)
if (dm_is_error(rc)) return

backup_block: block
! VACUUM INTO.
! Use VACUUM INTO.
if (app%vacuum) then
rc = dm_db_vacuum(db, into=app%backup)
exit backup_block
end if

! SQLite backup API.
! Use SQLite backup API.
if (app%verbose) then
! Using callback.
rc = dm_db_backup(db = db, &
Expand Down
7 changes: 3 additions & 4 deletions app/dmbeat.f90
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ program dmbeat
integer, parameter :: APP_MINOR = 9
integer, parameter :: APP_PATCH = 4

logical, parameter :: APP_RPC_DEFLATE = .true. !! Compress RPC data.

integer, parameter :: HOST_LEN = 256 !! Max. length of host name.
integer, parameter :: USERNAME_LEN = 256 !! Max. length of user name.
integer, parameter :: PASSWORD_LEN = 256 !! Max. length of password.
Expand All @@ -39,7 +37,7 @@ program dmbeat
class(logger_class), pointer :: logger ! Logger object.

integer :: rc ! Return code.
type(app_type) :: app ! App configuration.
type(app_type) :: app ! App settings.

! Initialise DMPACK.
call dm_init()
Expand Down Expand Up @@ -232,7 +230,7 @@ subroutine run(app, error)
call dm_system_uptime(uptime, rc)
beat%uptime = int(uptime, kind=i4)

! Send RPC request to API.
! Send RPC request to API, use Zstandard compression.
rc = dm_rpc_send(request = request, &
response = response, &
type = beat, &
Expand All @@ -243,6 +241,7 @@ subroutine run(app, error)
compression = Z_TYPE_ZSTD)

if (dm_is_error(rc)) call logger%debug('failed to send beat to host ' // app%host, error=rc)

has_api_status = .false.

if (response%content_type == MIME_TEXT) then
Expand Down
28 changes: 14 additions & 14 deletions app/dmdbctl.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ program dmdbctl
character(len=*), parameter :: APP_NAME = 'dmdbctl'
integer, parameter :: APP_MAJOR = 0
integer, parameter :: APP_MINOR = 9
integer, parameter :: APP_PATCH = 1
integer, parameter :: APP_PATCH = 2

! Database operations (CRUD).
integer, parameter :: OP_NONE = 0
integer, parameter :: OP_CREATE = 1
integer, parameter :: OP_READ = 2
integer, parameter :: OP_UPDATE = 3
integer, parameter :: OP_DELETE = 4
integer, parameter :: NOPS = 4
integer, parameter :: OP_LAST = 4

! Affected data type attributes.
integer, parameter :: ATTR_NONE = 0
Expand All @@ -31,22 +31,22 @@ program dmdbctl
integer, parameter :: ATTR_X = 7
integer, parameter :: ATTR_Y = 8
integer, parameter :: ATTR_Z = 9
integer, parameter :: NATTRS = 9
integer, parameter :: ATTR_LAST = 9

type :: app_type
!! Command-line arguments.
character(len=FILE_PATH_LEN) :: database = ' ' !! Path to SQLite database file.
integer :: operation = OP_NONE !! Database operation (CRUD).
integer :: type = TYPE_NONE !! Entity type (node, sensor, target).
logical :: mask(NATTRS) = .false. !! Attribute mask.
logical :: verbose = .false. !! Print debug messages to stderr.
type(node_type) :: node !! Node type.
type(sensor_type) :: sensor !! Sensor type.
type(target_type) :: target !! Target type.
character(len=FILE_PATH_LEN) :: database = ' ' !! Path to SQLite database file.
integer :: operation = OP_NONE !! Database operation (CRUD).
integer :: type = TYPE_NONE !! Entity type (node, sensor, target).
logical :: mask(ATTR_LAST) = .false. !! Attribute mask.
logical :: verbose = .false. !! Print debug messages to stderr.
type(node_type) :: node !! Node type.
type(sensor_type) :: sensor !! Sensor type.
type(target_type) :: target !! Target type.
end type app_type

integer :: rc ! Return code.
type(app_type) :: app ! App configuration.
type(app_type) :: app ! App settings.

! Initialise DMPACK.
call dm_init()
Expand Down Expand Up @@ -382,7 +382,7 @@ integer function read_args(app) result(rc)
character(len=TYPE_NAME_LEN) :: type ! DMPACK derived type name.

integer :: i, n
logical :: mask(NOPS) ! CRUD operation mask.
logical :: mask(OP_LAST) ! CRUD operation mask.
type(arg_type) :: args(16)

rc = E_NONE
Expand Down Expand Up @@ -412,7 +412,7 @@ integer function read_args(app) result(rc)
if (dm_is_error(rc)) return

! CRUD operation.
mask = [ (args(i)%passed, i = 1, NOPS) ]
mask = [ (args(i)%passed, i = 1, OP_LAST) ]
n = count(mask)

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

character, parameter :: APP_CSV_SEPARATOR = ',' !! CSV field separator.
logical, parameter :: APP_MQ_BLOCKING = .true. !! Observation forwarding is blocking.
Expand Down Expand Up @@ -338,7 +338,7 @@ integer function read_observ(observ, node_id, sensor_id, source, debug) result(r

! Wait the set delay time of the request.
delay = max(0, request%delay)
if (delay <= 0) cycle req_loop
if (delay == 0) cycle req_loop

if (debug_ .and. i < n) then
call logger%debug('next ' // request_name_string(observ%requests(i + 1)%name, i + 1, n, observ%name) // &
Expand Down
4 changes: 2 additions & 2 deletions app/dmgrc.f90
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ program dmgrc
class(logger_class), pointer :: logger ! Logger object.

integer :: rc ! Return code.
type(app_type) :: app ! App configuration.
type(mqueue_type) :: mqueue ! Message queue.
type(app_type) :: app ! App settings.
type(mqueue_type) :: mqueue ! POSIX message queue.

! Initialise DMPACK.
call dm_init()
Expand Down
2 changes: 1 addition & 1 deletion app/dminit.f90
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ program dminit
end type app_type

integer :: rc ! Return code.
type(app_type) :: app ! App type.
type(app_type) :: app ! App settings.

! Initialise DMPACK.
call dm_init()
Expand Down
8 changes: 4 additions & 4 deletions app/dmpipe.f90
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ program dmpipe
character(len=*), parameter :: APP_NAME = 'dmpipe'
integer, parameter :: APP_MAJOR = 0
integer, parameter :: APP_MINOR = 9
integer, parameter :: APP_PATCH = 1
integer, parameter :: APP_PATCH = 2

character, parameter :: APP_CSV_SEPARATOR = ',' !! CSV field separator.
logical, parameter :: APP_MQ_BLOCKING = .true. !! Observation forwarding is blocking.
Expand Down Expand Up @@ -41,7 +41,7 @@ program dmpipe
class(logger_class), pointer :: logger ! Logger object.

integer :: rc ! Return code.
type(app_type) :: app ! App configuration.
type(app_type) :: app ! App settings.

! Initialise DMPACK.
call dm_init()
Expand Down Expand Up @@ -255,7 +255,7 @@ integer function read_observ(pipe, observ, node_id, sensor_id, source, debug) re
return
end if

! Read files in requests sequentially.
! Read pipes in requests sequentially.
req_loop: do i = 1, n
! Get pointer to next request.
request => observ%requests(i)
Expand Down Expand Up @@ -331,7 +331,7 @@ integer function read_observ(pipe, observ, node_id, sensor_id, source, debug) re

! Wait the set delay time of the request.
delay = max(0, request%delay)
if (delay <= 0) cycle req_loop
if (delay == 0) cycle req_loop

if (debug_ .and. i < n) then
call logger%debug('next ' // request_name_string(observ%requests(i + 1)%name, i + 1, n, observ%name) // &
Expand Down
2 changes: 1 addition & 1 deletion app/dmplot.f90
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ program dmplot
end type app_type

integer :: rc ! Return code.
type(app_type) :: app ! App configuration.
type(app_type) :: app ! App settings.

! Initialise DMPACK.
call dm_init()
Expand Down
24 changes: 13 additions & 11 deletions app/dmrecv.f90
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ program dmrecv
character(len=*), parameter :: APP_NAME = 'dmrecv'
integer, parameter :: APP_MAJOR = 0
integer, parameter :: APP_MINOR = 9
integer, parameter :: APP_PATCH = 2
integer, parameter :: APP_PATCH = 3

logical, parameter :: APP_MQ_BLOCKING = .true. !! Observation forwarding is blocking.

Expand All @@ -48,14 +48,14 @@ program dmrecv

class(logger_class), pointer :: logger ! Logger object.

integer :: rc
type(app_type) :: app
type(mqueue_type) :: mqueue
integer :: rc ! Return code.
type(app_type) :: app ! App settings.
type(mqueue_type) :: mqueue ! POSIX message queue.

! Initialise DMPACK.
call dm_init()

! Get command-line arguments, read options from configuration file.
! Get command-line arguments and read options from configuration file.
rc = read_args(app)
if (dm_is_error(rc)) call dm_stop(STOP_FAILURE)

Expand Down Expand Up @@ -165,11 +165,13 @@ integer function read_args(app) result(rc)
return
end if

if (app%format /= FORMAT_BLOCK .and. app%format /= FORMAT_CSV .and. &
app%format /= FORMAT_JSONL .and. app%format /= FORMAT_NML) then
call dm_error_out(rc, 'invalid format')
return
end if
select case (app%format)
case (FORMAT_BLOCK, FORMAT_CSV, FORMAT_JSONL, FORMAT_NML)
continue
case default
call dm_error_out(rc, 'invalid format')
return
end select

if (app%type /= TYPE_OBSERV .and. app%type /= TYPE_LOG) then
call dm_error_out(rc, 'invalid type')
Expand Down Expand Up @@ -266,7 +268,7 @@ subroutine run(app, mqueue)
! Handle message queue error.
if (dm_is_error(rc)) then
call logger%error('failed to read from mqueue /' // app%name, error=rc)
call dm_sleep(1)
call dm_sleep(5)
cycle ipc_loop
end if

Expand Down
Loading

0 comments on commit 057c094

Please sign in to comment.