trunk/branch integration: adding new files

This commit is contained in:
Marian Krivos 2011-08-22 16:14:00 +00:00
parent fbe704af43
commit 51ddc1baaa
18 changed files with 3286 additions and 0 deletions

176
Foundation/src/Ascii.cpp Normal file
View File

@ -0,0 +1,176 @@
//
// Ascii.cpp
//
// $Id: //poco/1.4/Foundation/src/Ascii.cpp#1 $
//
// Library: Foundation
// Package: Core
// Module: Ascii
//
// Copyright (c) 2010, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Ascii.h"
namespace Poco {
const int Ascii::CHARACTER_PROPERTIES[128] =
{
/* 00 . */ ACP_CONTROL,
/* 01 . */ ACP_CONTROL,
/* 02 . */ ACP_CONTROL,
/* 03 . */ ACP_CONTROL,
/* 04 . */ ACP_CONTROL,
/* 05 . */ ACP_CONTROL,
/* 06 . */ ACP_CONTROL,
/* 07 . */ ACP_CONTROL,
/* 08 . */ ACP_CONTROL,
/* 09 . */ ACP_CONTROL | ACP_SPACE,
/* 0a . */ ACP_CONTROL | ACP_SPACE,
/* 0b . */ ACP_CONTROL | ACP_SPACE,
/* 0c . */ ACP_CONTROL | ACP_SPACE,
/* 0d . */ ACP_CONTROL | ACP_SPACE,
/* 0e . */ ACP_CONTROL,
/* 0f . */ ACP_CONTROL,
/* 10 . */ ACP_CONTROL,
/* 11 . */ ACP_CONTROL,
/* 12 . */ ACP_CONTROL,
/* 13 . */ ACP_CONTROL,
/* 14 . */ ACP_CONTROL,
/* 15 . */ ACP_CONTROL,
/* 16 . */ ACP_CONTROL,
/* 17 . */ ACP_CONTROL,
/* 18 . */ ACP_CONTROL,
/* 19 . */ ACP_CONTROL,
/* 1a . */ ACP_CONTROL,
/* 1b . */ ACP_CONTROL,
/* 1c . */ ACP_CONTROL,
/* 1d . */ ACP_CONTROL,
/* 1e . */ ACP_CONTROL,
/* 1f . */ ACP_CONTROL,
/* 20 */ ACP_SPACE | ACP_PRINT,
/* 21 ! */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 22 " */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 23 # */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 24 $ */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 25 % */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 26 & */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 27 ' */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 28 ( */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 29 ) */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 2a * */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 2b + */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 2c , */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 2d - */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 2e . */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 2f / */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 30 0 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
/* 31 1 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
/* 32 2 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
/* 33 3 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
/* 34 4 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
/* 35 5 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
/* 36 6 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
/* 37 7 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
/* 38 8 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
/* 39 9 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
/* 3a : */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 3b ; */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 3c < */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 3d = */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 3e > */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 3f ? */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 40 @ */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 41 A */ ACP_HEXDIGIT | ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 42 B */ ACP_HEXDIGIT | ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 43 C */ ACP_HEXDIGIT | ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 44 D */ ACP_HEXDIGIT | ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 45 E */ ACP_HEXDIGIT | ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 46 F */ ACP_HEXDIGIT | ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 47 G */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 48 H */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 49 I */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 4a J */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 4b K */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 4c L */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 4d M */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 4e N */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 4f O */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 50 P */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 51 Q */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 52 R */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 53 S */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 54 T */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 55 U */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 56 V */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 57 W */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 58 X */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 59 Y */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 5a Z */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
/* 5b [ */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 5c \ */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 5d ] */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 5e ^ */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 5f _ */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 60 ` */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 61 a */ ACP_HEXDIGIT | ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 62 b */ ACP_HEXDIGIT | ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 63 c */ ACP_HEXDIGIT | ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 64 d */ ACP_HEXDIGIT | ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 65 e */ ACP_HEXDIGIT | ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 66 f */ ACP_HEXDIGIT | ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 67 g */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 68 h */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 69 i */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 6a j */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 6b k */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 6c l */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 6d m */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 6e n */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 6f o */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 70 p */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 71 q */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 72 r */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 73 s */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 74 t */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 75 u */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 76 v */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 77 w */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 78 x */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 79 y */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 7a z */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
/* 7b { */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 7c | */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 7d } */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 7e ~ */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
/* 7f . */ ACP_CONTROL
};
} // namespace Poco

View File

@ -0,0 +1,171 @@
//
// AtomicCounter.cpp
//
// $Id: //poco/1.4/Foundation/src/AtomicCounter.cpp#1 $
//
// Library: Foundation
// Package: Core
// Module: AtomicCounter
//
// Copyright (c) 2009, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/AtomicCounter.h"
namespace Poco {
#if POCO_OS == POCO_OS_WINDOWS_NT
//
// Windows
//
AtomicCounter::AtomicCounter():
_counter(0)
{
}
AtomicCounter::AtomicCounter(AtomicCounter::ValueType initialValue):
_counter(initialValue)
{
}
AtomicCounter::AtomicCounter(const AtomicCounter& counter):
_counter(counter.value())
{
}
AtomicCounter::~AtomicCounter()
{
}
AtomicCounter& AtomicCounter::operator = (const AtomicCounter& counter)
{
InterlockedExchange(&_counter, counter.value());
return *this;
}
AtomicCounter& AtomicCounter::operator = (AtomicCounter::ValueType value)
{
InterlockedExchange(&_counter, value);
return *this;
}
#elif POCO_OS == POCO_OS_MAC_OS_X
//
// Mac OS X
//
AtomicCounter::AtomicCounter():
_counter(0)
{
}
AtomicCounter::AtomicCounter(AtomicCounter::ValueType initialValue):
_counter(initialValue)
{
}
AtomicCounter::AtomicCounter(const AtomicCounter& counter):
_counter(counter.value())
{
}
AtomicCounter::~AtomicCounter()
{
}
AtomicCounter& AtomicCounter::operator = (const AtomicCounter& counter)
{
_counter = counter.value();
return *this;
}
AtomicCounter& AtomicCounter::operator = (AtomicCounter::ValueType value)
{
_counter = value;
return *this;
}
#else
//
// Generic implementation based on FastMutex
//
AtomicCounter::AtomicCounter()
{
_counter.value = 0;
}
AtomicCounter::AtomicCounter(AtomicCounter::ValueType initialValue)
{
_counter.value = initialValue;
}
AtomicCounter::AtomicCounter(const AtomicCounter& counter)
{
_counter.value = counter.value();
}
AtomicCounter::~AtomicCounter()
{
}
AtomicCounter& AtomicCounter::operator = (const AtomicCounter& counter)
{
FastMutex::ScopedLock lock(_counter.mutex);
_counter.value = counter.value();
return *this;
}
AtomicCounter& AtomicCounter::operator = (AtomicCounter::ValueType value)
{
FastMutex::ScopedLock lock(_counter.mutex);
_counter.value = value;
return *this;
}
#endif // POCO_OS
} // namespace Poco

View File

@ -0,0 +1,186 @@
// Environment_VX.cpp
//
// $Id: //poco/1.4/Foundation/src/Environment_VX.cpp#1 $
//
// Library: Foundation
// Package: Core
// Module: Environment
//
// Copyright (c) 2004-2011, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Environment_VX.h"
#include "Poco/Exception.h"
#include "Poco/Buffer.h"
#include <VxWorks.h>
#include <envLib.h>
#include <hostLib.h>
#include <ifLib.h>
#include <sockLib.h>
#include <ioLib.h>
#include <version.h>
#include <cstring>
#include <unistd.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <unistd.h>
namespace Poco {
EnvironmentImpl::StringMap EnvironmentImpl::_map;
FastMutex EnvironmentImpl::_mutex;
std::string EnvironmentImpl::getImpl(const std::string& name)
{
FastMutex::ScopedLock lock(_mutex);
const char* val = getenv(name.c_str());
if (val)
return std::string(val);
else
throw NotFoundException(name);
}
bool EnvironmentImpl::hasImpl(const std::string& name)
{
FastMutex::ScopedLock lock(_mutex);
return getenv(name.c_str()) != 0;
}
void EnvironmentImpl::setImpl(const std::string& name, const std::string& value)
{
FastMutex::ScopedLock lock(_mutex);
std::string var = name;
var.append("=");
var.append(value);
_map[name] = var;
if (putenv((char*) _map[name].c_str()))
{
std::string msg = "cannot set environment variable: ";
msg.append(name);
throw SystemException(msg);
}
}
std::string EnvironmentImpl::osNameImpl()
{
return runtimeName;
}
std::string EnvironmentImpl::osVersionImpl()
{
return runtimeVersion;
}
std::string EnvironmentImpl::osArchitectureImpl()
{
#if POCO_ARCH == POCO_ARCH_IA32
return "i386";
#elif POCO_ARCH == POCO_ARCH_MIPS
return "mips";
#elif POCO_ARCH == POCO_ARCH_PPC
return "ppc";
#elif POCO_ARCH == POCO_ARCH_ARM
return "arm";
#elif POCO_ARCH == POCO_ARCH_SH
return "sh";
#else
return "unknown";
#endif
}
std::string EnvironmentImpl::nodeNameImpl()
{
char buffer[64];
if (gethostname(buffer, sizeof(buffer)) == OK)
return buffer;
else
return "unknown";
}
unsigned EnvironmentImpl::processorCountImpl()
{
return 1;
}
void EnvironmentImpl::nodeIdImpl(NodeId& id)
{
std::memset(&id, 0, sizeof(id));
int ifIndex = 0;
char ifName[32];
char ifAddr[4];
int s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (s == -1) return;
for (;;)
{
if (ifIndexToIfName(ifIndex, ifName) == OK)
{
if (ifAddrGet(ifName, ifAddr) == OK)
{
struct arpreq ar;
std::memset(&ar, 0, sizeof(ar));
struct sockaddr_in* pAddr = reinterpret_cast<struct sockaddr_in*>(&ar.arp_pa);
pAddr->sin_family = AF_INET;
std::memcpy(&pAddr->sin_addr, ifAddr, sizeof(struct in_addr));
int rc = ioctl(s, SIOCGARP, reinterpret_cast<int>(&ar));
if (rc < 0) continue;
std::memcpy(&id, ar.arp_ha.sa_data, sizeof(id));
close(s);
return;
}
}
else break;
}
close(s);
throw SystemException("cannot get Ethernet hardware address");
}
} // namespace Poco

View File

@ -0,0 +1,259 @@
//
// Environment_WINCE.cpp
//
// $Id: //poco/1.4/Foundation/src/Environment_WINCE.cpp#1 $
//
// Library: Foundation
// Package: Core
// Module: Environment
//
// Copyright (c) 2009-2010, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Environment_WINCE.h"
#include "Poco/Exception.h"
#include "Poco/UnicodeConverter.h"
#include "Poco/String.h"
#include "Poco/Path.h"
#include "Poco/NumberFormatter.h"
#include <sstream>
#include <cstring>
#include <windows.h>
#include <iphlpapi.h>
namespace Poco {
const std::string EnvironmentImpl::TEMP("TEMP");
const std::string EnvironmentImpl::TMP("TMP");
const std::string EnvironmentImpl::HOMEPATH("HOMEPATH");
const std::string EnvironmentImpl::COMPUTERNAME("COMPUTERNAME");
const std::string EnvironmentImpl::OS("OS");
const std::string EnvironmentImpl::NUMBER_OF_PROCESSORS("NUMBER_OF_PROCESSORS");
const std::string EnvironmentImpl::PROCESSOR_ARCHITECTURE("PROCESSOR_ARCHITECTURE");
std::string EnvironmentImpl::getImpl(const std::string& name)
{
std::string value;
if (!envVar(name, &value)) throw NotFoundException(name);
return value;
}
bool EnvironmentImpl::hasImpl(const std::string& name)
{
return envVar(name, 0);
}
void EnvironmentImpl::setImpl(const std::string& name, const std::string& value)
{
throw NotImplementedException("Cannot set environment variables on Windows CE");
}
std::string EnvironmentImpl::osNameImpl()
{
return "Windows CE";
}
std::string EnvironmentImpl::osVersionImpl()
{
OSVERSIONINFOW vi;
vi.dwOSVersionInfoSize = sizeof(vi);
if (GetVersionExW(&vi) == 0) throw SystemException("Cannot get OS version information");
std::ostringstream str;
str << vi.dwMajorVersion << "." << vi.dwMinorVersion << " (Build " << (vi.dwBuildNumber & 0xFFFF);
std::string version;
UnicodeConverter::toUTF8(vi.szCSDVersion, version);
if (!version.empty()) str << ": " << version;
str << ")";
return str.str();
}
std::string EnvironmentImpl::osArchitectureImpl()
{
SYSTEM_INFO si;
GetSystemInfo(&si);
switch (si.wProcessorArchitecture)
{
case PROCESSOR_ARCHITECTURE_INTEL:
return "IA32";
case PROCESSOR_ARCHITECTURE_MIPS:
return "MIPS";
case PROCESSOR_ARCHITECTURE_ALPHA:
return "ALPHA";
case PROCESSOR_ARCHITECTURE_PPC:
return "PPC";
case PROCESSOR_ARCHITECTURE_IA64:
return "IA64";
#ifdef PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
return "IA64/32";
#endif
#ifdef PROCESSOR_ARCHITECTURE_AMD64
case PROCESSOR_ARCHITECTURE_AMD64:
return "AMD64";
#endif
case PROCESSOR_ARCHITECTURE_SHX:
return "SHX";
case PROCESSOR_ARCHITECTURE_ARM:
return "ARM";
default:
return "Unknown";
}
}
std::string EnvironmentImpl::nodeNameImpl()
{
HKEY hKey;
DWORD dwDisposition;
if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"\\Ident", 0, 0, 0, 0, 0, &hKey, &dwDisposition) != ERROR_SUCCESS)
throw SystemException("Cannot get node name", "registry key not found");
std::string value;
DWORD dwType;
BYTE bData[1026];
DWORD dwData = sizeof(bData);
if (RegQueryValueExW(hKey, L"Name", 0, &dwType, bData, &dwData) == ERROR_SUCCESS)
{
switch (dwType)
{
case REG_SZ:
UnicodeConverter::toUTF8(reinterpret_cast<wchar_t*>(bData), value);
break;
default:
RegCloseKey(hKey);
throw SystemException("Cannot get node name", "registry value has wrong type");
}
}
else
{
RegCloseKey(hKey);
throw SystemException("Cannot get node name", "registry value not found");
}
RegCloseKey(hKey);
return value;
}
void EnvironmentImpl::nodeIdImpl(NodeId& id)
{
PIP_ADAPTER_INFO pAdapterInfo;
PIP_ADAPTER_INFO pAdapter = 0;
ULONG len = sizeof(IP_ADAPTER_INFO);
pAdapterInfo = reinterpret_cast<IP_ADAPTER_INFO*>(new char[len]);
// Make an initial call to GetAdaptersInfo to get
// the necessary size into len
DWORD rc = GetAdaptersInfo(pAdapterInfo, &len);
if (rc == ERROR_BUFFER_OVERFLOW)
{
delete [] reinterpret_cast<char*>(pAdapterInfo);
pAdapterInfo = reinterpret_cast<IP_ADAPTER_INFO*>(new char[len]);
}
else if (rc != ERROR_SUCCESS)
{
throw SystemException("cannot get network adapter list");
}
try
{
bool found = false;
if (GetAdaptersInfo(pAdapterInfo, &len) == NO_ERROR)
{
pAdapter = pAdapterInfo;
while (pAdapter && !found)
{
if (pAdapter->Type == MIB_IF_TYPE_ETHERNET && pAdapter->AddressLength == sizeof(id))
{
std::memcpy(&id, pAdapter->Address, pAdapter->AddressLength);
found = true;
}
pAdapter = pAdapter->Next;
}
}
else throw SystemException("cannot get network adapter list");
if (!found) throw SystemException("no Ethernet adapter found");
}
catch (Exception&)
{
delete [] reinterpret_cast<char*>(pAdapterInfo);
throw;
}
delete [] reinterpret_cast<char*>(pAdapterInfo);
}
unsigned EnvironmentImpl::processorCountImpl()
{
SYSTEM_INFO si;
GetSystemInfo(&si);
return si.dwNumberOfProcessors;
}
bool EnvironmentImpl::envVar(const std::string& name, std::string* value)
{
if (icompare(name, TEMP) == 0)
{
if (value) *value = Path::temp();
}
else if (icompare(name, TMP) == 0)
{
if (value) *value = Path::temp();
}
else if (icompare(name, HOMEPATH) == 0)
{
if (value) *value = Path::home();
}
else if (icompare(name, COMPUTERNAME) == 0)
{
if (value) *value = nodeNameImpl();
}
else if (icompare(name, OS) == 0)
{
if (value) *value = osNameImpl();
}
else if (icompare(name, NUMBER_OF_PROCESSORS) == 0)
{
if (value) *value = NumberFormatter::format(processorCountImpl());
}
else if (icompare(name, PROCESSOR_ARCHITECTURE) == 0)
{
if (value) *value = osArchitectureImpl();
}
else return false;
return true;
}
} // namespace Poco

388
Foundation/src/File_VX.cpp Normal file
View File

@ -0,0 +1,388 @@
//
// File_VX.cpp
//
// $Id: //poco/1.4/Foundation/src/File_VX.cpp#1 $
//
// Library: Foundation
// Package: Filesystem
// Module: File
//
// Copyright (c) 2004-2011, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/File_VX.h"
#include "Poco/Buffer.h"
#include "Poco/Exception.h"
#include <algorithm>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <utime.h>
#include <cstring>
namespace Poco {
FileImpl::FileImpl()
{
}
FileImpl::FileImpl(const std::string& path): _path(path)
{
std::string::size_type n = _path.size();
if (n > 1 && _path[n - 1] == '/')
_path.resize(n - 1);
}
FileImpl::~FileImpl()
{
}
void FileImpl::swapImpl(FileImpl& file)
{
std::swap(_path, file._path);
}
void FileImpl::setPathImpl(const std::string& path)
{
_path = path;
std::string::size_type n = _path.size();
if (n > 1 && _path[n - 1] == '/')
_path.resize(n - 1);
}
bool FileImpl::existsImpl() const
{
poco_assert (!_path.empty());
struct stat st;
return stat(const_cast<char*>(_path.c_str()), &st) == 0;
}
bool FileImpl::canReadImpl() const
{
poco_assert (!_path.empty());
return true;
}
bool FileImpl::canWriteImpl() const
{
poco_assert (!_path.empty());
return true;
}
bool FileImpl::canExecuteImpl() const
{
return false;
}
bool FileImpl::isFileImpl() const
{
poco_assert (!_path.empty());
struct stat st;
if (stat(const_cast<char*>(_path.c_str()), &st) == 0)
return S_ISREG(st.st_mode);
else
handleLastErrorImpl(_path);
return false;
}
bool FileImpl::isDirectoryImpl() const
{
poco_assert (!_path.empty());
struct stat st;
if (stat(const_cast<char*>(_path.c_str()), &st) == 0)
return S_ISDIR(st.st_mode);
else
handleLastErrorImpl(_path);
return false;
}
bool FileImpl::isLinkImpl() const
{
return false;
}
bool FileImpl::isDeviceImpl() const
{
poco_assert (!_path.empty());
struct stat st;
if (stat(const_cast<char*>(_path.c_str()), &st) == 0)
return S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode);
else
handleLastErrorImpl(_path);
return false;
}
bool FileImpl::isHiddenImpl() const
{
poco_assert (!_path.empty());
Path p(_path);
p.makeFile();
return p.getFileName()[0] == '.';
}
Timestamp FileImpl::createdImpl() const
{
poco_assert (!_path.empty());
struct stat st;
if (stat(const_cast<char*>(_path.c_str()), &st) == 0)
return Timestamp::fromEpochTime(st.st_ctime);
else
handleLastErrorImpl(_path);
return 0;
}
Timestamp FileImpl::getLastModifiedImpl() const
{
poco_assert (!_path.empty());
struct stat st;
if (stat(const_cast<char*>(_path.c_str()), &st) == 0)
return Timestamp::fromEpochTime(st.st_mtime);
else
handleLastErrorImpl(_path);
return 0;
}
void FileImpl::setLastModifiedImpl(const Timestamp& ts)
{
poco_assert (!_path.empty());
struct utimbuf tb;
tb.actime = ts.epochTime();
tb.modtime = ts.epochTime();
if (utime(const_cast<char*>(_path.c_str()), &tb) != 0)
handleLastErrorImpl(_path);
}
FileImpl::FileSizeImpl FileImpl::getSizeImpl() const
{
poco_assert (!_path.empty());
struct stat st;
if (stat(const_cast<char*>(_path.c_str()), &st) == 0)
return st.st_size;
else
handleLastErrorImpl(_path);
return 0;
}
void FileImpl::setSizeImpl(FileSizeImpl size)
{
poco_assert (!_path.empty());
int fd = open(_path.c_str(), O_WRONLY, S_IRWXU);
if (fd != -1)
{
try
{
if (ftruncate(fd, size) != 0)
handleLastErrorImpl(_path);
}
catch (...)
{
close(fd);
throw;
}
}
}
void FileImpl::setWriteableImpl(bool flag)
{
poco_assert (!_path.empty());
}
void FileImpl::setExecutableImpl(bool flag)
{
poco_assert (!_path.empty());
}
void FileImpl::copyToImpl(const std::string& path) const
{
poco_assert (!_path.empty());
int sd = open(_path.c_str(), O_RDONLY, 0);
if (sd == -1) handleLastErrorImpl(_path);
struct stat st;
if (fstat(sd, &st) != 0)
{
close(sd);
handleLastErrorImpl(_path);
}
const long blockSize = st.st_blksize;
int dd = open(path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, st.st_mode & S_IRWXU);
if (dd == -1)
{
close(sd);
handleLastErrorImpl(path);
}
Buffer<char> buffer(blockSize);
try
{
int n;
while ((n = read(sd, buffer.begin(), blockSize)) > 0)
{
if (write(dd, buffer.begin(), n) != n)
handleLastErrorImpl(path);
}
if (n < 0)
handleLastErrorImpl(_path);
}
catch (...)
{
close(sd);
close(dd);
throw;
}
close(sd);
close(dd);
}
void FileImpl::renameToImpl(const std::string& path)
{
poco_assert (!_path.empty());
if (rename(_path.c_str(), path.c_str()) != 0)
handleLastErrorImpl(_path);
}
void FileImpl::removeImpl()
{
poco_assert (!_path.empty());
int rc;
if (!isLinkImpl() && isDirectoryImpl())
rc = rmdir(_path.c_str());
else
rc = unlink(const_cast<char*>(_path.c_str()));
if (rc) handleLastErrorImpl(_path);
}
bool FileImpl::createFileImpl()
{
poco_assert (!_path.empty());
int n = open(_path.c_str(), O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
if (n != -1)
{
close(n);
return true;
}
if (n == -1 && errno == EEXIST)
return false;
else
handleLastErrorImpl(_path);
return false;
}
bool FileImpl::createDirectoryImpl()
{
poco_assert (!_path.empty());
if (existsImpl() && isDirectoryImpl())
return false;
if (mkdir(_path.c_str()) != 0)
handleLastErrorImpl(_path);
return true;
}
void FileImpl::handleLastErrorImpl(const std::string& path)
{
switch (errno)
{
case EIO:
throw IOException(path);
case EPERM:
throw FileAccessDeniedException("insufficient permissions", path);
case EACCES:
throw FileAccessDeniedException(path);
case ENOENT:
throw FileNotFoundException(path);
case ENOTDIR:
throw OpenFileException("not a directory", path);
case EISDIR:
throw OpenFileException("not a file", path);
case EROFS:
throw FileReadOnlyException(path);
case EEXIST:
throw FileExistsException(path);
case ENOSPC:
throw FileException("no space left on device", path);
case ENOTEMPTY:
throw FileException("directory not empty", path);
case ENAMETOOLONG:
throw PathSyntaxException(path);
case ENFILE:
case EMFILE:
throw FileException("too many open files", path);
default:
throw FileException(std::strerror(errno), path);
}
}
} // namespace Poco

View File

@ -0,0 +1,423 @@
//
// File_WIN32U.cpp
//
// $Id: //poco/1.4/Foundation/src/File_WINCE.cpp#1 $
//
// Library: Foundation
// Package: Filesystem
// Module: File
//
// Copyright (c) 2006-2010, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/File_WINCE.h"
#include "Poco/Exception.h"
#include "Poco/String.h"
#include "Poco/UnicodeConverter.h"
#include "Poco/Path.h"
#include "Poco/UnWindows.h"
namespace Poco {
class FileHandle
{
public:
FileHandle(const std::string& path, const std::wstring& upath, DWORD access, DWORD share, DWORD disp)
{
_h = CreateFileW(upath.c_str(), access, share, 0, disp, 0, 0);
if (_h == INVALID_HANDLE_VALUE)
{
FileImpl::handleLastErrorImpl(path);
}
}
~FileHandle()
{
if (_h != INVALID_HANDLE_VALUE) CloseHandle(_h);
}
HANDLE get() const
{
return _h;
}
private:
HANDLE _h;
};
FileImpl::FileImpl()
{
}
FileImpl::FileImpl(const std::string& path): _path(path)
{
std::string::size_type n = _path.size();
if (n > 1 && (_path[n - 1] == '\\' || _path[n - 1] == '/') && !((n == 3 && _path[1]==':')))
{
_path.resize(n - 1);
}
UnicodeConverter::toUTF16(_path, _upath);
}
FileImpl::~FileImpl()
{
}
void FileImpl::swapImpl(FileImpl& file)
{
std::swap(_path, file._path);
std::swap(_upath, file._upath);
}
void FileImpl::setPathImpl(const std::string& path)
{
_path = path;
std::string::size_type n = _path.size();
if (n > 1 && (_path[n - 1] == '\\' || _path[n - 1] == '/') && !((n == 3 && _path[1]==':')))
{
_path.resize(n - 1);
}
UnicodeConverter::toUTF16(_path, _upath);
}
bool FileImpl::existsImpl() const
{
poco_assert (!_path.empty());
DWORD attr = GetFileAttributesW(_upath.c_str());
if (attr == 0xFFFFFFFF)
{
switch (GetLastError())
{
case ERROR_FILE_NOT_FOUND:
case ERROR_PATH_NOT_FOUND:
case ERROR_NOT_READY:
case ERROR_INVALID_DRIVE:
return false;
default:
handleLastErrorImpl(_path);
}
}
return true;
}
bool FileImpl::canReadImpl() const
{
poco_assert (!_path.empty());
DWORD attr = GetFileAttributesW(_upath.c_str());
if (attr == 0xFFFFFFFF)
{
switch (GetLastError())
{
case ERROR_ACCESS_DENIED:
return false;
default:
handleLastErrorImpl(_path);
}
}
return true;
}
bool FileImpl::canWriteImpl() const
{
poco_assert (!_path.empty());
DWORD attr = GetFileAttributesW(_upath.c_str());
if (attr == 0xFFFFFFFF)
handleLastErrorImpl(_path);
return (attr & FILE_ATTRIBUTE_READONLY) == 0;
}
bool FileImpl::canExecuteImpl() const
{
Path p(_path);
return icompare(p.getExtension(), "exe") == 0;
}
bool FileImpl::isFileImpl() const
{
return !isDirectoryImpl() && !isDeviceImpl();
}
bool FileImpl::isDirectoryImpl() const
{
poco_assert (!_path.empty());
DWORD attr = GetFileAttributesW(_upath.c_str());
if (attr == 0xFFFFFFFF)
handleLastErrorImpl(_path);
return (attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
}
bool FileImpl::isLinkImpl() const
{
return false;
}
bool FileImpl::isDeviceImpl() const
{
return false;
}
bool FileImpl::isHiddenImpl() const
{
poco_assert (!_path.empty());
DWORD attr = GetFileAttributesW(_upath.c_str());
if (attr == 0xFFFFFFFF)
handleLastErrorImpl(_path);
return (attr & FILE_ATTRIBUTE_HIDDEN) != 0;
}
Timestamp FileImpl::createdImpl() const
{
poco_assert (!_path.empty());
WIN32_FILE_ATTRIBUTE_DATA fad;
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
handleLastErrorImpl(_path);
return Timestamp::fromFileTimeNP(fad.ftCreationTime.dwLowDateTime, fad.ftCreationTime.dwHighDateTime);
}
Timestamp FileImpl::getLastModifiedImpl() const
{
poco_assert (!_path.empty());
WIN32_FILE_ATTRIBUTE_DATA fad;
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
handleLastErrorImpl(_path);
return Timestamp::fromFileTimeNP(fad.ftLastWriteTime.dwLowDateTime, fad.ftLastWriteTime.dwHighDateTime);
}
void FileImpl::setLastModifiedImpl(const Timestamp& ts)
{
poco_assert (!_path.empty());
UInt32 low;
UInt32 high;
ts.toFileTimeNP(low, high);
FILETIME ft;
ft.dwLowDateTime = low;
ft.dwHighDateTime = high;
FileHandle fh(_path, _upath, GENERIC_WRITE, FILE_SHARE_WRITE, OPEN_EXISTING);
if (SetFileTime(fh.get(), 0, &ft, &ft) == 0)
handleLastErrorImpl(_path);
}
FileImpl::FileSizeImpl FileImpl::getSizeImpl() const
{
poco_assert (!_path.empty());
WIN32_FILE_ATTRIBUTE_DATA fad;
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
handleLastErrorImpl(_path);
LARGE_INTEGER li;
li.LowPart = fad.nFileSizeLow;
li.HighPart = fad.nFileSizeHigh;
return li.QuadPart;
}
void FileImpl::setSizeImpl(FileSizeImpl size)
{
poco_assert (!_path.empty());
FileHandle fh(_path, _upath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING);
LARGE_INTEGER li;
li.QuadPart = size;
if (SetFilePointer(fh.get(), li.LowPart, &li.HighPart, FILE_BEGIN) == -1)
handleLastErrorImpl(_path);
if (SetEndOfFile(fh.get()) == 0)
handleLastErrorImpl(_path);
}
void FileImpl::setWriteableImpl(bool flag)
{
poco_assert (!_path.empty());
DWORD attr = GetFileAttributesW(_upath.c_str());
if (attr == -1)
handleLastErrorImpl(_path);
if (flag)
attr &= ~FILE_ATTRIBUTE_READONLY;
else
attr |= FILE_ATTRIBUTE_READONLY;
if (SetFileAttributesW(_upath.c_str(), attr) == 0)
handleLastErrorImpl(_path);
}
void FileImpl::setExecutableImpl(bool flag)
{
// not supported
}
void FileImpl::copyToImpl(const std::string& path) const
{
poco_assert (!_path.empty());
std::wstring upath;
UnicodeConverter::toUTF16(path, upath);
if (CopyFileW(_upath.c_str(), upath.c_str(), FALSE) != 0)
{
FileImpl copy(path);
copy.setWriteableImpl(true);
}
else handleLastErrorImpl(_path);
}
void FileImpl::renameToImpl(const std::string& path)
{
poco_assert (!_path.empty());
std::wstring upath;
UnicodeConverter::toUTF16(path, upath);
if (MoveFileW(_upath.c_str(), upath.c_str()) == 0)
handleLastErrorImpl(_path);
}
void FileImpl::removeImpl()
{
poco_assert (!_path.empty());
if (isDirectoryImpl())
{
if (RemoveDirectoryW(_upath.c_str()) == 0)
handleLastErrorImpl(_path);
}
else
{
if (DeleteFileW(_upath.c_str()) == 0)
handleLastErrorImpl(_path);
}
}
bool FileImpl::createFileImpl()
{
poco_assert (!_path.empty());
HANDLE hFile = CreateFileW(_upath.c_str(), GENERIC_WRITE, 0, 0, CREATE_NEW, 0, 0);
if (hFile != INVALID_HANDLE_VALUE)
{
CloseHandle(hFile);
return true;
}
else if (GetLastError() == ERROR_FILE_EXISTS)
return false;
else
handleLastErrorImpl(_path);
return false;
}
bool FileImpl::createDirectoryImpl()
{
poco_assert (!_path.empty());
if (existsImpl() && isDirectoryImpl())
return false;
if (CreateDirectoryW(_upath.c_str(), 0) == 0)
handleLastErrorImpl(_path);
return true;
}
void FileImpl::handleLastErrorImpl(const std::string& path)
{
switch (GetLastError())
{
case ERROR_FILE_NOT_FOUND:
throw FileNotFoundException(path);
case ERROR_PATH_NOT_FOUND:
case ERROR_BAD_NETPATH:
case ERROR_CANT_RESOLVE_FILENAME:
case ERROR_INVALID_DRIVE:
throw PathNotFoundException(path);
case ERROR_ACCESS_DENIED:
throw FileAccessDeniedException(path);
case ERROR_ALREADY_EXISTS:
case ERROR_FILE_EXISTS:
throw FileExistsException(path);
case ERROR_INVALID_NAME:
case ERROR_DIRECTORY:
case ERROR_FILENAME_EXCED_RANGE:
case ERROR_BAD_PATHNAME:
throw PathSyntaxException(path);
case ERROR_FILE_READ_ONLY:
throw FileReadOnlyException(path);
case ERROR_CANNOT_MAKE:
throw CreateFileException(path);
case ERROR_DIR_NOT_EMPTY:
throw FileException("directory not empty", path);
case ERROR_WRITE_FAULT:
throw WriteFileException(path);
case ERROR_READ_FAULT:
throw ReadFileException(path);
case ERROR_SHARING_VIOLATION:
throw FileException("sharing violation", path);
case ERROR_LOCK_VIOLATION:
throw FileException("lock violation", path);
case ERROR_HANDLE_EOF:
throw ReadFileException("EOF reached", path);
case ERROR_HANDLE_DISK_FULL:
case ERROR_DISK_FULL:
throw WriteFileException("disk is full", path);
case ERROR_NEGATIVE_SEEK:
throw FileException("negative seek", path);
default:
throw FileException(path);
}
}
} // namespace Poco

View File

@ -0,0 +1,79 @@
//
// MemoryStream.cpp
//
// $Id: //poco/1.4/Foundation/src/MemoryStream.cpp#1 $
//
// Library: Foundation
// Package: Streams
// Module: MemoryStream
//
// Copyright (c) 2009, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/MemoryStream.h"
namespace Poco {
MemoryIOS::MemoryIOS(char* pBuffer, std::streamsize bufferSize):
_buf(pBuffer, bufferSize)
{
poco_ios_init(&_buf);
}
MemoryIOS::~MemoryIOS()
{
}
MemoryInputStream::MemoryInputStream(const char* pBuffer, std::streamsize bufferSize):
MemoryIOS(const_cast<char*>(pBuffer), bufferSize),
std::istream(&_buf)
{
}
MemoryInputStream::~MemoryInputStream()
{
}
MemoryOutputStream::MemoryOutputStream(char* pBuffer, std::streamsize bufferSize):
MemoryIOS(pBuffer, bufferSize),
std::ostream(&_buf)
{
}
MemoryOutputStream::~MemoryOutputStream()
{
}
} // namespace Poco

View File

@ -0,0 +1,102 @@
//
// Mutex_WINCE.cpp
//
// $Id: //poco/1.4/Foundation/src/Mutex_WINCE.cpp#1 $
//
// Library: Foundation
// Package: Threading
// Module: Mutex
//
// Copyright (c) 2004-2010, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Mutex_WINCE.h"
namespace Poco {
MutexImpl::MutexImpl()
{
_mutex = CreateMutexW(NULL, FALSE, NULL);
if (!_mutex) throw SystemException("cannot create mutex");
}
MutexImpl::~MutexImpl()
{
CloseHandle(_mutex);
}
void MutexImpl::lockImpl()
{
switch (WaitForSingleObject(_mutex, INFINITE))
{
case WAIT_OBJECT_0:
return;
default:
throw SystemException("cannot lock mutex");
}
}
bool MutexImpl::tryLockImpl()
{
switch (WaitForSingleObject(_mutex, 0))
{
case WAIT_TIMEOUT:
return false;
case WAIT_OBJECT_0:
return true;
default:
throw SystemException("cannot lock mutex");
}
}
bool MutexImpl::tryLockImpl(long milliseconds)
{
switch (WaitForSingleObject(_mutex, milliseconds + 1))
{
case WAIT_TIMEOUT:
return false;
case WAIT_OBJECT_0:
return true;
default:
throw SystemException("cannot lock mutex");
}
}
void MutexImpl::unlockImpl()
{
ReleaseMutex(_mutex);
}
} // namespace Poco

View File

@ -0,0 +1,145 @@
//
// Path_WIN32U.cpp
//
// $Id: //poco/1.4/Foundation/src/Path_WINCE.cpp#1 $
//
// Library: Foundation
// Package: Filesystem
// Module: Path
//
// Copyright (c) 2006-2010, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Path_WINCE.h"
#include "Poco/Environment_WINCE.h"
#include "Poco/UnicodeConverter.h"
#include "Poco/Buffer.h"
#include "Poco/Environment.h"
#include "Poco/Exception.h"
#include "Poco/UnWindows.h"
namespace Poco {
std::string PathImpl::currentImpl()
{
return("\\");
}
std::string PathImpl::homeImpl()
{
return("\\");
}
std::string PathImpl::tempImpl()
{
Buffer<wchar_t> buffer(MAX_PATH_LEN);
DWORD n = GetTempPathW(static_cast<DWORD>(buffer.size()), buffer.begin());
if (n > 0)
{
std::string result;
UnicodeConverter::toUTF8(buffer.begin(), result);
if (result[n - 1] != '\\')
result.append("\\");
return result;
}
throw SystemException("Cannot get current directory");
}
std::string PathImpl::nullImpl()
{
return "NUL:";
}
std::string PathImpl::expandImpl(const std::string& path)
{
std::string result;
std::string::const_iterator it = path.begin();
std::string::const_iterator end = path.end();
while (it != end)
{
if (*it == '%')
{
++it;
if (it != end && *it == '%')
{
result += '%';
}
else
{
std::string var;
while (it != end && *it != '%') var += *it++;
if (it != end) ++it;
result += Environment::get(var, "");
}
}
else result += *it++;
}
return result;
}
void PathImpl::listRootsImpl(std::vector<std::string>& roots)
{
roots.clear();
roots.push_back("\\");
WIN32_FIND_DATAW fd;
HANDLE hFind = FindFirstFileW(L"\\*.*", &fd);
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
(fd.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY))
{
std::wstring name(fd.cFileName);
name += L"\\Vol:";
HANDLE h = CreateFileW(name.c_str(), GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (h != INVALID_HANDLE_VALUE)
{
// its a device volume
CloseHandle(h);
std::string name;
UnicodeConverter::toUTF8(fd.cFileName, name);
std::string root = "\\" + name;
roots.push_back(root);
}
}
}
while (FindNextFileW(hFind, &fd));
FindClose(hFind);
}
}
} // namespace Poco

View File

@ -0,0 +1,104 @@
//
// Process_VX.cpp
//
// $Id: //poco/1.4/Foundation/src/Process_VX.cpp#1 $
//
// Library: Foundation
// Package: Processes
// Module: Process
//
// Copyright (c) 2004-2011, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Process_VX.h"
#include "Poco/Exception.h"
namespace Poco {
//
// ProcessHandleImpl
//
ProcessHandleImpl::ProcessHandleImpl(int pid):
_pid(pid)
{
}
ProcessHandleImpl::~ProcessHandleImpl()
{
}
int ProcessHandleImpl::id() const
{
return _pid;
}
int ProcessHandleImpl::wait() const
{
throw Poco::NotImplementedException("Process::wait()");
}
//
// ProcessImpl
//
ProcessImpl::PIDImpl ProcessImpl::idImpl()
{
return 0;
}
void ProcessImpl::timesImpl(long& userTime, long& kernelTime)
{
userTime = 0;
kernelTime = 0;
}
ProcessHandleImpl* ProcessImpl::launchImpl(const std::string& command, const ArgsImpl& args, Pipe* inPipe, Pipe* outPipe, Pipe* errPipe)
{
throw Poco::NotImplementedException("Process::launch()");
}
void ProcessImpl::killImpl(PIDImpl pid)
{
throw Poco::NotImplementedException("Process::kill()");
}
void ProcessImpl::requestTerminationImpl(PIDImpl pid)
{
throw Poco::NotImplementedException("Process::requestTermination()");
}
} // namespace Poco

View File

@ -0,0 +1,197 @@
//
// Process_WINCE.cpp
//
// $Id: //poco/1.4/Foundation/src/Process_WINCE.cpp#1 $
//
// Library: Foundation
// Package: Processes
// Module: Process
//
// Copyright (c) 2004-2010, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Process_WINCE.h"
#include "Poco/Exception.h"
#include "Poco/NumberFormatter.h"
#include "Poco/NamedEvent.h"
#include "Poco/UnicodeConverter.h"
#include "Poco/Pipe.h"
namespace Poco {
//
// ProcessHandleImpl
//
ProcessHandleImpl::ProcessHandleImpl(HANDLE hProcess, UInt32 pid):
_hProcess(hProcess),
_pid(pid)
{
}
ProcessHandleImpl::~ProcessHandleImpl()
{
CloseHandle(_hProcess);
}
UInt32 ProcessHandleImpl::id() const
{
return _pid;
}
int ProcessHandleImpl::wait() const
{
DWORD rc = WaitForSingleObject(_hProcess, INFINITE);
if (rc != WAIT_OBJECT_0)
throw SystemException("Wait failed for process", NumberFormatter::format(_pid));
DWORD exitCode;
if (GetExitCodeProcess(_hProcess, &exitCode) == 0)
throw SystemException("Cannot get exit code for process", NumberFormatter::format(_pid));
return exitCode;
}
//
// ProcessImpl
//
ProcessImpl::PIDImpl ProcessImpl::idImpl()
{
return GetCurrentProcessId();
}
void ProcessImpl::timesImpl(long& userTime, long& kernelTime)
{
FILETIME ftCreation;
FILETIME ftExit;
FILETIME ftKernel;
FILETIME ftUser;
if (GetThreadTimes(GetCurrentThread(), &ftCreation, &ftExit, &ftKernel, &ftUser) != 0)
{
ULARGE_INTEGER time;
time.LowPart = ftKernel.dwLowDateTime;
time.HighPart = ftKernel.dwHighDateTime;
kernelTime = long(time.QuadPart/10000000L);
time.LowPart = ftUser.dwLowDateTime;
time.HighPart = ftUser.dwHighDateTime;
userTime = long(time.QuadPart/10000000L);
}
else
{
userTime = kernelTime = -1;
}
}
ProcessHandleImpl* ProcessImpl::launchImpl(const std::string& command, const ArgsImpl& args, Pipe* inPipe, Pipe* outPipe, Pipe* errPipe)
{
std::wstring ucommand;
UnicodeConverter::toUTF16(command, ucommand);
std::string commandLine;
for (ArgsImpl::const_iterator it = args.begin(); it != args.end(); ++it)
{
if (it != args.begin()) commandLine.append(" ");
commandLine.append(*it);
}
std::wstring ucommandLine;
UnicodeConverter::toUTF16(commandLine, ucommandLine);
PROCESS_INFORMATION processInfo;
BOOL rc = CreateProcessW(
ucommand.c_str(),
const_cast<wchar_t*>(ucommandLine.c_str()),
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
NULL/*&startupInfo*/,
&processInfo
);
if (rc)
{
CloseHandle(processInfo.hThread);
return new ProcessHandleImpl(processInfo.hProcess, processInfo.dwProcessId);
}
else throw SystemException("Cannot launch process", command);
}
void ProcessImpl::killImpl(PIDImpl pid)
{
HANDLE hProc = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
if (hProc)
{
if (TerminateProcess(hProc, 0) == 0)
{
CloseHandle(hProc);
throw SystemException("cannot kill process");
}
CloseHandle(hProc);
}
else
{
switch (GetLastError())
{
case ERROR_ACCESS_DENIED:
throw NoPermissionException("cannot kill process");
case ERROR_NOT_FOUND:
throw NotFoundException("cannot kill process");
default:
throw SystemException("cannot kill process");
}
}
}
void ProcessImpl::requestTerminationImpl(PIDImpl pid)
{
NamedEvent ev(terminationEventName(pid));
ev.set();
}
std::string ProcessImpl::terminationEventName(PIDImpl pid)
{
std::string evName("POCOTRM");
NumberFormatter::appendHex(evName, pid, 8);
return evName;
}
} // namespace Poco

View File

@ -0,0 +1,70 @@
//
// RWLock_VX.cpp
//
// $Id: //poco/1.4/Foundation/src/RWLock_VX.cpp#2 $
//
// Library: Foundation
// Package: Threading
// Module: RWLock
//
// Copyright (c) 2004-2011, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/RWLock_VX.h"
#include <cstring>
namespace Poco {
RWLockImpl::RWLockImpl()
{
#if defined(POCO_VXWORKS)
// This workaround is for VxWorks 5.x where
// pthread_mutex_init() won't properly initialize the mutex
// resulting in a subsequent freeze in pthread_mutex_destroy()
// if the mutex has never been used.
std::memset(&_mutex, 0, sizeof(_mutex));
#endif
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
if (pthread_mutex_init(&_mutex, &attr))
{
pthread_mutexattr_destroy(&attr);
throw SystemException("cannot create mutex");
}
pthread_mutexattr_destroy(&attr);
}
RWLockImpl::~RWLockImpl()
{
pthread_mutex_destroy(&_mutex);
}
} // namespace Poco

View File

@ -0,0 +1,196 @@
//
// RWLock_WINCE.cpp
//
// $Id: //poco/1.4/Foundation/src/RWLock_WINCE.cpp#1 $
//
// Library: Foundation
// Package: Threading
// Module: RWLock
//
// Copyright (c) 2009-2010, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/RWLock_WINCE.h"
#include "Poco/Thread.h"
namespace Poco {
RWLockImpl::RWLockImpl():
_readerCount(0),
_readerWaiting(0),
_writerCount(0),
_writerWaiting(0),
_writeLock(false)
{
InitializeCriticalSection(&_cs);
_readerGreen = CreateEventW(NULL, FALSE, TRUE, NULL);
if (!_readerGreen) throw SystemException("Cannot create RWLock");
_writerGreen = CreateEventW(NULL, FALSE, TRUE, NULL);
if (!_writerGreen)
{
CloseHandle(_readerGreen);
throw SystemException("Cannot create RWLock");
}
}
RWLockImpl::~RWLockImpl()
{
CloseHandle(_readerGreen);
CloseHandle(_writerGreen);
DeleteCriticalSection(&_cs);
}
void RWLockImpl::readLockImpl()
{
tryReadLockImpl(INFINITE);
}
bool RWLockImpl::tryReadLockImpl(DWORD timeout)
{
bool wait = false;
do
{
EnterCriticalSection(&_cs);
if (!_writerCount && !_writerWaiting)
{
if (wait)
{
_readerWaiting--;
wait = false;
}
_readerCount++;
}
else
{
if (!wait)
{
_readerWaiting++;
wait = true;
}
ResetEvent(_readerGreen);
}
LeaveCriticalSection(&_cs);
if (wait)
{
if (WaitForSingleObject(_readerGreen, timeout) != WAIT_OBJECT_0)
{
EnterCriticalSection(&_cs);
_readerWaiting--;
SetEvent(_readerGreen);
SetEvent(_writerGreen);
LeaveCriticalSection(&_cs);
return false;
}
}
}
while (wait);
return true;
}
void RWLockImpl::writeLockImpl()
{
tryWriteLockImpl(INFINITE);
}
bool RWLockImpl::tryWriteLockImpl(DWORD timeout)
{
bool wait = false;
do
{
EnterCriticalSection(&_cs);
if (!_readerCount && !_writerCount)
{
if (wait)
{
_writerWaiting--;
wait = false;
}
_writerCount++;
}
else
{
if (!wait)
{
_writerWaiting++;
wait = true;
}
ResetEvent(_writerGreen);
}
LeaveCriticalSection(&_cs);
if (wait)
{
if (WaitForSingleObject(_writerGreen, timeout) != WAIT_OBJECT_0)
{
EnterCriticalSection(&_cs);
_writerWaiting--;
SetEvent(_readerGreen);
SetEvent(_writerGreen);
LeaveCriticalSection(&_cs);
return false;
}
}
}
while (wait);
_writeLock = true;
return true;
}
void RWLockImpl::unlockImpl()
{
EnterCriticalSection(&_cs);
if (_writeLock)
{
_writeLock = false;
_writerCount--;
}
else
{
_readerCount--;
}
if (_writerWaiting)
SetEvent(_writerGreen);
else if (_readerWaiting)
SetEvent(_readerGreen);
LeaveCriticalSection(&_cs);
}
} // namespace Poco

View File

@ -0,0 +1,157 @@
//
// SharedLibrary_VX.cpp
//
// $Id: //poco/1.4/Foundation/src/SharedLibrary_VX.cpp#1 $
//
// Library: Foundation
// Package: SharedLibrary
// Module: SharedLibrary
//
// Copyright (c) 2004-2011, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/SharedLibrary_VX.h"
#include "Poco/Exception.h"
#include "Poco/Format.h"
#include <loadLib.h>
#include <unldLib.h>
#include <ioLib.h>
#include <symLib.h>
#include <sysSymTbl.h>
#include <cstring>
struct SymLookup
{
const char* name;
int group;
void* addr;
};
extern "C" bool lookupFunc(char* name, int val, SYM_TYPE type, int arg, UINT16 group)
{
SymLookup* symLookup = reinterpret_cast<SymLookup*>(arg);
if (group == symLookup->group && std::strcmp(name, symLookup->name) == 0)
{
symLookup->addr = reinterpret_cast<void*>(val);
return TRUE;
}
else return FALSE;
}
namespace Poco {
FastMutex SharedLibraryImpl::_mutex;
SharedLibraryImpl::SharedLibraryImpl():
_moduleId(0)
{
}
SharedLibraryImpl::~SharedLibraryImpl()
{
}
void SharedLibraryImpl::loadImpl(const std::string& path)
{
FastMutex::ScopedLock lock(_mutex);
if (_moduleId) throw LibraryAlreadyLoadedException(path);
int fd = open(const_cast<char*>(path.c_str()), O_RDONLY, 0);
if (fd)
{
_moduleId = loadModule(fd, LOAD_GLOBAL_SYMBOLS);
if (!_moduleId)
{
int err = errno;
close(fd);
throw LibraryLoadException(Poco::format("error %d", err));
}
}
else
{
int err = errno;
throw LibraryLoadException(Poco::format("cannot open library (error %d)", err));
}
_path = path;
}
void SharedLibraryImpl::unloadImpl()
{
FastMutex::ScopedLock lock(_mutex);
if (_moduleId)
{
unldByModuleId(_moduleId, 0);
_moduleId = 0;
}
}
bool SharedLibraryImpl::isLoadedImpl() const
{
return _moduleId != 0;
}
void* SharedLibraryImpl::findSymbolImpl(const std::string& name)
{
poco_assert (_moduleId != 0);
FastMutex::ScopedLock lock(_mutex);
MODULE_INFO mi;
if (!moduleInfoGet(_moduleId, &mi)) return 0;
SymLookup symLookup;
symLookup.name = name.c_str();
symLookup.group = mi.group;
symLookup.addr = 0;
symEach(sysSymTbl, reinterpret_cast<FUNCPTR>(lookupFunc), reinterpret_cast<int>(&symLookup));
return symLookup.addr;
}
const std::string& SharedLibraryImpl::getPathImpl() const
{
return _path;
}
std::string SharedLibraryImpl::suffixImpl()
{
return ".out";
}
} // namespace Poco

View File

@ -0,0 +1,200 @@
//
// TextBufferIterator.cpp
//
// $Id: //poco/1.4/Foundation/src/TextBufferIterator.cpp#1 $
//
// Library: Foundation
// Package: Text
// Module: TextBufferIterator
//
// Copyright (c) 2010, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/TextBufferIterator.h"
#include "Poco/TextEncoding.h"
#include <algorithm>
#include <cstring>
namespace Poco {
TextBufferIterator::TextBufferIterator():
_pEncoding(0),
_it(0),
_end(0)
{
}
TextBufferIterator::TextBufferIterator(const char* begin, const TextEncoding& encoding):
_pEncoding(&encoding),
_it(begin),
_end(begin + std::strlen(begin))
{
}
TextBufferIterator::TextBufferIterator(const char* begin, std::size_t size, const TextEncoding& encoding):
_pEncoding(&encoding),
_it(begin),
_end(begin + size)
{
}
TextBufferIterator::TextBufferIterator(const char* begin, const char* end, const TextEncoding& encoding):
_pEncoding(&encoding),
_it(begin),
_end(end)
{
}
TextBufferIterator::TextBufferIterator(const char* end):
_pEncoding(0),
_it(end),
_end(end)
{
}
TextBufferIterator::~TextBufferIterator()
{
}
TextBufferIterator::TextBufferIterator(const TextBufferIterator& it):
_pEncoding(it._pEncoding),
_it(it._it),
_end(it._end)
{
}
TextBufferIterator& TextBufferIterator::operator = (const TextBufferIterator& it)
{
if (&it != this)
{
_pEncoding = it._pEncoding;
_it = it._it;
_end = it._end;
}
return *this;
}
void TextBufferIterator::swap(TextBufferIterator& it)
{
std::swap(_pEncoding, it._pEncoding);
std::swap(_it, it._it);
std::swap(_end, it._end);
}
int TextBufferIterator::operator * () const
{
poco_check_ptr (_pEncoding);
poco_assert (_it != _end);
const char* it = _it;
unsigned char buffer[TextEncoding::MAX_SEQUENCE_LENGTH];
unsigned char* p = buffer;
if (it != _end)
*p++ = *it++;
else
*p++ = 0;
int read = 1;
int n = _pEncoding->queryConvert(buffer, 1);
while (-1 > n && (_end - it) >= -n - read)
{
while (read < -n && it != _end)
{
*p++ = *it++;
read++;
}
n = _pEncoding->queryConvert(buffer, read);
}
if (-1 > n)
{
return -1;
}
else
{
return n;
}
}
TextBufferIterator& TextBufferIterator::operator ++ ()
{
poco_check_ptr (_pEncoding);
poco_assert (_it != _end);
unsigned char buffer[TextEncoding::MAX_SEQUENCE_LENGTH];
unsigned char* p = buffer;
if (_it != _end)
*p++ = *_it++;
else
*p++ = 0;
int read = 1;
int n = _pEncoding->sequenceLength(buffer, 1);
while (-1 > n && (_end - _it) >= -n - read)
{
while (read < -n && _it != _end)
{
*p++ = *_it++;
read++;
}
n = _pEncoding->sequenceLength(buffer, read);
}
while (read < n && _it != _end)
{
_it++;
read++;
}
return *this;
}
TextBufferIterator TextBufferIterator::operator ++ (int)
{
TextBufferIterator prev(*this);
operator ++ ();
return prev;
}
} // namespace Poco

View File

@ -0,0 +1,227 @@
//
// Thread_WINCE.h
//
// $Id: //poco/1.4/Foundation/src/Thread_WINCE.cpp#1 $
//
// Library: Foundation
// Package: Threading
// Module: Thread
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Thread_WINCE.h"
#include "Poco/Exception.h"
#include "Poco/ErrorHandler.h"
namespace Poco {
ThreadImpl::CurrentThreadHolder ThreadImpl::_currentThreadHolder;
ThreadImpl::ThreadImpl():
_pRunnableTarget(0),
_thread(0),
_threadId(0),
_prio(PRIO_NORMAL_IMPL),
_stackSize(POCO_THREAD_STACK_SIZE)
{
}
ThreadImpl::~ThreadImpl()
{
if (_thread) CloseHandle(_thread);
}
void ThreadImpl::setPriorityImpl(int prio)
{
if (prio != _prio)
{
_prio = prio;
if (_thread)
{
if (SetThreadPriority(_thread, _prio) == 0)
throw SystemException("cannot set thread priority");
}
}
}
void ThreadImpl::setOSPriorityImpl(int prio)
{
setPriorityImpl(prio);
}
void ThreadImpl::startImpl(Runnable& target)
{
if (isRunningImpl())
throw SystemException("thread already running");
_pRunnableTarget = &target;
createImpl(runnableEntry, this);
}
void ThreadImpl::startImpl(Callable target, void* pData)
{
if (isRunningImpl())
throw SystemException("thread already running");
_callbackTarget.callback = target;
_callbackTarget.pData = pData;
createImpl(callableEntry, this);
}
void ThreadImpl::createImpl(Entry ent, void* pData)
{
_thread = CreateThread(NULL, _stackSize, ent, pData, 0, &_threadId);
if (!_thread)
throw SystemException("cannot create thread");
if (_prio != PRIO_NORMAL_IMPL && !SetThreadPriority(_thread, _prio))
throw SystemException("cannot set thread priority");
}
void ThreadImpl::joinImpl()
{
if (!_thread) return;
switch (WaitForSingleObject(_thread, INFINITE))
{
case WAIT_OBJECT_0:
threadCleanup();
return;
default:
throw SystemException("cannot join thread");
}
}
bool ThreadImpl::joinImpl(long milliseconds)
{
if (!_thread) return true;
switch (WaitForSingleObject(_thread, milliseconds + 1))
{
case WAIT_TIMEOUT:
return false;
case WAIT_OBJECT_0:
threadCleanup();
return true;
default:
throw SystemException("cannot join thread");
}
}
bool ThreadImpl::isRunningImpl() const
{
if (_thread)
{
DWORD ec = 0;
return GetExitCodeThread(_thread, &ec) && ec == STILL_ACTIVE;
}
return false;
}
void ThreadImpl::threadCleanup()
{
if (!_thread) return;
if (CloseHandle(_thread)) _thread = 0;
}
ThreadImpl* ThreadImpl::currentImpl()
{
return _currentThreadHolder.get();
}
ThreadImpl::TIDImpl ThreadImpl::currentTidImpl()
{
return GetCurrentThreadId();
}
DWORD WINAPI ThreadImpl::runnableEntry(LPVOID pThread)
{
_currentThreadHolder.set(reinterpret_cast<ThreadImpl*>(pThread));
try
{
reinterpret_cast<ThreadImpl*>(pThread)->_pRunnableTarget->run();
}
catch (Exception& exc)
{
ErrorHandler::handle(exc);
}
catch (std::exception& exc)
{
ErrorHandler::handle(exc);
}
catch (...)
{
ErrorHandler::handle();
}
return 0;
}
DWORD WINAPI ThreadImpl::callableEntry(LPVOID pThread)
{
_currentThreadHolder.set(reinterpret_cast<ThreadImpl*>(pThread));
try
{
ThreadImpl* pTI = reinterpret_cast<ThreadImpl*>(pThread);
pTI->_callbackTarget.callback(pTI->_callbackTarget.pData);
}
catch (Exception& exc)
{
ErrorHandler::handle(exc);
}
catch (std::exception& exc)
{
ErrorHandler::handle(exc);
}
catch (...)
{
ErrorHandler::handle();
}
return 0;
}
} // namespace Poco

View File

@ -0,0 +1,100 @@
//
// Timezone_VXX.cpp
//
// $Id: //poco/1.4/Foundation/src/Timezone_VX.cpp#1 $
//
// Library: Foundation
// Package: DateTime
// Module: Timezone
//
// Copyright (c) 2004-2011, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Timezone.h"
#include "Poco/Exception.h"
#include "Poco/Environment.h"
#include <ctime>
namespace Poco {
int Timezone::utcOffset()
{
std::time_t now = std::time(NULL);
struct std::tm t;
gmtime_r(&now, &t);
std::time_t utc = std::mktime(&t);
return now - utc;
}
int Timezone::dst()
{
std::time_t now = std::time(NULL);
struct std::tm t;
if (!localtime_r(&now, &t))
throw Poco::SystemException("cannot get local time DST offset");
return t.tm_isdst == 1 ? 3600 : 0;
}
bool Timezone::isDst(const Timestamp& timestamp)
{
std::time_t time = timestamp.epochTime();
struct std::tm* tms = std::localtime(&time);
if (!tms) throw Poco::SystemException("cannot get local time DST flag");
return tms->tm_isdst > 0;
}
std::string Timezone::name()
{
// format of TIMEZONE environment variable:
// name_of_zone:<(unused)>:time_in_minutes_from_UTC:daylight_start:daylight_end
std::string tz = Environment::get("TIMEZONE", "UTC");
std::string::size_type pos = tz.find(':');
if (pos != std::string::npos)
return tz.substr(0, pos);
else
return tz;
}
std::string Timezone::standardName()
{
return name();
}
std::string Timezone::dstName()
{
return name();
}
} // namespace Poco

View File

@ -0,0 +1,106 @@
//
// Timezone_WINCE.cpp
//
// $Id: //poco/1.4/Foundation/src/Timezone_WINCE.cpp#1 $
//
// Library: Foundation
// Package: DateTime
// Module: Timezone
//
// Copyright (c) 2004-2010, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Timezone.h"
#include "Poco/UnicodeConverter.h"
#include "Poco/Exception.h"
#include "Poco/UnWindows.h"
#include <ctime>
#include "wce_time.h"
namespace Poco {
int Timezone::utcOffset()
{
TIME_ZONE_INFORMATION tzInfo;
DWORD dstFlag = GetTimeZoneInformation(&tzInfo);
return -tzInfo.Bias*60;
}
int Timezone::dst()
{
TIME_ZONE_INFORMATION tzInfo;
DWORD dstFlag = GetTimeZoneInformation(&tzInfo);
return dstFlag == TIME_ZONE_ID_DAYLIGHT ? -tzInfo.DaylightBias*60 : 0;
}
bool Timezone::isDst(const Timestamp& timestamp)
{
std::time_t time = timestamp.epochTime();
struct std::tm* tms = wceex_localtime(&time);
if (!tms) throw SystemException("cannot get local time DST flag");
return tms->tm_isdst > 0;
}
std::string Timezone::name()
{
std::string result;
TIME_ZONE_INFORMATION tzInfo;
DWORD dstFlag = GetTimeZoneInformation(&tzInfo);
WCHAR* ptr = dstFlag == TIME_ZONE_ID_DAYLIGHT ? tzInfo.DaylightName : tzInfo.StandardName;
UnicodeConverter::toUTF8(ptr, result);
return result;
}
std::string Timezone::standardName()
{
std::string result;
TIME_ZONE_INFORMATION tzInfo;
DWORD dstFlag = GetTimeZoneInformation(&tzInfo);
WCHAR* ptr = tzInfo.StandardName;
UnicodeConverter::toUTF8(ptr, result);
return result;
}
std::string Timezone::dstName()
{
std::string result;
TIME_ZONE_INFORMATION tzInfo;
DWORD dstFlag = GetTimeZoneInformation(&tzInfo);
WCHAR* ptr = tzInfo.DaylightName;
UnicodeConverter::toUTF8(ptr, result);
return result;
}
} // namespace Poco