1 // (c) Bernhard Tittelbach, 2013
6 zmq "github.com/vaughan0/go-zmq"
7 r3events "svn.spreadspace.org/realraum/go.svn/r3events"
10 type hippocampus map[string]interface{}
12 func BrainCenter( zmq_ctx *zmq.Context, listen_addr string, event_chan <- chan interface{} ) {
13 zbrain_chans, err := ZmqsBindNewReplySocket(zmq_ctx, listen_addr)
14 if err != nil { panic(err) }
15 defer zbrain_chans.Close()
16 h := make(hippocampus,5)
19 case event, ec_still_open := <- event_chan:
20 if ! ec_still_open { return }
21 h[r3events.NameOfStruct(event)] = event
22 Debug_.Printf("Brain: stored %s, %s", r3events.NameOfStruct(event), event)
24 case brain_request := <- zbrain_chans.In():
25 if len(brain_request) == 0 { continue }
26 requested_eventname := string(brain_request[0])
27 Debug_.Printf("Brain: received request: %s", requested_eventname)
28 retr_event, is_in_map := h[requested_eventname]
30 data, err := r3events.MarshalEvent2ByteByte(retr_event)
32 zbrain_chans.Out() <- data
35 Syslog_.Print("BrainCenter", err)
36 Debug_.Print("BrainCenter", err)
39 zbrain_chans.Out() <- [][]byte{[]byte("UNKNOWN")}