mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
reference/SshBasics: Ssh polymorphism/RTTI example for the SshBasics reference example set. (#207)
This patch aims to add a polymorphism & RTTI example to the SShBasics reference examples set. Demonstrates: - Creating three different channels (Scp, SFtp, and SshExec) in the same Ssh object array, - Identifying and converting the stored Ssh objects to the proper channels respectively and calling them.
This commit is contained in:
parent
a15023e1bb
commit
a3f8c79a19
4 changed files with 48 additions and 0 deletions
42
reference/SshBasics/Polymorphism.cpp
Normal file
42
reference/SshBasics/Polymorphism.cpp
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
#include "SshBasics.h"
|
||||||
|
|
||||||
|
// SshPolymorphism:
|
||||||
|
// Demonstrates polymorphism and RTTI for Ssh objects.
|
||||||
|
|
||||||
|
void SshPolymorphism(SshSession& session)
|
||||||
|
{
|
||||||
|
constexpr const char *path = "/readme.txt";
|
||||||
|
|
||||||
|
Array<Ssh> channels;
|
||||||
|
|
||||||
|
channels.Create<Scp>(session);
|
||||||
|
channels.Create<SFtp>(session);
|
||||||
|
channels.Create<SshExec>(session);
|
||||||
|
|
||||||
|
for(Ssh& channel : channels){
|
||||||
|
if(channel.Is<Scp>()) {
|
||||||
|
LOG("\nFound: Scp object");
|
||||||
|
LOG("-----------------\n");
|
||||||
|
LOG(channel.To<Scp>().LoadFile(path));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if(channel.Is<SFtp>()) {
|
||||||
|
LOG("\nFound: Sftp object");
|
||||||
|
LOG("------------------\n");
|
||||||
|
LOG(channel.To<SFtp>().GetInfo(path).GetName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if(channel.Is<SshExec>()) {
|
||||||
|
LOG("\nFound: Exec object");
|
||||||
|
LOG("------------------\n");
|
||||||
|
String out, err;
|
||||||
|
channel.To<SshExec>().Execute("ls -l", out, err);
|
||||||
|
LOG(out);
|
||||||
|
LOG(err);
|
||||||
|
}
|
||||||
|
if(channel.IsError()) {
|
||||||
|
LOG("Operation failed. Reason: " << channel.GetErrorDesc());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -18,6 +18,8 @@ void ScpGet(SshSession& session);
|
||||||
void ForwardTcpIp(SshSession& session);
|
void ForwardTcpIp(SshSession& session);
|
||||||
void X11Forwarding(SshSession& session);
|
void X11Forwarding(SshSession& session);
|
||||||
void SshPick(SshSession& session);
|
void SshPick(SshSession& session);
|
||||||
|
void SshPolymorphism(SshSession& session);
|
||||||
void TraceVerbose();
|
void TraceVerbose();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ file
|
||||||
ExecMT.cpp,
|
ExecMT.cpp,
|
||||||
"Misc. examples" readonly separator,
|
"Misc. examples" readonly separator,
|
||||||
PickSemantics.cpp,
|
PickSemantics.cpp,
|
||||||
|
Polymorphism.cpp,
|
||||||
VerboseLogging.cpp;
|
VerboseLogging.cpp;
|
||||||
|
|
||||||
mainconfig
|
mainconfig
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,11 @@ CONSOLE_APP_MAIN
|
||||||
ForwardTcpIp(session);
|
ForwardTcpIp(session);
|
||||||
#elif defined(SSH_PICK_SEMANTICS)
|
#elif defined(SSH_PICK_SEMANTICS)
|
||||||
SshPick(session);
|
SshPick(session);
|
||||||
|
#elif defined(SSH_POLYMORPHISM)
|
||||||
|
SshPolymorphism(session);
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LOG(session.GetErrorDesc());
|
LOG(session.GetErrorDesc());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue