WinProcess.h
上传用户:cnxinhai
上传日期:2013-08-06
资源大小:265k
文件大小:5k
- /* This is the class that handles the Windows system functionality.
- * Process and thread stuff is handled here.
- *
- * Copyright (C) 2001, 2002 Adam Schlag
- */
- /*
- * FreeBurn Software License
- * (based on the Apache Software License)
- *
- * Version 1.1
- *
- * Copyright (c) 2001, 2002 The FreeBurn Project. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. The end-user documentation included with the redistribution, if any, must
- * include the following acknowledgment:
- *
- * "This product includes software developed by the FreeBurn
- * Project (http://freeburn.sourceforge.net/)."
- *
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "FreeBurn" and "FreeBurn Project" must not be
- * used to endorse or promote products derived from this software
- * without prior written permission. For written permission, please
- * contact aschlag@users.sourceforge.net.
- *
- * 5. Products derived from this software may not be called "FreeBurn",
- * nor may "FreeBurn" appear in their name, without prior written
- * permission of the FreeBurn Project.
- *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE FREEBURN PROJECT OR ITS
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the FreeBurn Project. For more
- * information on the FreeBurn Project and FreeBurn, please see
- * <http://freeburn.sourceforge.net/>.
- *
- * This software is distributed with software that is released under the GNU
- * General Public License (GPL). You can find the terms of this license in the
- * file GPL.txt distributed in this package. You can find information on the
- * software distributed with this package in the file PROGRAMS.txt.
- */
- // although we are only going to read 80 characters at a time,
- // we'll keep the buffer large until we know we won't need a
- // smaller buffer
- #define BUFFER_SIZE 1024
- class CWinProcess : public CBaseThread
- {
- public:
-
- // basic constructor and destructors for the class
- CWinProcess();
- ~CWinProcess();
- // creates the process based on the command string.
- // returns a zero if successful, -1 if an error
- FXint createCommandWithPipes(FXString& commandString);
- // this method gets the string of text that has been saved
- // for reading. It contains the output of the process
- FXint getStringText(FXString& outputString);
- // these are methods for returning handles that are used
- // for reading the output of a process we start, and for
- // letting the application know that the thread is complete.
- // NOTE: FXInputHandle is synonomous with HANDLE in Windows
- FXInputHandle getProcessEventHandle();
- FXInputHandle getCompleteEventHandle();
- protected:
- // this is the function/method to run
- // in a seperate thread. The thread will catch
- // the I/O of the created process, and save the
- // output into a string (m_readBuffer) that a
- // program or application can read from with the
- // method getStringText().
- void theThreadFunc (void);
- // These are the handles to the process events
- FXInputHandle m_processEvent;
- FXInputHandle m_completeEvent;
-
- // These are the handles to the stdout/stderr
- // read handle and the stdin write handle
- FXInputHandle m_stdoutReadHandle;
- FXInputHandle m_stdinWriteHandle;
-
- // This is a handle to a semaphore so reading from the output
- // string with getStringText() is serialized. This is to prevent
- // the caller of getStringText() from getting text that is garbled,
- // or not getting text becasue of the asynchrounous nature of the
- // thread we start and CreateProcess().
- FXInputHandle m_threadSemaphore;
-
- // These hold the data to be returned with getStringText()
- FXchar m_readBuffer[BUFFER_SIZE];
- FXint m_charsRead;
- };