本文整理汇总了C++中Slave::setPID方法的典型用法代码示例。如果您正苦于以下问题:C++ Slave::setPID方法的具体用法?C++ Slave::setPID怎么用?C++ Slave::setPID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slave
的用法示例。
在下文中一共展示了Slave::setPID方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: holdSlave
Slave* Slave::holdSlave( const QString &protocol, const KURL& url )
{
//kdDebug(7002) << "holdSlave '" << protocol << "' for " << url.prettyURL() << endl;
// Firstly take into account all special slaves
if (protocol == "data")
return 0;
DCOPClient *client = kapp->dcopClient();
if (!client->isAttached())
client->attach();
QString prefix = locateLocal("socket", KGlobal::instance()->instanceName());
KTempFile socketfile(prefix, QString::fromLatin1(".slave-socket"));
if ( socketfile.status() != 0 )
return 0;
#ifdef __CYGWIN__
socketfile.close();
socketfile.unlink();
#endif
#ifndef Q_WS_WIN
KServerSocket *kss = new KServerSocket(QFile::encodeName(socketfile.name()));
Slave *slave = new Slave(kss, protocol, socketfile.name());
#else
Slave *slave = 0;
#endif
QByteArray params, reply;
QCString replyType;
QDataStream stream(params, IO_WriteOnly);
stream << url << socketfile.name();
QCString launcher = KApplication::launcher();
if (!client->call(launcher, launcher, "requestHoldSlave(KURL,QString)",
params, replyType, reply)) {
delete slave;
return 0;
}
QDataStream stream2(reply, IO_ReadOnly);
pid_t pid;
stream2 >> pid;
if (!pid)
{
delete slave;
return 0;
}
#ifndef Q_WS_WIN
slave->setPID(pid);
QTimer::singleShot(1000*SLAVE_CONNECTION_TIMEOUT_MIN, slave, SLOT(timeout()));
#endif
return slave;
}
示例2: DataProtocol
Slave *Slave::createSlave(const QString &protocol, const KURL &url, int &error, QString &error_text)
{
// kdDebug(7002) << "createSlave '" << protocol << "' for " << url.prettyURL() << endl;
// Firstly take into account all special slaves
if(protocol == "data")
return new DataProtocol();
DCOPClient *client = kapp->dcopClient();
if(!client->isAttached())
client->attach();
QString prefix = locateLocal("socket", KGlobal::instance()->instanceName());
KTempFile socketfile(prefix, QString::fromLatin1(".slave-socket"));
if(socketfile.status() != 0)
{
error_text = i18n("Unable to create io-slave: %1").arg(strerror(errno));
error = KIO::ERR_CANNOT_LAUNCH_PROCESS;
return 0;
}
#ifdef __CYGWIN__
socketfile.close();
#endif
KServerSocket *kss = new KServerSocket(QFile::encodeName(socketfile.name()));
Slave *slave = new Slave(kss, protocol, socketfile.name());
// WABA: if the dcopserver is running under another uid we don't ask
// klauncher for a slave, because the slave might have that other uid
// as well, which might either be a) undesired or b) make it impossible
// for the slave to connect to the application.
// In such case we start the slave via KProcess.
// It's possible to force this by setting the env. variable
// KDE_FORK_SLAVES, Clearcase seems to require this.
static bool bForkSlaves = !QCString(getenv("KDE_FORK_SLAVES")).isEmpty();
if(bForkSlaves || !client->isAttached() || client->isAttachedToForeignServer())
{
QString _name = KProtocolInfo::exec(protocol);
if(_name.isEmpty())
{
error_text = i18n("Unknown protocol '%1'.").arg(protocol);
error = KIO::ERR_CANNOT_LAUNCH_PROCESS;
delete slave;
return 0;
}
QString lib_path = KLibLoader::findLibrary(_name.latin1());
if(lib_path.isEmpty())
{
error_text = i18n("Can not find io-slave for protocol '%1'.").arg(protocol);
error = KIO::ERR_CANNOT_LAUNCH_PROCESS;
return 0;
}
KProcess proc;
proc << locate("exe", "kioslave") << lib_path << protocol << "" << socketfile.name();
kdDebug(7002) << "kioslave"
<< ", " << lib_path << ", " << protocol << ", " << QString::null << ", " << socketfile.name() << endl;
proc.start(KProcess::DontCare);
slave->setPID(proc.pid());
QTimer::singleShot(1000 * SLAVE_CONNECTION_TIMEOUT_MIN, slave, SLOT(timeout()));
return slave;
}
QByteArray params, reply;
QCString replyType;
QDataStream stream(params, IO_WriteOnly);
stream << protocol << url.host() << socketfile.name();
QCString launcher = KApplication::launcher();
if(!client->call(launcher, launcher, "requestSlave(QString,QString,QString)", params, replyType, reply))
{
error_text = i18n("Cannot talk to klauncher");
error = KIO::ERR_SLAVE_DEFINED;
delete slave;
return 0;
}
QDataStream stream2(reply, IO_ReadOnly);
QString errorStr;
pid_t pid;
stream2 >> pid >> errorStr;
if(!pid)
{
error_text = i18n("Unable to create io-slave:\nklauncher said: %1").arg(errorStr);
error = KIO::ERR_CANNOT_LAUNCH_PROCESS;
delete slave;
return 0;
}
slave->setPID(pid);
QTimer::singleShot(1000 * SLAVE_CONNECTION_TIMEOUT_MIN, slave, SLOT(timeout()));
return slave;
}