Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

wvstreamfunex.cc

Go to the documentation of this file.
00001 #include <wvstreamlist.h>
00002 #include <wvpipe.h>
00003 #include <wvlog.h>
00004 #include <wvmodem.h>
00005 
00006 void concallback(WvStream &con, void *userdata)
00007 {
00008     WvStream &modem = *(WvStream *)userdata;
00009     
00010     char *str = con.getline(0);
00011     if (str)
00012         modem.print("%s\r", str); // modems like CR, not newline
00013 }
00014 
00015 int main()
00016 {
00017     const char *argv1[] = { "sh", "-c", 
00018                                 "while :; do echo foo; sleep 3; done" };
00019     const char *argv2[] = { "sh", "-c", 
00020                                 "while :; do echo snorkle; sleep 2; done" };
00021 
00022     WvLog log("logger", WvLog::Info);
00023     WvLog modemlog("modem", WvLog::Info);
00024     WvPipe pipe1(argv1[0], argv1, false, true, false);
00025     WvPipe pipe2(argv2[0], argv2, false, true, false);
00026     WvModem modem("/dev/ttyS2", O_RDWR);
00027 
00028     pipe1.autoforward(log);
00029     pipe2.autoforward(log);
00030     wvcon->setcallback(concallback, &modem);
00031     modem.autoforward(modemlog);
00032     
00033     WvStreamList l;
00034     l.append(&pipe1, false);
00035     l.append(&pipe2, false);
00036     l.append(&modem, false);
00037     l.append(wvcon, false);
00038     
00039     if (!modem.isok())
00040         modemlog(WvLog::Error, "%s\n", modem.errstr());
00041     
00042     while (wvcon->isok())
00043     {
00044         if (l.select(1000))
00045             l.callback();
00046         else
00047             log("[TICK]\n");
00048     }
00049 }

Generated on Sat Aug 24 21:09:35 2002 for WvStreams by doxygen1.2.15