Класс для работы с процессами. Подробнее...
#include <system/process_abstraction.h>
Открытые члены | |
| ProcessAbstraction (void) | |
| void | CreateProcess (const char *Command, const char *argv[]=NULL) |
| ALIAS_FUNCTION_2 (CreateProcess, aliasCreateProcess, const char *, const char **) | |
| void | CreateProcess (const std::string &Command, const char *argv[]=NULL) |
| void | Wait (void) |
| void | TerminateProcess (void) |
| virtual | ~ProcessAbstraction () |
Закрытые члены | |
| ProcessAbstraction (const ProcessAbstraction &) | |
| ProcessAbstraction | operator= (const ProcessAbstraction &) |
Закрытые данные | |
| void * | ProcessHandle |
Класс для работы с процессами.
См. определение в файле process_abstraction.h строка 48
| nitro::ProcessAbstraction::ProcessAbstraction | ( | void | ) |
Конструктор.
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле process_abstraction.cpp строка 28
Перекрестные ссылки nitro::exception::code() и nitro::exception::what().
{
try
{
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "ProcessAbstraction::ProcessAbstraction( void )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "ProcessAbstraction::ProcessAbstraction( void )::An error occured" ) , 0 ) );
}
}

| nitro::ProcessAbstraction::~ProcessAbstraction | ( | ) | [virtual] |
Деструктор.
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле process_abstraction.cpp строка 198
Перекрестные ссылки ProcessHandle.
{
try
{
#if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
delete ( ProcessInfo * )ProcessHandle;
#endif
#if defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM )
delete ( int * )ProcessHandle;
#endif
}
catch( ... )
{
}
}
| nitro::ProcessAbstraction::ProcessAbstraction | ( | const ProcessAbstraction & | ) | [private] |
Конструктор копирования.
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле process_abstraction.cpp строка 215
Перекрестные ссылки nitro::exception::code() и nitro::exception::what().
{
try
{
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "ProcessAbstraction::ProcessAbstraction( const ProcessAbstraction & )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "ProcessAbstraction::ProcessAbstraction( const ProcessAbstraction & )::An error occured" ) , 0 ) );
}
}

| nitro::ProcessAbstraction::ALIAS_FUNCTION_2 | ( | CreateProcess | , | |
| aliasCreateProcess | , | |||
| const char * | , | |||
| const char ** | ||||
| ) |
| void nitro::ProcessAbstraction::CreateProcess | ( | const char * | Command, | |
| const char * | argv[] = NULL | |||
| ) |
Функция запускает дочерний процесс.
| Command | - Исполняемый файл. | |
| argv | - Параметры. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле process_abstraction.cpp строка 43
Перекрестные ссылки nitro::exception::code(), DEFINE_DYNAMIC_ARRAY, nitro::FSPath::ExtractFileName(), ProcessHandle и nitro::exception::what().
Используется в CreateProcess().
{
try
{
#if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
ProcessHandle = new ProcessInfo;
ZeroMemory( &( ( ( ProcessInfo * )ProcessHandle )->si ) , sizeof( ( ( ProcessInfo * )ProcessHandle )->si ) );
( ( ProcessInfo * )ProcessHandle )->si.cb = sizeof( ( ( ProcessInfo * )ProcessHandle )->si );
ZeroMemory( &( ( ( ProcessInfo * )ProcessHandle )->pi ) , sizeof( ( ( ProcessInfo * )ProcessHandle )->pi ) );
std::string CommandLine( Command );
for( std::size_t i( 0 ) ; argv && argv[ i ] ; i++ )
{
CommandLine += " ";
CommandLine += argv[ i ];
}
if( !CreateProcessA( NULL , ( LPSTR )CommandLine.c_str() , NULL , NULL , FALSE , 0 , NULL , NULL , &( ( ( ProcessInfo * )ProcessHandle )->si ) , &( ( ( ProcessInfo * )ProcessHandle )->pi ) ) )
{
throw( nitro::exception( std::string( "An error occured while process startup " ) + Command , 0 ) );
}
#endif
#if defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM )
ProcessHandle = new int;
*( ( int * )ProcessHandle ) = fork();
if( *( ( int * )ProcessHandle ) == 0 )
{
std::size_t ArgCounter( 0 );
if( argv )
{
for( ; argv[ ArgCounter ] != NULL ; ArgCounter++ );
}
DEFINE_DYNAMIC_ARRAY( const char * , Args , ArgCounter + 2 )
std::string FileName( FSPath::ExtractFileName( std::string( Command ) ) );
Args[ 0 ] = FileName.c_str();
for( std::size_t i( 1 ) ; i < ArgCounter + 2 ; i++ )
{
if( argv )
{
Args[ i ] = argv[ i - 1 ];
}
else
{
Args[ i ] = NULL;
}
}
if( strchr( Command , '/' ) || strchr( Command , '\\' ) )
{
// указан только путь к экзешнику
if( execv( Command , ( char * const * )Args ) == -1 )
{
throw( nitro::exception( std::string( "An error occured while process startup " ) + Command , 0 ) );
}
}
else
{
// указан только сам экзешник
if( execvp( Command , ( char * const * )Args ) == -1 )
{
throw( nitro::exception( std::string( "An error occured while process startup " ) + Command , 0 ) );
}
}
}
#endif
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "ProcessAbstraction::CreateProcess( const char * Command , const char * argv [] )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "ProcessAbstraction::CreateProcess( const char * Command , const char * argv [] )::An error occured" ) , 0 ) );
}
}

| void nitro::ProcessAbstraction::CreateProcess | ( | const std::string & | Command, | |
| const char * | argv[] = NULL | |||
| ) |
Функция запускает дочерний процесс.
| Command | - Исполняемый файл. | |
| argv | - Параметры. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле process_abstraction.cpp строка 126
Перекрестные ссылки nitro::exception::code(), CreateProcess() и nitro::exception::what().
{
try
{
CreateProcess( Command.c_str() , argv );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "ProcessAbstraction::CreateProcess( const std::string & Command , const char * argv [] /* = NULL */ )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "ProcessAbstraction::CreateProcess( const std::string & Command , const char * argv [] /* = NULL */ )::An error occured" ) , 0 ) );
}
}

| ProcessAbstraction nitro::ProcessAbstraction::operator= | ( | const ProcessAbstraction & | ) | [private] |
Оператор присваивания.
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле process_abstraction.cpp строка 230
Перекрестные ссылки nitro::exception::code() и nitro::exception::what().
{
try
{
return( *this );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "ProcessAbstraction::operator=( const ProcessAbstraction & )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "ProcessAbstraction::operator=( const ProcessAbstraction & )::An error occured" ) , 0 ) );
}
}

| void nitro::ProcessAbstraction::TerminateProcess | ( | void | ) |
Функция уничтожает процесс.
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле process_abstraction.cpp строка 167
Перекрестные ссылки nitro::exception::code(), ProcessHandle и nitro::exception::what().
{
try
{
#if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
if( ::TerminateProcess( ( ( ProcessInfo * )ProcessHandle )->pi.hProcess, 0 ) == 0 )
{
throw( nitro::exception( "An error occured while process termination" , 1 ) );
}
CloseHandle( ( ( ProcessInfo * )ProcessHandle )->pi.hProcess );
CloseHandle( ( ( ProcessInfo * )ProcessHandle )->pi.hThread );
#endif
#if defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM )
if( kill( *( ( int * )ProcessHandle ) , SIGKILL ) != 0 )
{
throw( nitro::exception( "An error occured while process termination" , 1 ) );
}
#endif
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "ProcessAbstraction::Wait( void )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "ProcessAbstraction::Wait( void )::An error occured" ) , 0 ) );
}
}

| void nitro::ProcessAbstraction::Wait | ( | void | ) |
Функция блокирует поток до тех пор пока не будет завершен дочерний поток.
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле process_abstraction.cpp строка 142
Перекрестные ссылки nitro::exception::code(), ProcessHandle и nitro::exception::what().
{
try
{
#if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
WaitForSingleObject( ( ( ProcessInfo * )ProcessHandle )->pi.hProcess, INFINITE );
CloseHandle( ( ( ProcessInfo * )ProcessHandle )->pi.hProcess );
CloseHandle( ( ( ProcessInfo * )ProcessHandle )->pi.hThread );
#endif
#if defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM )
waitpid( *( ( int * )ProcessHandle ) , NULL , WUNTRACED );
#endif
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "ProcessAbstraction::Wait( void )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "ProcessAbstraction::Wait( void )::An error occured" ) , 0 ) );
}
}

void* nitro::ProcessAbstraction::ProcessHandle [private] |
Хэндл процесса.
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле process_abstraction.h строка 226
Используется в CreateProcess(), TerminateProcess(), Wait() и ~ProcessAbstraction().
1.6.1