| 1 | /* |
| 2 | * File: UtilityRunner.cpp |
| 3 | * |
| 4 | * Author: Jacob Dekel |
| 5 | * Created on: Aug 7, 2009 |
| 6 | * |
| 7 | * Copyright (c) 2009-2013 Jacob Dekel |
| 8 | * $Id$ |
| 9 | * |
| 10 | * This program is free software: you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation, either version 3 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include "UtilityRunner.h" |
| 26 | #include "HerculesStudio.h" |
| 27 | #include "UtilityExecutor.h" |
| 28 | #include "StringTokenizer.h" |
| 29 | #include "ConfigurationEditor.h" |
| 30 | |
| 31 | #include <QProcess> |
| 32 | |
| 33 | #include <sstream> |
| 34 | #include <cerrno> |
| 35 | #include <cstdio> |
| 36 | |
| 37 | UtilityRunner::UtilityRunner(UtilityExecutor * utilityExecutor) |
| 38 | : mUtilityExecutor(utilityExecutor), mProcess(utilityExecutor->getQProcess()) |
| 39 | { |
| 40 | |
| 41 | } |
| 42 | |
| 43 | UtilityRunner::~UtilityRunner() |
| 44 | { |
| 45 | |
| 46 | } |
| 47 | |
| 48 | void UtilityRunner::run() |
| 49 | { |
| 50 | //mUtilityExecutor->getQProcess()->waitForStarted(); |
| 51 | mProcess = mUtilityExecutor->getQProcess(); |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | void UtilityRunner::updateStatus(const std::string& line) |
| 56 | { |
| 57 | Tokenizer::handle pos, lastPos; |
| 58 | std::string word = StringTokenizer::getFirstWord(line, pos, lastPos, " \t\n"); |
| 59 | hOutDebug(1,"util runner line:" << line); |
| 60 | if (line.length() == 0) |
| 61 | return; |
| 62 | |
| 63 | if (word == "HHCDU044I") // dasdinit |
| 64 | { |
| 65 | QByteArray qline(line.c_str()); |
| 66 | emit error(qline); |
| 67 | int i = line.find(":") + 2; |
| 68 | int cyls = ConfigurationEditor::parseNum(line.substr(i),10); |
| 69 | emit maximumChanged(cyls); |
| 70 | return; |
| 71 | } |
| 72 | if (line.compare(0,5,"NMEM=") == 0) // dasdisup |
| 73 | { |
| 74 | int currMem = ConfigurationEditor::parseNum(line.substr(5),10); |
| 75 | emit maximumChanged(currMem); |
| 76 | return; |
| 77 | } |
| 78 | if (line.compare(0,4,"POS=") == 0) // dasdcopy |
| 79 | { |
| 80 | int currMem = ConfigurationEditor::parseNum(line.substr(5),10); |
| 81 | emit valueChanged(currMem); |
| 82 | return; |
| 83 | } |
| 84 | if (line.compare(0,5,"IPOS=") == 0) // hetmap |
| 85 | { |
| 86 | int currMem = ConfigurationEditor::parseNum(line.substr(5),10); |
| 87 | emit valueChanged(currMem); |
| 88 | return; |
| 89 | } |
| 90 | if (line.compare(0,4,"MEM=") == 0) // dasdisup |
| 91 | { |
| 92 | int currMem = ConfigurationEditor::parseNum(line.substr(5),10); |
| 93 | emit valueChanged(currMem); |
| 94 | return; |
| 95 | } |
| 96 | if (line.compare(0,5,"ETRK=") == 0) // dasdls, dasdcat |
| 97 | { |
| 98 | int currMem = ConfigurationEditor::parseNum(line.substr(5),10); |
| 99 | emit maximumChanged(currMem); |
| 100 | return; |
| 101 | } |
| 102 | if (line.compare(0,4,"TRK=") == 0) // dasdcopy |
| 103 | { |
| 104 | int currMem = ConfigurationEditor::parseNum(line.substr(4),10); |
| 105 | emit valueChanged(currMem); |
| 106 | return; |
| 107 | } |
| 108 | if (line.compare(0,5,"CYLS=") == 0) // dasdconv |
| 109 | { |
| 110 | int currMem = ConfigurationEditor::parseNum(line.substr(5),10); |
| 111 | emit maximumChanged(currMem); |
| 112 | return; |
| 113 | } |
| 114 | if (line.compare(0,4,"CYL=") == 0) // dasdinit |
| 115 | { |
| 116 | int currMem = ConfigurationEditor::parseNum(line.substr(4),10); |
| 117 | emit valueChanged(currMem); |
| 118 | return; |
| 119 | } |
| 120 | if (line.compare(0,4,"BLK=") == 0) // dasdinit |
| 121 | { |
| 122 | int currMem = ConfigurationEditor::parseNum(line.substr(4),10); |
| 123 | emit valueChanged(currMem); |
| 124 | return; |
| 125 | } |
| 126 | if (line.compare(0,5,"TRKS=") == 0) // dasdcopy |
| 127 | { |
| 128 | int currMem = ConfigurationEditor::parseNum(line.substr(5),10); |
| 129 | emit maximumChanged(currMem); |
| 130 | return; |
| 131 | } |
| 132 | if (line.compare(0,5,"CTRK=") == 0) // dasdls, dasdcat |
| 133 | { |
| 134 | int currMem = ConfigurationEditor::parseNum(line.substr(5),10); |
| 135 | emit valueChanged(currMem); |
| 136 | hOutDebug(2,"Value changed " << currMem); |
| 137 | return; |
| 138 | } |
| 139 | if (line.compare(0,7,"OUTCYL=") == 0) |
| 140 | { |
| 141 | int currCyl = ConfigurationEditor::parseNum(line.substr(7),10); |
| 142 | emit valueChanged(currCyl); |
| 143 | return; |
| 144 | } |
| 145 | if (line.compare(0,5,"SIZE=") == 0) // dasdcopy |
| 146 | { |
| 147 | // swallow this message |
| 148 | return; |
| 149 | } |
| 150 | if (line.length() > 5 && line.compare(2,4,"CYL=") == 0) |
| 151 | { |
| 152 | int currCyl = ConfigurationEditor::parseNum(line.substr(4),10); |
| 153 | hOutDebug(5, "emitting value changed to " << currCyl); |
| 154 | emit valueChanged(currCyl); |
| 155 | return; |
| 156 | } |
| 157 | if (line.length() > 2 && line.compare(2,8,"REQCYLS=") == 0) |
| 158 | { |
| 159 | int currCyl = ConfigurationEditor::parseNum(line.substr(8),10); |
| 160 | emit valueChanged(currCyl); |
| 161 | return; |
| 162 | } |
| 163 | if (line.length() > 2 && line.compare(2,4,"BLK=") == 0) |
| 164 | { |
| 165 | int currCyl = ConfigurationEditor::parseNum(line.substr(4),10); |
| 166 | emit valueChanged(currCyl); |
| 167 | return; |
| 168 | } |
| 169 | else |
| 170 | { |
| 171 | QByteArray qline(line.c_str()); |
| 172 | emit error(qline); |
| 173 | } |
| 174 | } |
| 175 | void UtilityRunner::readStandardOutput() |
| 176 | { |
| 177 | if (mProcess == NULL) return; |
| 178 | mProcess->setReadChannel(QProcess::StandardOutput); |
| 179 | while (true) |
| 180 | { |
| 181 | QByteArray output = mProcess->readLine(); |
| 182 | if (output.length() == 0) break; |
| 183 | hOutDebug(2,"util runner:" << output.data()); |
| 184 | updateStatus(QString(output).toStdString()); |
| 185 | } |
| 186 | } |
| 187 | void UtilityRunner::readStandardError() |
| 188 | { |
| 189 | if (mProcess == NULL) return; |
| 190 | mProcess->setReadChannel(QProcess::StandardError); |
| 191 | while (true) |
| 192 | { |
| 193 | QByteArray output = mProcess->readLine(); |
| 194 | if (output.length() == 0) break; |
| 195 | output.replace('\n','\0'); |
| 196 | output.replace('\r','\0'); |
| 197 | hOutDebug(2,"util runner err:" << output.data()); |
| 198 | updateStatus(QString(output).toStdString()); |
| 199 | } |
| 200 | } |