Пример #1
0
void SessionServer::Private::onNewLocalConnection() {
	QLocalServer * server = dynamic_cast< QLocalServer * >( this->sender() );
	assert( server || !"QLocalServer casting failed" );
	while( server->hasPendingConnections() ) {
		QLocalSocket * socket = server->nextPendingConnection();
		ServerSession * session = new ServerSession( socket, this );
		this->pendingSessions.push( session );
	}
	emit this->newConnection();
}
Пример #2
0
void MobilityConnection::connectToSimulator()
{
    // 1. check availability
    QLocalSocket *socket = new QLocalSocket;
    QString simVersion = SimulatorConnection::instance()->simulatorVersion().toString();
    socket->connectToServer(QLatin1String(SIMULATOR_MOBILITY_SERVERNAME) + simVersion, QLocalSocket::ReadWrite);
    if (!socket->waitForConnected(1000)) {
        qFatal("Could not connect to mobility server");
        socket->deleteLater();
        return;
    }
    mSendSocket = socket;

    // 2. Create the local server used for initiating the backchannel.
    const qint64 pid = QCoreApplication::applicationPid();
    QLocalServer *server = new QLocalServer(this);
    if (!server->listen(qt_mobilityServerName(simVersion, pid)))
        qFatal("Can't create local mobility server for this application.");

    // 3. Send initial application connect command.
    ApplicationConnectCommand command;
    ApplicationConnectCommand::Request &request = command.request;
    request.applicationPid = pid;
    request.applicationName[0] = 0;
    request.version = mobilityVersion;
    qt_sendAndReceiveApplicationConnect(socket, command);

    mSimulatorVersion = command.reply.version;

    // We usually want to get the initial state from the simulator directly, probably
    // before the event loop is started up. Hence we block until the simulator has established
    // the back channel.
    if (!server->waitForNewConnection(1000))
        qFatal("Simulator didn't establish mobility-backchannel on time");
    mReceiveSocket = server->nextPendingConnection();
    server->close();

    connect(mReceiveSocket, SIGNAL(readyRead()), SLOT(onReadyRead()));
}
/*!
    \internal
    Called with an incoming connection
*/
void QJsonServer::handleLocalConnection()
{
    QLocalServer *server = qobject_cast<QLocalServer *>(sender());
    if (!server)
        return;

    if (QLocalSocket *socket = server->nextPendingConnection()) {
        socket->setReadBufferSize(64*1024);
        Q_D(QJsonServer);
        QJsonAuthority *authority = d->m_localServers.value(server);
        QJsonServerClient *client = new QJsonServerClient(this);
        client->setAuthority(authority);
        client->setSocket(socket);
        connect(client, SIGNAL(authorized(const QString&)),
                this, SLOT(handleClientAuthorized(const QString&)));
        connect(client, SIGNAL(disconnected(const QString&)),
                this, SLOT(clientDisconnected(const QString&)));
        connect(client, SIGNAL(messageReceived(const QString&, const QJsonObject&)),
                this, SLOT(receiveMessage(const QString&, const QJsonObject&)));
        connect(client, SIGNAL(authorizationFailed()),
                this, SLOT(handleAuthorizationFailed()));
        client->start();
    }
Пример #4
0
void Server::start() {
  QString sockPath = "/tmp/qeventloop_test";
  QLocalServer* server = new QLocalServer();
  QFile sockFile(sockPath);
  if (sockFile.exists()) {
    sockFile.remove();
  }
  server->listen(sockPath);
  QObject::connect(server, &QLocalServer::newConnection, [this, server]() {
    m_sock = server->nextPendingConnection();
    QObject::connect(m_sock, &QLocalSocket::disconnected, m_sock, &QLocalSocket::deleteLater);
    QObject::connect(m_sock, &QLocalSocket::readyRead, this, &Server::onReadyRead,
                     Qt::QueuedConnection);

    sendData(m_sock, 1);

    QEventLoop loop;
    QObject::connect(&m_result1, &Result::ready, &loop, &QEventLoop::quit);
    qDebug("start event loop to wait for 1");
    loop.exec();
    qDebug("end event loop to wait for 1");
  });
}
Пример #5
0
int main(int argc, char *argv[])
{
	Local a(argc, argv);
	int single;
	if ((single = Config::getValue("/Interface/Single", 1))){
		QLocalSocket socket;
		socket.connectToServer("BiliLocalInstance");
		if (socket.waitForConnected()){
			QDataStream s(&socket);
			s << a.arguments().mid(1);
			socket.waitForBytesWritten();
			return 0;
		}
	}
	loadTranslator();
	setDefaultFont();
	setToolTipBase();
	Interface w;
	Plugin::loadPlugins();
	if (!w.testAttribute(Qt::WA_WState_ExplicitShowHide)){
		w.show();
	}
	w.tryLocal(a.arguments().mid(1));
	QLocalServer *server = nullptr;
	if (single){
		server = new QLocalServer(lApp);
		server->listen("BiliLocalInstance");
		QObject::connect(server, &QLocalServer::newConnection, [&](){
			QLocalSocket *r = server->nextPendingConnection();
			r->waitForReadyRead();
			QDataStream s(r);
			QStringList args;
			s >> args;
			delete r;
			w.tryLocal(args);
		});
	}
Пример #6
0
RunControl *WinRtDebugSupport::createDebugRunControl(WinRtRunConfiguration *runConfig,
                                                     Core::Id mode,
                                                     QString *errorMessage)
{
    // FIXME: This is just working for local debugging;
    using namespace Debugger;
    DebuggerStartParameters params;
    params.startMode = AttachExternal;
    // The first Thread needs to be resumed manually.
    params.commandsAfterConnect = "~0 m";

    QFileInfo debuggerHelper(QCoreApplication::applicationDirPath()
                             + QLatin1String("/winrtdebughelper.exe"));
    if (!debuggerHelper.isExecutable()) {
        *errorMessage = tr("The WinRT debugging helper is missing from your Qt Creator "
                           "installation. It was assumed to be located at %1").arg(
                    debuggerHelper.absoluteFilePath());
        return 0;
    }

    if (useQmlDebugging(runConfig)) {
        quint16 qmlDebugPort = 0;
        if (!getFreePort(qmlDebugPort, errorMessage))
            return 0;
        runConfig->setArguments(runConfig->arguments() + QLatin1Char(' ')
                    + QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlDebuggerServices, qmlDebugPort));
        params.qmlServerAddress = QHostAddress::LocalHost;
        params.qmlServerPort = qmlDebugPort;
    }

    WinRtRunnerHelper *runner = new WinRtRunnerHelper(runConfig, errorMessage);
    if (!errorMessage->isEmpty())
        return 0;

    QLocalServer server;
    server.listen(QLatin1String("QtCreatorWinRtDebugPIDPipe"));

    runner->debug(debuggerHelper.absoluteFilePath());
    if (!runner->waitForStarted()) {
        *errorMessage = tr("Cannot start the WinRT Runner Tool.");
        return 0;
    }

    if (!server.waitForNewConnection(10000)) {
        *errorMessage = tr("Cannot establish connection to the WinRT debugging helper.");
        return 0;
    }

    while (server.hasPendingConnections()) {
        QLocalSocket *connection = server.nextPendingConnection();
        if (connection->waitForReadyRead(1000)) {
            const QByteArray &output = connection->readAll();
            QList<QByteArray> arg = output.split(':');
            if (arg.first() == "PID") {
                bool ok =false;
                params.attachPID = arg.last().toInt(&ok);
                if (!ok) {
                    *errorMessage = tr("Cannot extract the PID from the WinRT debugging helper. "
                                       "(output: %1)").arg(QString::fromLocal8Bit(output));
                    return 0;
                }
                server.close();
                Debugger::DebuggerRunControl *debugRunControl
                        = createDebuggerRunControl(params, runConfig, errorMessage, mode);
                runner->setDebugRunControl(debugRunControl);
                new WinRtDebugSupport(debugRunControl, runner);
                return debugRunControl;
            }
        }
    }

    server.close();

    *errorMessage = tr("Cannot create an appropriate run control for "
                       "the current run configuration.");

    return 0;
}
Пример #7
0
RunControl *WinRtDebugSupport::createDebugRunControl(WinRtRunConfiguration *runConfig,
                                                     RunMode mode,
                                                     QString *errorMessage)
{
    // FIXME: This is just working for local debugging;
    using namespace Debugger;
    DebuggerStartParameters params;
    params.startMode = AttachExternal;
    params.languages |= CppLanguage;
    params.breakOnMain = mode == DebugRunModeWithBreakOnMain;
    // The first Thread needs to be resumed manually.
    params.commandsAfterConnect = "~0 m";
    Kit *kit = runConfig->target()->kit();
    params.debuggerCommand = DebuggerKitInformation::debuggerCommand(kit).toString();
    if (ToolChain *tc = ToolChainKitInformation::toolChain(kit))
        params.toolChainAbi = tc->targetAbi();

    QFileInfo debuggerHelper(QCoreApplication::applicationDirPath()
                             + QLatin1String("/winrtdebughelper.exe"));
    if (!debuggerHelper.isExecutable()) {
        *errorMessage = tr("The WinRT debugging helper is missing from your Qt Creator "
                           "installation. It was assumed to be located at %1").arg(
                    debuggerHelper.absoluteFilePath());
        return 0;
    }

    WinRtRunnerHelper *runner = new WinRtRunnerHelper(runConfig, errorMessage);
    if (!errorMessage->isEmpty())
        return 0;

    QLocalServer server;
    server.listen(QLatin1String("QtCreatorWinRtDebugPIDPipe"));

    runner->debug(debuggerHelper.absoluteFilePath());
    if (!runner->waitForStarted()) {
        *errorMessage = tr("Cannot start the WinRT Runner Tool.");
        return 0;
    }

    if (!server.waitForNewConnection(10000)) {
        *errorMessage = tr("Cannot establish connection to the WinRT debugging helper.");
        return 0;
    }

    while (server.hasPendingConnections()) {
        QLocalSocket *connection = server.nextPendingConnection();
        if (connection->waitForReadyRead(1000)) {
            const QByteArray &output = connection->readAll();
            QList<QByteArray> arg = output.split(':');
            if (arg.first() == "PID") {
                bool ok =false;
                params.attachPID = arg.last().toInt(&ok);
                if (!ok) {
                    *errorMessage = tr("Cannot extract the PID from the WinRT debugging helper. "
                                       "(output: %1)").arg(QString::fromLocal8Bit(output));
                    return 0;
                }
                server.close();
                params.runConfiguration = runConfig;
                Debugger::DebuggerRunControl *debugRunControl
                        = createDebuggerRunControl(params, errorMessage);
                runner->setRunControl(debugRunControl);
                new WinRtDebugSupport(debugRunControl, runner);
                return debugRunControl;
            }
        }
    }

    server.close();

    *errorMessage = tr("Cannot create an appropriate run control for "
                       "the current run configuration.");

    return 0;
}