| 1 | /* |
| 2 | * File: LogRunner.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 "LogRunner.h"cxx . . $ `<file>/HercStudio/LogRunner.h`/ |
| 26 | #include "HerculesStudio.h"cxx . . $ `<file>/HercStudio/HerculesStudio.h`/ |
| 27 | #include "NamedPipe.h"cxx . . $ `<file>/HercStudio/NamedPipe.h`/ |
| 28 | #include "Preferences.h"cxx . . $ `<file>/HercStudio/Preferences.h`/ |
| 29 | |
| 30 | LogRunnercxx . . $ LogRunner#::LogRunnercxx . . $ LogRunner#LogRunner(5d9b11d72cda9ed7).(SynchronizedQueuecxx . . $ SynchronizedQueue#& logQueue, HerculesExecutorcxx . . $ HerculesExecutor# * herculesExecutor, int maxQueueSize) |
| 31 | : Runnercxx . . $ Runner#(logQueue), mHerculesExecutorcxx . . $ LogRunner#mHerculesExecutor.(herculesExecutor), mMaxQueueSizecxx . . $ LogRunner#mMaxQueueSize.(maxQueueSize) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | LogRunnercxx . . $ LogRunner#::~cxx . . $ LogRunner#`~LogRunner`(49f6e7a06ebc5aa8).LogRunnercxx . . $ LogRunner#() |
| 36 | { |
| 37 | |
| 38 | } |
| 39 | |
| 40 | void LogRunnercxx . . $ LogRunner#::runcxx . . $ LogRunner#run(49f6e7a06ebc5aa8).() |
| 41 | { |
| 42 | mQueuecxx . . $ Runner#mQueue..push_backcxx . . $ SynchronizedQueue#push_back(3203d9f8f38841a4).("logger started"cxx . . $ QByteArray#QByteArray(34d26762b42c433a).); |
| 43 | emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! newDatacxx . . $ Runner#newData(49f6e7a06ebc5aa8).(); |
| 44 | |
| 45 | #ifdef hFramework |
| 46 | mProcess = mHerculesExecutor->getQProcess(); |
| 47 | connect(mProcess, |
| 48 | SIGNAL(readyReadStandardOutput()), |
| 49 | this, |
| 50 | SLOT(readStandardOutput())); |
| 51 | return; |
| 52 | #else |
| 53 | QFilecxx . . $ QFile#& logFile = NamedPipecxx . . $ NamedPipe#::getInstancecxx . . $ NamedPipe#getInstance(464fad7f4e589b3).().getHerculesLogfilecxx . . $ NamedPipe#getHerculesLogfile(b409ea4a0265da19).(); |
| 54 | QByteArraycxx . . $ QByteArray# buffcxx . . $ QByteArray#QByteArray(49f6e7a06ebc5aa8).; |
| 55 | buff.resizecxx . . $ QByteArray#resize(d4f767463ce0a6b3).(512); |
| 56 | mRunningcxx . . $ LogRunner#mRunning. = true; |
| 57 | bool lineRead = false; |
| 58 | int startupCounter = 0; |
| 59 | |
| 60 | while(mRunningcxx . . $ LogRunner#mRunning.) |
| 61 | { |
| 62 | int size; |
| 63 | if ((size = logFile.readLinecxx . . $ QIODevice#readLine(2e638bc8ed65be6c).(buff.datacxx . . $ QByteArray#data(41208ce6ca65dd58).(),512)) <= 0) |
| 64 | { |
| 65 | // we wait up to 2 seconds for data to appear in the log |
| 66 | if (!lineRead) |
| 67 | { |
| 68 | if (startupCounter++ < 200) |
| 69 | { |
| 70 | QThreadcxx . . $ QThread#::msleepcxx . . $ QThread#msleep(2c44cd906ae4e829).(10); |
| 71 | continue; // retry reading by returning to main loop |
| 72 | } |
| 73 | } |
| 74 | mQueuecxx . . $ Runner#mQueue..push_backcxx . . $ SynchronizedQueue#push_back(3203d9f8f38841a4).("logger ended"cxx . . $ QByteArray#QByteArray(34d26762b42c433a).); |
| 75 | emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! newDatacxx . . $ Runner#newData(49f6e7a06ebc5aa8).(); |
| 76 | break; |
| 77 | } |
| 78 | |
| 79 | lineRead = true; |
| 80 | buff[cxx . . $ QByteArray#`operator[]`(6eaff86c84670f1a).size-1] =cxx . . $ QByteRef#`operator=`(fee4eda3ac0bfad3). '\0'; |
| 81 | mQueuecxx . . $ Runner#mQueue..push_backcxx . . $ SynchronizedQueue#push_back(45672f3c6961a244).(buff); |
| 82 | emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! newDatacxx . . $ Runner#newData(49f6e7a06ebc5aa8).(); |
| 83 | while (mQueuecxx . . $ Runner#mQueue..sizecxx . . $ SynchronizedQueue#size(b126dc7c1de90089).() > mMaxQueueSizecxx . . $ LogRunner#mMaxQueueSize.) // do not flood the queue |
| 84 | QThreadcxx . . $ QThread#::msleepcxx . . $ QThread#msleep(2c44cd906ae4e829).(100); // yield |
| 85 | } |
| 86 | #endif |
| 87 | } |
| 88 | |
| 89 | #ifdef hFramework |
| 90 | void LogRunner::readStandardOutput() |
| 91 | { |
| 92 | mProcess->setReadChannel(QProcess::StandardOutput); |
| 93 | while (true) |
| 94 | { |
| 95 | QByteArray output = mProcess->readLine(); |
| 96 | if (output.length() == 0) break; |
| 97 | #ifndef hCRLF |
| 98 | output[output.length()-1]='\0'; |
| 99 | #else |
| 100 | output[output.length()-2]='\0'; |
| 101 | #endif |
| 102 | mQueue.push_back(output.data()); |
| 103 | emit newData(); |
| 104 | } |
| 105 | } |
| 106 | #endif |