mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-31 18:46:29 +03:00
Added: display new line character in selection. Fixed a crash when trying to write into a broken pipe.
54 lines
1.2 KiB
C++
54 lines
1.2 KiB
C++
#include "busprocess.hpp"
|
|
|
|
namespace ecode {
|
|
|
|
BusProcess::BusProcess( const Command& command ) : mCommand( command ), mProcess() {}
|
|
|
|
BusProcess::~BusProcess() {
|
|
close();
|
|
}
|
|
|
|
bool BusProcess::start() {
|
|
bool res = mCommand.arguments.empty()
|
|
? mProcess.create( mCommand.command,
|
|
Process::getDefaultOptions() | Process::Options::EnableAsync |
|
|
Process::Options::CombinedStdoutStderr,
|
|
mCommand.environment )
|
|
: mProcess.create( mCommand.command, mCommand.arguments,
|
|
Process::getDefaultOptions() | Process::Options::EnableAsync |
|
|
Process::Options::CombinedStdoutStderr,
|
|
mCommand.environment );
|
|
if ( res )
|
|
setState( State::Running );
|
|
|
|
return res;
|
|
}
|
|
|
|
bool BusProcess::close() {
|
|
if ( mState == State::Running ) {
|
|
bool res = mProcess.kill();
|
|
if ( res )
|
|
setState( State::Closed );
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void BusProcess::startAsyncRead( ReadFn readFn ) {
|
|
mProcess.startAsyncRead( readFn, readFn );
|
|
}
|
|
|
|
size_t BusProcess::write( const char* buffer, const size_t& size ) {
|
|
if ( mState == State::Running ) {
|
|
if ( !mProcess.isAlive() ) {
|
|
setState( State::Closed );
|
|
return 0;
|
|
}
|
|
|
|
return mProcess.write( buffer, size );
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
} // namespace ecode
|