/** Processes all message received on command */ void CommandBase::processCommandChannelMessage(const Container &rx) { // react to emccmd executed message if (rx.type() == MT_EMCCMD_EXECUTED) { handleEmccmdExecutedMessage(rx); } // react to emccmd completed message else if (rx.type() == MT_EMCCMD_COMPLETED) { handleEmccmdCompletedMessage(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 commandMessageReceived(rx); }
/** Connects the 0MQ sockets */ bool QApplicationLauncher::connectSockets() { m_context = new PollingZMQContext(this, 1); connect(m_context, SIGNAL(pollError(int,QString)), this, SLOT(pollError(int,QString))); m_context->start(); m_commandSocket = m_context->createSocket(ZMQSocket::TYP_DEALER, this); m_commandSocket->setLinger(0); m_commandSocket->setIdentity(QString("%1-%2").arg(m_commandIdentity).arg(QCoreApplication::applicationPid()).toLocal8Bit()); m_subscribeSocket = m_context->createSocket(ZMQSocket::TYP_SUB, this); m_subscribeSocket->setLinger(0); try { m_commandSocket->connectTo(m_commandUri); m_subscribeSocket->connectTo(m_subscribeUri); } catch (const zmq::error_t &e) { QString errorString; errorString = QString("Error %1: ").arg(e.num()) + QString(e.what()); updateState(Service::Error, Service::SocketError, errorString); return false; } connect(m_subscribeSocket, SIGNAL(messageReceived(QList<QByteArray>)), this, SLOT(subscribeMessageReceived(QList<QByteArray>))); connect(m_commandSocket, SIGNAL(messageReceived(QList<QByteArray>)), this, SLOT(commandMessageReceived(QList<QByteArray>))); #ifdef QT_DEBUG DEBUG_TAG(1, m_commandIdentity, "sockets connected" << m_subscribeUri << m_commandUri) #endif return true; }