1 ;;; 8sync --- Asynchronous programming for Guile
2 ;;; Copyright (C) 2015 Christopher Allan Webber <cwebber@dustycloud.org>
4 ;;; This file is part of 8sync.
6 ;;; 8sync is free software: you can redistribute it and/or modify it
7 ;;; under the terms of the GNU Lesser General Public License as
8 ;;; published by the Free Software Foundation, either version 3 of the
9 ;;; License, or (at your option) any later version.
11 ;;; 8sync is distributed in the hope that it will be useful,
12 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU Lesser General Public License for more details.
16 ;;; You should have received a copy of the GNU Lesser General Public
17 ;;; License along with 8sync. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (8sync repl)
20 #:use-module (oop goops)
22 #:use-module (system repl server)
23 #:use-module (system repl coop-server)
24 #:export (<repl-manager>))
26 (define-class <repl-manager> (<actor>)
27 (path #:init-keyword #:path
28 #:init-value "/tmp/8sync-socket"
29 #:getter repl-manager-path)
30 (socket #:init-value #f
31 #:accessor repl-manager-socket)
32 (poll-every #:init-keyword #:poll-every
34 #:getter repl-manager-poll-every)
35 (actions #:allocation #:each-subclass
36 ;; @@: Should we add a stop action?
37 #:init-value (build-actions
38 (*cleanup* repl-manager-cleanup)
39 (*init* repl-manager-init))))
41 (define (repl-manager-cleanup repl-manager message)
42 ;; Close the socket, if open
43 (and=> (repl-manager-socket repl-manager)
45 ;; Delete the file, if it exists
46 (when (file-exists? (repl-manager-path repl-manager))
47 (delete-file (repl-manager-path repl-manager))))
49 (define (repl-manager-init repl-manager message)
51 (make-unix-domain-server-socket #:path (repl-manager-path repl-manager)))
53 (spawn-coop-repl-server socket))
54 (set! (repl-manager-socket repl-manager) socket)
55 (while (actor-alive? repl-manager)
56 (poll-coop-repl-server server)
57 (8sleep (repl-manager-poll-every repl-manager))))