Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 63 lines (55 sloc) 2.05 kb
704f3fe @telent a channel is an agent that wraps a connection and deals with incoming…
authored
1 (ns psadan.channel
2 (:use clojure.pprint)
3 (:require
4 [psadan.connection :as conn]
5 [psadan.protocol :as proto]
40a198e @telent conn/register-global sticks the global into a hash for later querying
authored
6 [psadan.pack :as pack]
704f3fe @telent a channel is an agent that wraps a connection and deals with incoming…
authored
7 [psadan.buffer :as buf]))
8
9 (defmulti handle-message
10 (fn [conn m]
11 [(:name (:interface m)) (:message m)]))
12
13 (defmethod handle-message [:wl_registry :global] [conn m]
40a198e @telent conn/register-global sticks the global into a hash for later querying
authored
14 ;; according to the protocol, 'name' is a uint. Confusing,
15 ;; but we stick with that nomenclature for consistency
16 (let [[name interface version] (:args m)]
17 (println ["global " name interface version])
18 (conn/register-global conn name interface version)))
704f3fe @telent a channel is an agent that wraps a connection and deals with incoming…
authored
19
20 (defmethod handle-message [:wl_callback :done] [conn m]
21 (let [object (conn/get-object conn (:object-id m))
22 promise (:promise object)]
23 (when promise
24 (deliver promise m))))
25
26 (defmethod handle-message :default [conn m]
27 (println ["unknown message" (:name (:interface m)) (:message m)]))
28
29 (defn listen [conn]
30 (let [buf (conn/read-buffer conn)
31 messages (buf/parse-messages buf conn :events)]
32 (printf "got a buffer, %d messages" (count messages))
33 (dorun (map #(handle-message conn %) messages)))
34 (send-off *agent* listen)
35 conn)
36
37 (defn open-channel [name]
38 (let [agent (agent (conn/open-connection name))]
39 (send-off agent listen)
c21d574 @telent move test-send-message to get-registry in channel ns
authored
40 agent))
41
42
43 (defn get-registry [channel]
44 (let [connection @channel
a54f6d3 @telent get-registry now does one write not two
authored
45 registry (conn/remember-object
46 connection
47 {:id 2
48 :interface (proto/find-interface-by-name :wl_registry)})
c21d574 @telent move test-send-message to get-registry in channel ns
authored
49 promise (promise)
a54f6d3 @telent get-registry now does one write not two
authored
50 done-cb (conn/remember-object
51 connection
52 {:id 3
53 :promise promise
54 :interface (proto/find-interface-by-name :wl_callback)})
55 display (:display connection)
c21d574 @telent move test-send-message to get-registry in channel ns
authored
56 ]
a54f6d3 @telent get-registry now does one write not two
authored
57 (conn/write-buffer
58 connection
59 (mapcat (fn [[object mtype message args]]
60 (pack/pack-message object mtype message args))
61 [[display :requests :get_registry [registry]]
62 [display :requests :sync [done-cb]]]))
c21d574 @telent move test-send-message to get-registry in channel ns
authored
63 @promise))
Something went wrong with that request. Please try again.