1
# ---------------------------------------------------------------------------
3
# - afnix:apx read/write stream class module -
4
# ---------------------------------------------------------------------------
5
# - This program is free software; you can redistribute it and/or modify -
6
# - it provided that this copyright notice is kept intact. -
8
# - This program is distributed in the hope that it will be useful, but -
9
# - without any warranty; without even the implied warranty of -
10
# - merchantability or fitness for a particular purpose. In no event shall -
11
# - the copyright holder be liable for any direct, indirect, incidental or -
12
# - special damages arising in any way out of the use of this software. -
13
# ---------------------------------------------------------------------------
14
# - copyright (c) 1999-2007 amaury darsch -
15
# ---------------------------------------------------------------------------
17
# ----------------------------------------------------------------------------
19
# ----------------------------------------------------------------------------
21
# the read/write stream class
22
const afnix:apx:rwstm (class)
24
# ----------------------------------------------------------------------------
26
# ----------------------------------------------------------------------------
28
# initialize the read/write stream
29
# @param is the input stream to use
30
# @param os the output stream to use
32
trans afnix:apx:rwstm:preset (is os) {
34
trans this:super (afnix:xml:XmlReader)
40
# ----------------------------------------------------------------------------
42
# ----------------------------------------------------------------------------
44
# @return true if the streams are still open
46
trans afnix:apx:rwstm:valid-p nil {
50
# @return the next available apx packet
52
trans afnix:apx:rwstm:read-apx-node nil {
55
# parse the input stream
61
# write an apx packet to the output stream
62
# @param node the apx node to write
64
trans afnix:apx:rwstm:write-apx-node (node) {
69
# @return the next available apx message
71
trans afnix:apx:rwstm:read-message nil {
73
const root (this:read-apx-node)
74
# attach the root node to an apx root object
75
const xapx (afnix:apx:root)
81
# write a request message with the command name and arguments
82
# @param name the command name
83
# @param argl the argument list
85
trans afnix:apx:rwstm:send-request-message (name argl) {
86
# create a new apx root note
87
const xapx (afnix:apx:root)
89
const rqst (xapx:add-request-command name)
90
# add the argument list
91
rqst:add-argument-list argl
93
this:write-apx-node xapx
96
# write a command message with the command
97
# @param cmd the command to send
99
trans afnix:apx:rwstm:send-command-message (cmd) {
100
# create a new apx root note
101
const xapx (afnix:apx:root)
103
xapx:add-request-command cmd
105
this:write-apx-node xapx
108
# write a message with a status code and a payload
109
# @param code the reply status code
110
# @param payl the reply payload
112
trans afnix:apx:rwstm:send-reply-message (code payl) {
113
# create a new apx root note
114
const xapx (afnix:apx:root)
116
const rply (xapx:add-reply-status code)
117
# set the reply payload
118
rply:set-payload-node payl
120
this:write-apx-node xapx