1 | ;; Copyright (C) 2010 FoAM vzw |
---|
2 | ;; This program is free software: you can redistribute it and/or modify |
---|
3 | ;; it under the terms of the GNU Affero General Public License as |
---|
4 | ;; published by the Free Software Foundation, either version 3 of the |
---|
5 | ;; License, or (at your option) any later version. |
---|
6 | ;; |
---|
7 | ;; This program is distributed in the hope that it will be useful, |
---|
8 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
9 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
10 | ;; GNU Affero General Public License for more details. |
---|
11 | ;; |
---|
12 | ;; You should have received a copy of the GNU Affero General Public License |
---|
13 | ;; along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
14 | |
---|
15 | (ns oak.remote-agent |
---|
16 | (:use oak.io) |
---|
17 | (:import |
---|
18 | java.net.Socket |
---|
19 | java.io.File |
---|
20 | java.io.IOException |
---|
21 | java.util.Random |
---|
22 | java.io.BufferedReader |
---|
23 | java.io.InputStreamReader |
---|
24 | FAtiMA.util.parsers.SocketListener |
---|
25 | FAtiMA.autobiographicalMemory.AutobiographicalMemory)) |
---|
26 | |
---|
27 | (defstruct remote-agent |
---|
28 | :properties |
---|
29 | :name |
---|
30 | :role |
---|
31 | :display-name |
---|
32 | :socket |
---|
33 | :relations |
---|
34 | :emotions |
---|
35 | :said |
---|
36 | :done |
---|
37 | :random |
---|
38 | :reader) |
---|
39 | |
---|
40 | (def remote-agent-properties (accessor remote-agent :properties)) |
---|
41 | (def remote-agent-name (accessor remote-agent :name)) |
---|
42 | (def remote-agent-role (accessor remote-agent :role)) |
---|
43 | (def remote-agent-display-name (accessor remote-agent :display-name)) |
---|
44 | (def remote-agent-socket (accessor remote-agent :socket)) |
---|
45 | (def remote-agent-relations (accessor remote-agent :relations)) |
---|
46 | (def remote-agent-emotions (accessor remote-agent :emotions)) |
---|
47 | (def remote-agent-said (accessor remote-agent :said)) |
---|
48 | (def remote-agent-done (accessor remote-agent :done)) |
---|
49 | (def remote-agent-random (accessor remote-agent :random)) |
---|
50 | (def remote-agent-reader (accessor remote-agent :reader)) |
---|
51 | |
---|
52 | (defn remote-agent-add-property [agent property] |
---|
53 | (merge agent {:properties (cons property (remote-agent-properties agent))})) |
---|
54 | |
---|
55 | (defn make-remote-agent [socket world] |
---|
56 | ;(.configureBlocking socket false) |
---|
57 | ;(. (AutobiographicalMemory/GetInstance) setSelf name) |
---|
58 | (let [reader (BufferedReader. |
---|
59 | (InputStreamReader. |
---|
60 | (.getInputStream (.socket socket)))) |
---|
61 | toks (.split (read-msg reader) " ")] |
---|
62 | (send-msg socket "OK") |
---|
63 | (struct |
---|
64 | remote-agent |
---|
65 | (reduce |
---|
66 | (fn [r prop] |
---|
67 | (let [tv (.split prop ":")] |
---|
68 | (assoc r (first tv) (second tv)))) |
---|
69 | {} |
---|
70 | (nthnext toks 3)) |
---|
71 | (nth toks 0) |
---|
72 | (nth toks 1) |
---|
73 | (nth toks 2) |
---|
74 | socket |
---|
75 | "none yet" |
---|
76 | "none yet" |
---|
77 | '() |
---|
78 | '() |
---|
79 | (new java.util.Random) |
---|
80 | reader |
---|
81 | ))) |
---|
82 | |
---|