linuxprocesspeer.cpp

来自「这是VCF框架的代码」· C++ 代码 · 共 197 行

CPP
197
字号
//LinuxProcessPeer.cpp/*Copyright 2000-2004 The VCF Project.Please see License.txt in the top level directorywhere you installed the VCF.*/#include "vcf/FoundationKit/FoundationKit.h"#include "vcf/FoundationKit/FoundationKitPrivate.h"#include <sys/wait.h>using namespace VCF;LinuxProcessPeer::LinuxProcessPeer()		: processHandle_( -1 )		, processFileName_(){}LinuxProcessPeer::~LinuxProcessPeer(){}int LinuxProcessPeer::getProcessID(){	return getpid();}int LinuxProcessPeer::getProcessThreadID(){	return pthread_self();}bool LinuxProcessPeer::createProcess( const String& processName, const String& arguments ){	bool result = false;    processFileName_ = "";    if( (processHandle_ = vfork()) == 0)    {        // child        char* pn  = strdup(processName.ansi_c_str());        CommandLine cmdLine;        cmdLine.splitLine(arguments);        const std::vector<String>& args = cmdLine.getOriginalCommandLine();        char **argv = new char*[args.size()+2];        argv[0] = strdup(pn);        for(size_t i=0; i<args.size(); ++i)        {            argv[i+1] = strdup(args[i].ansi_c_str());        }        argv[args.size()+1] = NULL;        if(execvp(pn, argv) == -1)        {            for(size_t i=0; i<args.size()+2; ++i)            {                free(argv[i]);            }            delete argv;            free(pn);            exit(-1);        }    }    else if(processHandle_ == -1)    {        // parent failed        result = false;    }    else    {        processFileName_ = processName;        // parent success        result = true;    }	return result;}String LinuxProcessPeer::getProcessFileName(){	return processFileName_;}OSHandleID LinuxProcessPeer::getHandleID(){	return reinterpret_cast<OSHandleID>( processHandle_ );}ulong32 LinuxProcessPeer::terminate(){	return kill(processHandle_, SIGKILL);}Waitable::WaitResult LinuxProcessPeer::wait( uint32 milliseconds ){	return wait();}Waitable::WaitResult LinuxProcessPeer::wait(){	Waitable::WaitResult result;    int stat_loc = 0;    if(waitpid(processHandle_, &stat_loc, 0) == -1)    {        result = Waitable::wrWaitFailed;    }    else    {        result = Waitable::wrWaitFinished;    }	return result;}/***CVS Log info*$Log$*Revision 1.5  2006/04/07 02:35:34  ddiego*initial checkin of merge from 0.6.9 dev branch.**Revision 1.4.2.2  2006/03/19 00:04:16  obirsoy*Linux FoundationKit improvements.**Revision 1.4.2.1  2005/11/28 21:01:06  ddiego*added wait function to process class. added stubs for linux.**Revision 1.4  2005/07/09 23:15:03  ddiego*merging in changes from devmain-0-6-7 branch.**Revision 1.3  2005/04/05 23:44:22  jabelardo*a lot of fixes to compile on linux, it does not run but at least it compile**Revision 1.2.4.1  2005/04/17 16:11:32  ddiego*brought the foundation, agg, and graphics kits uptodate on linux**Revision 1.2  2004/08/07 02:49:13  ddiego*merged in the devmain-0-6-5 branch to stable**Revision 1.1.2.2  2004/04/29 04:07:08  marcelloptr*reformatting of source files: macros and csvlog and copyright sections**Revision 1.1.2.1  2004/04/28 03:29:39  ddiego*migration towards new directory structure**Revision 1.6  2004/04/03 15:48:46  ddiego*Merged over code from the 0-6-3 branch.**Revision 1.5.2.1  2004/02/16 05:34:05  ddiego*updated linux makefiles as a result of new locale support - pushed in stubs for locale peer impl, but no functionality at this point**Revision 1.5  2003/12/18 05:16:01  ddiego*merge from devmain-0-6-2 branch into the stable branch**Revision 1.4.4.1  2003/10/02 04:50:52  ddiego*changes to ensure the code compiles on linux. made a bunch of updates to*the makefiles**Revision 1.4  2003/05/17 20:37:34  ddiego*this is the checkin for the 0.6.1 release - represents the merge over from*the devmain-0-6-0 branch plus a few minor bug fixes**Revision 1.3.2.2  2003/03/23 03:23:57  marcelloptr*3 empty lines at the end of the files**Revision 1.3.2.1  2003/03/12 03:12:18  ddiego*switched all member variable that used the "m_"<name> prefix to* <name>"_" suffix nameing standard.*Also changed all vcf builder files to accomadate this.*Changes were made to the Stream classes to NOT multiple inheritance and to*be a little more correct. Changes include breaking the FileStream into two*distinct classes, one for input and one for output.**Revision 1.3  2003/02/26 04:30:49  ddiego*merge of code in the devmain-0-5-9 branch into the current tree.*most additions are in the area of the current linux port, but the major*addition to this release is the addition of a Condition class (currently*still under development) and the change over to using the Delegate class*exclusively from the older event handler macros.**Revision 1.2.2.1  2002/12/27 23:04:51  marcelloptr*Improved macros for automatic import/export of libraries. - Warning fixes. - Other Minor Changes.**Revision 1.2  2002/11/18 00:46:09  ddiego*this is the merge over of all the bug fixes and features (mostly*VCF Builder stuff) from the devmain-0-5-8 branch**Revision 1.1.8.1  2002/09/27 01:54:58  ddiego*added support for bezier curves - remeber to change over to using teh MgcBeziers in Win32 too**Revision 1.1  2002/05/27 15:58:22  ddiego*added linux peer classes for the FoundationKit port to linux*this now means the FoundationKit will start up correctly on*linu thought it is still not 100% functional yet**/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?