summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/Service.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/Ice/Service.cpp')
-rw-r--r--cpp/src/Ice/Service.cpp92
1 files changed, 68 insertions, 24 deletions
diff --git a/cpp/src/Ice/Service.cpp b/cpp/src/Ice/Service.cpp
index bcc93beaa5e..13631d3209b 100644
--- a/cpp/src/Ice/Service.cpp
+++ b/cpp/src/Ice/Service.cpp
@@ -15,10 +15,10 @@
#include <IceUtil/Mutex.h>
#include <IceUtil/ArgVector.h>
#include <IceUtil/FileUtil.h>
+#include <IceUtil/StringConverter.h>
#include <Ice/Service.h>
#include <Ice/LoggerI.h>
#include <Ice/Initialize.h>
-#include <Ice/StringConverter.h>
#include <Ice/Communicator.h>
#include <Ice/LocalException.h>
#include <Ice/Properties.h>
@@ -204,11 +204,14 @@ class SMEventLoggerI : public Ice::Logger, public SMEventLogger
{
public:
- SMEventLoggerI(const string& source, const StringConverterPtr& stringConverter) :
+ SMEventLoggerI(const string& source, const IceUtil::StringConverterPtr& stringConverter) :
_stringConverter(stringConverter)
{
- _source = RegisterEventSourceW(0, IceUtil::stringToWstring(
- nativeToUTF8(_stringConverter, mangleSource(source))).c_str());
+ //
+ // Don't need to use a wide string converter as the wide string is passed
+ // to Windows API.
+ //
+ _source = RegisterEventSourceW(0, IceUtil::nativeToWnative(_stringConverter, 0, mangleSource(source)).c_str());
if(_source == 0)
{
SyscallException ex(__FILE__, __LINE__);
@@ -224,12 +227,16 @@ public:
}
static void
- addKeys(const string& source, const StringConverterPtr& stringConverter)
+ addKeys(const string& source, const IceUtil::StringConverterPtr& stringConverter)
{
HKEY hKey;
DWORD d;
+ //
+ // Don't need to use a wide string converter as the wide string is passed
+ // to Windows API.
+ //
LONG err = RegCreateKeyExW(HKEY_LOCAL_MACHINE,
- IceUtil::stringToWstring(nativeToUTF8(stringConverter, createKey(source))).c_str(),
+ IceUtil::nativeToWnative(stringConverter, 0, createKey(source)).c_str(),
0, const_cast<wchar_t*>(L"REG_SZ"), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &hKey, &d);
if(err != ERROR_SUCCESS)
@@ -282,10 +289,14 @@ public:
}
static void
- removeKeys(const string& source, const StringConverterPtr& stringConverter)
+ removeKeys(const string& source, const IceUtil::StringConverterPtr& stringConverter)
{
+ //
+ // Don't need to use a wide string converter as the wide string is passed
+ // to Windows API.
+ //
LONG err = RegDeleteKeyW(HKEY_LOCAL_MACHINE,
- IceUtil::stringToWstring(nativeToUTF8(stringConverter, createKey(source))).c_str());
+ IceUtil::nativeToWnative(stringConverter, 0, createKey(source)).c_str());
if(err != ERROR_SUCCESS)
{
SyscallException ex(__FILE__, __LINE__);
@@ -310,7 +321,11 @@ public:
virtual void
print(const string& message)
{
- wstring msg = IceUtil::stringToWstring(nativeToUTF8(_stringConverter, message));
+ //
+ // Don't need to use a wide string converter as the wide string is passed
+ // to Windows API.
+ //
+ wstring msg = IceUtil::nativeToWnative(_stringConverter, 0, message);
const wchar_t* messages[1];
messages[0] = msg.c_str();
//
@@ -344,7 +359,11 @@ public:
}
s.append(message);
- wstring msg = IceUtil::stringToWstring(nativeToUTF8(_stringConverter, s));
+ //
+ // Don't need to use a wide string converter as the wide string is passed
+ // to Windows API.
+ //
+ wstring msg = IceUtil::nativeToWnative(_stringConverter, 0, s);
const wchar_t* messages[1];
messages[0] = msg.c_str();
//
@@ -370,7 +389,11 @@ public:
virtual void
warning(const string& message)
{
- wstring msg = IceUtil::stringToWstring(nativeToUTF8(_stringConverter, message));
+ //
+ // Don't need to use a wide string converter as the wide string is passed
+ // to Windows API.
+ //
+ wstring msg = IceUtil::nativeToWnative(_stringConverter, 0, message);
const wchar_t* messages[1];
messages[0] = msg.c_str();
//
@@ -396,7 +419,11 @@ public:
virtual void
error(const string& message)
{
- wstring msg = IceUtil::stringToWstring(nativeToUTF8(_stringConverter, message));
+ //
+ // Don't need to use a wide string converter as the wide string is passed
+ // to Windows API.
+ //
+ wstring msg = IceUtil::nativeToWnative(_stringConverter, 0, message);
const wchar_t* messages[1];
messages[0] = msg.c_str();
//
@@ -445,7 +472,7 @@ private:
return "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\" + mangleSource(name);
}
- StringConverterPtr _stringConverter;
+ IceUtil::StringConverterPtr _stringConverter;
HANDLE _source;
static HMODULE _module;
};
@@ -462,7 +489,6 @@ Ice::Service::Service()
_nohup = true;
_service = false;
_instance = this;
-
#ifndef _WIN32
_changeDirectory = true;
_closeFiles = true;
@@ -525,7 +551,7 @@ Ice::Service::main(int& argc, char* argv[], const InitializationData& initializa
InitializationData initData = initializationData;
try
{
- initData.properties = createProperties(argc, argv, initData.properties, initData.stringConverter);
+ initData.properties = createProperties(argc, argv, initData.properties);
}
catch(const Ice::Exception& ex)
{
@@ -542,6 +568,7 @@ Ice::Service::main(int& argc, char* argv[], const InitializationData& initializa
string name;
string eventLogSource;
int idx = 1;
+ const IceUtil::StringConverterPtr stringConverter = IceUtil::getProcessStringConverter();
while(idx < argc)
{
if(strcmp(argv[idx], "--service") == 0)
@@ -562,7 +589,7 @@ Ice::Service::main(int& argc, char* argv[], const InitializationData& initializa
if(LoggerIPtr::dynamicCast(_logger))
{
string eventLogSource = initData.properties->getPropertyWithDefault("Ice.EventLog.Source", name);
- _logger = new SMEventLoggerIWrapper(new SMEventLoggerI(eventLogSource, initData.stringConverter), "");
+ _logger = new SMEventLoggerIWrapper(new SMEventLoggerI(eventLogSource, stringConverter), "");
setProcessLogger(_logger);
}
@@ -688,7 +715,12 @@ Ice::Service::main(int& argc, char* argv[], const InitializationData& initializa
_logger = getProcessLogger();
if(LoggerIPtr::dynamicCast(_logger))
{
- _logger = new LoggerI(initData.properties->getProperty("Ice.ProgramName"), "");
+ const bool convert =
+ initData.properties->getPropertyAsIntWithDefault("Ice.LogStdErr.Convert", 1) == 1 &&
+ initData.properties->getProperty("Ice.StdErr").empty();
+
+ _logger = new LoggerI(initData.properties->getProperty("Ice.ProgramName"), "", convert,
+ IceUtil::getProcessStringConverter());
setProcessLogger(_logger);
}
}
@@ -713,10 +745,10 @@ Ice::Service::main(int& argc, wchar_t* argv[], const InitializationData& initial
//
// MinGW doesn't see the main overload if we don't create the temp args object here.
//
- Ice::StringSeq args = Ice::argsToStringSeq(argc, argv, initializationData.stringConverter);
+ Ice::StringSeq args = Ice::argsToStringSeq(argc, argv);
return main(args, initializationData);
# else
- return main(Ice::argsToStringSeq(argc, argv, initializationData.stringConverter), initializationData);
+ return main(Ice::argsToStringSeq(argc, argv), initializationData);
# endif
}
@@ -773,7 +805,7 @@ Ice::Service::checkSystem() const
int
Ice::Service::run(int& argc, wchar_t* argv[], const InitializationData& initData)
{
- StringSeq args = Ice::argsToStringSeq(argc, argv, initData.stringConverter);
+ StringSeq args = Ice::argsToStringSeq(argc, argv);
IceUtilInternal::ArgVector av(args);
return run(av.argc, av.argv, initData);
}
@@ -1078,9 +1110,15 @@ Ice::Service::runService(int argc, char* argv[], const InitializationData& initD
_initData = initData;
+ //
+ // Don't need to use a wide string converter as the wide string is passed
+ // to Windows API.
+ //
SERVICE_TABLE_ENTRYW ste[] =
{
- { const_cast<wchar_t*>(IceUtil::stringToWstring(nativeToUTF8(_initData.stringConverter, _name)).c_str()), Ice_Service_ServiceMain },
+ { const_cast<wchar_t*>(
+ IceUtil::nativeToWnative(IceUtil::getProcessStringConverter(), 0, _name).c_str()),
+ Ice_Service_ServiceMain },
{ 0, 0 },
};
@@ -1260,8 +1298,14 @@ Ice::Service::serviceMain(int argc, wchar_t* argv[])
//
// Merge the executable's arguments with the service's arguments.
//
+ const IceUtil::StringConverterPtr converter(IceUtil::getProcessStringConverter());
+
+ //
+ // Don't need to pass a wide string converter in the bellow argv conversions
+ // as argv come from Windows API.
+ //
char** args = new char*[_serviceArgs.size() + argc];
- args[0] = const_cast<char*>(UTF8ToNative(_initData.stringConverter, IceUtil::wstringToString(argv[0])).c_str());
+ args[0] = const_cast<char*>(IceUtil::wnativeToNative(converter, 0, argv[0]).c_str());
int i = 1;
for(vector<string>::iterator p = _serviceArgs.begin(); p != _serviceArgs.end(); ++p)
{
@@ -1269,7 +1313,7 @@ Ice::Service::serviceMain(int argc, wchar_t* argv[])
}
for(int j = 1; j < argc; ++j)
{
- args[i++] = const_cast<char*>(UTF8ToNative(_initData.stringConverter, IceUtil::wstringToString(argv[j])).c_str());
+ args[i++] = const_cast<char*>(IceUtil::wnativeToNative(converter, 0, argv[j]).c_str());
}
argc += static_cast<int>(_serviceArgs.size());
@@ -1743,7 +1787,7 @@ Ice::Service::runDaemon(int argc, char* argv[], const InitializationData& initDa
//
if(_pidFile.size() > 0)
{
- IceUtilInternal::ofstream of(Ice::nativeToUTF8(_communicator, _pidFile));
+ IceUtilInternal::ofstream of(_pidFile);
of << getpid() << endl;
if(!of)