home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / source / xpipe.cpp < prev    next >
C/C++ Source or Header  |  1997-04-05  |  3KB  |  114 lines

  1. #include "XPipe.h"
  2.  
  3.  
  4. /*@ 
  5. @class XPipe
  6. @parent XIO
  7. @type overview
  8. @symbol _
  9. */
  10.  
  11. /*@ 
  12. @class XPipe
  13. @type overview
  14. @symbol _
  15. @remarks XPipe is a class which provides data-communication between related processes.
  16. Therefore you redirect stdin/stdout/stderr to a pipes read- and/or write-handle(s) of the
  17. server and client process. The client must be a client-process (see OS/2-docs for details).<BR>
  18. To do <B>realy</B> client/server data-communication use DDE (class XDDE) or named pipes (XNamedPipeServer, XNamedPipeClient).<P>
  19. Example:<PRE>
  20.  
  21.    ULONG hfSave, hfNew = XPIPE_STDERROR;
  22.  
  23.    //save stderror-handle
  24.    XPipe::DuplicateHandle( XPIPE_STDERROR, hfSave);
  25.  
  26.    //create a pipe and open it
  27.    XPipe pipe;
  28.    pipe.Open();
  29.  
  30.    //set the write-handle from the pipe as stderror so the client will write to it
  31.    XPipe::DuplicateHandle( pipe1.GetWriteHandle(), hfNew);
  32.  
  33.    //start the client-process here
  34.    XProcess::ExecuteProg(.......);
  35.  
  36.    //close write-handle of the pipe
  37.    XPipe::CloseHandle( pipe.GetWriteHandle());
  38.  
  39.    //bring the saved handde from stderror back
  40.    XPipe::DuplicateHandle( hfSave, hfNew);
  41.  
  42.    //close stderror
  43.    XPipe::CloseHandle(hfSave);
  44.  
  45.    ULONG cbRead;
  46.    char buffer[XPIPE_DEFAULTSIZE];
  47.  
  48.    do
  49.      {
  50.          //read data like a file
  51.          cbRead = pipe.Read( achBuf, XPIPE_DEFAULTSIZE);
  52.      } while(cbRead);
  53.  
  54.    //close the pipe
  55.    pipe.Close();
  56. </PRE>
  57. */
  58.  
  59.  
  60. /*@ XPipe::CloseHandle()
  61. @group open/close
  62. @remarks Close a single handle.
  63. @parameters ULONG handle   handle to close.
  64. */
  65.  
  66.  
  67. /*@ XPipe::GetWriteHandle()
  68. @group misc
  69. @remarks Returns the write-handle from a pipe
  70. @returns ULONG writeHandle
  71. */
  72.  
  73.  
  74. /*@ XPipe::GetReadHandle()
  75. @group misc
  76. @remarks Returns the read-handle from a pipe
  77. @returns ULONG readHandle
  78. */
  79.  
  80.  
  81. /*@ XPipe::Open()
  82. @group open/close
  83. @remarks Opens a pipe. Afte it is open you can redirect stdin/stdout/stderr to one of its handles.
  84. @parameters LONG buffersize    size of the buffer (default is 4096)
  85. */
  86. LONG XPipe::Open(const LONG size)
  87. {
  88.     return DosCreatePipe(&handle, &handle2, size);
  89. }
  90.  
  91.  
  92. /*@ XPipe::DuplicateHandle(const ULONG handleFrom, ULONG & handleTo)
  93. @group misc
  94. @remarks Dupplicate a handle.
  95. */
  96. ULONG XPipe::DuplicateHandle(const ULONG handleFrom, ULONG & handleTo)
  97. {
  98.     return DosDupHandle(handleFrom, &handleTo);
  99. }
  100.  
  101.  
  102. /*@ XPipe::Close()
  103. @group open/close
  104. @remarks Close the pipe.
  105. */
  106. void XPipe::Close()
  107. {
  108.     DosClose(handle2);
  109.     handle2 = NULLHANDLE;
  110.     DosClose(handle);
  111.     handle = NULLHANDLE;
  112. }
  113.  
  114.