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"><rudiments/private/chatincludes.h></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 "fd".</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 "wfd" and read from "rfd".</font>
~chat();
<font color="#0000ff">// These methods process "script" 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">// <script></font>
<font color="#0000ff">// <timeout seconds="2"/></font>
<font color="#0000ff">// <abort string="ERROR"/></font>
<font color="#0000ff">// <send string="AT Z\p\p\p\r\n"/></font>
<font color="#0000ff">// <expect string="OK"/></font>
<font color="#0000ff">// <clearabort/></font>
<font color="#0000ff">// <abort string="(NO DIALTONE|NO DIAL TONE)"/></font>
<font color="#0000ff">// <abort string="NO CARRIER"/></font>
<font color="#0000ff">// <abort string="BUSY"/></font>
<font color="#0000ff">// <timeout seconds="30"/></font>
<font color="#0000ff">// <send string="ATDT18005555555\r\n"/></font>
<font color="#0000ff">// <expect string="CONNECT"/></font>
<font color="#0000ff">// </script></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 <send> 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 <=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 <timeout> tag specified the number of seconds to wait</font>
<font color="#0000ff">// for a response after a <send> tag has been fully processed</font>
<font color="#0000ff">// before runScript() will fail, returning a RESULT_TIMEOUT.</font>
<font color="#0000ff">// If no <timeout> 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 <abort> 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 <send> tag, then</font>
<font color="#0000ff">// runScript() will return a value greater than 1 and set</font>
<font color="#0000ff">// "abort" to the regular expression that caused the abort.</font>
<font color="#0000ff">// Multiple <abort> tags may be used to define multiple abort</font>
<font color="#0000ff">// conditions.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// The <clearabort> tag clears all previously defined abort</font>
<font color="#0000ff">// conditions.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// The <expect> 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 <send> 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 "script", if an abort condition is met, the</font>
<font color="#0000ff">// "abort" 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 "script" as runScript() above does, but also</font>
<font color="#0000ff">// looks through "script" 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 "variables", the value</font>
<font color="#0000ff">// is substituted in for the variable.</font>
<font color="#a020f0"> #include </font><font color="#ff00ff"><rudiments/private/chat.h></font>
};
<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
}
<font color="#a020f0">#endif</font>
<font color="#a020f0">#endif</font>
</pre>
</body>
</html>
|