sessioncontroller.cc 6.14 KB
Newer Older
1
2
3
4
5

#include "rsmcore/sessioncontroller.hh"
#include "rsmcore/sessionworker.hh"

#include <QThread>
6
7
#include "radixbug/bug.hh"

8
9
10
11
12
13
14
15
16
17
18
19
20
namespace rsm
{
class SessionControllerImpl
{
 public:
  SessionWorker* worker;
  QThread* thread;

  SessionControllerImpl()
  {
    worker = new SessionWorker();
    thread = new QThread();
    worker->moveToThread(thread);
21
22
    thread->start();

23
24
25
  }  // SessionControllerImpl constructor
  ~SessionControllerImpl()
  {
26
    radix_tagged_line("~SessionControllerImpl()");
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
    if (worker != nullptr)
    {
      delete worker;
    }
    if (thread != nullptr)
    {
      if (thread->isRunning())
      {
        thread->quit();
        thread->wait();
        delete thread;
      }
    }
  }  // SessionControllerImpl destructor
};   // class SessionControllerImpl

43
44
45
46
47
48
49
50
51
52
53
SessionController::SessionController(QObject* parent)
    : QObject(parent)
{
  qRegisterMetaType<SessionVerbosity>("SessionVerbosity");
  p = new SessionControllerImpl();

  // forward signals from worker
  QObject::connect(p->worker, &SessionWorker::connectionFailed, this,
                   &SessionController::connectionFailed);
  QObject::connect(p->worker, &SessionWorker::connectionSuccessful, this,
                   &SessionController::connectionSuccessful);
54
55
56
57
58
  QObject::connect(p->worker, &SessionWorker::disconnectSuccessful, this,
                   &SessionController::disconnectSuccessful);
  QObject::connect(p->worker,
                   &SessionWorker::interactiveAuthenticationRequested, this,
                   &SessionController::interactiveAuthenticationRequested);
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
  QObject::connect(p->worker, &SessionWorker::verifyKnownHostSuccessful, this,
                   &SessionController::verifyKnownHostSuccessful);
  QObject::connect(p->worker, &SessionWorker::getServerPublicKeyFailed, this,
                   &SessionController::getServerPublicKeyFailed);
  QObject::connect(p->worker, &SessionWorker::hostUnknown, this,
                   &SessionController::hostUnknown);
  QObject::connect(p->worker, &SessionWorker::hostPublicKeyChanged, this,
                   &SessionController::hostPublicKeyChanged);
  QObject::connect(p->worker, &SessionWorker::hostPublicKeyUnavailable, this,
                   &SessionController::hostPublicKeyUnavailable);
  QObject::connect(p->worker, &SessionWorker::knownHostError, this,
                   &SessionController::knownHostError);
  QObject::connect(p->worker, &SessionWorker::updateKnownHostsFailed, this,
                   &SessionController::updateKnownHostsFailed);
  QObject::connect(p->worker, &SessionWorker::authenticationError, this,
                   &SessionController::authenticationError);
  QObject::connect(p->worker, &SessionWorker::authenticationSucceeded, this,
                   &SessionController::authenticationSucceeded);
  QObject::connect(p->worker, &SessionWorker::passwordRequested, this,
                   &SessionController::passwordRequested);
  QObject::connect(p->worker, &SessionWorker::loginBannerIssued, this,
                   &SessionController::loginBannerIssued);
  QObject::connect(p->worker, &SessionWorker::execOutputReady, this,
                   &SessionController::execOutputReady);
  QObject::connect(p->worker, &SessionWorker::execFailed, this,
                   &SessionController::execFailed);
  QObject::connect(p->worker, &SessionWorker::execFinished, this,
                   &SessionController::execFinished);

  // connect
  QObject::connect(this, &SessionController::setHostRequested, p->worker,
                   &SessionWorker::setHost);
  QObject::connect(this, &SessionController::setLogVerbosityRequested,
                   p->worker, &SessionWorker::setLogVerbosity);
  QObject::connect(this, &SessionController::setPortRequested, p->worker,
                   &SessionWorker::setPort);
  QObject::connect(this, &SessionController::setUserRequested, p->worker,
                   &SessionWorker::setUser);
  QObject::connect(this, &SessionController::connectRequested, p->worker,
                   &SessionWorker::connect);
  QObject::connect(this, &SessionController::disconnectRequested, p->worker,
                   &SessionWorker::disconnect);
  QObject::connect(this, &SessionController::verifyKnownHostRequested,
                   p->worker, &SessionWorker::verifyKnownHost);

  QObject::connect(this, &SessionController::acceptHostPublicKeyUpdateRequested,
                   p->worker, &SessionWorker::acceptHostPublicKeyUpdate);
  QObject::connect(this, &SessionController::authenticateRequested, p->worker,
                   &SessionWorker::authenticate);
  QObject::connect(this, &SessionController::authenticateWithPasswordRequested,
                   p->worker, &SessionWorker::authenticateWithPassword);
110
111
  QObject::connect(this, &SessionController::authenticatePromptsRequested,
                   p->worker, &SessionWorker::authenticatePrompts);
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
  QObject::connect(this, &SessionController::requestExecRequested, p->worker,
                   &SessionWorker::requestExec);
}

SessionController::~SessionController()
{
  if (p != nullptr)
  {
    delete p;
  }
}

QByteArray SessionController::readExecOutput()
{
  return p->worker->readExecOutput();
}

void SessionController::setHost(QString host) { emit setHostRequested(host); }

void SessionController::setLogVerbosity(SessionVerbosity level)
{
  emit setLogVerbosityRequested(level);
}

void SessionController::setPort(int port) { emit setPortRequested(port); }

void SessionController::setUser(QString name) { emit setUserRequested(name); }

void SessionController::connect() { emit connectRequested(); }

void SessionController::disconnect() { emit disconnectRequested(); }

void SessionController::verifyKnownHost() { emit verifyKnownHostRequested(); }

void SessionController::acceptHostPublicKeyUpdate()
{
  emit acceptHostPublicKeyUpdateRequested();
}

void SessionController::authenticate() { emit authenticateRequested(); }

void SessionController::authenticateWithPassword(QString pswd)
{
  emit authenticateWithPasswordRequested(pswd);
}

158
159
160
161
162
void SessionController::authenticatePrompts(QStringList responses)
{
  emit authenticatePromptsRequested(responses);
}

163
164
165
166
167
void SessionController::requestExec(QString command)
{
  emit requestExecRequested(command);
}

168
}  // namespace rsm