| 1 | #cxx . . $ `<file>/HercPrinter/PrintRunner.cpp`/include "PrintRunner.h"cxx . . $ `<file>/HercPrinter/PrintRunner.h`/ |
| 2 | #include "PrinterItem.h"cxx . . $ `<file>/HercPrinter/PrinterItem.h`/ |
| 3 | |
| 4 | #include <QHostAddress> |
| 5 | #include <QElapsedTimer> |
| 6 | #include <QtGlobal> |
| 7 | #include <algorithm> |
| 8 | |
| 9 | PrinterSocketcxx . . $ PrinterSocket#::PrinterSocketcxx . . $ PrinterSocket#PrinterSocket(49f6e7a06ebc5aa8).() : |
| 10 | QTcpSocketcxx . . $ QTcpSocket#() |
| 11 | { |
| 12 | mBuffPoscxx . . $ PrinterSocket#mBuffPos. = mBuffcxx . . $ PrinterSocket#mBuff.; |
| 13 | } |
| 14 | |
| 15 | QByteArraycxx . . $ QByteArray# PrinterSocketcxx . . $ PrinterSocket#::returnLinecxx . . $ PrinterSocket#returnLine(531409eeffcde449).(const char *end) |
| 16 | { |
| 17 | end++; |
| 18 | QByteArraycxx . . $ QByteArray# linecxx . . $ QByteArray#QByteArray(34d26762b42c433a).(mBuffcxx . . $ PrinterSocket#mBuff., end-mBuffcxx . . $ PrinterSocket#mBuff.); |
| 19 | |
| 20 | memmove(mBuffcxx . . $ PrinterSocket#mBuff., end, mBuffPoscxx . . $ PrinterSocket#mBuffPos.-end); |
| 21 | |
| 22 | mBuffPoscxx . . $ PrinterSocket#mBuffPos. -= (end - mBuffcxx . . $ PrinterSocket#mBuff.); |
| 23 | return linecxx . . $ QByteArray#QByteArray(3203d9f8f38841a4).; |
| 24 | } |
| 25 | |
| 26 | char *PrinterSocketcxx . . $ PrinterSocket#::nextPoscxx . . $ PrinterSocket#nextPos(41208ce6ca65dd58).() |
| 27 | { |
| 28 | char * maybeEndF = stdcxx . . $ std/::findcxx . . $ std/find(a92da12e15934614).(mBuffcxx . . $ PrinterSocket#mBuff., mBuffPoscxx . . $ PrinterSocket#mBuffPos., '\f'); |
| 29 | char * maybeEndN = stdcxx . . $ std/::findcxx . . $ std/find(a92da12e15934614).(mBuffcxx . . $ PrinterSocket#mBuff., mBuffPoscxx . . $ PrinterSocket#mBuffPos., '\n'); |
| 30 | char * maybeEndR = stdcxx . . $ std/::findcxx . . $ std/find(a92da12e15934614).(mBuffcxx . . $ PrinterSocket#mBuff., mBuffPoscxx . . $ PrinterSocket#mBuffPos., '\r'); |
| 31 | |
| 32 | char * ret = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(maybeEndF, maybeEndN), maybeEndR); |
| 33 | if (ret < mBuffPoscxx . . $ PrinterSocket#mBuffPos.) return ret; |
| 34 | |
| 35 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 36 | } |
| 37 | |
| 38 | QByteArraycxx . . $ QByteArray# PrinterSocketcxx . . $ PrinterSocket#::readLinecxx . . $ PrinterSocket#readLine(b3c286cec66e09f4).() |
| 39 | { |
| 40 | char *pos = nextPoscxx . . $ PrinterSocket#nextPos(41208ce6ca65dd58).(); |
| 41 | if (pos != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 42 | { |
| 43 | return returnLinecxx . . $ QByteArray#QByteArray(3203d9f8f38841a4).(pos); |
| 44 | } |
| 45 | |
| 46 | while (true) |
| 47 | { |
| 48 | waitForReadyReadcxx . . $ QAbstractSocket#waitForReadyRead(83c267b20bac841a).(500); |
| 49 | if (bytesAvailablecxx . . $ PrinterSocket#bytesAvailable(98833e9ab7de59a4).() > 0) |
| 50 | { |
| 51 | qint64cxx . . $ qint64# len = readcxx . . $ QIODevice#read(2e638bc8ed65be6c).(mBuffPoscxx . . $ PrinterSocket#mBuffPos., 255); |
| 52 | if (len < 0) returncxx . . $ QByteArray#QByteArray(3203d9f8f38841a4). ""cxx . . $ QByteArray#QByteArray(34d26762b42c433a).; |
| 53 | mBuffPoscxx . . $ PrinterSocket#mBuffPos. += len; |
| 54 | pos = nextPoscxx . . $ PrinterSocket#nextPos(41208ce6ca65dd58).(); |
| 55 | if (pos != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) return returnLinecxx . . $ QByteArray#QByteArray(3203d9f8f38841a4).(pos); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | qint64cxx . . $ qint64# PrinterSocketcxx . . $ PrinterSocket#::bytesAvailablecxx . . $ PrinterSocket#bytesAvailable(98833e9ab7de59a4).() const |
| 61 | { |
| 62 | return QTcpSocketcxx . . $ QTcpSocket#::bytesAvailablecxx . . $ QAbstractSocket#bytesAvailable(98833e9ab7de59a4).() + (mBuffPoscxx . . $ PrinterSocket#mBuffPos. - mBuffcxx . . $ PrinterSocket#mBuff.); |
| 63 | } |
| 64 | |
| 65 | PrintRunnercxx . . $ PrintRunner#::PrintRunnercxx . . $ PrintRunner#PrintRunner(1bfb4126af2d922f).(SynchronizedQueuecxx . . $ SynchronizedQueue#& queue, PrinterItemConstPtrcxx . . $ PrinterItemConstPtr#& printerItem, int maxQueueSize) : |
| 66 | Runnercxx . . $ Runner#(queue), mQueuecxx . . $ PrintRunner#mQueue.(queue), mPrinterItemcxx . . $ PrintRunner#mPrinterItem.(printerItem), mMaxQueueSizecxx . . $ PrintRunner#mMaxQueueSize.(maxQueueSize) |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | void PrintRunnercxx . . $ PrintRunner#::readFromSocketcxx . . $ PrintRunner#readFromSocket(49f6e7a06ebc5aa8).() |
| 71 | { |
| 72 | while((mSocketcxx . . $ PrintRunner#mSocket.->cxx . . $ QSharedPointer#`operator->`(5a2a78a048fb49a8).statecxx . . $ QAbstractSocket#state(626498656f2ff1ae).() == QAbstractSocketcxx . . $ QAbstractSocket#::ConnectedStatecxx . . $ QAbstractSocket#ConnectedState. && mRunningcxx . . $ PrintRunner#mRunning.) || mSocketcxx . . $ PrintRunner#mSocket.->cxx . . $ QSharedPointer#`operator->`(5a2a78a048fb49a8).bytesAvailablecxx . . $ PrinterSocket#bytesAvailable(98833e9ab7de59a4).() > 0) |
| 73 | { |
| 74 | mSocketcxx . . $ PrintRunner#mSocket.->cxx . . $ QSharedPointer#`operator->`(5a2a78a048fb49a8).waitForReadyReadcxx . . $ QAbstractSocket#waitForReadyRead(83c267b20bac841a).(500); |
| 75 | if (mSocketcxx . . $ PrintRunner#mSocket.->cxx . . $ QSharedPointer#`operator->`(5a2a78a048fb49a8).bytesAvailablecxx . . $ PrinterSocket#bytesAvailable(98833e9ab7de59a4).() > 0) |
| 76 | { |
| 77 | bool ff = false; |
| 78 | QByteArraycxx . . $ QByteArray# line = mSocketcxx . . $ QByteArray#QByteArray(3203d9f8f38841a4).->cxx . . $ QSharedPointer#`operator->`(5a2a78a048fb49a8).readLinecxx . . $ PrinterSocket#readLine(b3c286cec66e09f4).(); |
| 79 | int len = line.lengthcxx . . $ QByteArray#length(455f465bc33b4cdf).(); |
| 80 | if ((line[cxx . . $ QByteArray#`operator[]`(6eaff86c84670f1a).len-1] ==cxx . . $ QByteRef#`operator==`(aec1b1cad4a17585). '\f') && (len > 1)) // in practice this is not likely to happen as all \f are preceded by \r or \n |
| 81 | { |
| 82 | line.datacxx . . $ QByteArray#data(41208ce6ca65dd58).()[len-1] = '\n'; |
| 83 | ff = true; |
| 84 | } |
| 85 | |
| 86 | if ( (len>0) && ((line[cxx . . $ QByteArray#`operator[]`(6eaff86c84670f1a).len-1] ==cxx . . $ QByteRef#`operator==`(aec1b1cad4a17585). '\n') || (line[cxx . . $ QByteArray#`operator[]`(6eaff86c84670f1a).len-1] ==cxx . . $ QByteRef#`operator==`(aec1b1cad4a17585). '\r')) ) |
| 87 | line.datacxx . . $ QByteArray#data(41208ce6ca65dd58).()[len-1] = '\0'; |
| 88 | |
| 89 | if (line.lengthcxx . . $ QByteArray#length(455f465bc33b4cdf).() != 0) |
| 90 | { |
| 91 | hOutDebugcxx . . $ `HercStudio/HerculesStudio.h:49:9`!(5,":" << line.data()); |
| 92 | if (ff) mQueuecxx . . $ PrintRunner#mQueue..push_backcxx . . $ SynchronizedQueue#push_back(3203d9f8f38841a4).("\f"cxx . . $ QByteArray#QByteArray(34d26762b42c433a).); // generate eject |
| 93 | #ifdef Q_OS_DARWIN |
| 94 | else mQueue.push_back((line)); |
| 95 | #else |
| 96 | else mQueuecxx . . $ PrintRunner#mQueue..push_backcxx . . $ SynchronizedQueue#push_back(3203d9f8f38841a4).(stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(line)); |
| 97 | #endif |
| 98 | emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! newDatacxx . . $ Runner#newData(49f6e7a06ebc5aa8).(); |
| 99 | while (mQueuecxx . . $ PrintRunner#mQueue..sizecxx . . $ SynchronizedQueue#size(b126dc7c1de90089).() > mMaxQueueSizecxx . . $ PrintRunner#mMaxQueueSize.) // do not flood the queue |
| 100 | QThreadcxx . . $ QThread#::msleepcxx . . $ QThread#msleep(2c44cd906ae4e829).(100); |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | void PrintRunnercxx . . $ PrintRunner#::waitForConnectedcxx . . $ PrintRunner#waitForConnected(49f6e7a06ebc5aa8).() |
| 107 | { |
| 108 | while(mSocketcxx . . $ PrintRunner#mSocket.->cxx . . $ QSharedPointer#`operator->`(5a2a78a048fb49a8).statecxx . . $ QAbstractSocket#state(626498656f2ff1ae).() != QAbstractSocketcxx . . $ QAbstractSocket#::ConnectedStatecxx . . $ QAbstractSocket#ConnectedState. && mRunningcxx . . $ PrintRunner#mRunning.) |
| 109 | { |
| 110 | hOutDebugcxx . . $ `HercStudio/HerculesStudio.h:49:9`!(1,"not connected:" << mSocket->state()); |
| 111 | if (mSocketcxx . . $ PrintRunner#mSocket.->cxx . . $ QSharedPointer#`operator->`(5a2a78a048fb49a8).statecxx . . $ QAbstractSocket#state(626498656f2ff1ae).() == QAbstractSocketcxx . . $ QAbstractSocket#::UnconnectedStatecxx . . $ QAbstractSocket#UnconnectedState.) |
| 112 | { |
| 113 | mSocketcxx . . $ PrintRunner#mSocket.->cxx . . $ QSharedPointer#`operator->`(5a2a78a048fb49a8).connectToHostcxx . . $ QAbstractSocket#connectToHost(f20c740007efd773).(QHostAddresscxx . . $ QHostAddress#QHostAddress(3520e46b33348bf6).(mPrinterItemcxx . . $ PrintRunner#mPrinterItem.->cxx . . $ QSharedPointer#`operator->`(5a2a78a048fb49a8).mIpcxx . . $ PrinterItem#mIp.), mPrinterItemcxx . . $ PrintRunner#mPrinterItem.->cxx . . $ QSharedPointer#`operator->`(5a2a78a048fb49a8).mPortcxx . . $ PrinterItem#mPort.); |
| 114 | mSocketcxx . . $ PrintRunner#mSocket.->cxx . . $ QSharedPointer#`operator->`(5a2a78a048fb49a8).waitForConnectedcxx . . $ QAbstractSocket#waitForConnected(83c267b20bac841a).(1000); |
| 115 | if(mRunningcxx . . $ PrintRunner#mRunning. && mSocketcxx . . $ PrintRunner#mSocket.->cxx . . $ QSharedPointer#`operator->`(5a2a78a048fb49a8).statecxx . . $ QAbstractSocket#state(626498656f2ff1ae).() != QAbstractSocketcxx . . $ QAbstractSocket#::ConnectedStatecxx . . $ QAbstractSocket#ConnectedState.) |
| 116 | QThreadcxx . . $ QThread#::msleepcxx . . $ QThread#msleep(2c44cd906ae4e829).(200); |
| 117 | hOutDebugcxx . . $ `HercStudio/HerculesStudio.h:49:9`!(1, "error:" << mSocket->errorString().toStdString()); |
| 118 | } |
| 119 | else |
| 120 | { |
| 121 | QThreadcxx . . $ QThread#::sleepcxx . . $ QThread#sleep(2c44cd906ae4e829).(1); |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | void PrintRunnercxx . . $ PrintRunner#::runcxx . . $ PrintRunner#run(49f6e7a06ebc5aa8).() |
| 127 | { |
| 128 | mSocketcxx . . $ PrintRunner#mSocket. =cxx . . $ QSharedPointer#`operator=`(392ad4e272af0338). QSharedPointercxx . . $ QSharedPointer#<PrinterSocketcxx . . $ PrinterSocket#>(new PrinterSocketcxx . . $ PrinterSocket#()); |
| 129 | mRunningcxx . . $ PrintRunner#mRunning. = true; |
| 130 | |
| 131 | qRegisterMetaTypecxx . . $ qRegisterMetaType(10e7a86562f422e7).<QAbstractSocketcxx . . $ QAbstractSocket#::SocketStatecxx . . $ QAbstractSocket#SocketState#>("QAbstractSocket::SocketState"); |
| 132 | mSocketcxx . . $ PrintRunner#mSocket.->cxx . . $ QSharedPointer#`operator->`(5a2a78a048fb49a8).moveToThreadcxx . . $ QObject#moveToThread(c0733f58611785eb).(this); |
| 133 | connectcxx . . $ QObject#connect(158df1d9a01a3410).(mSocketcxx . . $ PrintRunner#mSocket..datacxx . . $ QSharedPointer#data(5a2a78a048fb49a8).(), SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(stateChanged(QAbstractSocket::SocketState)),this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!(socketStateChanged(QAbstractSocket::SocketState))); |
| 134 | |
| 135 | while(mRunningcxx . . $ PrintRunner#mRunning.) |
| 136 | { |
| 137 | QElapsedTimercxx . . $ QElapsedTimer# timercxx . . $ QElapsedTimer#QElapsedTimer(49f6e7a06ebc5aa8).; |
| 138 | timer.startcxx . . $ QElapsedTimer#start(49f6e7a06ebc5aa8).(); |
| 139 | emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! waitingcxx . . $ PrintRunner#waiting(49f6e7a06ebc5aa8).(); |
| 140 | waitForConnectedcxx . . $ PrintRunner#waitForConnected(49f6e7a06ebc5aa8).(); |
| 141 | |
| 142 | if (!mRunningcxx . . $ PrintRunner#mRunning.) break; |
| 143 | |
| 144 | emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! connectedcxx . . $ PrintRunner#connected(49f6e7a06ebc5aa8).(); |
| 145 | hOutDebugcxx . . $ `HercStudio/HerculesStudio.h:49:9`!(1,"appl connected"); |
| 146 | |
| 147 | readFromSocketcxx . . $ PrintRunner#readFromSocket(49f6e7a06ebc5aa8).(); |
| 148 | hOutDebugcxx . . $ `HercStudio/HerculesStudio.h:49:9`!(1, "state:" << mSocket->state() << " running: " << (mRunning? "y" : "n") ); |
| 149 | emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! disconnectedcxx . . $ PrintRunner#disconnected(49f6e7a06ebc5aa8).(); |
| 150 | if (timer.elapsedcxx . . $ QElapsedTimer#elapsed(98833e9ab7de59a4).() < 1000) |
| 151 | { |
| 152 | QThreadcxx . . $ QThread#::msleepcxx . . $ QThread#msleep(2c44cd906ae4e829).(1000); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! stoppedWaitingcxx . . $ PrintRunner#stoppedWaiting(49f6e7a06ebc5aa8).(); |
| 157 | mSocketcxx . . $ PrintRunner#mSocket.->cxx . . $ QSharedPointer#`operator->`(5a2a78a048fb49a8).closecxx . . $ QAbstractSocket#close(49f6e7a06ebc5aa8).(); |
| 158 | } |
| 159 | |
| 160 | void PrintRunnercxx . . $ PrintRunner#::socketStateChangedcxx . . $ PrintRunner#socketStateChanged(369bba9c19fba560).(QAbstractSocketcxx . . $ QAbstractSocket#::SocketStatecxx . . $ QAbstractSocket#SocketState# state) |
| 161 | { |
| 162 | static QAbstractSocketcxx . . $ QAbstractSocket#::SocketStatecxx . . $ QAbstractSocket#SocketState# prevState = QAbstractSocketcxx . . $ QAbstractSocket#::UnconnectedStatecxx . . $ QAbstractSocket#UnconnectedState.; |
| 163 | if (state != prevState) |
| 164 | { |
| 165 | if (state == QAbstractSocketcxx . . $ QAbstractSocket#::ConnectedStatecxx . . $ QAbstractSocket#ConnectedState. && prevState != QAbstractSocketcxx . . $ QAbstractSocket#::ConnectedStatecxx . . $ QAbstractSocket#ConnectedState.) |
| 166 | { |
| 167 | hOutDebugcxx . . $ `HercStudio/HerculesStudio.h:49:9`!(1,"Connected"); |
| 168 | emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! connectedcxx . . $ PrintRunner#connected(49f6e7a06ebc5aa8).(); |
| 169 | } |
| 170 | if (state != QAbstractSocketcxx . . $ QAbstractSocket#::ConnectedStatecxx . . $ QAbstractSocket#ConnectedState. && prevState == QAbstractSocketcxx . . $ QAbstractSocket#::ConnectedStatecxx . . $ QAbstractSocket#ConnectedState.) |
| 171 | { |
| 172 | hOutDebugcxx . . $ `HercStudio/HerculesStudio.h:49:9`!(1,"Disconnected"); |
| 173 | emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! disconnectedcxx . . $ PrintRunner#disconnected(49f6e7a06ebc5aa8).(); |
| 174 | } |
| 175 | prevState = state; |
| 176 | } |
| 177 | hOutDebugcxx . . $ `HercStudio/HerculesStudio.h:49:9`!(1, "Socket state: " << state); |
| 178 | } |
| 179 | |
| 180 | void PrintRunnercxx . . $ PrintRunner#::stopcxx . . $ PrintRunner#stop(49f6e7a06ebc5aa8).() |
| 181 | { |
| 182 | mRunningcxx . . $ PrintRunner#mRunning. = false; |
| 183 | } |