Открытые члены | Закрытые члены | Закрытые данные

Класс nitro::ProcessAbstraction

Класс для работы с процессами. Подробнее...

#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 ) );
                }
        }

Граф вызовов:


Данные класса

Хэндл процесса.

Исключения:
nitro::exception Кидает исключение этого типа с описанием ошибки.
Автор:
Додонов А.А.

См. определение в файле process_abstraction.h строка 226

Используется в CreateProcess(), TerminateProcess(), Wait() и ~ProcessAbstraction().


Объявления и описания членов классов находятся в файлах:

Generated by  doxygen 1.6.1