[ <- Previous Page ] | [ ^ Table Of Contents ^ ] | [ Next Page -> ] |
zWebit uses standard Unix pipe structures for interprocess communication. After a data acquisition program receives a transaction and updates the idata table with the transaction, the program notifies the delivery programs about the data via zPipe messages.
zWebit uses the zPipe class to handle interprocess communication. Each data delivery program has a unique pipe assigned to it. Data collection programs send the delivery programs a wake up call via method zPipe::writePipes ( ) when data arrives. After the delivery program performs its task, it returns to sleep until it receives another message.
The zPipe class structure is designed so that many processes can write to the same pipe, a single process can write to many pipes, and a process can only read from a single pipe.
The general idea is that each data delivery program has one and only one pipe associated with it. Any time a data acqusition program captures data, it will send a message to the appropriate delivery programs. When a delivery program receives a wake-up message via zPipe, it determines which transactions it needs to process, processes them sequentially and then goes back to sleep and waits for another pipe message.
This class is designed for one zPipe instance in each program. Multiple instances of this class may result in undefined behavior in the program due to the interrupt handler logic and should not be neccessary.
The zPipe class handles creation and processing of pipes. The application programs only need to name the pipes and read/write to them. Data acquisition programs may need to notify several delivery programs. Acquisition programs need to make one call to zPipe::SetPipePath( ), and one call to zLog::AddPipeToList( ) for each delivery program requiring notification. zPipe::writePipes ( ) is called one time to send a message to all pipes.
Data delivery programs are assigned one pipe. Delivery programs make one call to zLog::SetPipePath( ) and one call to zLog::AddPipeToList( ). Delivery programs use the zLog::readPipe ( ) method to sleep and wait for the next inbound transaction.
When assigning pipe names, it is best to assign meaningful names like TOLAB and FROMLAB. This makes subsequent troubleshooting easier.
Directory names must be valid. A default directory structure is set up for test and prod pipes as zwebit/test/pipes and zwebit/prod/pipes.
Method/Function | Description | Return Code |
---|---|---|
void setPipePath (const zString & path) | Used to set the directory pathname path where the physical pipe files are located. This parameter must be a valid directory name and have beginning and ending "/" characters. | |
int addPipeToList (const zString & Pipename) | Add a pipe Pipename to a linked list of pipes. | -1=Error 0=Success |
void setLog (zLog & log) | Optionally assign a zLog reference for error reporting. | |
void writePipes ( ) | This routine is used by data acquisition programs to send wake up calls to delivery programs. One call writes to all pipes. | |
int getPipeCnt ( ) | Returns the number of pipes in the list. | Count |
int getPipeName (int PipeNo zString & Pipename) | Returns a pipe name Pipename for a given number PipeNo. | -1=Error 0=Success |
int readPipe ( ) | Wait for a message coming in via pipe. | -1=Error 0=Success |
This program is on the receiving end of one pipe.
/* recvpipe.cpp Copyright (c) 2001 HSC GNU/GPL This program receives a pipe message */ #include#include "../../base/zstring.cpp" #include "../../base/zlog.cpp" #include "../../base/zpipe.cpp" using namespace std; /********************************************************************/ int main( int argc, char *argv[] ) { zPipe pipe; zString PipeName; /* set up directory */ pipe.setPipePath( "/tmp/" ); /* listen on pipe 1 */ pipe.addPipeToList( "testpipe1.pipe" ); cout << "program recvpipe waiting for some pipe data" << endl; pipe.readPipe(); cout << "program recvpipe received a message...." << endl; return 0; }
This program is on the sending end of two pipes.
/* sendpipe.cpp Copyright (c) 2001 HSC GNU/GPL This program sends a pipe message */ #include#include "../../base/zstring.cpp" #include "../../base/zlog.cpp" #include "../../base/zpipe.cpp" using namespace std; /********************************************************************/ int main( int argc, char *argv[] ) { zPipe pipe; zString PipeName; /* set up directory */ pipe.setPipePath( "/tmp/" ); /* prepare to send data to two programs */ pipe.addPipeToList( "testpipe1.pipe" ); pipe.addPipeToList( "testpipe2.pipe" ); /* display the pipe names */ int PipeCnt = pipe.getPipeCnt(); for( int i = 0; i < PipeCnt; i++ ){ pipe.getPipeName( i, PipeName ); cout << "Pipe " << i << " name is -> " << PipeName << endl; } /* send all pipes in the list a wakeup message */ pipe.writePipes(); return 0; }
[ <- Previous Page ] | [ ^ Table Of Contents ^ ] | [ ^ Top Of Page ^ ] | [ Next Page -> ] |
Visit the GNU home page.
FSF & GNU inquiries & questions to
gnu@gnu.org.
Comments on these web pages to
info@zhsac.com.
Copyright (C) 2003 HealthCare Systems and Consulting
Verbatim copying and distribution of this entire article is
permitted in any medium, provided this notice is preserved.
Last updated: 07/21/2003