MCPcopy Create free account
hub / github.com/KangLin/RabbitRemoteControl / OnInit

Method OnInit

Plugins/SSH/BackendSSH.cpp:40–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40CBackendSSH::OnInitReturnValue CBackendSSH::OnInit()
41{
42 bool check = false;
43 if(!m_pTerminal)
44 {
45 Q_ASSERT(m_pTerminal);
46 return OnInitReturnValue::Fail;
47 }
48
49 m_pChannelSSH = new CChannelSSHTerminal(this, &m_pPara->m_SSH);
50 if(!m_pChannelSSH) {
51 qCritical(log) << "new CChannelSSH fail";
52 return OnInitReturnValue::Fail;
53 }
54
55 check = connect(m_pChannelSSH, &CChannelSSHTerminal::sigSecurityLevel,
56 this, &CBackendSSH::sigSecurityLevel);
57 Q_ASSERT(check);
58
59 check = connect(m_pChannelSSH, &CChannelSSHTerminal::sigConnected,
60 this, [&](){
61 if(!m_pPara->GetCommands().isEmpty()) {
62 foreach (auto c, m_pPara->GetCommands()) {
63 emit m_pTerminal->sendData(c.toStdString().c_str(), c.length());
64 emit m_pTerminal->sendData("\r", 1);
65 }
66 }
67 emit sigRunning();
68 });
69 Q_ASSERT(check);
70 check = connect(m_pChannelSSH, &CChannelSSHTerminal::readyRead,
71 this, [&](){
72 char* buf = nullptr;
73 qint64 nLen = 0;
74 qint64 nRet = 0;
75 if(m_pChannelSSH) {
76 nLen = m_pChannelSSH->bytesAvailable();
77 if(nLen <= 0) {
78 qDebug(log) << "No data";
79 return;
80 }
81 buf = new char[nLen];
82 nRet = m_pChannelSSH->read(buf, nLen);
83 }
84 if(m_pTerminal && nRet > 0) {
85 QByteArray data(buf, nRet);
86 if(m_pOperate) {
87 emit m_pOperate->sigReceiveData(data);
88 if(m_pOperate->GetStats())
89 m_pOperate->GetStats()->AddReceives(nRet);
90 }
91 } else
92 qCritical(log) << "The m_pTerminal is nullptr or nRet <= 0";
93 //qDebug(log) << "Write data to QTermWidget: " << nRet << nLen;
94 if(buf)
95 delete []buf;
96 });
97 Q_ASSERT(check);

Callers

nothing calls this directly

Calls 10

GetCommandsMethod · 0.80
bytesAvailableMethod · 0.80
readMethod · 0.80
AddReceivesMethod · 0.80
AddSendsMethod · 0.80
isEmptyMethod · 0.45
GetStatsMethod · 0.45
WakeUpMethod · 0.45
SetSizeMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected