1 ; Dolda Connect - Modular multiuser Direct Connect-style client
2 ; Copyright (C) 2007 Fredrik Tolf <fredrik@dolda2000.com>
4 ; This program is free software; you can redistribute it and/or modify
5 ; it under the terms of the GNU General Public License as published by
6 ; the Free Software Foundation; either version 2 of the License, or
7 ; (at your option) any later version.
9 ; This program is distributed in the hope that it will be useful,
10 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ; GNU General Public License for more details.
14 ; You should have received a copy of the GNU General Public License
15 ; along with this program; if not, write to the Free Software
16 ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 (define-module (dolcon util))
19 (use-modules (dolcon ui))
21 (define fnetnodes '())
22 (define loop-procs '())
25 (define-public dc-fn-update
28 (let ((resp (dc-ecmd "lsnodes")) (er #f))
29 (if (and resp (begin (set! er (dc-extract resp)) er) (= (cdr (assq 'code er)) 200))
31 (apply (lambda (id net name users state uid)
37 (cons 'state (list-ref '(syn hs est dead) state))
44 (define-public dc-fn-getattrib
46 (if (not (assq id fnetnodes))
48 (let ((aform (assq id fnetnodes)))
50 (cdr (assq attrib (cdr aform)))
53 (define-public dc-fn-getname
55 (dc-fn-getattrib id 'name)))
57 (define-public dc-getfnetnodes
59 (map (lambda (o) (car o))
64 (let ((aform (assq id fnetnodes)))
66 (set-cdr! (assq attr (cdr aform)) val)
69 (define-public dc-fnproc-reg
71 (set! fn-procs (cons (list event proc)
74 (define-public dc-handle-fn
77 (let* ((notify (lambda (event data) (for-each (lambda (o) (if (eq? event (car o)) ((cadr o) data))) fn-procs)))
78 (ua (lambda (r a) (let* ((ires (dc-intresp r))
79 (hubform (assq (car ires) fnetnodes)))
81 (begin (fn-updattr (car ires) a (cadr ires))
82 (notify a (cdr (assq (car ires) fnetnodes)))))))))
83 (dc-loop-reg ".notify" 601 (lambda (r er) (let* ((ires (dc-intresp r))
84 (hubform (assq (car ires) fnetnodes)))
86 (begin (fn-updattr (car ires) 'state (list-ref '(syn hs est dead) (cadr ires)))
87 (notify 'state (cdr hubform)))))))
88 (dc-loop-reg ".notify" 602 (lambda (r er) (ua r 'name)))
89 (dc-loop-reg ".notify" 605 (lambda (r er) (ua r 'users)))
90 (dc-loop-reg ".notify" 604 (lambda (r er)
91 (let* ((ires (dc-intresp r))
92 (new (list (cons 'id (car ires))
93 (cons 'net (cadr ires))
98 (cons (cons (car ires) new)
100 (notify 'creat new))))
101 (dc-loop-reg ".notify" 603 (lambda (r er)
102 (let* ((ires (dc-intresp r)) (nform (assq (car ires) fnetnodes)))
103 (notify 'dstr (cdr nform))
104 (set! fnetnodes (delq nform fnetnodes))))))))
106 (define-public dc-loop-reg
107 (lambda (cmd code proc)
108 (set! loop-procs (cons (cons (cons cmd code) proc)
111 (define-public dc-loop
115 (while (let ((resp (dc-getresp)))
117 (let* ((er (dc-extract resp)) (code (cdr (assq 'code er))) (cmd (cdr (assq 'cmd er))))
120 (if (and (or (not (caar o)) (equal? cmd (caar o)))
121 (or (not (cdar o)) (equal? code (cdar o))))
126 (for-each (lambda (o)
127 (if (equal? (caar o) ".periodic")