WvStreams
wvstreamfunex.cc
1/*
2 * A fun WvStream example.
3 *
4 * Some text about this example...
5 */
6
7#include <wvistreamlist.h>
8#include <wvpipe.h>
9#include <wvlog.h>
10#include <wvmodem.h>
11
12void concallback(WvStream &con, void *userdata)
13{
14 WvStream &modem = *(WvStream *)userdata;
15
16 char *str = con.getline();
17 if (str)
18 modem.print("%s\r", str); // modems like CR, not newline
19}
20
21int main()
22{
23 const char *argv1[] = { "sh", "-c",
24 "while :; do echo foo; sleep 3; done", NULL };
25 const char *argv2[] = { "sh", "-c",
26 "while :; do echo snorkle; sleep 2; done", NULL };
27
28 WvLog log("logger", WvLog::Info);
29 WvLog modemlog("modem", WvLog::Info);
30 WvPipe pipe1(argv1[0], argv1, false, true, false);
31 WvPipe pipe2(argv2[0], argv2, false, true, false);
32 WvModem modem("/dev/ttyS2", O_RDWR);
33
34 pipe1.autoforward(log);
35 pipe2.autoforward(log);
36 wvcon->setcallback(concallback, &modem);
37 modem.autoforward(modemlog);
38
40 l.append(&pipe1, false);
41 l.append(&pipe2, false);
42 l.append(&modem, false);
43 l.append(wvcon, false);
44
45 if (!modem.isok())
46 modemlog(WvLog::Error, "%s\n", modem.errstr());
47
48 while (wvcon->isok())
49 {
50 if (l.select(1000))
51 l.callback();
52 else
53 log("[TICK]\n");
54 }
55}
WvStreamList holds a list of WvStream objects – and its select() and callback() functions know how to...
Definition: wvistreamlist.h:21
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
Definition: wvlog.h:57
WvModem implements a named modem that really needs to be opened, closed, and manipulated in lots of w...
Definition: wvmodem.h:81
Implementation of a WvPipe stream.
Definition: wvpipe.h:33
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
Definition: wvstream.h:25
virtual bool isok() const
return true if the stream is actually usable right now
Definition: wvstream.cc:445
void autoforward(WvStream &s)
set the callback function for this stream to an internal routine that auto-forwards all incoming stre...
Definition: wvstream.cc:362
void setcallback(IWvStreamCallback _callfunc)
define the callback function for this stream, called whenever the callback() member is run,...
Definition: wvstream.cc:1129
bool select(time_t msec_timeout)
Return true if any of the requested features are true on the stream.
Definition: wvstream.h:376
char * getline(time_t wait_msec=0, char separator='\n', int readahead=1024)
Read up to one line of data from the stream and return a pointer to the internal buffer containing th...
Definition: wvstream.h:175
virtual void callback()
if the stream has a callback function defined, call it now.
Definition: wvstream.cc:401