Debian Codegraph @

tests/publish+browse.scm

raw symbols SCIP
1 ;;; Guile-Avahi --- Guile bindings for Avahi.
2 ;;; Copyright (C) 2007 Ludovic Courtès <[email protected]>
3 ;;;
4 ;;; This file is part of Guile-Avahi.
5 ;;;
6 ;;; Guile-Avahi is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU Lesser General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
10 ;;;
11 ;;; Guile-Avahi is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
14 ;;; General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU Lesser General Public License
17 ;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 ;;;
20 ;;; Excercise the lookup API, using the publication API to have something to
21 ;;; browse.
22 ;;;
23
24 (use-modules (avahi)
25 (avahi client)
26 (avahi client publish)
27 (avahi client lookup)
28 (avahi test))
29
30 (define %service-name
31 (make-service-name))
32
33
34
35 (dynamic-wind
36 (lambda ()
37 #t)
38
39 (lambda ()
40 (define domain-browser #f)
41 (define service-type-browser #f)
42 (define service-browser #f)
43
44 (define seen-service-type? #f)
45 (define seen-service? #f)
46
47
48 (define (domain-browser-callback browser interface protocol event
49 domain flags)
50 ;;(format #t "domain-browser: ~a ~a ~a~%"
51 ;; event domain flags)
52 #t)
53
54 (define (service-type-browser-callback browser interface protocol event
55 service-type domain flags)
56 ;;(format #t "service-type: ~a ~a ~a ~a~%"
57 ;; event service-type domain flags)
58 (set! seen-service-type?
59 (or seen-service-type?
60 (and (eq? event browser-event/new)
61 (equal? %service-type service-type)))))
62
63 (define (service-browser-callback browser interface protocol event
64 service-name service-type
65 domain flags)
66 ;;(format #t "service: ~a ~a ~a ~a ~a~%"
67 ;; event service-name service-type domain flags)
68 (set! seen-service?
69 (or seen-service?
70 (and (eq? event browser-event/new)
71 (memq lookup-result-flag/our-own flags)
72 (equal? %service-name service-name)))))
73
74 (define (make-group-callback client)
75 (lambda (group state)
76 ;;(format #t "group-state: ~a~%" state)
77 (if (eq? state entry-group-state/established)
78 (begin
79 ;; Everything was published, so let's browse!
80 (set! domain-browser
81 (make-domain-browser client interface/unspecified
82 protocol/unspecified
83 #f
84 domain-browser-type/browse
85 '()
86 domain-browser-callback))
87 (set! service-type-browser
88 (make-service-type-browser client
89 interface/unspecified
90 protocol/unspecified
91 #f '()
92 service-type-browser-callback))
93 (set! service-browser
94 (make-service-browser client
95 interface/unspecified
96 protocol/unspecified
97 %service-type #f '()
98 service-browser-callback))))))
99
100 (define client-callback
101 (let ((group #f))
102 (lambda (client state)
103 ;;(format #t "client: ~a~%" state)
104 (if (eq? state client-state/s-running)
105 (begin
106 ;; The client is ready so start publishing a service.
107 (set! group (make-entry-group client
108 (make-group-callback client)))
109 (add-entry-group-service! group interface/unspecified
110 protocol/unspecified '()
111 %service-name
112 %service-type #f #f
113 1234 "scheme=yes" "java=no")
114 (commit-entry-group group))))))
115
116
117 (assert-exit (let* ((poll (make-simple-poll))
118 (client (make-client (simple-poll poll)
119 (list
120 client-flag/ignore-user-config)
121 client-callback)))
122 (and (client? client)
123 (iterate-simple-poll-until-true
124 poll
125 (lambda ()
126 (and seen-service-type? seen-service?
127 (begin
128 (free-service-browser! service-browser)
129 (free-service-type-browser!
130 service-type-browser))
131 (freed-service-browser? service-browser)
132 (freed-service-type-browser?
133 service-type-browser))))))))
134
135 (lambda ()
136 ;; failure.
137 (assert-exit 1)))
138
139
140 ;;; arch-tag: f173da7a-afde-4510-bf8b-f2d60148d1fd