Esempio n. 1
0
QByteArray TasInfoLoggerUtil::loadLoggedData(QFile* file, const QString& name, QHash<QString,QString> params)
{
    TasDataModel* tasModel = new TasDataModel();
    QString qtVersion = "Qt" + QString(qVersion());
    TasObjectContainer& container = tasModel->addNewObjectContainer(1, qtVersion, "qt");
    TasObject& parentData = container.addNewObject("0", name, "logData");   

    int counter = 0;
    QTextStream in(file);
    in.seek(0);
    while (!in.atEnd()) {
        TasObject& obj = parentData.addObject();
        obj.setId(QString::number(counter));        
        obj.setType("logEntry");
        obj.setName("LogEntry");
        //load attributes format is: title:value;title:value....
        QStringList line = in.readLine().split(ATTR_DELIM, QString::SkipEmptyParts);
        QString attrPair;
        foreach(attrPair, line){
            QStringList attribute = attrPair.split(VALUE_DELIM, QString::SkipEmptyParts);
            obj.addAttribute(attribute.first(),attribute.last());
        }
        counter++;
    }
void ShellCommandService::shellStatus(qint64 pid, TasResponse& response)
{
    TasLogger::logger()->debug("ShellCommandService::service: looking for pid " +
                               QString::number(pid));

    if (mTasks.contains(pid)) {
        TasLogger::logger()->debug("ShellCommandService::got it");

        ShellTask* task = mTasks.value(pid);

        TasLogger::logger()->debug("ShellCommandService::setting run data");
        TasDataModel* model = new TasDataModel();
        QString qtVersion = "Qt" + QString(qVersion());
        TasObjectContainer& container = model->addNewObjectContainer(1, qtVersion, "qt");

        TasObject& output = container.addNewObject("2","Response","Response");

        ShellTask::Status status = task->status();

        switch (status) {
        case ShellTask::ERR:
            output.addAttribute("status", "ERROR");
            break;
        case ShellTask::RUNNING:
            output.addAttribute("status", "RUNNING");
            break;
        case ShellTask::FINISHED:
            output.addAttribute("status", "FINISHED");
            output.addAttribute("exitCode", task->returnCode());
            break;
        case ShellTask::NOT_STARTED:
        default:
            output.addAttribute("status", "NOT_STARTED");
            break;

        }
        output.addAttribute("output", QString(task->responseData()));

        // Clean up if process is done.
        if (status != ShellTask::RUNNING) {
            mTasks.remove(pid);
            if (task->isRunning()) {
                task->endTask();
            } else {
                task->deleteLater();
                task = 0;
            }


            TasLogger::logger()->debug("ShellCommandService::service: deleting");

            TasLogger::logger()->debug("ShellCommandService::service: donne");
        }

        QByteArray xml;
        model->serializeModel(xml);
        delete model;
        response.setData(xml);
    }

    TasLogger::logger()->debug("ShellCommandService::service: shell status done");
}