|
@@ -0,0 +1,140 @@
|
|
|
+#include "remoteprocess.h"
|
|
|
+
|
|
|
+
|
|
|
+#include <iostream>
|
|
|
+#include <thread>
|
|
|
+
|
|
|
+using namespace QSsh;
|
|
|
+
|
|
|
+const QByteArray StderrOutput("ChannelTest");
|
|
|
+
|
|
|
+RemoteProcess::RemoteProcess(const QSsh::SshConnectionParameters ¶ms)
|
|
|
+ : m_sshParams(params),
|
|
|
+ m_timeoutTimer(new QTimer(this)),
|
|
|
+ m_sshConnection(0),
|
|
|
+ m_remoteRunner(new SshRemoteProcessRunner(this)),
|
|
|
+ m_state(Inactive)
|
|
|
+{
|
|
|
+
|
|
|
+ connect(m_remoteRunner, SIGNAL(connectionError()),
|
|
|
+ SLOT(handleConnectionError()));
|
|
|
+ connect(m_remoteRunner, SIGNAL(processStarted()),
|
|
|
+ SLOT(handleProcessStarted()));
|
|
|
+ connect(m_remoteRunner, SIGNAL(readyReadStandardOutput()), SLOT(handleProcessStdout()));
|
|
|
+ connect(m_remoteRunner, SIGNAL(readyReadStandardError()), SLOT(handleProcessStderr()));
|
|
|
+ connect(m_remoteRunner, SIGNAL(processClosed(int)),
|
|
|
+ SLOT(handleProcessClosed(int)));
|
|
|
+ m_started = false;
|
|
|
+
|
|
|
+ // m_remoteRunner->run("ls -a /tmp", m_sshParams);
|
|
|
+}
|
|
|
+
|
|
|
+RemoteProcess::~RemoteProcess()
|
|
|
+{
|
|
|
+ if(m_started)
|
|
|
+ {
|
|
|
+ delete m_remoteRunner;
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void RemoteProcess::run()
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+// std::cout << "Testing successful remote process... " << std::flush;
|
|
|
+// m_state = TestingSuccess;
|
|
|
+
|
|
|
+ mbQueryState = true;
|
|
|
+// m_timeoutTimer->start();
|
|
|
+ m_remoteRunner->run("ps -ef | grep driver_", m_sshParams);
|
|
|
+}
|
|
|
+
|
|
|
+void RemoteProcess::runCmd(QString strcmd)
|
|
|
+{
|
|
|
+ QByteArray ba(strcmd.toLatin1().data());
|
|
|
+ m_remoteRunner->run(ba, m_sshParams);
|
|
|
+}
|
|
|
+
|
|
|
+void RemoteProcess::handleConnectionError()
|
|
|
+{
|
|
|
+ const QString error = m_state == TestingIoDevice || m_state == TestingProcessChannels
|
|
|
+ ? m_sshConnection->errorString() : m_remoteRunner->lastConnectionErrorString();
|
|
|
+
|
|
|
+ std::cerr << "Error: Connection failure (" << qPrintable(error) << ")." << std::endl;
|
|
|
+}
|
|
|
+
|
|
|
+void RemoteProcess::handleProcessStarted()
|
|
|
+{
|
|
|
+ if (m_started) {
|
|
|
+ // std::cerr << "Error: Received started() signal again." << std::endl;
|
|
|
+ } else {
|
|
|
+ m_started = true;
|
|
|
+ std::cout<<" connected."<<std::endl;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void RemoteProcess::handleProcessStdout()
|
|
|
+{
|
|
|
+ if (!m_started) {
|
|
|
+ std::cerr << "Error: Remote output from non-started process."
|
|
|
+ << std::endl;
|
|
|
+ // QCoreApplication::exit(EXIT_FAILURE);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ m_remoteStdout = m_remoteRunner->readAllStandardOutput();
|
|
|
+ std::cout<<" out: "<<m_remoteStdout.data()<<std::endl;
|
|
|
+ if(mbQueryState)
|
|
|
+ {
|
|
|
+ mbQueryState = false;
|
|
|
+ QString str = m_remoteStdout;
|
|
|
+ bool brm = false;
|
|
|
+ bool bgr = false;
|
|
|
+ int nState = 0;
|
|
|
+ if(str.indexOf("/driver_cloud_grpc_server_h264")>=0)
|
|
|
+ {
|
|
|
+ brm = true;
|
|
|
+
|
|
|
+ }
|
|
|
+ if(str.indexOf("/driver_group_grpc_server")>=0)
|
|
|
+ {
|
|
|
+ bgr = true;
|
|
|
+ }
|
|
|
+ if(brm&&bgr)
|
|
|
+ {
|
|
|
+ nState = 3;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(brm)
|
|
|
+ {
|
|
|
+ nState = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(bgr)
|
|
|
+ nState = 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ emit ServiceState(nState);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void RemoteProcess::handleProcessStderr()
|
|
|
+{
|
|
|
+ if (!m_started) {
|
|
|
+ std::cerr << "Error: Remote error output from non-started process."
|
|
|
+ << std::endl;
|
|
|
+
|
|
|
+ } else {
|
|
|
+ m_remoteStderr = m_remoteRunner->readAllStandardError();
|
|
|
+ std::cout<<"error: "<<m_remoteStderr.data()<<std::endl;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void RemoteProcess::handleProcessClosed(int exitStatus)
|
|
|
+{
|
|
|
+ std::cout<<" process close. "<<std::endl;
|
|
|
+}
|