[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 07/09: service: Mark action and state methods as deprecated.
From: |
Ludovic Courtès |
Subject: |
[shepherd] 07/09: service: Mark action and state methods as deprecated. |
Date: |
Wed, 5 Apr 2023 17:33:59 -0400 (EDT) |
civodul pushed a commit to branch wip-goopsless
in repository shepherd.
commit 315af3912f562e3d7fab231801150fb4bb6d89d3
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Wed Apr 5 22:33:23 2023 +0200
service: Mark action and state methods as deprecated.
* modules/shepherd/service.scm (service-running?, service-stopped?)
(service-action-list, lookup-service-action, service-defines-action?):
New procedures.
(define-deprecated-method): New macro.
(define-deprecated-service-getter): Redefine in terms of
'define-deprecated-method'.
(action-list, running?, stopped?, enabled?, lookup-action)
(defines-action): Define as deprecated methods. Adjust users
accordingly.
---
modules/shepherd/service.scm | 84 +++++++++++++++++++++++++++-----------------
1 file changed, 51 insertions(+), 33 deletions(-)
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 1e7bb05..d42c386 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -59,10 +59,10 @@
service-documentation
service-canonical-name
- running?
- action-list
- lookup-action
- defines-action?
+ service-running?
+ service-action-list
+ lookup-service-action
+ service-defines-action?
with-service-registry
action?
@@ -147,7 +147,13 @@
one-shot?
transient?
respawn?
- canonical-name))
+ canonical-name
+ running?
+ stopped?
+ enabled?
+ action-list
+ lookup-action
+ defines-action?))
(define sleep (@ (fibers) sleep))
@@ -608,32 +614,29 @@ channel and wait for its reply."
"Record the current time as the last respawn time for @var{service}."
(put-message (service-control service) 'record-respawn-time))
-(define-method (running? (service <service>))
+(define (service-running? service)
"Return true if @var{service} is not stopped."
- (not (stopped? service)))
+ (not (service-stopped? service)))
-(define (stopped? service)
+(define (service-stopped? service)
"Return true if @var{service} is stopped."
(eq? 'stopped (service-status service)))
-;; Return a list of all actions implemented by OBJ.
-(define-method (action-list (obj <service>))
- (map action-name (service-actions obj)))
+(define (service-action-list service)
+ "Return the list of actions implemented by @var{service} (a list of
+symbols)."
+ (map action-name (service-actions service)))
-;; Return the action ACTION or #f if none was found.
-(define-method (lookup-action (obj <service>) action)
+(define (lookup-service-action service action)
+ "Return the action @var{action} of @var{service} or #f if none was found."
(find (match-lambda
(($ <action> name)
(eq? name action)))
- (service-actions obj)))
-
-;; Return whether OBJ implements the action ACTION.
-(define-method (defines-action? (obj <service>) action)
- (and (lookup-action obj action) #t))
+ (service-actions service)))
-(define-method (enabled? (service <service>))
- "Return true if @var{service} is enabled."
- (service-enabled? service))
+(define (service-defines-action? service action)
+ "Return whether @var{service} implements the action @var{action}."
+ (and (lookup-service-action service action) #t))
;; Enable the service, allow it to get started.
(define-method (enable (obj <service>))
@@ -772,14 +775,14 @@ NEW-SERVICE."
canonical names for all of the services which have been stopped (including
transitive dependent services). This method will print a warning if SERVICE
is not already running, and will return SERVICE's canonical name in a list."
- (if (stopped? service)
+ (if (service-stopped? service)
(begin
(local-output (l10n "Service ~a is not running.")
(service-canonical-name service))
(list (service-canonical-name service)))
(let ((name (service-canonical-name service))
(stopped-dependents (fold-services (lambda (other acc)
- (if (and (running? other)
+ (if (and (service-running?
other)
(required-by?
service other))
(append (stop other) acc)
acc))
@@ -851,7 +854,7 @@ is not already running, and will return SERVICE's canonical
name in a list."
(service obj)
(action the-action))))))))
- (let ((proc (or (and=> (lookup-action obj the-action)
+ (let ((proc (or (and=> (lookup-service-action obj the-action)
action-procedure)
default-action)))
;; Invoking THE-ACTION is allowed even when the service is not running, as
@@ -898,7 +901,7 @@ is not already running, and will return SERVICE's canonical
name in a list."
(for-each
(lambda (the-action)
(let ((action-object
- (lookup-action obj (string->symbol the-action))))
+ (lookup-service-action obj (string->symbol the-action))))
(unless action-object
(raise (condition (&unknown-action-error
(action the-action)
@@ -982,7 +985,7 @@ requests arriving on @var{channel}."
(#f (loop (register service
(unregister (list old))))))))))
(('unregister services) ;no reply
- (match (remove stopped? services)
+ (match (remove service-stopped? services)
(()
(loop (unregister services)))
(lst ;
@@ -1101,7 +1104,8 @@ Used by `start'."
;; Stopping by name.
(define-method (stop (obj <symbol>) . args)
- (let ((which (find (negate stopped?) (lookup-services obj))))
+ (let ((which (find (negate service-stopped?)
+ (lookup-services obj))))
(if which
(apply stop which args)
;; Only print an error if the service does not exist.
@@ -2416,7 +2420,7 @@ This will remove a service either if it is identified by
its canonical
name, or if it is the only service providing the service that is
requested to be removed."
(define (deregister service)
- (when (running? service)
+ (when (service-running? service)
(stop service))
;; Remove services provided by service from the hash table.
(put-message (current-registry-channel)
@@ -2468,13 +2472,16 @@ requested to be removed."
;;; Deprecated aliases.
;;;
-(define-syntax-rule (define-deprecated-service-getter name alias)
- (define-method (name (service <service>))
+(define-syntax-rule (define-deprecated-method (name (service class) formals
...) alias)
+ (define-method (name (service class) formals ...)
(issue-deprecation-warning
(format #f "GOOPS method '~a' is \
deprecated in favor of procedure '~a'"
'name 'alias))
- (alias service)))
+ (alias service formals ...)))
+
+(define-syntax-rule (define-deprecated-service-getter name alias)
+ (define-deprecated-method (name (service <service>)) alias))
(define-deprecated-service-getter provided-by service-provision)
(define-deprecated-service-getter required-by service-requirement)
@@ -2483,6 +2490,17 @@ deprecated in favor of procedure '~a'"
(define-deprecated-service-getter respawn? respawn-service?)
(define-deprecated-service-getter canonical-name service-canonical-name)
+(define-deprecated-service-getter action-list service-action-list)
+
+(define-deprecated-service-getter running? service-running?)
+(define-deprecated-service-getter stopped? service-stopped?)
+(define-deprecated-service-getter enabled? service-enabled?)
+
+(define-deprecated-method (lookup-action (service <service>) action)
+ lookup-service-action)
+(define-deprecated-method (defines-action? (service <service>) action)
+ service-defines-action?)
+
@@ -2495,7 +2513,7 @@ deprecated in favor of procedure '~a'"
;; suspending via (@ (fibers) sleep), 'spawn-command', or similar.
(for-each
(lambda (service)
- (when (running? service)
+ (when (service-running? service)
(stop service)))
(service-list)))
@@ -2619,7 +2637,7 @@ we want to receive these signals."
(local-output (l10n "Running as PID 1, so not daemonizing.")))
((fold-services (lambda (service found?)
(or found?
- (and (running? service)
+ (and (service-running? service)
(not (eq? service root-service)))))
#f)
(local-output
- [shepherd] branch wip-goopsless created (now 6f7228f), Ludovic Courtès, 2023/04/05
- [shepherd] 03/09: service: Rename <service> getters following Scheme conventions., Ludovic Courtès, 2023/04/05
- [shepherd] 02/09: comm: Remove use of (oop goops)., Ludovic Courtès, 2023/04/05
- [shepherd] 01/09: args: Remove use of (oop goops)., Ludovic Courtès, 2023/04/05
- [shepherd] 04/09: service: Add getters for <service> and remove uses of 'slot-ref'., Ludovic Courtès, 2023/04/05
- [shepherd] 07/09: service: Mark action and state methods as deprecated.,
Ludovic Courtès <=
- [shepherd] 08/09: service: Provide 'service' constructor., Ludovic Courtès, 2023/04/05
- [shepherd] 05/09: Remove example of the 'unknown' service., Ludovic Courtès, 2023/04/05
- [shepherd] 06/09: service: Replace 'canonical-name' method with 'service-canonical-name'., Ludovic Courtès, 2023/04/05
- [shepherd] 09/09: service: Use 'service' procedure to replace (make <service> ...)., Ludovic Courtès, 2023/04/05