1 /**************************************************************************
5 Unix Remote Printing Operation
6 Copyright (c) Arto Hyvättinen 2010
8 This file is part of URPO.
10 URPO 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.
15 URPO 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.
21 **************************************************************************/
27 #include <QStringList>
32 /*! Process running ssh/scp command
34 @author Arto Hyvättinen
36 @date 2010-06-11 - 2010-06-12
38 Run ssh/scp etc. command.
40 Read setting using UrpoConnect settings information object.
41 Support debug monitoring using debugMessage-signals, monitor defined in settings object
43 First, connect finished()-signal. Then, run command.
44 Command is run asynchronosly.
48 // Get list of available printers
50 QString command = "ssh ";
51 command.append(getConnection()->getKeyOption());
52 command.append(getConnection()->getHostString());
53 command.append(" env LANG=en lpstat -p");
55 process = new UrpoProcess( connect );
57 connect( process, SIGNAL(finished(bool)), this, SLOT( readOutput(bool) ) );
58 process.start(command);
61 ::readOutput(bool success)
65 foreach(QString line, process->getOutput() )
69 cout << "Error " << process->getError();
76 class UrpoProcess : public QObject
81 @param connection Pointer to connection settings information
83 explicit UrpoProcess(QObject* parent = 0);
87 Ready /*! Ready for connecting */ = 0,
88 Running /*! Command running */ = 1,
89 Successed /*! Command successed */ = 2,
90 Failed /*! Command failed */ = 3
94 NoError /*! No errors happends */ = 0,
95 ProcessError /*! Error running process */ = 1,
96 ConnectionError /*! Error connecting host */ = 2,
97 AuthError /*! Authentication failed */ = 3,
98 Timeout /*! Timed out */ = 4,
99 Cancelled /*! User cancelled operation */ = 5
102 /*! Get output of command
103 @return Output of command, list of QStrings
105 QStringList getOutput();
109 Start process running command. When process finish
110 (successed/failed), finished() signal will be emitted
112 @param command Command to execute
114 void start(const QString& command);
118 If process failed, get error code
121 UrpoError getError() const { return error_; }
122 /*! Error of process (in string)
124 If process failed, return error string readable by user
129 QString getErrorString() const;
133 @return Status (Ready, Running, Successed, Failed)
135 UrpoStatus getStatus() const { return status_; }
138 /*! Send debug message
140 @param message Message to debug monitor
142 If debug monitor has been connected, send message to debug monitor
145 void sendDebugMessage(QString message) { emit debugMessage(message); }
149 Process time out, if running command last more than timeout
152 @param msecs Timeout in msecs
154 void setTimeout(int msecs) { timeout_=msecs; }
158 @return Timeout in msecs */
159 int getTimeout() { return timeout_; }
162 /*! Process finished (successed of failed)
164 @param success True if process successed, false if failed
166 Emitted when process finished.
167 Output of process can be reader throught getOutput() */
168 void finished(bool success);
169 /** Send debug messages
171 UrpoConnection can set up a debug monitor, a QObject receiving
172 debugMsg signals. Debug messages contains information about
173 process output, errors etc.
175 @param message Message send to debug monitor */
176 void debugMessage(QString message);
181 Terminate process. Emit finished(false) signal and set Cancelled error */
184 /*! SSH client has finished */
185 void processFinished(int exitCode,QProcess::ExitStatus exitStatus);
186 /*! Timeout during connecting */
195 static int const DEFAULTTIMEOUT = 30000;
197 void fail(UrpoError error);
205 int timeout_; /*! Timeout in msecs */
208 #endif // URPOPROCESS_H