28 #include <QtCore/QTextStream>
29 #include <QtCore/QMap>
33 class KJavaProcessPrivate
47 d(new KJavaProcessPrivate)
50 connect(
this, SIGNAL(readyReadStandardOutput()),
52 connect(
this, SIGNAL(finished(
int,QProcess::ExitStatus)),
54 connect(
this, SIGNAL(error(QProcess::ProcessError)),
58 d->mainClass =
"-help";
63 if ( state() != NotRunning )
65 kDebug(6100) <<
"stopping java process";
73 return state() != NotRunning;
93 d->classPath = classpath;
99 d->systemProps.insert( name, value );
104 d->mainClass = className;
122 QTextStream
output( &buff, QIODevice::ReadWrite );
126 const QByteArray space(
" " );
139 QStringList::ConstIterator it = args.begin();
140 const QStringList::ConstIterator itEnd = args.end();
141 for( ; it != itEnd; ++it )
143 if( !(*it).isEmpty() )
145 output << (*it).toLocal8Bit();
156 const int size = buff->size() - 8;
158 kDebug(6100) <<
"KJavaProcess::storeSize, size = " << size_str;
160 for(
int i = 0; i < 8; ++i )
161 buff->data()[ i ] = size_str[i].toLatin1();
168 QByteArray buff =
addArgs( cmd_code, args );
170 kDebug(6100) <<
"<KJavaProcess::send " << (int)cmd_code;
176 const QByteArray& data )
180 kDebug(6100) <<
"KJavaProcess::send, qbytearray is size = " << data.size();
182 QByteArray buff =
addArgs( cmd_code, args );
194 if( !d->classPath.isEmpty() )
196 args <<
"-classpath";
197 args << d->classPath;
204 for( ; it != itEnd; ++it )
206 if( !it.key().isEmpty() )
208 QString currarg =
"-D" + it.key();
209 if( !it.value().isEmpty() )
210 currarg +=
'=' + it.value();
216 if( !d->extraArgs.isEmpty() )
221 kWarning(6100) <<
"Extra args for JVM cannot be parsed, arguments = " << d->extraArgs;
225 args << d->mainClass;
227 if ( !d->classArgs.isNull() )
228 args << d->classArgs;
236 return waitForStarted();
241 closeReadChannel( StandardOutput );
252 char length[9] = { 0 };
253 const int num_bytes = read( length, 8 );
254 if( num_bytes == -1 )
256 kError(6100) <<
"could not read 8 characters for the message length!!!!" << endl;
260 const QString lengthstr( length );
262 const int num_len = lengthstr.toInt( &ok );
265 kError(6100) <<
"could not parse length out of: " << lengthstr << endl;
270 char*
const msg =
new char[num_len];
271 const int num_bytes_msg = read( msg, num_len );
272 if( num_bytes_msg == -1 || num_bytes_msg != num_len )
274 kError(6100) <<
"could not read the msg, num_bytes_msg = " << num_bytes_msg << endl;
279 emit
received( QByteArray( msg, num_len ) );
286 if ( exitStatus() == NormalExit ) {
289 kDebug(6100) <<
"jvm exited with status " << status;
293 #include "kjavaprocess.moc"