~ubuntu-branches/ubuntu/wily/afnix/wily

« back to all changes in this revision

Viewing changes to prj/apx/src/app/apx-rwstm.als

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2011-03-16 21:31:18 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110316213118-gk4k3ez3e5d2huna
Tags: 2.0.0-1
* QA upload.
* New upstream release
* Debian source format is 3.0 (quilt)
* Fix debhelper-but-no-misc-depends
* Fix ancient-standards-version
* Fix package-contains-linda-override
* debhelper compatibility is 7
* Fix dh-clean-k-is-deprecated

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# ---------------------------------------------------------------------------
2
 
# - apx-rwstm                                                               -
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.                  -
7
 
# -                                                                         -
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
 
# ---------------------------------------------------------------------------
16
 
 
17
 
# ----------------------------------------------------------------------------
18
 
# - global section                                                           -
19
 
# ----------------------------------------------------------------------------
20
 
 
21
 
# the read/write stream class
22
 
const afnix:apx:rwstm (class)
23
 
 
24
 
# ----------------------------------------------------------------------------
25
 
# - initial section                                                          -
26
 
# ----------------------------------------------------------------------------
27
 
 
28
 
# initialize the read/write stream
29
 
# @param is the input stream to use
30
 
# @param os the output stream to use
31
 
 
32
 
trans afnix:apx:rwstm:preset (is os) {
33
 
  # set the base object
34
 
  trans this:super (afnix:xml:XmlReader)
35
 
  # set the i/o stream
36
 
  const this:is is
37
 
  const this:os os
38
 
}
39
 
 
40
 
# ----------------------------------------------------------------------------
41
 
# - method section                                                          -
42
 
# ----------------------------------------------------------------------------
43
 
 
44
 
# @return true if the streams are still open
45
 
 
46
 
trans afnix:apx:rwstm:valid-p nil {
47
 
  is:valid-p
48
 
}
49
 
 
50
 
# @return the next available apx packet
51
 
 
52
 
trans afnix:apx:rwstm:read-apx-node nil {
53
 
  # reset the reader
54
 
  this:reset
55
 
  # parse the input stream
56
 
  this:parse this:is
57
 
  # get the root node
58
 
  this:get-root
59
 
}
60
 
 
61
 
# write an apx packet to the output stream
62
 
# @param node the apx node to write
63
 
 
64
 
trans afnix:apx:rwstm:write-apx-node (node) {
65
 
  node:write this:os
66
 
  this:os:write-eof
67
 
}
68
 
 
69
 
# @return the next available apx message
70
 
 
71
 
trans afnix:apx:rwstm:read-message nil {
72
 
  # get the root node
73
 
  const root (this:read-apx-node)
74
 
  # attach the root node to an apx root object
75
 
  const xapx (afnix:apx:root)
76
 
  xapx:attach-node root
77
 
  # here is the result
78
 
  eval xapx
79
 
}
80
 
 
81
 
# write a request message with the command name and arguments
82
 
# @param name the command name
83
 
# @param argl the argument list
84
 
 
85
 
trans afnix:apx:rwstm:send-request-message (name argl) {
86
 
  # create a new apx root note
87
 
  const xapx (afnix:apx:root)
88
 
  # add a request node
89
 
  const rqst (xapx:add-request-command name)
90
 
  # add the argument list
91
 
  rqst:add-argument-list argl
92
 
  # write the message
93
 
  this:write-apx-node xapx
94
 
}
95
 
 
96
 
# write a command message with the command
97
 
# @param cmd the command to send
98
 
 
99
 
trans afnix:apx:rwstm:send-command-message (cmd) {
100
 
  # create a new apx root note
101
 
  const xapx (afnix:apx:root)
102
 
  # add a request node
103
 
  xapx:add-request-command cmd
104
 
  # write the message
105
 
  this:write-apx-node xapx
106
 
}
107
 
 
108
 
# write a message with a status code and a payload
109
 
# @param code the reply status code
110
 
# @param payl the reply payload
111
 
 
112
 
trans afnix:apx:rwstm:send-reply-message (code payl) {
113
 
  # create a new apx root note
114
 
  const xapx (afnix:apx:root)
115
 
  # add a reply node
116
 
  const rply (xapx:add-reply-status code)
117
 
  # set the reply payload
118
 
  rply:set-payload-node payl
119
 
  # write the message
120
 
  this:write-apx-node xapx
121
 
}