コード例 #1
0
bool QApplicationConfig::connectSocket()
{
    m_context = new PollingZMQContext(this, 1);
    connect(m_context, SIGNAL(pollError(int,QString)),
            this, SLOT(pollError(int,QString)));
    m_context->start();

    m_configSocket = m_context->createSocket(ZMQSocket::TYP_DEALER, this);
    m_configSocket->setLinger(0);
    m_configSocket->setIdentity(QString("%1-%2").arg("appconfig").arg(QCoreApplication::applicationPid()).toLocal8Bit());

    try {
        m_configSocket->connectTo(m_configUri);
    }
    catch (const zmq::error_t &e) {
        QString errorString;
        errorString = QString("Error %1: ").arg(e.num()) + QString(e.what());
        updateError(SocketError, errorString);
        updateState(Error);
        return false;
    }

    connect(m_configSocket, SIGNAL(messageReceived(QList<QByteArray>)),
            this, SLOT(configMessageReceived(QList<QByteArray>)));

    return true;
}
コード例 #2
0
ファイル: configbase.cpp プロジェクト: ftkalcevic/QtQuickVcp
/** Processes all message received on config */
void ConfigBase::processConfigChannelMessage(const Container &rx)
{

    // react to describe application message
    if (rx.type() == MT_DESCRIBE_APPLICATION)
    {

        if (m_state == State::Listing)
        {
            emit fsmListingApplicationRetrieved(QPrivateSignal());
        }
        handleDescribeApplicationMessage(rx);
    }

    // react to application detail message
    else if (rx.type() == MT_APPLICATION_DETAIL)
    {

        if (m_state == State::Loading)
        {
            emit fsmLoadingApplicationLoaded(QPrivateSignal());
        }
        handleApplicationDetailMessage(rx);
    }

    // react to error message
    else if (rx.type() == MT_ERROR)
    {

        // update error string with note
        m_errorString = "";
        for (int i = 0; i < rx.note_size(); ++i)
        {
            m_errorString.append(QString::fromStdString(rx.note(i)) + "\n");
        }
        emit errorStringChanged(m_errorString);
    }

    emit configMessageReceived(rx);
}