File: chat.h.html

package info (click to toggle)
rudiments 0.31-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,516 kB
  • ctags: 3,248
  • sloc: asm: 23,776; cpp: 22,792; sh: 7,769; ansic: 1,769; makefile: 1,054; xml: 169; perl: 19
file content (119 lines) | stat: -rw-r--r-- 8,715 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<html>
<head>
<title>~/src/firstworks/rudiments-0.31/include/rudiments/chat.h.html</title>
<meta name="Generator" content="Vim/7.0">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#ffffff" text="#000000">
<pre>
<font color="#0000ff">// Copyright (c) 2004 David Muse</font>
<font color="#0000ff">// See the COPYING file for more information.</font>

<font color="#a020f0">#ifndef RUDIMENTS_CHAT_H</font>
<font color="#a020f0">#define RUDIMENTS_CHAT_H</font>

<font color="#a020f0">#include </font><font color="#ff00ff">&lt;rudiments/private/chatincludes.h&gt;</font>

<font color="#0000ff">// The chat class implements methods for chatting with something (such as</font>
<font color="#0000ff">// a modem) over a file descriptor or set of file descriptors.</font>

<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
<font color="#2e8b57"><b>namespace</b></font> rudiments {
<font color="#a020f0">#endif</font>

<font color="#2e8b57"><b>class</b></font> chatprivate;

<font color="#2e8b57"><b>class</b></font> chat {
        <font color="#a52a2a"><b>public</b></font>:
                chat(<font color="#2e8b57"><b>const</b></font> filedescriptor *fd);
                <font color="#0000ff">// Initializes an instance of chat.  Data will be</font>
                <font color="#0000ff">// written to and read from &quot;fd&quot;.</font>
                chat(<font color="#2e8b57"><b>const</b></font> filedescriptor *rfd, <font color="#2e8b57"><b>const</b></font> filedescriptor *wfd);
                <font color="#0000ff">// Initializes an instance of chat.  Data will be</font>
                <font color="#0000ff">// written to &quot;wfd&quot; and read from &quot;rfd&quot;.</font>
                ~chat();

                <font color="#0000ff">// These methods process &quot;script&quot; which is expected to be</font>
                <font color="#0000ff">// a chunk of XML of the following format:</font>
                <font color="#0000ff">//</font>
                <font color="#0000ff">// &lt;script&gt;</font>
                <font color="#0000ff">//    &lt;timeout seconds=&quot;2&quot;/&gt;</font>
                <font color="#0000ff">//    &lt;abort string=&quot;ERROR&quot;/&gt;</font>
                <font color="#0000ff">//    &lt;send string=&quot;AT Z\p\p\p\r\n&quot;/&gt;</font>
                <font color="#0000ff">//    &lt;expect string=&quot;OK&quot;/&gt;</font>
                <font color="#0000ff">//    &lt;clearabort/&gt;</font>
                <font color="#0000ff">//    &lt;abort string=&quot;(NO DIALTONE|NO DIAL TONE)&quot;/&gt;</font>
                <font color="#0000ff">//    &lt;abort string=&quot;NO CARRIER&quot;/&gt;</font>
                <font color="#0000ff">//    &lt;abort string=&quot;BUSY&quot;/&gt;</font>
                <font color="#0000ff">//    &lt;timeout seconds=&quot;30&quot;/&gt;</font>
                <font color="#0000ff">//    &lt;send string=&quot;ATDT18005555555\r\n&quot;/&gt;</font>
                <font color="#0000ff">//    &lt;expect string=&quot;CONNECT&quot;/&gt;</font>
                <font color="#0000ff">// &lt;/script&gt;</font>
                <font color="#0000ff">//</font>
                <font color="#0000ff">// runScript() processes each tag sequentially and may abort</font>
                <font color="#0000ff">// before processing all of the tags if a user-initiated abort</font>
                <font color="#0000ff">// occurs, if an abort condition is met or if a timeout occurs.</font>
                <font color="#0000ff">//</font>
                <font color="#0000ff">// The &lt;send&gt; tag specifies data to be written.  The following</font>
                <font color="#0000ff">// escape sequences are recognized:</font>
                <font color="#0000ff">//    \d - 1 second pause</font>
                <font color="#0000ff">//    \p - 1/10th of a second pause</font>
                <font color="#0000ff">//    \r - carriage return</font>
                <font color="#0000ff">//    \n - new line</font>
                <font color="#0000ff">//    \b - backspace</font>
                <font color="#0000ff">//    \000 - an octal sequence</font>
                <font color="#0000ff">//            (where 000 is replaced with 3 numbers &lt;=8)</font>
                <font color="#0000ff">//    \N - null</font>
                <font color="#0000ff">// If a filedescriptor-level error occurs writing data, then</font>
                <font color="#0000ff">// runScript() will return RESULT_ERROR.</font>
                <font color="#0000ff">//    </font>
                <font color="#0000ff">// The &lt;timeout&gt; tag specified the number of seconds to wait</font>
                <font color="#0000ff">// for a response after a &lt;send&gt; tag has been fully processed</font>
                <font color="#0000ff">// before runScript() will fail, returning a RESULT_TIMEOUT.</font>
                <font color="#0000ff">// If no &lt;timeout&gt; tag is defined, a default timeout of 45</font>
                <font color="#0000ff">// seconds will be used.</font>
                <font color="#0000ff">//</font>
                <font color="#0000ff">// The &lt;abort&gt; tag specifies a regular expression that defines</font>
                <font color="#0000ff">// an abort condition.  If the regular expression is evaluated</font>
                <font color="#0000ff">// true in the data read after processing a &lt;send&gt; tag, then</font>
                <font color="#0000ff">// runScript() will return a value greater than 1 and set</font>
                <font color="#0000ff">// &quot;abort&quot; to the regular expression that caused the abort.</font>
                <font color="#0000ff">// Multiple &lt;abort&gt; tags may be used to define multiple abort</font>
                <font color="#0000ff">// conditions.</font>
                <font color="#0000ff">//</font>
                <font color="#0000ff">// The &lt;clearabort&gt; tag clears all previously defined abort</font>
                <font color="#0000ff">// conditions.</font>
                <font color="#0000ff">//</font>
                <font color="#0000ff">// The &lt;expect&gt; tag defines a regular expression that is</font>
                <font color="#0000ff">// expected to be evaluated true in the data read after</font>
                <font color="#0000ff">// processing a &lt;send&gt; tag.  As soon as the expression is</font>
                <font color="#0000ff">// evaluated true, the next tag in the script is processed.</font>
                <font color="#0000ff">// If a filedescriptor-level error occurs reading data, then</font>
                <font color="#0000ff">// runScript() will return RESULT_ERROR.</font>
                <font color="#0000ff">//</font>
                <font color="#0000ff">// If runScript() successfully processes all tags then it</font>
                <font color="#0000ff">// returns RESULT_SUCCESS.</font>
                <font color="#2e8b57"><b>int</b></font>   runScript(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *script, <font color="#2e8b57"><b>char</b></font> **abort);
                        <font color="#0000ff">// Runs &quot;script&quot;, if an abort condition is met, the</font>
                        <font color="#0000ff">// &quot;abort&quot; is allocated and set to the abort string</font>
                        <font color="#0000ff">// from the script that caught the condition.</font>
                <font color="#2e8b57"><b>int</b></font>   runScript(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *script, <font color="#2e8b57"><b>char</b></font> **abort,
                                                constnamevaluepairs *variables);
                        <font color="#0000ff">// Runs &quot;script&quot; as runScript() above does, but also</font>
                        <font color="#0000ff">// looks through &quot;script&quot; for variables of format:</font>
                        <font color="#0000ff">//   $(variable)</font>
                        <font color="#0000ff">// For each variable that it finds, if there is a</font>
                        <font color="#0000ff">// matching name/value pair in &quot;variables&quot;, the value</font>
                        <font color="#0000ff">// is substituted in for the variable.</font>

<font color="#a020f0">        #include </font><font color="#ff00ff">&lt;rudiments/private/chat.h&gt;</font>
};

<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
}
<font color="#a020f0">#endif</font>

<font color="#a020f0">#endif</font>
</pre>
</body>
</html>