forked from chrisoldwood/DDECmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServersCmd.cpp
75 lines (57 loc) · 2.21 KB
/
ServersCmd.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
////////////////////////////////////////////////////////////////////////////////
//! \file ServersCmd.cpp
//! \brief The ServersCmd class definition.
//! \author Chris Oldwood
#include "Common.hpp"
#include "ServersCmd.hpp"
#include <Core/tiostream.hpp>
#include <NCL/DDEClient.hpp>
#include <WCL/StrArray.hpp>
#include "CmdLineArgs.hpp"
#include <WCL/StringIO.hpp>
#include <NCL/DDEClientFactory.hpp>
////////////////////////////////////////////////////////////////////////////////
//! The table of command specific command line switches.
static Core::CmdLineSwitch s_switches[] =
{
{ USAGE, TXT("?"), nullptr, Core::CmdLineSwitch::ONCE, Core::CmdLineSwitch::NONE, nullptr, TXT("Display the command syntax") },
{ USAGE, nullptr, TXT("help"), Core::CmdLineSwitch::ONCE, Core::CmdLineSwitch::NONE, nullptr, TXT("Display the command syntax") },
};
static size_t s_switchCount = ARRAY_SIZE(s_switches);
////////////////////////////////////////////////////////////////////////////////
//! Constructor.
ServersCmd::ServersCmd(int argc, tchar* argv[])
: WCL::ConsoleCmd(s_switches, s_switches+s_switchCount, argc, argv, USAGE)
{
}
////////////////////////////////////////////////////////////////////////////////
//! Destructor.
ServersCmd::~ServersCmd()
{
}
////////////////////////////////////////////////////////////////////////////////
//! Get the description of the command.
const tchar* ServersCmd::getDescription()
{
return TXT("List the running servers and their topics");
}
////////////////////////////////////////////////////////////////////////////////
//! Get the expected command usage.
const tchar* ServersCmd::getUsage()
{
return TXT("USAGE: DDECmd servers");
}
////////////////////////////////////////////////////////////////////////////////
//! The implementation of the command.
int ServersCmd::doExecute(tostream& out, tostream& /*err*/)
{
ASSERT(m_parser.getUnnamedArgs().at(0) == TXT("servers"));
DDE::IDDEClientPtr client = DDE::DDEClientFactory::create();
// Find the running servers.
CStrArray servers, topics;
client->QueryAll(servers, topics);
// Display results.
for (size_t i = 0, size = servers.Size(); i != size; ++i)
out << servers[i] << TXT("|") << topics[i] << std::endl;
return EXIT_SUCCESS;
}