summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid/Parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/IceGrid/Parser.cpp')
-rw-r--r--cpp/src/IceGrid/Parser.cpp188
1 files changed, 65 insertions, 123 deletions
diff --git a/cpp/src/IceGrid/Parser.cpp b/cpp/src/IceGrid/Parser.cpp
index 28b09bb87dc..3c45b2c44d6 100644
--- a/cpp/src/IceGrid/Parser.cpp
+++ b/cpp/src/IceGrid/Parser.cpp
@@ -251,71 +251,17 @@ Ice::StringConverterPtr windowsConsoleConverter = 0;
void outputNewline()
{
-#ifdef _WIN32
- fprintf_s(stdout, "\n");
-#else
- cout << endl;
-#endif
+ consoleOut << endl;
}
void flushOutput()
{
-#ifdef _WIN32
- fflush(stdout);
-#else
- cout << flush;
-#endif
-}
-
-#ifdef _WIN32
-string toConsoleEncoding(const string& s)
-{
- if(windowsConsoleConverter)
- {
- try
- {
- // Convert from UTF-8 to console CP
- string consoleString;
- windowsConsoleConverter->fromUTF8(reinterpret_cast<const IceUtil::Byte*>(s.data()),
- reinterpret_cast<const IceUtil::Byte*>(s.data() + s.size()),
- consoleString);
-
- return consoleString;
- }
- catch(const IceUtil::IllegalConversionException&)
- {
- //
- // If there is a problem with the encoding conversions we just
- // return the original message without encoding conversions.
- //
- return s;
- }
- }
- else
- {
- return s;
- }
+ consoleOut << flush;
}
-#endif
void outputString(const string& s)
{
-#ifdef _WIN32
- if(windowsConsoleConverter)
- {
- fprintf_s(stdout, "%s", toConsoleEncoding(s).c_str());
- }
- else
- {
- //
- // Use fprintf_s to avoid encoding conversion when stdout is connected
- // to Windows console.
- //
- fprintf_s(stdout, "%s", s.c_str());
- }
-#else
- cout << s;
-#endif
+ consoleOut << s;
}
void writeMessage(const string& message, bool indent)
@@ -383,8 +329,6 @@ void printLogMessage(const string& p, const Ice::LogMessage& logMessage)
}
}
-
-
class RemoteLoggerI : public Ice::RemoteLogger
{
public:
@@ -481,7 +425,7 @@ Parser::usage(const string& category, const string& command)
}
else
{
- cout << _helpCommands[category][command];
+ consoleOut << _helpCommands[category][command];
}
}
@@ -505,7 +449,7 @@ Parser::usage(const string& category, const list<string>& args)
void
Parser::usage()
{
- cout <<
+ consoleOut <<
"help Print this message.\n"
"exit, quit Exit this program.\n"
"CATEGORY help Print the help section of the given CATEGORY.\n"
@@ -1119,11 +1063,11 @@ Parser::pingNode(const list<string>& args)
{
if(_admin->pingNode(args.front()))
{
- cout << "node is up" << endl;
+ consoleOut << "node is up" << endl;
}
else
{
- cout << "node is down" << endl;
+ consoleOut << "node is down" << endl;
}
}
catch(const Ice::Exception& ex)
@@ -1144,7 +1088,7 @@ Parser::printLoadNode(const list<string>& args)
try
{
LoadInfo load = _admin->getNodeLoad(args.front());
- cout << "load average (1/5/15): " << load.avg1 << " / " << load.avg5 << " / " << load.avg15 << endl;
+ consoleOut << "load average (1/5/15): " << load.avg1 << " / " << load.avg5 << " / " << load.avg15 << endl;
}
catch(const Ice::Exception& ex)
{
@@ -1167,11 +1111,11 @@ Parser::printNodeProcessorSockets(const list<string>& args)
{
try
{
- cout << _admin->getNodeProcessorSocketCount(args.front()) << endl;
+ consoleOut << _admin->getNodeProcessorSocketCount(args.front()) << endl;
}
catch(const Ice::OperationNotExistException&)
{
- cout << "not supported" << endl;
+ consoleOut << "not supported" << endl;
}
}
else
@@ -1202,17 +1146,19 @@ Parser::printNodeProcessorSockets(const list<string>& args)
}
}
- cout.flags(ios::left);
- cout << setw(20) << "Hostname" << setw(20) << "| # of sockets" << setw(39) << "| Nodes" << endl;
- cout << setw(79) << "=====================================================================" << endl;
+ ostringstream os;
+ os.flags(ios::left);
+ os << setw(20) << "Hostname" << setw(20) << "| # of sockets" << setw(39) << "| Nodes" << endl;
+ os << setw(79) << "=====================================================================" << endl;
for(map<string, pair< vector<string>, int> >::const_iterator q = processorSocketCounts.begin();
q != processorSocketCounts.end(); ++q)
{
- cout << setw(20) << setiosflags(ios::left) <<q->first;
- cout << "| " << setw(18) << setiosflags(ios::left) << q->second.second;
- cout << "| " << setw(37) << setiosflags(ios::left) << toString(q->second.first);
- cout << endl;
+ os << setw(20) << setiosflags(ios::left) <<q->first;
+ os << "| " << setw(18) << setiosflags(ios::left) << q->second.second;
+ os << "| " << setw(37) << setiosflags(ios::left) << toString(q->second.first);
+ os << endl;
}
+ consoleOut << os.str() << flush;
}
}
catch(const Ice::Exception& ex)
@@ -1251,8 +1197,10 @@ Parser::listAllNodes(const list<string>& args)
try
{
+ ostringstream os;
Ice::StringSeq names = _admin->getAllNodeNames();
- copy(names.begin(), names.end(), ostream_iterator<string>(cout,"\n"));
+ copy(names.begin(), names.end(), ostream_iterator<string>(os,"\n"));
+ consoleOut << os.str();
}
catch(const Ice::Exception& ex)
{
@@ -1300,11 +1248,11 @@ Parser::pingRegistry(const list<string>& args)
{
if(_admin->pingRegistry(args.front()))
{
- cout << "registry is up" << endl;
+ consoleOut << "registry is up" << endl;
}
else
{
- cout << "registry is down" << endl;
+ consoleOut << "registry is down" << endl;
}
}
catch(const Ice::Exception& ex)
@@ -1350,8 +1298,10 @@ Parser::listAllRegistries(const list<string>& args)
try
{
+ ostringstream os;
Ice::StringSeq names = _admin->getAllRegistryNames();
- copy(names.begin(), names.end(), ostream_iterator<string>(cout,"\n"));
+ copy(names.begin(), names.end(), ostream_iterator<string>(os,"\n"));
+ consoleOut << os.str();
}
catch(const Ice::Exception& ex)
{
@@ -1574,39 +1524,39 @@ Parser::stateServer(const list<string>& args)
{
case Inactive:
{
- cout << "inactive (" << enabled << ")" << endl;
+ consoleOut << "inactive (" << enabled << ")" << endl;
break;
}
case Activating:
{
- cout << "activating (" << enabled << ")" << endl;
+ consoleOut << "activating (" << enabled << ")" << endl;
break;
}
case Active:
{
int pid = _admin->getServerPid(args.front());
- cout << "active (pid = " << pid << ", " << enabled << ")" << endl;
+ consoleOut << "active (pid = " << pid << ", " << enabled << ")" << endl;
break;
}
case ActivationTimedOut:
{
int pid = _admin->getServerPid(args.front());
- cout << "activation timed out (pid = " << pid << ", " << enabled << ")" << endl;
+ consoleOut << "activation timed out (pid = " << pid << ", " << enabled << ")" << endl;
break;
}
case Deactivating:
{
- cout << "deactivating (" << enabled << ")" << endl;
+ consoleOut << "deactivating (" << enabled << ")" << endl;
break;
}
case Destroying:
{
- cout << "destroying (" << enabled << ")" << endl;
+ consoleOut << "destroying (" << enabled << ")" << endl;
break;
}
case Destroyed:
{
- cout << "destroyed (" << enabled << ")" << endl;
+ consoleOut << "destroyed (" << enabled << ")" << endl;
break;
}
default:
@@ -1633,7 +1583,7 @@ Parser::pidServer(const list<string>& args)
int pid = _admin->getServerPid(args.front());
if(pid > 0)
{
- cout << pid << endl;
+ consoleOut << pid << endl;
}
else
{
@@ -1668,14 +1618,14 @@ Parser::propertiesServer(const list<string>& args, bool single)
if(single)
{
string val = propAdmin->getProperty(*(++args.begin()));
- cout << val << endl;
+ consoleOut << val << endl;
}
else
{
Ice::PropertyDict properties = propAdmin->getPropertiesForPrefix("");
for(Ice::PropertyDict::const_iterator p = properties.begin(); p != properties.end(); ++p)
{
- cout << p->first << "=" << p->second << endl;
+ consoleOut << p->first << "=" << p->second << endl;
}
}
}
@@ -1730,8 +1680,10 @@ Parser::listAllServers(const list<string>& args)
try
{
+ ostringstream os;
Ice::StringSeq ids = _admin->getAllServerIds();
- copy(ids.begin(), ids.end(), ostream_iterator<string>(cout,"\n"));
+ copy(ids.begin(), ids.end(), ostream_iterator<string>(os,"\n"));
+ consoleOut << os.str();
}
catch(const Ice::Exception& ex)
{
@@ -1926,14 +1878,14 @@ Parser::propertiesService(const list<string>& args, bool single)
if(single)
{
string val = propAdmin->getProperty(property);
- cout << val << endl;
+ consoleOut << val << endl;
}
else
{
Ice::PropertyDict properties = propAdmin->getPropertiesForPrefix("");
for(Ice::PropertyDict::const_iterator p = properties.begin(); p != properties.end(); ++p)
{
- cout << p->first << "=" << p->second << endl;
+ consoleOut << p->first << "=" << p->second << endl;
}
}
}
@@ -1974,7 +1926,7 @@ Parser::listServices(const list<string>& args)
{
if(p->descriptor)
{
- cout << p->descriptor->name << endl;
+ consoleOut << p->descriptor->name << endl;
}
}
}
@@ -2001,15 +1953,15 @@ Parser::endpointsAdapter(const list<string>& args)
if(adpts.size() == 1 && adpts.begin()->id == adapterId)
{
string endpoints = _communicator->proxyToString(adpts.begin()->proxy);
- cout << (endpoints.empty() ? string("<inactive>") : endpoints) << endl;
+ consoleOut << (endpoints.empty() ? string("<inactive>") : endpoints) << endl;
}
else
{
for(AdapterInfoSeq::const_iterator p = adpts.begin(); p != adpts.end(); ++p)
{
- cout << (p->id.empty() ? string("<empty>") : p->id) << ": ";
+ consoleOut << (p->id.empty() ? string("<empty>") : p->id) << ": ";
string endpoints = _communicator->proxyToString(p->proxy);
- cout << (endpoints.empty() ? string("<inactive>") : endpoints) << endl;
+ consoleOut << (endpoints.empty() ? string("<inactive>") : endpoints) << endl;
}
}
}
@@ -2049,8 +2001,10 @@ Parser::listAllAdapters(const list<string>& args)
try
{
+ ostringstream os;
Ice::StringSeq ids = _admin->getAllAdapterIds();
- copy(ids.begin(), ids.end(), ostream_iterator<string>(cout,"\n"));
+ copy(ids.begin(), ids.end(), ostream_iterator<string>(os,"\n"));
+ consoleOut << os.str();
}
catch(const Ice::Exception& ex)
{
@@ -2122,7 +2076,7 @@ Parser::findObject(const list<string>& args)
ObjectInfoSeq objects = _admin->getObjectInfosByType(*(args.begin()));
for(ObjectInfoSeq::const_iterator p = objects.begin(); p != objects.end(); ++p)
{
- cout << _communicator->proxyToString(p->proxy) << endl;
+ consoleOut << _communicator->proxyToString(p->proxy) << endl;
}
}
catch(const Ice::Exception& ex)
@@ -2149,8 +2103,8 @@ Parser::describeObject(const list<string>& args)
if(arg.find('*') == string::npos)
{
ObjectInfo info = _admin->getObjectInfo(Ice::stringToIdentity(arg));
- cout << "proxy = `" << _communicator->proxyToString(info.proxy) << "'" << endl;
- cout << "type = `" << info.type << "'" << endl;
+ consoleOut << "proxy = `" << _communicator->proxyToString(info.proxy) << "'" << endl;
+ consoleOut << "type = `" << info.type << "'" << endl;
return;
}
else
@@ -2165,7 +2119,7 @@ Parser::describeObject(const list<string>& args)
for(ObjectInfoSeq::const_iterator p = objects.begin(); p != objects.end(); ++p)
{
- cout << "proxy = `" << _communicator->proxyToString(p->proxy) << "' type = `" << p->type << "'" << endl;
+ consoleOut << "proxy = `" << _communicator->proxyToString(p->proxy) << "' type = `" << p->type << "'" << endl;
}
}
@@ -2198,7 +2152,7 @@ Parser::listObject(const list<string>& args)
for(ObjectInfoSeq::const_iterator p = objects.begin(); p != objects.end(); ++p)
{
- cout << _communicator->identityToString(p->proxy->ice_getIdentity()) << endl;
+ consoleOut << _communicator->identityToString(p->proxy->ice_getIdentity()) << endl;
}
}
catch(const Ice::Exception& ex)
@@ -2245,7 +2199,7 @@ Parser::show(const string& reader, const list<string>& origArgs)
string id = *p++;
string filename = *p++;
- cout << reader << " `" << id << "' " << filename << ": " << flush;
+ consoleOut << reader << " `" << id << "' " << filename << ": " << flush;
Ice::StringSeq lines;
bool head = opts.isSet("head");
@@ -2574,19 +2528,19 @@ Parser::showLog(const string& id, const string& reader, bool tail, bool follow,
void
Parser::showBanner()
{
- cout << "Ice " << ICE_STRING_VERSION << " Copyright (c) 2003-2016 ZeroC, Inc." << endl;
+ consoleOut << "Ice " << ICE_STRING_VERSION << " Copyright (c) 2003-2016 ZeroC, Inc." << endl;
}
void
Parser::showCopying()
{
- cout << "This command is not implemented." << endl;
+ consoleOut << "This command is not implemented." << endl;
}
void
Parser::showWarranty()
{
- cout << "This command is not implemented." << endl;
+ consoleOut << "This command is not implemented." << endl;
}
//
@@ -2654,7 +2608,7 @@ Parser::getInput(char* buf, size_t& result, size_t maxSize)
}
}
#else
- cout << parser->getPrompt() << flush;
+ consoleOut << parser->getPrompt() << flush;
string line;
while(true)
{
@@ -2746,11 +2700,11 @@ Parser::invalidCommand(const list<string>& s)
string cat = *s.begin();
if(_helpCommands.find(cat) == _helpCommands.end())
{
- cerr << "unknown `" << cat << "' command (see `help' for more info)" << endl;
+ consoleErr << "unknown `" << cat << "' command (see `help' for more info)" << endl;
}
else if(s.size() == 1)
{
- cerr << "invalid `" << cat << "' command (see `" << cat << " help' for more info)" << endl;
+ consoleErr << "invalid `" << cat << "' command (see `" << cat << " help' for more info)" << endl;
}
else
{
@@ -2758,12 +2712,12 @@ Parser::invalidCommand(const list<string>& s)
if(_helpCommands[cat].find(cmd) == _helpCommands[cat].end())
{
cmd = cat + " " + cmd;
- cerr << "unknown `" << cmd << "' command (see `" << cat << " help' for more info)" << endl;
+ consoleErr << "unknown `" << cmd << "' command (see `" << cat << " help' for more info)" << endl;
}
else
{
cmd = cat + " " + cmd;
- cerr << "invalid `" << cmd << "' command (see `" << cmd << " help' for more info)" << endl;
+ consoleErr << "invalid `" << cmd << "' command (see `" << cmd << " help' for more info)" << endl;
}
}
}
@@ -2819,13 +2773,7 @@ void
Parser::error(const char* s)
{
- cerr << "error: "
-#ifdef _WIN32
- << toConsoleEncoding(s)
-#else
- << s
-#endif
- << endl;
+ consoleErr << "error: " << s << endl;
_errors++;
}
@@ -2838,13 +2786,7 @@ Parser::error(const string& s)
void
Parser::warning(const char* s)
{
- cerr << "warning: "
-#ifdef _WIN32
- << toConsoleEncoding(s)
-#else
- << s
-#endif
- << endl;
+ consoleErr << "warning: " << s << endl;
}
void