summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/Instance.cpp42
-rw-r--r--cpp/src/Ice/PropertiesI.cpp11
-rw-r--r--cpp/src/Ice/ReferenceFactory.cpp2
-rwxr-xr-xcpp/src/Ice/StringConverter.cpp129
-rw-r--r--cpp/src/IceGrid/NodeCache.cpp6
-rw-r--r--cpp/src/IceGrid/ServerI.cpp11
-rw-r--r--cpp/src/IceUtil/Thread.cpp9
7 files changed, 188 insertions, 22 deletions
diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp
index d4ae7b27c76..dbb7524c0f0 100644
--- a/cpp/src/Ice/Instance.cpp
+++ b/cpp/src/Ice/Instance.cpp
@@ -409,15 +409,22 @@ IceInternal::Instance::stringToIdentity(const string& s) const
if(_initData.stringConverter)
{
string tmpString;
- _initData.stringConverter->fromUTF8(reinterpret_cast<const Byte*>(ident.name.data()),
- reinterpret_cast<const Byte*>(ident.name.data() + ident.name.size()),
- tmpString);
- ident.name = tmpString;
+ if(!ident.name.empty())
+ {
+ _initData.stringConverter->fromUTF8(reinterpret_cast<const Byte*>(ident.name.data()),
+ reinterpret_cast<const Byte*>(ident.name.data() + ident.name.size()),
+ tmpString);
+ ident.name = tmpString;
+ }
- _initData.stringConverter->fromUTF8(reinterpret_cast<const Byte*>(ident.category.data()),
- reinterpret_cast<const Byte*>(ident.category.data() + ident.category.size()),
- tmpString);
- ident.category = tmpString;
+ if(!ident.category.empty())
+ {
+ _initData.stringConverter->fromUTF8(reinterpret_cast<const Byte*>(ident.category.data()),
+ reinterpret_cast<const Byte*>(ident.category.data() +
+ ident.category.size()),
+ tmpString);
+ ident.category = tmpString;
+ }
}
return ident;
@@ -431,14 +438,21 @@ IceInternal::Instance::identityToString(const Identity& ident) const
if(_initData.stringConverter)
{
UTF8BufferI buffer;
- Byte* last = _initData.stringConverter->toUTF8(ident.name.data(), ident.name.data() + ident.name.size(),
- buffer);
- name = string(reinterpret_cast<const char*>(buffer.getBuffer()), last - buffer.getBuffer());
+ Byte* last;
+ if(!ident.name.empty())
+ {
+ last = _initData.stringConverter->toUTF8(ident.name.data(), ident.name.data() + ident.name.size(),
+ buffer);
+ name = string(reinterpret_cast<const char*>(buffer.getBuffer()), last - buffer.getBuffer());
+ }
buffer.reset();
- last = _initData.stringConverter->toUTF8(ident.category.data(), ident.category.data() + ident.category.size(),
- buffer);
- category = string(reinterpret_cast<const char*>(buffer.getBuffer()), last - buffer.getBuffer());
+ if(!ident.category.empty())
+ {
+ last = _initData.stringConverter->toUTF8(ident.category.data(),
+ ident.category.data() + ident.category.size(), buffer);
+ category = string(reinterpret_cast<const char*>(buffer.getBuffer()), last - buffer.getBuffer());
+ }
}
if(category.empty())
diff --git a/cpp/src/Ice/PropertiesI.cpp b/cpp/src/Ice/PropertiesI.cpp
index 09d38acc992..4bd8711b351 100644
--- a/cpp/src/Ice/PropertiesI.cpp
+++ b/cpp/src/Ice/PropertiesI.cpp
@@ -413,13 +413,16 @@ Ice::PropertiesI::parseLine(const string& line, const StringConverterPtr& conver
if(converter)
{
string tmp;
- converter->fromUTF8(reinterpret_cast<const Byte*>(key.data()),
+ converter->fromUTF8(reinterpret_cast<const Byte*>(key.data()),
reinterpret_cast<const Byte*>(key.data() + key.size()), tmp);
key.swap(tmp);
- converter->fromUTF8(reinterpret_cast<const Byte*>(value.data()),
- reinterpret_cast<const Byte*>(value.data() + value.size()), tmp);
- value.swap(tmp);
+ if(!value.empty())
+ {
+ converter->fromUTF8(reinterpret_cast<const Byte*>(value.data()),
+ reinterpret_cast<const Byte*>(value.data() + value.size()), tmp);
+ value.swap(tmp);
+ }
}
setProperty(key, value);
diff --git a/cpp/src/Ice/ReferenceFactory.cpp b/cpp/src/Ice/ReferenceFactory.cpp
index 5ba3c621c12..4c055017f68 100644
--- a/cpp/src/Ice/ReferenceFactory.cpp
+++ b/cpp/src/Ice/ReferenceFactory.cpp
@@ -541,7 +541,7 @@ IceInternal::ReferenceFactory::create(const string& str)
throw ex;
}
- if(_instance->initializationData().stringConverter)
+ if(_instance->initializationData().stringConverter && !adapter.empty())
{
string tmpAdapter;
_instance->initializationData().stringConverter->fromUTF8(
diff --git a/cpp/src/Ice/StringConverter.cpp b/cpp/src/Ice/StringConverter.cpp
index 985111f9aa9..e6b112fd1bc 100755
--- a/cpp/src/Ice/StringConverter.cpp
+++ b/cpp/src/Ice/StringConverter.cpp
@@ -8,12 +8,49 @@
// **********************************************************************
#include <Ice/StringConverter.h>
-#include <IceUtil/Unicode.h>
+#include <IceUtil/IceUtil.h>
#include <Ice/LocalException.h>
using namespace IceUtil;
using namespace std;
+
+#ifdef _WIN32
+namespace
+{
+//
+// Helper function
+//
+
+string getMessageForLastError()
+{
+ LPVOID lpMsgBuf = 0;
+ DWORD ok = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ GetLastError(),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ (LPTSTR)&lpMsgBuf,
+ 0,
+ NULL);
+
+ string msg;
+ if(ok)
+ {
+ msg = (LPCTSTR)lpMsgBuf;
+ LocalFree(lpMsgBuf);
+ }
+ else
+ {
+ msg = "Unknown Windows error";
+ }
+ return msg;
+}
+}
+#endif
+
+
namespace Ice
{
@@ -64,6 +101,12 @@ void
UnicodeWstringConverter::fromUTF8(const Byte* sourceStart, const Byte* sourceEnd,
wstring& target) const
{
+ if(sourceStart == sourceEnd)
+ {
+ target = L"";
+ return;
+ }
+
ConversionResult result =
convertUTF8ToUTFWstring(sourceStart, sourceEnd, target, lenientConversion);
@@ -82,4 +125,88 @@ UnicodeWstringConverter::fromUTF8(const Byte* sourceStart, const Byte* sourceEnd
}
}
}
+
+#ifdef _WIN32
+WindowsStringConverter::WindowsStringConverter(unsigned int cp) :
+ _cp(cp)
+{
+}
+
+Byte*
+WindowsStringConverter::toUTF8(const char* sourceStart,
+ const char* sourceEnd,
+ UTF8Buffer& buffer) const
+{
+ //
+ // First convert to UTF-16
+ //
+ int sourceSize = sourceEnd - sourceStart;
+ if(sourceSize == 0)
+ {
+ return buffer.getMoreBytes(1, 0);
+ }
+
+ size_t size = 0;
+ int writtenWchar = 0;
+ IceUtil::ScopedArray<wchar_t> wbuffer;
+ do
+ {
+ size = size == 0 ? static_cast<size_t>(sourceSize) + 2 : 2 * size;
+ wbuffer.reset(new wchar_t[size]);
+
+ writtenWchar = MultiByteToWideChar(_cp, MB_ERR_INVALID_CHARS, sourceStart,
+ sourceSize, wbuffer.get(), size);
+ } while(writtenWchar == 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER);
+
+ if(writtenWchar == 0)
+ {
+ throw StringConversionException(__FILE__, __LINE__, getMessageForLastError());
+ }
+
+ //
+ // Then convert this UTF-16 wbuffer into UTF-8
+ //
+ return _unicodeWstringConverter.toUTF8(wbuffer.get(), wbuffer.get() + writtenWchar, buffer);
+}
+
+void
+WindowsStringConverter::fromUTF8(const Byte* sourceStart, const Byte* sourceEnd,
+ string& target) const
+{
+ if(sourceStart == sourceEnd)
+ {
+ target = "";
+ return;
+ }
+
+ //
+ // First convert to wstring (UTF-16)
+ //
+ wstring wtarget;
+ _unicodeWstringConverter.fromUTF8(sourceStart, sourceEnd, wtarget);
+
+ //
+ // And then to a multi-byte narrow string
+ //
+ size_t size = 0;
+ int writtenChar = 0;
+ IceUtil::ScopedArray<char> buffer;
+ do
+ {
+ size = size == 0 ? static_cast<size_t>(sourceEnd - sourceStart) + 2 : 2 * size;
+ buffer.reset(new char[size]);
+ writtenChar = WideCharToMultiByte(_cp, 0, wtarget.data(), wtarget.size(),
+ buffer.get(), size, 0, 0);
+ } while(writtenChar == 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER);
+
+ if(writtenChar == 0)
+ {
+ throw StringConversionException(__FILE__, __LINE__, getMessageForLastError());
+ }
+
+ target.assign(buffer.get(), writtenChar);
+}
+
+#endif
+
}
diff --git a/cpp/src/IceGrid/NodeCache.cpp b/cpp/src/IceGrid/NodeCache.cpp
index fde6cf359ad..c222c680cad 100644
--- a/cpp/src/IceGrid/NodeCache.cpp
+++ b/cpp/src/IceGrid/NodeCache.cpp
@@ -876,6 +876,12 @@ NodeEntry::getInternalServerDescriptor(const ServerInfo& info) const
servicesStr += s->name + " ";
}
props.push_back(createProperty("IceBox.LoadOrder", servicesStr));
+
+ if(iceBox->adapters.empty() &&
+ getProperty(iceBox->propertySet.properties, "IceBox.ServiceManager.RegisterProcess") != "0")
+ {
+ server->processRegistered = true;
+ }
}
//
diff --git a/cpp/src/IceGrid/ServerI.cpp b/cpp/src/IceGrid/ServerI.cpp
index 27fd7396399..2535bfc7abc 100644
--- a/cpp/src/IceGrid/ServerI.cpp
+++ b/cpp/src/IceGrid/ServerI.cpp
@@ -1153,7 +1153,13 @@ ServerI::adapterDeactivated(const string& id)
ServerCommandPtr command;
{
Lock sync(*this);
- if(_state == Active && _serverLifetimeAdapters.find(id) != _serverLifetimeAdapters.end())
+ while(_state == ServerI::Activating)
+ {
+ wait(); // Wait for activate() to set the state to WaitForActivation
+ }
+
+ if((_state == Active || _state == WaitForActivation) &&
+ _serverLifetimeAdapters.find(id) != _serverLifetimeAdapters.end())
{
setStateNoSync(Deactivating);
}
@@ -1440,12 +1446,13 @@ ServerI::deactivate()
Ice::ProcessPrx process;
{
Lock sync(*this);
- assert(_desc);
if(_state != Deactivating && _state != DeactivatingWaitForProcess)
{
return;
}
+ assert(_desc);
+
//
// If a process object is supposed to be registered and it's
// not set yet, we wait for the server to set this process
diff --git a/cpp/src/IceUtil/Thread.cpp b/cpp/src/IceUtil/Thread.cpp
index 6f306f345de..c0694ec351d 100644
--- a/cpp/src/IceUtil/Thread.cpp
+++ b/cpp/src/IceUtil/Thread.cpp
@@ -7,6 +7,15 @@
//
// **********************************************************************
+#ifdef __sun //
+// Solaris 10 bug: it's supposed to be defined in pthread.h
+//
+#ifndef __EXTENSIONS__
+#define __EXTENSIONS__
+#endif
+#include <limits.h>
+#endif
+
#include <IceUtil/Thread.h>
#include <IceUtil/Time.h>
#include <IceUtil/ThreadException.h>