Exemplo n.º 1
0
//=============================================================================
// METHOD: SPELLserverCif::notifyError
//=============================================================================
void SPELLserverCif::notifyError( const std::string& error, const std::string& reason, bool fatal )
{
    DEBUG("[CIF] Error notification: " + error + " (" + reason + ")");

    SPELLipcMessage errorMsg( MessageId::MSG_ID_ERROR);
    errorMsg.setType(MSG_TYPE_ERROR);
    errorMsg.set( MessageField::FIELD_PROC_ID, getProcId() );
    errorMsg.set( MessageField::FIELD_DATA_TYPE, MessageValue::DATA_TYPE_STATUS );
    errorMsg.set( MessageField::FIELD_EXEC_STATUS, StatusToString(STATUS_ERROR) );
    errorMsg.set( MessageField::FIELD_ERROR, error );
    errorMsg.set( MessageField::FIELD_REASON, reason );
    if (fatal)
    {
        errorMsg.set( MessageField::FIELD_FATAL, PythonConstants::True );
    }
    else
    {
        errorMsg.set( MessageField::FIELD_FATAL, PythonConstants::False );
    }

    completeMessage( &errorMsg );

    m_asRun->writeErrorInfo( error, reason );

    sendGUIMessage(&errorMsg);
}
Exemplo n.º 2
0
//=============================================================================
// METHOD: SPELLserverCif::error
//=============================================================================
void SPELLserverCif::error( const std::string& msg, unsigned int scope )
{
    if ( getVerbosity() > getVerbosityFilter() ) return;

    DEBUG("[CIF] Error message: " + msg);

    // We shall not bufferize in manual mode
    if (isManual())
    {
        completeMessage( &m_wrMessage );
        std::string timeStr = getTimestampUsec();
        m_wrMessage.set(MessageField::FIELD_TEXT,msg);
        m_wrMessage.set(MessageField::FIELD_LEVEL,MessageValue::DATA_SEVERITY_ERROR);
        m_wrMessage.set(MessageField::FIELD_MSGTYPE,LanguageConstants::DISPLAY);
        m_wrMessage.set(MessageField::FIELD_TIME, timeStr);
        m_wrMessage.set(MessageField::FIELD_SCOPE, ISTR(scope));
        sendGUIMessage(&m_wrMessage);
    }
    else
    {
        m_buffer->error( msg, scope );
    }

    m_asRun->writeError( getStack(), msg, scope );
}
Exemplo n.º 3
0
//=============================================================================
// METHOD: SPELLserverCif::notifyStatus
//=============================================================================
void SPELLserverCif::notifyStatus( const SPELLstatusInfo& st )
{
    DEBUG("[CIF] Status notification: " + StatusToString(st.status) + " (" + st.condition + ")");

    m_stMessage.set(MessageField::FIELD_EXEC_STATUS, StatusToString(st.status));

    completeMessage( &m_stMessage );

    // Condition information
    if (st.condition.size()>0)
    {
        m_stMessage.set( MessageField::FIELD_CONDITION, st.condition );
    }

    // Action information
    if (st.actionLabel != "")
    {
        m_stMessage.set( MessageField::FIELD_ACTION_LABEL, st.actionLabel );
        m_stMessage.set( MessageField::FIELD_ACTION_ENABLED, st.actionEnabled ? MessageValue::DATA_TRUE : MessageValue::DATA_FALSE );
    }

    m_asRun->writeStatus( st.status );

    SPELLipcMessage* response = sendGUIRequest(&m_stMessage, SPELL_CIF_NOTIFICATION_TIMEOUT_SEC);
    if (response) delete response;
}
/**
 * ブラウザとの間に新しいソケットを開く
 */
void YASWebProxy::openNewSocket()
{
    QTcpSocket* socket = server->nextPendingConnection();
    connect(socket, SIGNAL(readyRead()), this, SLOT(openTunnel()));
    connect(socket, SIGNAL(disconnected()), socket, SLOT(deleteLater()));
    HttpParser* parser = new HttpParser(HttpParser::REQUEST, socket);
    parser->setObjectName("requestParser");
    connect(parser, SIGNAL(completeMessage(QByteArray)), this, SLOT(onRequest(QByteArray)));
}
Exemplo n.º 5
0
//=============================================================================
// METHOD: SPELLserverCif::notifyReturn
//=============================================================================
void SPELLserverCif::notifyReturn()
{
    DEBUG("[CIF] Procedure return");

    m_lnMessage.set( MessageField::FIELD_DATA_TYPE, MessageValue::DATA_TYPE_RETURN );
    m_lnMessage.setType(MSG_TYPE_NOTIFY);

    completeMessage( &m_lnMessage );
    m_lnMessage.set(MessageField::FIELD_MSG_SEQUENCE, ISTR(m_sequenceStack));
    m_sequenceStack++;
    m_lnMessage.set(MessageField::FIELD_CODE_NAME, getCodeName() );

    m_asRun->writeReturn( (m_sequence-1) );

    SPELLipcMessage* response = sendGUIRequest(&m_lnMessage, SPELL_CIF_NOTIFICATION_TIMEOUT_SEC);
    if (response) delete response;
}
Exemplo n.º 6
0
//=============================================================================
// METHOD: SPELLserverCif::notifyCall
//=============================================================================
void SPELLserverCif::notifyCall()
{
    std::string stack = getStack();

    DEBUG("[CIF] Procedure call: " + stack );

    m_lnMessage.set( MessageField::FIELD_DATA_TYPE, MessageValue::DATA_TYPE_CALL );
    m_lnMessage.setType(MSG_TYPE_NOTIFY);

    completeMessage( &m_lnMessage );
    m_lnMessage.set(MessageField::FIELD_MSG_SEQUENCE, ISTR(m_sequenceStack));
    m_sequenceStack++;
    m_lnMessage.set(MessageField::FIELD_CODE_NAME, getCodeName() );

    m_asRun->writeCall( stack, (m_sequence-1) );

    SPELLipcMessage* response = sendGUIRequest(&m_lnMessage, SPELL_CIF_NOTIFICATION_TIMEOUT_SEC);
    if (response) delete response;
}
Exemplo n.º 7
0
//=============================================================================
// METHOD: SPELLserverCif::notifyLine
//=============================================================================
void SPELLserverCif::notifyLine()
{
    std::string stack = getStack();

    if (m_lastStack == stack) return;
    m_lastStack = stack;

    std::string stage = getStage();

    DEBUG("[CIF] Procedure line: " + stack + "(" + stage + ")");

    m_lnMessage.set( MessageField::FIELD_DATA_TYPE, MessageValue::DATA_TYPE_LINE );
    m_lnMessage.setType(MSG_TYPE_NOTIFY_ASYNC);

    completeMessage( &m_lnMessage );
    m_lnMessage.set(MessageField::FIELD_MSG_SEQUENCE, ISTR(m_sequenceStack));
    m_sequenceStack++;
    m_lnMessage.set(MessageField::FIELD_CODE_NAME, getCodeName() );

    if (stage.find(":") != std::string::npos)
    {
        std::vector<std::string> stage_title = tokenize(stage,":");
        if (stage_title.size()==2)
        {
            m_lnMessage.set(MessageField::FIELD_STAGE_ID,stage_title[0]);
            m_lnMessage.set(MessageField::FIELD_STAGE_TL,stage_title[1]);
        }
        else
        {
            m_lnMessage.set(MessageField::FIELD_STAGE_ID,"(none)");
            m_lnMessage.set(MessageField::FIELD_STAGE_TL,"(none)");
        }
    }
    else
    {
        m_lnMessage.set(MessageField::FIELD_STAGE_ID,stage);
        m_lnMessage.set(MessageField::FIELD_STAGE_TL,stage);
    }

    m_asRun->writeLine( stack, (m_sequence-1) );

    sendGUIMessage(&m_lnMessage);
}
/**
 * ブラウザとのソケットと本来のホストとのソケットを接続するトンネルを作成
 */
void YASWebProxy::openTunnel()
{
    QTcpSocket* socket = qobject_cast<QTcpSocket*>(sender());
    QByteArray data = socket->readAll();

    HttpParser* parser = socket->findChild<HttpParser*>("requestParser");
    parser->input(data);

    QTcpSocket* proxySocket = socket->findChild<QTcpSocket*>("tunnel");
    if (!proxySocket) {
        // 本来のホストへのソケットを作成
        proxySocket = new QTcpSocket(socket);
        proxySocket->setObjectName("tunnel");
        proxySocket->connectToHost(parser->url.host(), parser->url.port(80));

        connect(proxySocket, SIGNAL(disconnected()), this, SLOT(closeProxySocket()));
        connect(proxySocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(closeProxySocket()));

        connect(proxySocket, SIGNAL(readyRead()), this, SLOT(forwardResponse()));
        if (parser->method == "CONNECT") {
            disconnect(socket, SIGNAL(readyRead()), this, SLOT(openTunnel()));
            connect(socket, SIGNAL(readyRead()), this, SLOT(forwardRequest()));
        } else {
            HttpParser* resParser = new HttpParser(HttpParser::RESPONSE, proxySocket);
            resParser->setObjectName("responseParser");
            resParser->setProperty("url", parser->url.toString());
            connect(resParser, SIGNAL(completeMessage(QByteArray)), this, SLOT(onResponse(QByteArray)));
        }
    }

    if (proxySocket->waitForConnected()) {
        if (parser->method == "CONNECT") {
            socket->write("HTTP/1.0 200 Connection established\r\n\r\n");
        } else {
            proxySocket->write(parser->dequeueData());
        }
    } else {
        proxySocket->disconnect();
    }
}
Exemplo n.º 9
0
//=============================================================================
// METHOD: SPELLserverCif::prompt
//=============================================================================
std::string SPELLserverCif::prompt( const std::string& message, PromptOptions options, unsigned int ptype, unsigned int scope )
{
    DEBUG("[CIF] Prompt message");

    std::string timeStr = getTimestampUsec();

    SPELLipcMessage promptMessage(MessageId::MSG_ID_PROMPT);

    completeMessage( &promptMessage );

    promptMessage.setType(MSG_TYPE_PROMPT);
    promptMessage.set(MessageField::FIELD_PROC_ID, getProcId() );
    promptMessage.set(MessageField::FIELD_TEXT, message);
    promptMessage.set(MessageField::FIELD_DATA_TYPE, ISTR(ptype));
    promptMessage.set(MessageField::FIELD_TIME, timeStr);
    promptMessage.set(MessageField::FIELD_SCOPE, ISTR(scope));

    // Used for the prompt display message
    PromptOptions optionsToShow;

    DEBUG("[CIF] Prompt typecode " + ISTR(ptype));

    if (ptype == LanguageConstants::PROMPT_NUM ||
            ptype == LanguageConstants::PROMPT_ALPHA ||
            ptype == LanguageConstants::PROMPT_DATE )
    {
        DEBUG("[CIF] Prompt is simple");
        promptMessage.set(MessageField::FIELD_EXPECTED, "");
    }
    else if ( ptype & LanguageConstants::PROMPT_LIST )
    {
        DEBUG("[CIF] Prompt is list");
        PromptOptions::iterator it;
        int keyCount = 1;
        std::string optionStr = "";
        std::string expectedStr = "";

        // Iterate over the option list and build the option and expected values strings
        for( it = options.begin(); it != options.end(); it++)
        {
            std::string key;
            std::string value;
            std::string opt = (*it);
            DEBUG("[CIF] Option: " + opt);

            if (optionStr.size()>0) optionStr += IPCinternals::OPT_SEPARATOR;
            if (expectedStr.size()>0) expectedStr += IPCinternals::OPT_SEPARATOR;

            if ( opt.find(IPCinternals::KEY_SEPARATOR) == std::string::npos )
            {
                // Put an internal key in this case
                key = ISTR(keyCount);
                value = opt;
                // Trim the value
                trim(value);
            }
            else
            {
                int idx = opt.find(IPCinternals::KEY_SEPARATOR);
                key = opt.substr(0, idx);
                // Trim the key
                trim(key);
                value = opt.substr(idx+1, opt.size()-idx);
                // Trim the value
                trim(value);
            }
            DEBUG("[CIF] Option key: '" + key + "'");
            DEBUG("[CIF] Option value: '" + value + "'");

            optionStr += key + IPCinternals::KEY_SEPARATOR + value;
            optionsToShow.push_back(key + ": " + value);

            if (ptype & LanguageConstants::PROMPT_ALPHA)
            {
                expectedStr += value;
                DEBUG("[CIF] Expected: " + value);
            }
            else
            {
                expectedStr += key;
                DEBUG("[CIF] Expected: " + key);
            }
            keyCount++;
        }
        promptMessage.set(MessageField::FIELD_EXPECTED, expectedStr);
        promptMessage.set(MessageField::FIELD_OPTIONS, optionStr);
    }
    else if (ptype == LanguageConstants::PROMPT_OK)
    {
        promptMessage.set(MessageField::FIELD_EXPECTED, "O");
        promptMessage.set(MessageField::FIELD_OPTIONS, "O" + IPCinternals::KEY_SEPARATOR + " Ok");
        optionsToShow.push_back("O: Ok");
    }
    else if (ptype == LanguageConstants::PROMPT_CANCEL)
    {
        promptMessage.set(MessageField::FIELD_EXPECTED, "C");
        promptMessage.set(MessageField::FIELD_OPTIONS, "C" + IPCinternals::KEY_SEPARATOR + " Cancel");
        optionsToShow.push_back("C: Cancel");
    }
    else if (ptype == LanguageConstants::PROMPT_YES)
    {
        promptMessage.set(MessageField::FIELD_EXPECTED, "Y");
        promptMessage.set(MessageField::FIELD_OPTIONS, "Y" + IPCinternals::KEY_SEPARATOR + " Yes");
        optionsToShow.push_back("Y: Yes");
    }
    else if (ptype == LanguageConstants::PROMPT_NO)
    {
        promptMessage.set(MessageField::FIELD_EXPECTED, "N");
        promptMessage.set(MessageField::FIELD_OPTIONS, "N" + IPCinternals::KEY_SEPARATOR + " No");
        optionsToShow.push_back("N: No");
    }
    else if (ptype == LanguageConstants::PROMPT_YES_NO)
    {
        promptMessage.set(MessageField::FIELD_EXPECTED, "Y|N");
        promptMessage.set(MessageField::FIELD_OPTIONS, "Y" + IPCinternals::KEY_SEPARATOR + " Yes|N" + IPCinternals::KEY_SEPARATOR + " No");
        optionsToShow.push_back("Y: Yes");
        optionsToShow.push_back("N: No");
    }
    else if (ptype == LanguageConstants::PROMPT_OK_CANCEL)
    {
        promptMessage.set(MessageField::FIELD_EXPECTED, "O|C");
        promptMessage.set(MessageField::FIELD_OPTIONS, "O" + IPCinternals::KEY_SEPARATOR + " Ok|C" + IPCinternals::KEY_SEPARATOR + " Cancel");
        optionsToShow.push_back("O: Ok");
        optionsToShow.push_back("C: Cancel");
    }
    DEBUG("[CIF] Option string: " + promptMessage.get(MessageField::FIELD_OPTIONS));
    DEBUG("[CIF] Expected string: " + promptMessage.get(MessageField::FIELD_EXPECTED));

    // Write the prompt display
    std::string msgToShow = message;
    if (optionsToShow.size()>0)
    {
        msgToShow += "\nAvailable options:\n";
        for(PromptOptions::iterator pit = optionsToShow.begin(); pit != optionsToShow.end(); pit++)
        {
            msgToShow += "   - " + (*pit) + "\n";
        }
    }

    // Send the display message via the buffer to ensure synchronization
    m_buffer->prompt(msgToShow, LanguageConstants::SCOPE_PROMPT);

    // Ensure buffer is flushed
    m_buffer->flush();

    // Write the prompt in the asrun
    m_asRun->writePrompt( getStack(), message, scope );

    DEBUG("[CIF] Messsage prepared");

    // Send request to client
    SPELLipcMessage* response = sendGUIRequest(&promptMessage, SPELL_CIF_PROMPT_TIMEOUT_SEC);

    DEBUG("[CIF] Prompt response received");

    std::string toProcess = "";
    if (response->getId() == MessageId::MSG_ID_CANCEL)
    {
        LOG_WARN("Prompt cancelled");
        DEBUG("[CIF] Prompt cancelled");
        toProcess = PROMPT_CANCELLED;
        // Abort execution in this case
        SPELLexecutor::instance().abort("Prompt cancelled",true);
    }
    else if (response->getId() == MessageId::MSG_ID_TIMEOUT)
    {
        LOG_ERROR("Prompt timed out");
        DEBUG("[CIF] Prompt timed out");
        toProcess = PROMPT_TIMEOUT;
        // Abort execution in this case
        SPELLexecutor::instance().abort("Prompt timed out", true);
    }
    else if (response->getType() == MSG_TYPE_ERROR)
    {
        std::string errorMsg = response->get( MessageField::FIELD_ERROR );
        DEBUG("[CIF] Prompt error: " + errorMsg );
        LOG_ERROR("Prompt error: " + errorMsg);
        toProcess = PROMPT_ERROR;
        // \todo Should fix this and use an error code
        if (errorMsg == "No controlling client")
        {
            warning("No controlling client to issue prompt!", LanguageConstants::SCOPE_SYS );
            SPELLexecutor::instance().pause();
        }
        else
        {
            error( "Prompt error: " + errorMsg, LanguageConstants::SCOPE_SYS  );
            // Abort execution in this case
            SPELLexecutor::instance().abort("Prompt error",true);
        }
    }
    else
    {
        toProcess = response->get(MessageField::FIELD_RVALUE);
        DEBUG("[CIF] Prompt response: " + toProcess);
    }

    // \todo When there is no controlling client we should keep the child procedure in prompt waiting state

    // Send the display message via the buffer to ensure synchronization
    m_buffer->write("Answer: '" + toProcess + "'", LanguageConstants::SCOPE_PROMPT);
    m_buffer->flush();

    m_asRun->writeAnswer( getStack(), toProcess, scope );
    return toProcess;
}
Exemplo n.º 10
0
//=============================================================================
// METHOD: SPELLserverCif::notify
//=============================================================================
void SPELLserverCif::notify( ItemNotification notification )
{
    DEBUG("[CIF] Item notification");

    completeMessage( &m_ntMessage );

    DEBUG("[CIF] Processing status");
    int sCount = 0;
    if (notification.status.find(IPCinternals::ARG_SEPARATOR) != std::string::npos )
    {
        std::vector<std::string> statusList = tokenize(notification.status,IPCinternals::ARG_SEPARATOR);
        std::vector<std::string>::iterator it;
        for( it = statusList.begin(); it != statusList.end(); it++)
        {
            if (*it == MessageValue::DATA_NOTIF_STATUS_OK) sCount++;
        }
        std::vector<std::string> commentList = tokenize(notification.comment,IPCinternals::ARG_SEPARATOR);
        if (commentList.size() == 1)
        {
            notification.comment = "";
            for( unsigned int count=0; count<statusList.size(); count++)
            {
                if (notification.comment.size()>0) notification.comment += IPCinternals::ARG_SEPARATOR;
                notification.comment += " ";
            }
        }
        std::vector<std::string> timeList = tokenize(notification.time, IPCinternals::ARG_SEPARATOR);
        if (timeList.size() == 1)
        {
            notification.time = "";
            std::string tstamp = timestamp();
            for( unsigned int count=0; count<statusList.size(); count++)
            {
                if (notification.time.size()>0) notification.time += IPCinternals::ARG_SEPARATOR;
                notification.time += tstamp;
            }
        }
    }
    else
    {
        sCount = (notification.status == MessageValue::DATA_NOTIF_STATUS_OK) ? 1 : 0;
    }

    std::stringstream buffer;
    buffer << sCount;

    m_ntMessage.set(MessageField::FIELD_NOTIF_ITEM_TYPE, NOTIF_TYPE_STR[notification.type]);
    m_ntMessage.set(MessageField::FIELD_NOTIF_ITEM_NAME, notification.name);
    m_ntMessage.set(MessageField::FIELD_NOTIF_ITEM_VALUE, notification.value);
    m_ntMessage.set(MessageField::FIELD_NOTIF_ITEM_STATUS, notification.status);
    m_ntMessage.set(MessageField::FIELD_NOTIF_ITEM_REASON, notification.comment);
    m_ntMessage.set(MessageField::FIELD_NOTIF_ITEM_TIME, notification.time);
    m_ntMessage.set(MessageField::FIELD_NOTIF_ITEM_SCOUNT, buffer.str());

    DEBUG("[CIF] Message prepared, sending");

    m_asRun->writeItem( getStack(),
                        NOTIF_TYPE_STR[notification.type],
                        notification.name,
                        notification.value,
                        notification.status,
                        notification.comment,
                        notification.time );

    SPELLipcMessage* response = sendGUIRequest(&m_ntMessage, SPELL_CIF_NOTIFICATION_TIMEOUT_SEC);
    if (response) delete response;
    DEBUG("[CIF] Notification sent");
}