home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Source / OPMPipeTool.cpp < prev    next >
C/C++ Source or Header  |  1996-08-12  |  4KB  |  164 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OPMPipeTool.cpp
  5.  
  6.  
  7. /*
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  14.  *    endorse or promote products derived from this software
  15.  *    without specific prior written permission.
  16.  * 3. See OCL.INF for a detailed copyright notice.
  17.  *
  18.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  19.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  22.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28.  * SUCH DAMAGE.
  29.  */
  30.  
  31. // $Header: W:/Projects/OCL/Source/rcs/OPMPipeTool.cpp 1.50 1996/08/11 23:49:26 B.STEIN Release $
  32.  
  33. #define __OCL_SOURCE__
  34.  
  35. #define OINCL_OSTRING
  36. #define OINCL_BASE
  37.  
  38. #include <ocl.hpp>
  39. #include <OPMPipeTool.hpp>
  40.  
  41. #if defined(__EMX__)
  42.   template class OThread<OPMPipeTool>;
  43. #endif
  44.  
  45.  
  46. OPMPipeTool::OPMPipeTool(PCSZ exename, PCSZ parms, 
  47.                          HWND notifyWindow,
  48.                          const ULONG sessionType,
  49.                          const ULONG pipeBuffer)
  50.   : printer(this, &OPMPipeTool::printout, 8192, FALSE),
  51.     bufferSize(pipeBuffer),
  52.     pipe(pipeBuffer),
  53.     readBuffer(pipeBuffer),
  54.     sType(sessionType),
  55.     childName(exename),
  56.     childParms(parms),
  57.     happ(NULLHANDLE),
  58.     hwndNotify(notifyWindow)
  59.  {}
  60.  
  61.  
  62. OPMPipeTool::~OPMPipeTool()
  63.  {}
  64.  
  65.  
  66. PSZ OPMPipeTool::isOfType() const
  67.  return("OPMPipeTool"); 
  68. }
  69.  
  70.  
  71. void OPMPipeTool::detachChild()
  72. {
  73.  HFILE       hfNewStdOut = -1, 
  74.              hfNewStdErr = -1,
  75.              hfStdOut = 1, 
  76.              hfStdErr = 2;
  77.  OString     Title("Spawned: ");
  78.  PROGDETAILS Details;
  79.  
  80. // Duplicate handles
  81.  
  82.  DosDupHandle(hfStdOut, &hfNewStdOut);
  83.  DosDupHandle(hfStdErr, &hfNewStdErr);
  84.  
  85. // Close existing handles for current process
  86.  
  87.  DosClose(hfStdOut);
  88.  DosClose(hfStdErr);
  89.  
  90. // Redirect existing handles to new file
  91.  DosDupHandle(pipe.ofh, &hfStdOut);
  92.  DosDupHandle(pipe.ofh, &hfStdErr);
  93.  
  94. // start printout thread
  95.  if (!printer.isRunning())
  96.    printer.run(); 
  97.  
  98. // Start new session
  99.  
  100.  Title + childName;
  101.  
  102.  memset(&Details, 0, sizeof(PROGDETAILS));
  103.  Details.Length          = sizeof(PROGDETAILS);
  104.  Details.progt.progc     = sType;
  105.  Details.progt.fbVisible = SHE_INVISIBLE;
  106.  Details.pszTitle        = Title;
  107.  Details.pszExecutable   = childName;
  108.  Details.pszParameters   = childParms;
  109.  Details.pszStartupDir   = "";
  110.  Details.swpInitial.fl   = SWP_HIDE | SWP_DEACTIVATE;
  111.  Details.swpInitial.hwndInsertBehind = HWND_TOP;
  112.  Details.swpInitial.hwnd             = HWND_DESKTOP;
  113.  
  114.  happ = WinStartApp(hwndNotify, 
  115.                     &Details, 
  116.                     NULL, 
  117.                     NULL, 
  118.                     SAF_STARTCHILDAPP | SAF_INSTALLEDCMDLINE);
  119.  
  120.  WinSetWindowPos(hwndNotify, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE);
  121.  
  122. // Get back original handles
  123.  DosDupHandle(hfNewStdOut, &hfStdOut);
  124.  DosDupHandle(hfNewStdErr, &hfStdErr);
  125.  DosClose(hfNewStdOut);
  126.  DosClose(hfNewStdErr);
  127.  
  128.  if (!happ)
  129.    throw OVioException("Spawn failed.", 0);
  130. }
  131.  
  132.  
  133. void OPMPipeTool::stopChild()
  134. {
  135.  if (!happ)
  136.    return;
  137.  if (WinTerminateApp(happ))
  138.    throw OVioException("Killing spawnded process failed.", 0);
  139. }
  140.  
  141.  
  142. void OPMPipeTool::setNotify(HWND notifyWindow)
  143. {
  144.  hwndNotify = notifyWindow;
  145. }
  146.  
  147. void OPMPipeTool::setNotify(OFrame& notifyWindow)
  148. {
  149.  hwndNotify = notifyWindow.frame;
  150. }
  151.  
  152. void OPMPipeTool::setNotify(pOFrame notifyWindow)
  153. {
  154.  hwndNotify = notifyWindow->frame;
  155. }
  156.  
  157.  
  158.  
  159. void OPMPipeTool::printout()
  160.  {}
  161.  
  162. // end of source
  163.