diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Glacier2/Glacier2Router.cpp | 66 | ||||
-rw-r--r-- | cpp/src/Glacier2Lib/SessionHelper.cpp | 8 | ||||
-rw-r--r-- | cpp/src/Ice/LoggerUtil.cpp | 69 | ||||
-rw-r--r-- | cpp/src/Ice/Service.cpp | 71 | ||||
-rw-r--r-- | cpp/src/IceBox/ServiceManagerI.cpp | 7 | ||||
-rw-r--r-- | cpp/src/IceGrid/IceGridNode.cpp | 47 | ||||
-rw-r--r-- | cpp/src/IceStorm/Service.cpp | 10 |
7 files changed, 102 insertions, 176 deletions
diff --git a/cpp/src/Glacier2/Glacier2Router.cpp b/cpp/src/Glacier2/Glacier2Router.cpp index 6bc83d2cbce..b7681c32a01 100644 --- a/cpp/src/Glacier2/Glacier2Router.cpp +++ b/cpp/src/Glacier2/Glacier2Router.cpp @@ -231,11 +231,10 @@ Glacier2::RouterService::start(int argc, char* argv[], int& status) return false; } } - catch(const Ice::Exception& ex) + catch(const std::exception& ex) { - ostringstream ostr; - ostr << ex; - error("permissions verifier `" + verifierPropertyValue + "' is invalid:\n" + ostr.str()); + ServiceError err(this); + err << "permissions verifier `" << verifierPropertyValue + "' is invalid:\n" << ex; return false; } @@ -259,9 +258,8 @@ Glacier2::RouterService::start(int argc, char* argv[], int& status) { if(!nowarn) { - ostringstream ostr; - ostr << ex; - warning("unable to contact permissions verifier `" + verifierPropertyValue + "'\n" + ostr.str()); + ServiceWarning warn(this); + warn << "unable to contact permissions verifier `" << verifierPropertyValue << "'\n" << ex; } verifier = PermissionsVerifierPrx::uncheckedCast(obj); } @@ -323,11 +321,11 @@ Glacier2::RouterService::start(int argc, char* argv[], int& status) { obj = communicator()->propertyToProxy(sessionManagerProperty); } - catch(const Ice::Exception& ex) + catch(const std::exception& ex) { - ostringstream ostr; - ostr << ex; - error("session manager `" + sessionManagerPropertyValue + "' is invalid\n:" + ostr.str()); + ServiceError err(this); + err << "session manager `" << sessionManagerPropertyValue + << "' is invalid\n:" << ex; return false; } try @@ -339,13 +337,13 @@ Glacier2::RouterService::start(int argc, char* argv[], int& status) return false; } } - catch(const Ice::Exception& ex) + catch(const std::exception& ex) { if(!nowarn) { - ostringstream ostr; - ostr << ex; - warning("unable to contact session manager `" + sessionManagerPropertyValue + "'\n" + ostr.str()); + ServiceWarning warn(this); + warn << "unable to contact session manager `" << sessionManagerPropertyValue << "'\n" + << ex; } sessionManager = SessionManagerPrx::uncheckedCast(obj); } @@ -392,11 +390,11 @@ Glacier2::RouterService::start(int argc, char* argv[], int& status) return false; } } - catch(const Ice::Exception& ex) + catch(const std::exception& ex) { - ostringstream ostr; - ostr << ex; - error("ssl permissions verifier `" + sslVerifierPropertyValue + "' is invalid:\n" + ostr.str()); + ServiceError err(this); + err << "ssl permissions verifier `" << sslVerifierPropertyValue << "' is invalid:\n" + << ex; return false; } @@ -422,10 +420,9 @@ Glacier2::RouterService::start(int argc, char* argv[], int& status) { if(!nowarn) { - ostringstream ostr; - ostr << ex; - warning("unable to contact ssl permissions verifier `" + sslVerifierPropertyValue + "'\n" + - ostr.str()); + ServiceWarning warn(this); + warn << "unable to contact ssl permissions verifier `" << sslVerifierPropertyValue << "'\n" + << ex; } sslVerifier = SSLPermissionsVerifierPrx::uncheckedCast(obj); } @@ -445,11 +442,10 @@ Glacier2::RouterService::start(int argc, char* argv[], int& status) { obj = communicator()->propertyToProxy(sslSessionManagerProperty); } - catch(const Ice::Exception& ex) + catch(const std::exception& ex) { - ostringstream ostr; - ostr << ex; - error("ssl session manager `" + sslSessionManagerPropertyValue + "' is invalid:\n" + ostr.str()); + ServiceError err(this); + err << "ssl session manager `" << sslSessionManagerPropertyValue << "' is invalid:\n" << ex; return false; } try @@ -465,10 +461,9 @@ Glacier2::RouterService::start(int argc, char* argv[], int& status) { if(!nowarn) { - ostringstream ostr; - ostr << ex; - warning("unable to contact ssl session manager `" + sslSessionManagerPropertyValue + "'\n" + - ostr.str()); + ServiceWarning warn(this); + warn << "unable to contact ssl session manager `" << sslSessionManagerPropertyValue + << "'\n" << ex; } sslSessionManager = SSLSessionManagerPrx::uncheckedCast(obj); } @@ -534,11 +529,12 @@ Glacier2::RouterService::start(int argc, char* argv[], int& status) adminAdapter->activate(); } } - catch(const Ice::Exception& ex) + catch(const std::exception& ex) { - ostringstream ostr; - ostr << ex; - error("caught exception activating object adapters\n" + ostr.str()); + { + ServiceError err(this); + err << "caught exception activating object adapters\n" << ex; + } stop(); return false; diff --git a/cpp/src/Glacier2Lib/SessionHelper.cpp b/cpp/src/Glacier2Lib/SessionHelper.cpp index 3080fe5c47f..a97e6706cd1 100644 --- a/cpp/src/Glacier2Lib/SessionHelper.cpp +++ b/cpp/src/Glacier2Lib/SessionHelper.cpp @@ -438,17 +438,15 @@ SessionHelperI::destroyInternal(const Ice::DispatcherCallPtr& disconnected) // This can also occur. // } - catch(const Ice::Exception& ex) + catch(const std::exception& ex) { // // Not expected. // - ostringstream os; - os << "SessionHelper: unexpected exception when destroying the session:\n"; - os << ex; if(communicator) { - communicator->getLogger()->warning(os.str()); + Ice::Warning warn(communicator->getLogger()); + warn << "SessionHelper: unexpected exception when destroying the session:\n" << ex; } } } diff --git a/cpp/src/Ice/LoggerUtil.cpp b/cpp/src/Ice/LoggerUtil.cpp index ebf9ea5de11..635fa8abd8f 100644 --- a/cpp/src/Ice/LoggerUtil.cpp +++ b/cpp/src/Ice/LoggerUtil.cpp @@ -23,6 +23,12 @@ extern bool ICE_DECLSPEC_IMPORT printStackTraces; } +string +Ice::LoggerOutputBase::str() const +{ + return _str.str(); +} + ostringstream& Ice::LoggerOutputBase::__str() { @@ -52,68 +58,6 @@ Ice::operator<<(Ice::LoggerOutputBase& out, const std::exception& ex) return out; } -Ice::Print::Print(const LoggerPtr& logger) : - _logger(logger) -{ -} - -Ice::Print::~Print() -{ - flush(); -} - -void -Ice::Print::flush() -{ - string s = __str().str(); - if(!s.empty()) - { - _logger->print(s); - } - __str().str(""); -} - -Ice::Warning::Warning(const LoggerPtr& logger) : - _logger(logger) -{ -} - -Ice::Warning::~Warning() -{ - flush(); -} - -void -Ice::Warning::flush() -{ - string s = __str().str(); - if(!s.empty()) - { - _logger->warning(s); - } - __str().str(""); -} - -Ice::Error::Error(const LoggerPtr& logger) : - _logger(logger) -{ -} - -Ice::Error::~Error() -{ - flush(); -} - -void -Ice::Error::flush() -{ - string s = __str().str(); - if(!s.empty()) - { - _logger->error(s); - } - __str().str(""); -} Ice::Trace::Trace(const LoggerPtr& logger, const string& category) : _logger(logger), @@ -137,6 +81,7 @@ Ice::Trace::flush() __str().str(""); } + Ice::LoggerPlugin::LoggerPlugin(const CommunicatorPtr& communicator, const LoggerPtr& logger) { if(communicator == 0) diff --git a/cpp/src/Ice/Service.cpp b/cpp/src/Ice/Service.cpp index 9b24501844c..232a155602e 100644 --- a/cpp/src/Ice/Service.cpp +++ b/cpp/src/Ice/Service.cpp @@ -23,6 +23,7 @@ #include <Ice/LocalException.h> #include <Ice/Properties.h> #include <Ice/Instance.h> +#include <Ice/LoggerUtil.h> #ifdef _WIN32 # include <winsock2.h> @@ -489,11 +490,10 @@ Ice::Service::shutdown() // Expected if the service communicator is being destroyed. // } - catch(const Ice::Exception& ex) + catch(const std::exception& ex) { - ostringstream ostr; - ostr << "exception during shutdown:\n" << ex; - warning(ostr.str()); + ServiceWarning warn(this); + warn << "exception during shutdown:\n" << ex; } catch(...) { @@ -529,9 +529,8 @@ Ice::Service::main(int& argc, char* argv[], const InitializationData& initializa } catch(const Ice::Exception& ex) { - ostringstream ostr; - ostr << ex; - error(ostr.str()); + ServiceError err(this); + err << "createProperties failed: " << ex; return EXIT_FAILURE; } @@ -842,21 +841,18 @@ Ice::Service::run(int& argc, char* argv[], const InitializationData& initData) } catch(const std::exception& ex) { - ostringstream ostr; - ostr << "service caught unhandled exception:\n" << ex.what(); - error(ostr.str()); + ServiceError err(this); + err << "service caught unhandled exception:\n" << ex; } catch(const std::string& msg) { - ostringstream ostr; - ostr << "service caught unhandled exception:\n" << msg; - error(ostr.str()); + ServiceError err(this); + err << "service caught unhandled exception:\n" << msg; } catch(const char* msg) { - ostringstream ostr; - ostr << "service caught unhandled exception:\n" << msg; - error(ostr.str()); + ServiceError err(this); + err << "service caught unhandled exception:\n" << msg; } catch(...) { @@ -1228,14 +1224,13 @@ Ice::Service::showServiceStatus(const string& msg, SERVICE_STATUS& status) break; } - ostringstream ostr; - ostr << msg << endl - << " Current state: " << state << endl - << " Exit code: " << status.dwWin32ExitCode << endl - << " Service specific exit code: " << status.dwServiceSpecificExitCode << endl - << " Check point: " << status.dwCheckPoint << endl - << " Wait hint: " << status.dwWaitHint; - trace(ostr.str()); + ServiceTrace tr(this); + tr << msg + << "\n Current state: " << state + << "\n Exit code: " << status.dwWin32ExitCode + << "\n Service specific exit code: " << status.dwServiceSpecificExitCode + << "\n Check point: " << status.dwCheckPoint + << "\n Wait hint: " << status.dwWaitHint; } void @@ -1288,9 +1283,10 @@ Ice::Service::serviceMain(int argc, wchar_t* argv[]) catch(const Ice::Exception& ex) { delete[] args; - ostringstream ostr; - ostr << "exception occurred while initializing a communicator:\n" << ex; - error(ostr.str()); + { + ServiceError err(this); + err << "exception occurred while initializing a communicator:\n" << ex; + } terminateService(EXIT_FAILURE); return; } @@ -1344,11 +1340,10 @@ Ice::Service::serviceMain(int argc, wchar_t* argv[]) status = tmpStatus; } } - catch(const IceUtil::Exception& ex) + catch(const std::exception& ex) { - ostringstream ostr; - ostr << "service caught unhandled Ice exception:\n" << ex; - error(ostr.str()); + ServiceError err(this); + err << "service caught unhandled std::exception:\n" << ex; } catch(...) { @@ -1387,9 +1382,8 @@ Ice::Service::control(int ctrl) { if(ctrl != SERVICE_CONTROL_INTERROGATE) { - ostringstream ostr; - ostr << "unrecognized service control code " << ctrl; - error(ostr.str()); + ServiceError err(this); + err << "unrecognized service control code " << ctrl; } serviceStatusManager->reportStatus(); @@ -1783,12 +1777,11 @@ Ice::Service::runDaemon(int argc, char* argv[], const InitializationData& initDa } } } - catch(const IceUtil::Exception& ex) + catch(const std::exception& ex) { - ostringstream ostr; - ostr << "service caught unhandled Ice exception:\n" << ex; - errMsg = ostr.str(); - error(errMsg); + ServiceError err(this); + err << "service caught unhandled std::exception:\n" << ex; + errMsg = err.str(); } catch(...) { diff --git a/cpp/src/IceBox/ServiceManagerI.cpp b/cpp/src/IceBox/ServiceManagerI.cpp index 2e04b637793..f1ef006a716 100644 --- a/cpp/src/IceBox/ServiceManagerI.cpp +++ b/cpp/src/IceBox/ServiceManagerI.cpp @@ -25,6 +25,7 @@ using namespace std; typedef IceBox::Service* (*SERVICE_FACTORY)(CommunicatorPtr); + namespace { @@ -623,7 +624,7 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint, } catch(const Exception& ex) { - ostringstream s; + LoggerOutputBase s; s << "ServiceManager: exception while starting service " << service << ":\n"; s << ex; @@ -672,7 +673,7 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint, } catch(const Exception& ex) { - ostringstream s; + LoggerOutputBase s; s << "ServiceManager: exception in entry point `" + entryPoint + "' for service " << info.name << ":\n"; s << ex; @@ -710,7 +711,7 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint, } catch(const Exception& ex) { - ostringstream s; + LoggerOutputBase s; s << "ServiceManager: exception while starting service " << info.name << ":\n"; s << ex; diff --git a/cpp/src/IceGrid/IceGridNode.cpp b/cpp/src/IceGrid/IceGridNode.cpp index 0c26b17ceda..210c1563fed 100644 --- a/cpp/src/IceGrid/IceGridNode.cpp +++ b/cpp/src/IceGrid/IceGridNode.cpp @@ -350,12 +350,12 @@ NodeService::startImpl(int argc, char* argv[], int& status) { if(!IceUtilInternal::directoryExists(dataPath)) { - ostringstream os; FileException ex(__FILE__, __LINE__); ex.path = dataPath; ex.error = IceInternal::getSystemErrno(); - os << ex; - error("property `IceGrid.Node.Data' is set to an invalid path:\n" + os.str()); + + ServiceError err(this); + err << "property `IceGrid.Node.Data' is set to an invalid path:\n" << ex; return false; } @@ -434,11 +434,10 @@ NodeService::startImpl(int argc, char* argv[], int& status) { mapper = UserAccountMapperPrx::uncheckedCast(communicator()->propertyToProxy(mapperProperty)); } - catch(const Ice::LocalException& ex) + catch(const std::exception& ex) { - ostringstream os; - os << "user account mapper `" << mapperProperty << "' is invalid:\n" << ex; - error(os.str()); + ServiceError err(this); + err << "user account mapper `" << mapperProperty << "' is invalid:\n" << ex; return false; } } @@ -627,28 +626,24 @@ NodeService::startImpl(int argc, char* argv[], int& status) } catch(const DeploymentException& ex) { - ostringstream ostr; - ostr << "failed to deploy application `" << desc << "':\n" << ex << ": " << ex.reason; - warning(ostr.str()); + ServiceWarning warn(this); + warn << "failed to deploy application `" << desc << "':\n" << ex; } catch(const AccessDeniedException& ex) { - ostringstream ostr; - ostr << "failed to deploy application `" << desc << "':\n" + ServiceWarning warn(this); + warn << "failed to deploy application `" << desc << "':\n" << "registry database is locked by `" << ex.lockUserId << "'"; - warning(ostr.str()); } catch(const std::exception& ex) { - ostringstream ostr; - ostr << "failed to deploy application `" << desc << "':\n" << ex.what(); - warning(ostr.str()); + ServiceWarning warn(this); + warn << "failed to deploy application `" << desc << "':\n" << ex; } catch(const string& reason) { - ostringstream ostr; - ostr << "failed to deploy application `" << desc << "':\n" << reason; - warning(ostr.str()); + ServiceWarning warn(this); + warn << "failed to deploy application `" << desc << "':\n" << reason; } } @@ -716,11 +711,10 @@ NodeService::stop() _adapter->deactivate(); _adapter = 0; } - catch(const Ice::LocalException& ex) + catch(const std::exception& ex) { - ostringstream ostr; - ostr << "unexpected exception while shutting down node:\n" << ex; - warning(ostr.str()); + ServiceWarning warn(this); + warn << "unexpected exception while shutting down node:\n" << ex; } } @@ -745,11 +739,10 @@ NodeService::stop() communicator()->shutdown(); communicator()->waitForShutdown(); } - catch(const Ice::LocalException& ex) + catch(const std::exception& ex) { - ostringstream ostr; - ostr << "unexpected exception while shutting down node:\n" << ex; - warning(ostr.str()); + ServiceWarning warn(this); + warn << "unexpected exception while shutting down node:\n" << ex; } // diff --git a/cpp/src/IceStorm/Service.cpp b/cpp/src/IceStorm/Service.cpp index fa94c80619a..b60ead9bc5f 100644 --- a/cpp/src/IceStorm/Service.cpp +++ b/cpp/src/IceStorm/Service.cpp @@ -151,7 +151,7 @@ ServiceI::start( { _instance = 0; - ostringstream s; + LoggerOutputBase s; s << "exception while starting IceStorm service " << name << ":\n"; s << ex; @@ -182,7 +182,7 @@ ServiceI::start( } catch(const Ice::LocalException& ex) { - ostringstream s; + LoggerOutputBase s; s << "failed to load default Freeze database plugin:\n" << ex; IceBox::FailureException e(__FILE__, __LINE__); @@ -215,7 +215,7 @@ ServiceI::start( { _instance = 0; - ostringstream s; + LoggerOutputBase s; s << "exception while starting IceStorm service " << name << ":\n"; s << ex; @@ -402,7 +402,7 @@ ServiceI::start( { _instance = 0; - ostringstream s; + LoggerOutputBase s; s << "exception while starting IceStorm service " << name << ":\n"; s << ex; @@ -443,7 +443,7 @@ ServiceI::start(const CommunicatorPtr& communicator, catch(const Ice::Exception& ex) { _instance = 0; - ostringstream s; + LoggerOutputBase s; s << "exception while starting IceStorm service " << name << ":\n"; s << ex; |