Expand watch model
- SHA
975aa178b0a888ab1a87057e6a5b6a4f6d58754d- Parents
-
3e11d13 - Tree
d72ad6d
975aa17
975aa178b0a888ab1a87057e6a5b6a4f6d58754d3e11d13
d72ad6d| Status | File | + | - |
|---|---|---|---|
| M |
src/fgof_watch.f90
|
15 | 10 |
| M |
src/fgof_watch_types.f90
|
17 | 0 |
| A |
test/test_event_model.f90
|
28 | 0 |
| M |
test/test_scaffold.f90
|
5 | 6 |
src/fgof_watch.f90modified@@ -1,5 +1,5 @@ | ||
| 1 | 1 | module fgof_watch |
| 2 | - use fgof_watch_types, only : FGOF_WATCH_EVT_NONE, watch_event, watch_options, watch_session | |
| 2 | + use fgof_watch_types, only : watch_event, watch_options, watch_session | |
| 3 | 3 | implicit none |
| 4 | 4 | private |
| 5 | 5 | |
@@ -19,19 +19,20 @@ contains | ||
| 19 | 19 | end if |
| 20 | 20 | |
| 21 | 21 | session%root = root |
| 22 | - session%active = len_trim(root) > 0 | |
| 22 | + session%active = len(root) > 0 | |
| 23 | + allocate(session%entries(0)) | |
| 23 | 24 | end subroutine init_watch |
| 24 | 25 | |
| 25 | - function poll_watch(session) result(event) | |
| 26 | - type(watch_session), intent(in) :: session | |
| 27 | - type(watch_event) :: event | |
| 26 | + function poll_watch(session) result(events) | |
| 27 | + type(watch_session), intent(inout) :: session | |
| 28 | + type(watch_event), allocatable :: events(:) | |
| 28 | 29 | |
| 29 | - event%kind = FGOF_WATCH_EVT_NONE | |
| 30 | - if (allocated(session%root)) then | |
| 31 | - event%path = session%root | |
| 32 | - else | |
| 33 | - event%path = "" | |
| 30 | + if (.not. session%active) then | |
| 31 | + allocate(events(0)) | |
| 32 | + return | |
| 34 | 33 | end if |
| 34 | + | |
| 35 | + allocate(events(0)) | |
| 35 | 36 | end function poll_watch |
| 36 | 37 | |
| 37 | 38 | subroutine reset_watch(session) |
@@ -41,6 +42,10 @@ contains | ||
| 41 | 42 | deallocate(session%root) |
| 42 | 43 | end if |
| 43 | 44 | |
| 45 | + if (allocated(session%entries)) then | |
| 46 | + deallocate(session%entries) | |
| 47 | + end if | |
| 48 | + | |
| 44 | 49 | session%options = watch_options() |
| 45 | 50 | session%active = .false. |
| 46 | 51 | end subroutine reset_watch |
src/fgof_watch_types.f90modified@@ -1,8 +1,13 @@ | ||
| 1 | 1 | module fgof_watch_types |
| 2 | + use, intrinsic :: iso_fortran_env, only : int64 | |
| 2 | 3 | implicit none |
| 3 | 4 | private |
| 4 | 5 | |
| 5 | 6 | integer, parameter, public :: FGOF_WATCH_EVT_NONE = 0 |
| 7 | + integer, parameter, public :: FGOF_WATCH_EVT_CREATED = 1 | |
| 8 | + integer, parameter, public :: FGOF_WATCH_EVT_MODIFIED = 2 | |
| 9 | + integer, parameter, public :: FGOF_WATCH_EVT_REMOVED = 3 | |
| 10 | + integer, parameter, public :: FGOF_WATCH_EVT_MOVED = 4 | |
| 6 | 11 | |
| 7 | 12 | public :: watch_event |
| 8 | 13 | public :: watch_options |
@@ -10,7 +15,9 @@ module fgof_watch_types | ||
| 10 | 15 | |
| 11 | 16 | type :: watch_event |
| 12 | 17 | integer :: kind = FGOF_WATCH_EVT_NONE |
| 18 | + logical :: is_directory = .false. | |
| 13 | 19 | character(len=:), allocatable :: path |
| 20 | + character(len=:), allocatable :: previous_path | |
| 14 | 21 | end type watch_event |
| 15 | 22 | |
| 16 | 23 | type :: watch_options |
@@ -18,9 +25,19 @@ module fgof_watch_types | ||
| 18 | 25 | logical :: recursive = .true. |
| 19 | 26 | end type watch_options |
| 20 | 27 | |
| 28 | + type :: watch_entry | |
| 29 | + character(len=:), allocatable :: path | |
| 30 | + integer(int64) :: inode = 0_int64 | |
| 31 | + integer(int64) :: size = 0_int64 | |
| 32 | + integer(int64) :: mtime_sec = 0_int64 | |
| 33 | + integer(int64) :: mtime_nsec = 0_int64 | |
| 34 | + logical :: is_directory = .false. | |
| 35 | + end type watch_entry | |
| 36 | + | |
| 21 | 37 | type :: watch_session |
| 22 | 38 | character(len=:), allocatable :: root |
| 23 | 39 | type(watch_options) :: options |
| 24 | 40 | logical :: active = .false. |
| 41 | + type(watch_entry), allocatable :: entries(:) | |
| 25 | 42 | end type watch_session |
| 26 | 43 | end module fgof_watch_types |
test/test_event_model.f90added@@ -0,0 +1,28 @@ | ||
| 1 | +program test_event_model | |
| 2 | + use fgof_watch_types, only : & | |
| 3 | + FGOF_WATCH_EVT_CREATED, & | |
| 4 | + FGOF_WATCH_EVT_MODIFIED, & | |
| 5 | + FGOF_WATCH_EVT_MOVED, & | |
| 6 | + FGOF_WATCH_EVT_NONE, & | |
| 7 | + FGOF_WATCH_EVT_REMOVED, & | |
| 8 | + watch_event | |
| 9 | + implicit none | |
| 10 | + | |
| 11 | + type(watch_event) :: event | |
| 12 | + | |
| 13 | + if (FGOF_WATCH_EVT_NONE /= 0) error stop "none event constant should be zero" | |
| 14 | + if (FGOF_WATCH_EVT_CREATED <= FGOF_WATCH_EVT_NONE) error stop "created event should be positive" | |
| 15 | + if (FGOF_WATCH_EVT_MODIFIED <= FGOF_WATCH_EVT_CREATED) error stop "modified event ordering should be stable" | |
| 16 | + if (FGOF_WATCH_EVT_REMOVED <= FGOF_WATCH_EVT_MODIFIED) error stop "removed event ordering should be stable" | |
| 17 | + if (FGOF_WATCH_EVT_MOVED <= FGOF_WATCH_EVT_REMOVED) error stop "moved event ordering should be stable" | |
| 18 | + | |
| 19 | + event%kind = FGOF_WATCH_EVT_MOVED | |
| 20 | + event%is_directory = .true. | |
| 21 | + event%path = "new-path" | |
| 22 | + event%previous_path = "old-path" | |
| 23 | + | |
| 24 | + if (event%kind /= FGOF_WATCH_EVT_MOVED) error stop "event kind should store move values" | |
| 25 | + if (.not. event%is_directory) error stop "event directory flag should be stored" | |
| 26 | + if (event%path /= "new-path") error stop "event path should be stored" | |
| 27 | + if (event%previous_path /= "old-path") error stop "event previous path should be stored" | |
| 28 | +end program test_event_model | |
test/test_scaffold.f90modified@@ -1,9 +1,9 @@ | ||
| 1 | 1 | program test_scaffold |
| 2 | 2 | use fgof_watch, only : init_watch, poll_watch, reset_watch |
| 3 | - use fgof_watch_types, only : FGOF_WATCH_EVT_NONE, watch_event, watch_options, watch_session | |
| 3 | + use fgof_watch_types, only : watch_event, watch_options, watch_session | |
| 4 | 4 | implicit none |
| 5 | 5 | |
| 6 | - type(watch_event) :: event | |
| 6 | + type(watch_event), allocatable :: events(:) | |
| 7 | 7 | type(watch_options) :: options |
| 8 | 8 | type(watch_session) :: session |
| 9 | 9 | |
@@ -16,10 +16,9 @@ program test_scaffold | ||
| 16 | 16 | if (session%options%poll_interval_ms /= 100) error stop "poll interval should be stored" |
| 17 | 17 | if (session%options%recursive) error stop "recursive flag should follow options" |
| 18 | 18 | |
| 19 | - event = poll_watch(session) | |
| 20 | - if (event%kind /= FGOF_WATCH_EVT_NONE) error stop "scaffold poll should report none" | |
| 21 | - if (.not. allocated(event%path)) error stop "scaffold poll should return a path" | |
| 22 | - if (event%path /= "src") error stop "scaffold poll should echo root path" | |
| 19 | + events = poll_watch(session) | |
| 20 | + if (.not. allocated(events)) error stop "poll should always allocate an event batch" | |
| 21 | + if (size(events) /= 0) error stop "placeholder poll should return an empty batch" | |
| 23 | 22 | |
| 24 | 23 | call reset_watch(session) |
| 25 | 24 | if (session%active) error stop "reset should deactivate session" |