Debian Codegraph @

HercPrinter/PrintRunner.h

raw symbols SCIP
1 /*
2 * File: PrintRunner.h
3 *
4 * Author: Jacob Dekel
5 * Created on: May 10, 2014
6 *
7 * Copyright (c) 2009-2014 Jacob Dekel
8 * $Id$
9 *
10 * This object monitors printer events
11 *
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 *
25 */
26 #ifndef PRINTRUNNER_H
27 #define PRINTRUNNER_H
28
29 #include "Runner.h"
30 #include "HerculesStudio.h"
31
32 #include <QTcpSocket>
33
34 mk_shared_constptr(PrinterItem)
35
36 class PrinterSocket : public QTcpSocket
37 {
38 public:
39 PrinterSocket();
40 QByteArray readLine();
41 qint64 bytesAvailable() const;
42 private:
43 QByteArray returnLine(const char *end);
44 char *nextPos();
45 char mBuff[2048];
46 char *mBuffPos;
47 };
48
49 class PrintRunner : public Runner
50 {
51 Q_OBJECT
52 public:
53 PrintRunner(SynchronizedQueue& queue, PrinterItemConstPtr& printerItem, int maxQueueSize);
54
55 virtual void run();
56 void stop();
57
58 private:
59 SynchronizedQueue& mQueue;
60 PrinterItemConstPtr mPrinterItem;
61 static const int MAX_LINE = 2048;
62 int mMaxQueueSize;
63 QSharedPointer<PrinterSocket> mSocket;
64 bool mRunning;
65 char mBuff[MAX_LINE];
66 int mCurrBufLen;
67
68 void waitForConnected();
69 void readFromSocket();
70
71
72 private slots:
73 void socketStateChanged(QAbstractSocket::SocketState state);
74
75 signals:
76 void waiting();
77 void stoppedWaiting();
78 void connected();
79 void disconnected();
80 };
81
82 #endif // PRINTRUNNER_H