2
3
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-14 02:27:40 -04:00

Fix line endings and tabs

This commit is contained in:
Branan Purvine-Riley
2011-04-11 16:27:55 -07:00
parent d4250e19b5
commit 908aaeb6f6
2738 changed files with 702562 additions and 702562 deletions

View File

@ -1,25 +1,25 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/

View File

@ -1,372 +1,372 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Addr.cpp
*
***/
#include "../../Pch.h"
#pragma hdrstop
/*****************************************************************************
*
* Private
*
***/
// hardcoded byte ordering -- Intel only
#ifdef _M_IX86
const unsigned kHostClassALoopbackAddr = 0x7f000001; // 127.0.0.1
const unsigned kHostClassALoopbackMask = 0x00ffffff;
const unsigned kNetClassALoopbackAddr = 0x0100007f; // 127.0.0.1
const unsigned kNetClassALoopbackMask = 0xffffff00;
const unsigned kHostClassANatAddr = 0x000000a0; // 10.0.0.0 - 10.255.255.255
const unsigned kHostClassANatMask = 0x000000ff;
const unsigned kNetClassANatAddr = 0x0a000000; // 10.0.0.0 - 10.255.255.255
const unsigned kNetClassANatMask = 0xff000000;
const unsigned kHostClassBNetAddr = 0x000010ac; // 172.16.0.0 - 172.31.255.255
const unsigned kHostClassBNetMask = 0x0000f0ff;
const unsigned kNetClassBNetAddr = 0xac100000; // 172.16.0.0 - 172.31.255.255
const unsigned kNetClassBNetMask = 0xfff00000;
const unsigned kHostClassCNatAddr = 0x0000a8c0; // 192.168.0.0 - 192.168.255.255
const unsigned kHostClassCNatMask = 0x0000ffff;
const unsigned kNetClassCNatAddr = 0xc0a80000; // 192.168.0.0 - 192.168.255.255
const unsigned kNetClassCNatMask = 0xffff0000;
#else
#error "Must implement for this architecture"
#endif // ifdef _M_IX86
/*****************************************************************************
*
* Internal functions
*
***/
//===========================================================================
// Address sort order:
// (highest)
// externally visible address
// 10.0.0.0 - 10.255.255.255
// 172.16.0.0 - 172.31.255.255
// 192.168.0.0 - 192.168.255.255
// 127.0.0.0 - 127.0.0.255
// (lowest)
static int NetAddressNodeSortValueNetOrder (NetAddressNode addr) {
// Loopback addresses
if ((addr & kNetClassALoopbackMask) == (kNetClassALoopbackAddr & kNetClassALoopbackMask))
return 4;
// Private addresses
if ((addr & kNetClassCNatMask) == (kNetClassCNatAddr & kNetClassCNatMask))
return 3;
if ((addr & kNetClassBNetMask) == (kNetClassBNetAddr & kNetClassBNetMask))
return 2;
if ((addr & kNetClassANatMask) == (kNetClassANatAddr & kNetClassANatMask))
return 1;
// Public addresses
return 0;
}
//===========================================================================
static int NetAddressNodeSortValueHostOrder (NetAddressNode addr) {
// Loopback addresses
if ((addr & kHostClassALoopbackMask) == (kHostClassALoopbackAddr & kHostClassALoopbackMask))
return 4;
// Private addresses
if ((addr & kHostClassCNatMask) == (kHostClassCNatAddr & kHostClassCNatMask))
return 3;
if ((addr & kHostClassBNetMask) == (kHostClassBNetAddr & kHostClassBNetMask))
return 2;
if ((addr & kHostClassANatMask) == (kHostClassANatAddr & kHostClassANatMask))
return 1;
// Public addresses
return 0;
}
//===========================================================================
static NetAddressNode NodeFromString (const wchar * string[]) {
// skip leading whitespace
const wchar * str = *string;
while (iswspace(*str))
++str;
// This function handles partial ip addresses (61.33)
// as well as full dotted quads. The address can be
// terminated by whitespace or ':' as well as '\0'
byte data[4];
* (dword *) data = 0;
for (unsigned i = sizeof(data); i--; ) {
if (!iswdigit(*str))
return (unsigned)-1;
unsigned value = StrToUnsigned(str, &str, 10);
if (value >= 256)
return (unsigned)-1;
data[i] = (byte) value;
if (!*str || (*str == ':') || iswspace(*str))
break;
static const wchar s_separator[] = L"\0...";
if (*str++ != s_separator[i])
return (unsigned)-1;
}
*string = str;
return * (NetAddressNode *) &data[0];
}
/*****************************************************************************
*
* Exports
*
***/
//===========================================================================
int NetAddressCompare (const NetAddress & a1, const NetAddress & a2) {
const sockaddr_in & i1 = * (const sockaddr_in *) &a1;
const sockaddr_in & i2 = * (const sockaddr_in *) &a2;
int d = i1.sin_addr.S_un.S_addr - i2.sin_addr.S_un.S_addr;
return d ? d : i1.sin_port - i2.sin_port;
}
//===========================================================================
bool NetAddressSameSystem (const NetAddress & a1, const NetAddress & a2) {
const sockaddr_in & i1 = * (const sockaddr_in *) &a1;
const sockaddr_in & i2 = * (const sockaddr_in *) &a2;
return i1.sin_addr.S_un.S_addr == i2.sin_addr.S_un.S_addr;
}
//===========================================================================
unsigned NetAddressHash (const NetAddress & addr) {
// by using only the node number as the hash value, users can safely use
// hash value to find addresses by either using either "SameSystem" or "Equal"
const sockaddr_in & iAddr = * (const sockaddr_in *) &addr;
return iAddr.sin_addr.S_un.S_addr;
}
//===========================================================================
void NetAddressToString (
const NetAddress & addr,
wchar * str,
unsigned chars,
ENetAddressFormat format
) {
ASSERT(str);
static const wchar * s_fmts[] = {
L"%S", // kNetAddressFormatNodeNumber
L"%S:%u", // kNetAddressFormatAll
};
ASSERT(format < arrsize(s_fmts));
const sockaddr_in & inetaddr = * (const sockaddr_in *) &addr;
StrPrintf(
str,
chars,
s_fmts[format],
inet_ntoa(inetaddr.sin_addr),
ntohs(inetaddr.sin_port)
);
}
//===========================================================================
bool NetAddressFromString (NetAddress * addr, const wchar str[], unsigned defaultPort) {
ASSERT(addr);
ASSERT(str);
// NetAddress is bigger than sockaddr_in so start by zeroing the whole thing
ZEROPTR(addr);
for (;;) {
NetAddressNode node = NodeFromString(&str);
if (node == (unsigned)-1)
break;
if (*str == L':')
defaultPort = StrToUnsigned(str + 1, nil, 10);
sockaddr_in * inetaddr = (sockaddr_in *) addr;
inetaddr->sin_family = AF_INET;
inetaddr->sin_port = htons((word) defaultPort);
inetaddr->sin_addr.S_un.S_addr = htonl(node);
// inetaddr->sin_zero already zeroed
return true;
}
// address already zeroed
return false;
}
//===========================================================================
unsigned NetAddressGetPort (
const NetAddress & addr
) {
return ntohs(((sockaddr_in *) &addr)->sin_port);
}
//===========================================================================
void NetAddressSetPort (
unsigned port,
NetAddress * addr
) {
((sockaddr_in *) addr)->sin_port = htons((word) port);
}
//============================================================================
NetAddressNode NetAddressGetNode (const NetAddress & addr) {
return ntohl(((const sockaddr_in *) &addr)->sin_addr.S_un.S_addr);
}
//===========================================================================
void NetAddressFromNode (
NetAddressNode node,
unsigned port,
NetAddress * addr
) {
ZEROPTR(addr);
sockaddr_in * inetaddr = (sockaddr_in *) addr;
inetaddr->sin_family = AF_INET;
inetaddr->sin_addr.S_un.S_addr = htonl(node);
inetaddr->sin_port = htons((word) port);
}
//===========================================================================
void NetAddressNodeToString (
NetAddressNode node,
wchar * str,
unsigned chars
) {
in_addr addr;
addr.S_un.S_addr = htonl(node);
StrPrintf(str, chars, L"%S", inet_ntoa(addr));
}
//===========================================================================
NetAddressNode NetAddressNodeFromString (
const wchar string[],
const wchar * endPtr[]
) {
if (!endPtr)
endPtr = &string;
*endPtr = string;
return NodeFromString(endPtr);
}
//===========================================================================
void NetAddressGetLoopback (
unsigned port,
NetAddress * addr
) {
NetAddressFromNode(
kHostClassALoopbackAddr,
port,
addr
);
}
//===========================================================================
unsigned NetAddressGetLocal (
unsigned count,
NetAddressNode addresses[]
) {
ASSERT(count);
ASSERT(addresses);
for (;;) {
// Get local computer name
char name[MAX_COMPUTERNAME_LENGTH + 1];
DWORD size = arrsize(name);
if (!GetComputerName(name, &size))
StrCopy(name, "localhost", arrsize(name));
// Get IPv4 addresses for local system
const struct hostent * host = gethostbyname(name);
if (!host || !host->h_name)
break;
host = gethostbyname(host->h_name);
if (!host)
break;
if (host->h_length != sizeof(dword))
break;
// Count total number of addresses
unsigned found = 0;
const dword ** addr = (const dword **) host->h_addr_list;
for (; *addr; ++addr)
++found;
if (!found)
break;
// Create a buffer to sort the addresses
NetAddressNode * dst;
if (found > count)
dst = ALLOCA(NetAddressNode, found);
else
dst = addresses;
// Fill address buffer
const dword * src = * (const dword **) host->h_addr_list;
for (unsigned index = 0; index < found; ++index)
dst[index] = ntohl(src[index]);
// Sort addresses by priority
QSORT(
NetAddressNode,
dst,
found,
NetAddressNodeSortValueHostOrder(elem1) - NetAddressNodeSortValueHostOrder(elem2)
);
// Return the number of addresses the user actually requested
if (found > count) {
for (unsigned index = 0; index < count; ++index)
addresses[index] = dst[index];
return count;
}
return found;
}
// Initialize with a valid value
addresses[0] = kHostClassALoopbackAddr;
return 1;
}
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Addr.cpp
*
***/
#include "../../Pch.h"
#pragma hdrstop
/*****************************************************************************
*
* Private
*
***/
// hardcoded byte ordering -- Intel only
#ifdef _M_IX86
const unsigned kHostClassALoopbackAddr = 0x7f000001; // 127.0.0.1
const unsigned kHostClassALoopbackMask = 0x00ffffff;
const unsigned kNetClassALoopbackAddr = 0x0100007f; // 127.0.0.1
const unsigned kNetClassALoopbackMask = 0xffffff00;
const unsigned kHostClassANatAddr = 0x000000a0; // 10.0.0.0 - 10.255.255.255
const unsigned kHostClassANatMask = 0x000000ff;
const unsigned kNetClassANatAddr = 0x0a000000; // 10.0.0.0 - 10.255.255.255
const unsigned kNetClassANatMask = 0xff000000;
const unsigned kHostClassBNetAddr = 0x000010ac; // 172.16.0.0 - 172.31.255.255
const unsigned kHostClassBNetMask = 0x0000f0ff;
const unsigned kNetClassBNetAddr = 0xac100000; // 172.16.0.0 - 172.31.255.255
const unsigned kNetClassBNetMask = 0xfff00000;
const unsigned kHostClassCNatAddr = 0x0000a8c0; // 192.168.0.0 - 192.168.255.255
const unsigned kHostClassCNatMask = 0x0000ffff;
const unsigned kNetClassCNatAddr = 0xc0a80000; // 192.168.0.0 - 192.168.255.255
const unsigned kNetClassCNatMask = 0xffff0000;
#else
#error "Must implement for this architecture"
#endif // ifdef _M_IX86
/*****************************************************************************
*
* Internal functions
*
***/
//===========================================================================
// Address sort order:
// (highest)
// externally visible address
// 10.0.0.0 - 10.255.255.255
// 172.16.0.0 - 172.31.255.255
// 192.168.0.0 - 192.168.255.255
// 127.0.0.0 - 127.0.0.255
// (lowest)
static int NetAddressNodeSortValueNetOrder (NetAddressNode addr) {
// Loopback addresses
if ((addr & kNetClassALoopbackMask) == (kNetClassALoopbackAddr & kNetClassALoopbackMask))
return 4;
// Private addresses
if ((addr & kNetClassCNatMask) == (kNetClassCNatAddr & kNetClassCNatMask))
return 3;
if ((addr & kNetClassBNetMask) == (kNetClassBNetAddr & kNetClassBNetMask))
return 2;
if ((addr & kNetClassANatMask) == (kNetClassANatAddr & kNetClassANatMask))
return 1;
// Public addresses
return 0;
}
//===========================================================================
static int NetAddressNodeSortValueHostOrder (NetAddressNode addr) {
// Loopback addresses
if ((addr & kHostClassALoopbackMask) == (kHostClassALoopbackAddr & kHostClassALoopbackMask))
return 4;
// Private addresses
if ((addr & kHostClassCNatMask) == (kHostClassCNatAddr & kHostClassCNatMask))
return 3;
if ((addr & kHostClassBNetMask) == (kHostClassBNetAddr & kHostClassBNetMask))
return 2;
if ((addr & kHostClassANatMask) == (kHostClassANatAddr & kHostClassANatMask))
return 1;
// Public addresses
return 0;
}
//===========================================================================
static NetAddressNode NodeFromString (const wchar * string[]) {
// skip leading whitespace
const wchar * str = *string;
while (iswspace(*str))
++str;
// This function handles partial ip addresses (61.33)
// as well as full dotted quads. The address can be
// terminated by whitespace or ':' as well as '\0'
byte data[4];
* (dword *) data = 0;
for (unsigned i = sizeof(data); i--; ) {
if (!iswdigit(*str))
return (unsigned)-1;
unsigned value = StrToUnsigned(str, &str, 10);
if (value >= 256)
return (unsigned)-1;
data[i] = (byte) value;
if (!*str || (*str == ':') || iswspace(*str))
break;
static const wchar s_separator[] = L"\0...";
if (*str++ != s_separator[i])
return (unsigned)-1;
}
*string = str;
return * (NetAddressNode *) &data[0];
}
/*****************************************************************************
*
* Exports
*
***/
//===========================================================================
int NetAddressCompare (const NetAddress & a1, const NetAddress & a2) {
const sockaddr_in & i1 = * (const sockaddr_in *) &a1;
const sockaddr_in & i2 = * (const sockaddr_in *) &a2;
int d = i1.sin_addr.S_un.S_addr - i2.sin_addr.S_un.S_addr;
return d ? d : i1.sin_port - i2.sin_port;
}
//===========================================================================
bool NetAddressSameSystem (const NetAddress & a1, const NetAddress & a2) {
const sockaddr_in & i1 = * (const sockaddr_in *) &a1;
const sockaddr_in & i2 = * (const sockaddr_in *) &a2;
return i1.sin_addr.S_un.S_addr == i2.sin_addr.S_un.S_addr;
}
//===========================================================================
unsigned NetAddressHash (const NetAddress & addr) {
// by using only the node number as the hash value, users can safely use
// hash value to find addresses by either using either "SameSystem" or "Equal"
const sockaddr_in & iAddr = * (const sockaddr_in *) &addr;
return iAddr.sin_addr.S_un.S_addr;
}
//===========================================================================
void NetAddressToString (
const NetAddress & addr,
wchar * str,
unsigned chars,
ENetAddressFormat format
) {
ASSERT(str);
static const wchar * s_fmts[] = {
L"%S", // kNetAddressFormatNodeNumber
L"%S:%u", // kNetAddressFormatAll
};
ASSERT(format < arrsize(s_fmts));
const sockaddr_in & inetaddr = * (const sockaddr_in *) &addr;
StrPrintf(
str,
chars,
s_fmts[format],
inet_ntoa(inetaddr.sin_addr),
ntohs(inetaddr.sin_port)
);
}
//===========================================================================
bool NetAddressFromString (NetAddress * addr, const wchar str[], unsigned defaultPort) {
ASSERT(addr);
ASSERT(str);
// NetAddress is bigger than sockaddr_in so start by zeroing the whole thing
ZEROPTR(addr);
for (;;) {
NetAddressNode node = NodeFromString(&str);
if (node == (unsigned)-1)
break;
if (*str == L':')
defaultPort = StrToUnsigned(str + 1, nil, 10);
sockaddr_in * inetaddr = (sockaddr_in *) addr;
inetaddr->sin_family = AF_INET;
inetaddr->sin_port = htons((word) defaultPort);
inetaddr->sin_addr.S_un.S_addr = htonl(node);
// inetaddr->sin_zero already zeroed
return true;
}
// address already zeroed
return false;
}
//===========================================================================
unsigned NetAddressGetPort (
const NetAddress & addr
) {
return ntohs(((sockaddr_in *) &addr)->sin_port);
}
//===========================================================================
void NetAddressSetPort (
unsigned port,
NetAddress * addr
) {
((sockaddr_in *) addr)->sin_port = htons((word) port);
}
//============================================================================
NetAddressNode NetAddressGetNode (const NetAddress & addr) {
return ntohl(((const sockaddr_in *) &addr)->sin_addr.S_un.S_addr);
}
//===========================================================================
void NetAddressFromNode (
NetAddressNode node,
unsigned port,
NetAddress * addr
) {
ZEROPTR(addr);
sockaddr_in * inetaddr = (sockaddr_in *) addr;
inetaddr->sin_family = AF_INET;
inetaddr->sin_addr.S_un.S_addr = htonl(node);
inetaddr->sin_port = htons((word) port);
}
//===========================================================================
void NetAddressNodeToString (
NetAddressNode node,
wchar * str,
unsigned chars
) {
in_addr addr;
addr.S_un.S_addr = htonl(node);
StrPrintf(str, chars, L"%S", inet_ntoa(addr));
}
//===========================================================================
NetAddressNode NetAddressNodeFromString (
const wchar string[],
const wchar * endPtr[]
) {
if (!endPtr)
endPtr = &string;
*endPtr = string;
return NodeFromString(endPtr);
}
//===========================================================================
void NetAddressGetLoopback (
unsigned port,
NetAddress * addr
) {
NetAddressFromNode(
kHostClassALoopbackAddr,
port,
addr
);
}
//===========================================================================
unsigned NetAddressGetLocal (
unsigned count,
NetAddressNode addresses[]
) {
ASSERT(count);
ASSERT(addresses);
for (;;) {
// Get local computer name
char name[MAX_COMPUTERNAME_LENGTH + 1];
DWORD size = arrsize(name);
if (!GetComputerName(name, &size))
StrCopy(name, "localhost", arrsize(name));
// Get IPv4 addresses for local system
const struct hostent * host = gethostbyname(name);
if (!host || !host->h_name)
break;
host = gethostbyname(host->h_name);
if (!host)
break;
if (host->h_length != sizeof(dword))
break;
// Count total number of addresses
unsigned found = 0;
const dword ** addr = (const dword **) host->h_addr_list;
for (; *addr; ++addr)
++found;
if (!found)
break;
// Create a buffer to sort the addresses
NetAddressNode * dst;
if (found > count)
dst = ALLOCA(NetAddressNode, found);
else
dst = addresses;
// Fill address buffer
const dword * src = * (const dword **) host->h_addr_list;
for (unsigned index = 0; index < found; ++index)
dst[index] = ntohl(src[index]);
// Sort addresses by priority
QSORT(
NetAddressNode,
dst,
found,
NetAddressNodeSortValueHostOrder(elem1) - NetAddressNodeSortValueHostOrder(elem2)
);
// Return the number of addresses the user actually requested
if (found > count) {
for (unsigned index = 0; index < count; ++index)
addresses[index] = dst[index];
return count;
}
return found;
}
// Initialize with a valid value
addresses[0] = kHostClassALoopbackAddr;
return 1;
}

View File

@ -1,41 +1,41 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Dll.cpp
*
***/
#include "../../Pch.h"
#pragma hdrstop
/*****************************************************************************
*
* Private
*
***/
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Dll.cpp
*
***/
#include "../../Pch.h"
#pragma hdrstop
/*****************************************************************************
*
* Private
*
***/

View File

@ -1,207 +1,207 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Misc.cpp
*
***/
#include "../../Pch.h"
#pragma hdrstop
/*****************************************************************************
*
* Private
*
***/
static MEMORYSTATUSEX s_memstatus;
/*****************************************************************************
*
* Exports
*
***/
//============================================================================
const wchar * AppGetCommandLine () {
return GetCommandLineW();
}
//============================================================================
void MachineGetName (wchar *computerName, unsigned int length) {
DWORD len = length;
GetComputerNameW(computerName, &len);
}
/*****************************************************************************
*
* System status
*
***/
//============================================================================
void MemoryGetStatus (MemoryStatus * status) {
MEMORYSTATUSEX mem;
mem.dwLength = sizeof(mem);
GlobalMemoryStatusEx(&mem);
const qword BYTES_PER_MB = 1024 * 1024;
status->totalPhysMB = unsigned(mem.ullTotalPhys / BYTES_PER_MB);
status->availPhysMB = unsigned(mem.ullAvailPhys / BYTES_PER_MB);
status->totalPageFileMB = unsigned(mem.ullTotalPageFile / BYTES_PER_MB);
status->availPageFileMB = unsigned(mem.ullAvailPageFile / BYTES_PER_MB);
status->totalVirtualMB = unsigned(mem.ullTotalVirtual / BYTES_PER_MB);
status->availVirtualMB = unsigned(mem.ullAvailVirtual / BYTES_PER_MB);
status->memoryLoad = mem.dwMemoryLoad;
}
//============================================================================
void DiskGetStatus (ARRAY(DiskStatus) * disks) {
for (;;) {
DWORD length = GetLogicalDriveStrings(0, NULL);
if (!length || length > 2048)
break;
wchar * buffer = ALLOCA(wchar, length + 1);
if (!GetLogicalDriveStringsW(length, buffer))
break;
for (; *buffer; buffer += StrLen(buffer) + 1) {
UINT driveType = GetDriveTypeW(buffer);
if (driveType != DRIVE_FIXED)
continue;
ULARGE_INTEGER freeBytes;
ULARGE_INTEGER totalBytes;
if (!GetDiskFreeSpaceExW(buffer, &freeBytes, &totalBytes, NULL))
continue;
DiskStatus status;
StrCopy(status.name, buffer, arrsize(status.name));
const qword BYTES_PER_MB = 1024 * 1024;
status.totalSpaceMB = unsigned(totalBytes.QuadPart / BYTES_PER_MB);
status.freeSpaceMB = unsigned(freeBytes.QuadPart / BYTES_PER_MB);
disks->Add(status);
}
break;
}
}
//============================================================================
// Loosely taken from MS's cpuid code sample
void CpuGetInfo (
word * cpuCaps,
dword * cpuVendor,
word * cpuSignature
) {
dword signature = 0;
dword extended = 0;
dword flags[2] = { 0, 0 };
cpuVendor[0] = 0;
_asm {
// Detect if cpuid instruction is supported by attempting
// to change the ID bit of EFLAGS
pushfd
pop eax // get EFLAGS
mov ecx, eax // store copy of original EFLAGS
xor eax, 0x200000 // flip ID bit
push eax
popfd // replace EFLAGS
pushfd // get EFLAGS
pop eax
xor eax, ecx
je DONE
// Get processor id (GenuineIntel, AuthenticAMD, etc)
xor eax, eax
cpuid
mov edi, cpuVendor
mov [edi + 0], ebx
mov [edi + 4], edx
mov [edi + 8], ecx
// Check if capability flags are supported
cmp eax, 1
jl DONE
// Get processor capability flags and signature
mov eax, 1
cpuid
mov signature, eax
mov [flags + 0], edx
mov [flags + 4], ecx
// Check for extended capabilities
mov eax, 0x80000000
cpuid
cmp eax, 0x80000001
jl DONE
// Get extended capabilities
mov eax, 0x80000001
cpuid
mov extended, edx
DONE:
}
// Decode capability flags
const static struct CpuCap {
word cpuFlag;
byte field;
byte bit;
} s_caps[] = {
// feature field bit
// ------- ----- ---
{ kCpuCapCmov, 0, 15 },
{ kCpuCapEst, 1, 7 },
{ kCpuCapHtt, 0, 28 },
{ kCpuCapMmx, 0, 23 },
{ kCpuCapPsn, 0, 18 },
{ kCpuCapSse, 0, 25 },
{ kCpuCapSse2, 0, 26 },
{ kCpuCapSse3, 1, 0 },
{ kCpuCapTsc, 0, 4 },
};
for (unsigned i = 0; i < arrsize(s_caps); ++i) {
const CpuCap & cap = s_caps[i];
if (flags[cap.field] & (1 << cap.bit))
*cpuCaps |= cap.cpuFlag;
}
// Copy signature
*cpuSignature = word(signature & 0xfff);
// If this is an AMD CPU, check for 3DNow support
const char * vendorAmd = "AuthenticAMD";
if (!MemCmp(vendorAmd, cpuVendor, 12)) {
if (extended & (1 << 31))
*cpuCaps |= kCpuCap3dNow;
}
}
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Misc.cpp
*
***/
#include "../../Pch.h"
#pragma hdrstop
/*****************************************************************************
*
* Private
*
***/
static MEMORYSTATUSEX s_memstatus;
/*****************************************************************************
*
* Exports
*
***/
//============================================================================
const wchar * AppGetCommandLine () {
return GetCommandLineW();
}
//============================================================================
void MachineGetName (wchar *computerName, unsigned int length) {
DWORD len = length;
GetComputerNameW(computerName, &len);
}
/*****************************************************************************
*
* System status
*
***/
//============================================================================
void MemoryGetStatus (MemoryStatus * status) {
MEMORYSTATUSEX mem;
mem.dwLength = sizeof(mem);
GlobalMemoryStatusEx(&mem);
const qword BYTES_PER_MB = 1024 * 1024;
status->totalPhysMB = unsigned(mem.ullTotalPhys / BYTES_PER_MB);
status->availPhysMB = unsigned(mem.ullAvailPhys / BYTES_PER_MB);
status->totalPageFileMB = unsigned(mem.ullTotalPageFile / BYTES_PER_MB);
status->availPageFileMB = unsigned(mem.ullAvailPageFile / BYTES_PER_MB);
status->totalVirtualMB = unsigned(mem.ullTotalVirtual / BYTES_PER_MB);
status->availVirtualMB = unsigned(mem.ullAvailVirtual / BYTES_PER_MB);
status->memoryLoad = mem.dwMemoryLoad;
}
//============================================================================
void DiskGetStatus (ARRAY(DiskStatus) * disks) {
for (;;) {
DWORD length = GetLogicalDriveStrings(0, NULL);
if (!length || length > 2048)
break;
wchar * buffer = ALLOCA(wchar, length + 1);
if (!GetLogicalDriveStringsW(length, buffer))
break;
for (; *buffer; buffer += StrLen(buffer) + 1) {
UINT driveType = GetDriveTypeW(buffer);
if (driveType != DRIVE_FIXED)
continue;
ULARGE_INTEGER freeBytes;
ULARGE_INTEGER totalBytes;
if (!GetDiskFreeSpaceExW(buffer, &freeBytes, &totalBytes, NULL))
continue;
DiskStatus status;
StrCopy(status.name, buffer, arrsize(status.name));
const qword BYTES_PER_MB = 1024 * 1024;
status.totalSpaceMB = unsigned(totalBytes.QuadPart / BYTES_PER_MB);
status.freeSpaceMB = unsigned(freeBytes.QuadPart / BYTES_PER_MB);
disks->Add(status);
}
break;
}
}
//============================================================================
// Loosely taken from MS's cpuid code sample
void CpuGetInfo (
word * cpuCaps,
dword * cpuVendor,
word * cpuSignature
) {
dword signature = 0;
dword extended = 0;
dword flags[2] = { 0, 0 };
cpuVendor[0] = 0;
_asm {
// Detect if cpuid instruction is supported by attempting
// to change the ID bit of EFLAGS
pushfd
pop eax // get EFLAGS
mov ecx, eax // store copy of original EFLAGS
xor eax, 0x200000 // flip ID bit
push eax
popfd // replace EFLAGS
pushfd // get EFLAGS
pop eax
xor eax, ecx
je DONE
// Get processor id (GenuineIntel, AuthenticAMD, etc)
xor eax, eax
cpuid
mov edi, cpuVendor
mov [edi + 0], ebx
mov [edi + 4], edx
mov [edi + 8], ecx
// Check if capability flags are supported
cmp eax, 1
jl DONE
// Get processor capability flags and signature
mov eax, 1
cpuid
mov signature, eax
mov [flags + 0], edx
mov [flags + 4], ecx
// Check for extended capabilities
mov eax, 0x80000000
cpuid
cmp eax, 0x80000001
jl DONE
// Get extended capabilities
mov eax, 0x80000001
cpuid
mov extended, edx
DONE:
}
// Decode capability flags
const static struct CpuCap {
word cpuFlag;
byte field;
byte bit;
} s_caps[] = {
// feature field bit
// ------- ----- ---
{ kCpuCapCmov, 0, 15 },
{ kCpuCapEst, 1, 7 },
{ kCpuCapHtt, 0, 28 },
{ kCpuCapMmx, 0, 23 },
{ kCpuCapPsn, 0, 18 },
{ kCpuCapSse, 0, 25 },
{ kCpuCapSse2, 0, 26 },
{ kCpuCapSse3, 1, 0 },
{ kCpuCapTsc, 0, 4 },
};
for (unsigned i = 0; i < arrsize(s_caps); ++i) {
const CpuCap & cap = s_caps[i];
if (flags[cap.field] & (1 << cap.bit))
*cpuCaps |= cap.cpuFlag;
}
// Copy signature
*cpuSignature = word(signature & 0xfff);
// If this is an AMD CPU, check for 3DNow support
const char * vendorAmd = "AuthenticAMD";
if (!MemCmp(vendorAmd, cpuVendor, 12)) {
if (extended & (1 << 31))
*cpuCaps |= kCpuCap3dNow;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,82 +1,82 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Str.cpp
*
***/
#include "../../Pch.h"
#pragma hdrstop
/*****************************************************************************
*
* Exports
*
***/
//===========================================================================
unsigned StrToAnsi (char * dest, const wchar source[], unsigned destChars) {
return StrToAnsi(dest, source, destChars, CP_ACP);
}
//===========================================================================
unsigned StrToAnsi (char * dest, const wchar source[], unsigned destChars, unsigned codePage) {
ASSERT(destChars != (unsigned)-1);
ASSERT(dest != nil);
int result = WideCharToMultiByte(codePage, 0, source, -1, dest, destChars, nil, nil);
if (result)
return result - 1; // return number of characters not including null terminator
else if (destChars) {
dest[destChars - 1] = 0; // null terminate the destination buffer
return destChars - 1;
}
else
return 0;
}
//===========================================================================
unsigned StrToUnicode (wchar * dest, const char source[], unsigned destChars) {
return StrToUnicode(dest, source, destChars, CP_ACP);
}
//===========================================================================
unsigned StrToUnicode (wchar * dest, const char source[], unsigned destChars, unsigned codePage) {
ASSERT(destChars != (unsigned)-1);
ASSERT(dest != nil);
int result = MultiByteToWideChar(codePage, 0, source, -1, dest, destChars);
if (result)
return result - 1; // return number of characters not including null terminator
else if (destChars) {
dest[destChars - 1] = 0; // null terminate the destination buffer
return destChars - 1;
}
else
return 0;
}
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Str.cpp
*
***/
#include "../../Pch.h"
#pragma hdrstop
/*****************************************************************************
*
* Exports
*
***/
//===========================================================================
unsigned StrToAnsi (char * dest, const wchar source[], unsigned destChars) {
return StrToAnsi(dest, source, destChars, CP_ACP);
}
//===========================================================================
unsigned StrToAnsi (char * dest, const wchar source[], unsigned destChars, unsigned codePage) {
ASSERT(destChars != (unsigned)-1);
ASSERT(dest != nil);
int result = WideCharToMultiByte(codePage, 0, source, -1, dest, destChars, nil, nil);
if (result)
return result - 1; // return number of characters not including null terminator
else if (destChars) {
dest[destChars - 1] = 0; // null terminate the destination buffer
return destChars - 1;
}
else
return 0;
}
//===========================================================================
unsigned StrToUnicode (wchar * dest, const char source[], unsigned destChars) {
return StrToUnicode(dest, source, destChars, CP_ACP);
}
//===========================================================================
unsigned StrToUnicode (wchar * dest, const char source[], unsigned destChars, unsigned codePage) {
ASSERT(destChars != (unsigned)-1);
ASSERT(dest != nil);
int result = MultiByteToWideChar(codePage, 0, source, -1, dest, destChars);
if (result)
return result - 1; // return number of characters not including null terminator
else if (destChars) {
dest[destChars - 1] = 0; // null terminate the destination buffer
return destChars - 1;
}
else
return 0;
}

View File

@ -1,359 +1,359 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Sync.cpp
*
***/
#include "../../Pch.h"
#pragma hdrstop
/****************************************************************************
*
* Spin lock functions
*
***/
//===========================================================================
static inline void EnterSpinLock (long * spinLock) {
for (;;)
if (*spinLock < 0)
if (!InterlockedIncrement(spinLock))
return;
else
InterlockedDecrement(spinLock);
}
//===========================================================================
static inline void LeaveSpinLock (long * spinLock) {
InterlockedDecrement(spinLock);
}
/****************************************************************************
*
* CLockWaitSet / CLockWaitSetAllocator
*
***/
class CLockWaitSet {
private:
unsigned m_refCount;
HANDLE m_waitEvent;
public:
LINK(CLockWaitSet) link;
inline CLockWaitSet ();
inline ~CLockWaitSet ();
inline void DecRef ();
inline void IncRef ();
inline void Signal ();
inline void Wait ();
};
class CLockWaitSetAllocator {
private:
CLockWaitSet m_array[256];
CLockWaitSetAllocator * m_prev;
LISTDECL(CLockWaitSet, link) m_spareList;
LISTDECL(CLockWaitSet, link) m_usedList;
static CLockWaitSetAllocator * s_allocator;
static long s_spinLock;
public:
CLockWaitSetAllocator (CLockWaitSetAllocator * prev);
~CLockWaitSetAllocator ();
static CLockWaitSet * Alloc ();
static void Free (CLockWaitSet * waitSet);
static void __cdecl Shutdown ();
};
CLockWaitSetAllocator * CLockWaitSetAllocator::s_allocator;
long CLockWaitSetAllocator::s_spinLock = -1;
//===========================================================================
CLockWaitSet::CLockWaitSet () {
m_refCount = 0;
m_waitEvent = CreateEvent(nil, true, false, nil);
}
//===========================================================================
CLockWaitSet::~CLockWaitSet () {
ASSERT(!m_refCount);
CloseHandle(m_waitEvent);
m_waitEvent = 0;
}
//===========================================================================
void CLockWaitSet::DecRef () {
ASSERT(m_refCount);
if (!--m_refCount) {
ResetEvent(m_waitEvent);
CLockWaitSetAllocator::Free(this);
}
}
//===========================================================================
void CLockWaitSet::IncRef () {
++m_refCount;
}
//===========================================================================
void CLockWaitSet::Signal () {
ASSERT(m_refCount);
SetEvent(m_waitEvent);
}
//===========================================================================
void CLockWaitSet::Wait () {
ASSERT(m_refCount);
WaitForSingleObject(m_waitEvent, INFINITE);
}
//===========================================================================
CLockWaitSetAllocator::CLockWaitSetAllocator (CLockWaitSetAllocator * prev) {
m_prev = prev;
if (prev) {
m_spareList.Link(&prev->m_spareList);
m_usedList.Link(&prev->m_usedList);
}
for (unsigned index = arrsize(m_array); index--; )
m_spareList.Link(&m_array[index]);
}
//===========================================================================
CLockWaitSetAllocator::~CLockWaitSetAllocator () {
DEL(m_prev);
}
//===========================================================================
CLockWaitSet * CLockWaitSetAllocator::Alloc () {
EnterSpinLock(&s_spinLock);
// If there is no active allocator or if the active allocator is full,
// create a new one
if (!s_allocator || !s_allocator->m_spareList.Head()) {
if (!s_allocator)
atexit(Shutdown);
s_allocator = NEW(CLockWaitSetAllocator)(s_allocator);
}
// Get an available wait set from the active allocator
CLockWaitSet * waitSet = s_allocator->m_spareList.Head();
s_allocator->m_usedList.Link(waitSet);
LeaveSpinLock(&s_spinLock);
return waitSet;
}
//===========================================================================
void CLockWaitSetAllocator::Free (CLockWaitSet * waitSet) {
EnterSpinLock(&s_spinLock);
// Return this wait set to the active allocator's spare list
ASSERT(s_allocator);
s_allocator->m_spareList.Link(waitSet);
LeaveSpinLock(&s_spinLock);
}
//===========================================================================
void CLockWaitSetAllocator::Shutdown () {
EnterSpinLock(&s_spinLock);
// Free all allocators
while (s_allocator) {
CLockWaitSetAllocator * prev = s_allocator->m_prev;
DEL(s_allocator);
s_allocator = prev;
}
LeaveSpinLock(&s_spinLock);
}
/****************************************************************************
*
* CLock
*
***/
//===========================================================================
CLock::CLock () {
m_waitSet = nil;
m_spinLock = -1;
m_readerCount = 0;
m_writerCount = 0;
}
//===========================================================================
CLock::~CLock () {
ASSERT(!m_waitSet);
ASSERT(m_spinLock == -1);
ASSERT(!m_readerCount);
ASSERT(!m_writerCount);
}
//===========================================================================
void CLock::EnterRead () {
EnterSpinLock(&m_spinLock);
for (;;) {
// If there are no writers, claim this lock for reading
if (!m_writerCount) {
++m_readerCount;
break;
}
// Otherwise, wait until the existing writer releases the lock
CLockWaitSet * waitSet = m_waitSet = (m_waitSet ? m_waitSet : CLockWaitSetAllocator::Alloc());
waitSet->IncRef();
LeaveSpinLock(&m_spinLock);
waitSet->Wait();
EnterSpinLock(&m_spinLock);
waitSet->DecRef();
}
LeaveSpinLock(&m_spinLock);
}
//===========================================================================
void CLock::EnterWrite () {
EnterSpinLock(&m_spinLock);
for (;;) {
// If there are no readers or writers, claim this lock for writing
if (!m_readerCount && !m_writerCount) {
++m_writerCount;
break;
}
// Otherwise, wait until the existing writer or all existing readers
// release the lock
CLockWaitSet * waitSet = m_waitSet = (m_waitSet ? m_waitSet : CLockWaitSetAllocator::Alloc());
waitSet->IncRef();
LeaveSpinLock(&m_spinLock);
waitSet->Wait();
EnterSpinLock(&m_spinLock);
waitSet->DecRef();
}
LeaveSpinLock(&m_spinLock);
}
//===========================================================================
void CLock::LeaveRead () {
EnterSpinLock(&m_spinLock);
// If this is the last reader, signal waiting threads to try claiming
// the lock again
ASSERT(m_readerCount);
if (!--m_readerCount)
if (m_waitSet) {
m_waitSet->Signal();
m_waitSet = nil;
}
LeaveSpinLock(&m_spinLock);
}
//===========================================================================
void CLock::LeaveWrite () {
EnterSpinLock(&m_spinLock);
// This is the last writer. Signal waiting threads to try claiming the
// lock again.
ASSERT(m_writerCount == 1);
--m_writerCount;
if (m_waitSet) {
m_waitSet->Signal();
m_waitSet = nil;
}
LeaveSpinLock(&m_spinLock);
}
/*****************************************************************************
*
* CEvent
*
***/
//============================================================================
CEvent::CEvent (
ECEventResetBehavior resetType,
bool initialSet
) {
m_handle = CreateEvent(
nil, // security attributes
(resetType == kEventManualReset) ? true : false,
initialSet,
nil // name
);
}
//============================================================================
CEvent::~CEvent () {
(void) CloseHandle(m_handle);
}
//============================================================================
void CEvent::Signal () {
SetEvent(m_handle);
}
//============================================================================
void CEvent::Reset () {
ResetEvent(m_handle);
}
//============================================================================
bool CEvent::Wait (unsigned waitMs) {
ThreadAssertCanBlock(__FILE__, __LINE__);
return WaitForSingleObject(m_handle, waitMs) == WAIT_OBJECT_0;
}
/****************************************************************************
*
* Exported functions
*
***/
//===========================================================================
long AtomicAdd (long * value, long increment) {
return InterlockedExchangeAdd(value, increment);
}
//===========================================================================
long AtomicSet (long * value, long set) {
return InterlockedExchange(value, set);
}
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Sync.cpp
*
***/
#include "../../Pch.h"
#pragma hdrstop
/****************************************************************************
*
* Spin lock functions
*
***/
//===========================================================================
static inline void EnterSpinLock (long * spinLock) {
for (;;)
if (*spinLock < 0)
if (!InterlockedIncrement(spinLock))
return;
else
InterlockedDecrement(spinLock);
}
//===========================================================================
static inline void LeaveSpinLock (long * spinLock) {
InterlockedDecrement(spinLock);
}
/****************************************************************************
*
* CLockWaitSet / CLockWaitSetAllocator
*
***/
class CLockWaitSet {
private:
unsigned m_refCount;
HANDLE m_waitEvent;
public:
LINK(CLockWaitSet) link;
inline CLockWaitSet ();
inline ~CLockWaitSet ();
inline void DecRef ();
inline void IncRef ();
inline void Signal ();
inline void Wait ();
};
class CLockWaitSetAllocator {
private:
CLockWaitSet m_array[256];
CLockWaitSetAllocator * m_prev;
LISTDECL(CLockWaitSet, link) m_spareList;
LISTDECL(CLockWaitSet, link) m_usedList;
static CLockWaitSetAllocator * s_allocator;
static long s_spinLock;
public:
CLockWaitSetAllocator (CLockWaitSetAllocator * prev);
~CLockWaitSetAllocator ();
static CLockWaitSet * Alloc ();
static void Free (CLockWaitSet * waitSet);
static void __cdecl Shutdown ();
};
CLockWaitSetAllocator * CLockWaitSetAllocator::s_allocator;
long CLockWaitSetAllocator::s_spinLock = -1;
//===========================================================================
CLockWaitSet::CLockWaitSet () {
m_refCount = 0;
m_waitEvent = CreateEvent(nil, true, false, nil);
}
//===========================================================================
CLockWaitSet::~CLockWaitSet () {
ASSERT(!m_refCount);
CloseHandle(m_waitEvent);
m_waitEvent = 0;
}
//===========================================================================
void CLockWaitSet::DecRef () {
ASSERT(m_refCount);
if (!--m_refCount) {
ResetEvent(m_waitEvent);
CLockWaitSetAllocator::Free(this);
}
}
//===========================================================================
void CLockWaitSet::IncRef () {
++m_refCount;
}
//===========================================================================
void CLockWaitSet::Signal () {
ASSERT(m_refCount);
SetEvent(m_waitEvent);
}
//===========================================================================
void CLockWaitSet::Wait () {
ASSERT(m_refCount);
WaitForSingleObject(m_waitEvent, INFINITE);
}
//===========================================================================
CLockWaitSetAllocator::CLockWaitSetAllocator (CLockWaitSetAllocator * prev) {
m_prev = prev;
if (prev) {
m_spareList.Link(&prev->m_spareList);
m_usedList.Link(&prev->m_usedList);
}
for (unsigned index = arrsize(m_array); index--; )
m_spareList.Link(&m_array[index]);
}
//===========================================================================
CLockWaitSetAllocator::~CLockWaitSetAllocator () {
DEL(m_prev);
}
//===========================================================================
CLockWaitSet * CLockWaitSetAllocator::Alloc () {
EnterSpinLock(&s_spinLock);
// If there is no active allocator or if the active allocator is full,
// create a new one
if (!s_allocator || !s_allocator->m_spareList.Head()) {
if (!s_allocator)
atexit(Shutdown);
s_allocator = NEW(CLockWaitSetAllocator)(s_allocator);
}
// Get an available wait set from the active allocator
CLockWaitSet * waitSet = s_allocator->m_spareList.Head();
s_allocator->m_usedList.Link(waitSet);
LeaveSpinLock(&s_spinLock);
return waitSet;
}
//===========================================================================
void CLockWaitSetAllocator::Free (CLockWaitSet * waitSet) {
EnterSpinLock(&s_spinLock);
// Return this wait set to the active allocator's spare list
ASSERT(s_allocator);
s_allocator->m_spareList.Link(waitSet);
LeaveSpinLock(&s_spinLock);
}
//===========================================================================
void CLockWaitSetAllocator::Shutdown () {
EnterSpinLock(&s_spinLock);
// Free all allocators
while (s_allocator) {
CLockWaitSetAllocator * prev = s_allocator->m_prev;
DEL(s_allocator);
s_allocator = prev;
}
LeaveSpinLock(&s_spinLock);
}
/****************************************************************************
*
* CLock
*
***/
//===========================================================================
CLock::CLock () {
m_waitSet = nil;
m_spinLock = -1;
m_readerCount = 0;
m_writerCount = 0;
}
//===========================================================================
CLock::~CLock () {
ASSERT(!m_waitSet);
ASSERT(m_spinLock == -1);
ASSERT(!m_readerCount);
ASSERT(!m_writerCount);
}
//===========================================================================
void CLock::EnterRead () {
EnterSpinLock(&m_spinLock);
for (;;) {
// If there are no writers, claim this lock for reading
if (!m_writerCount) {
++m_readerCount;
break;
}
// Otherwise, wait until the existing writer releases the lock
CLockWaitSet * waitSet = m_waitSet = (m_waitSet ? m_waitSet : CLockWaitSetAllocator::Alloc());
waitSet->IncRef();
LeaveSpinLock(&m_spinLock);
waitSet->Wait();
EnterSpinLock(&m_spinLock);
waitSet->DecRef();
}
LeaveSpinLock(&m_spinLock);
}
//===========================================================================
void CLock::EnterWrite () {
EnterSpinLock(&m_spinLock);
for (;;) {
// If there are no readers or writers, claim this lock for writing
if (!m_readerCount && !m_writerCount) {
++m_writerCount;
break;
}
// Otherwise, wait until the existing writer or all existing readers
// release the lock
CLockWaitSet * waitSet = m_waitSet = (m_waitSet ? m_waitSet : CLockWaitSetAllocator::Alloc());
waitSet->IncRef();
LeaveSpinLock(&m_spinLock);
waitSet->Wait();
EnterSpinLock(&m_spinLock);
waitSet->DecRef();
}
LeaveSpinLock(&m_spinLock);
}
//===========================================================================
void CLock::LeaveRead () {
EnterSpinLock(&m_spinLock);
// If this is the last reader, signal waiting threads to try claiming
// the lock again
ASSERT(m_readerCount);
if (!--m_readerCount)
if (m_waitSet) {
m_waitSet->Signal();
m_waitSet = nil;
}
LeaveSpinLock(&m_spinLock);
}
//===========================================================================
void CLock::LeaveWrite () {
EnterSpinLock(&m_spinLock);
// This is the last writer. Signal waiting threads to try claiming the
// lock again.
ASSERT(m_writerCount == 1);
--m_writerCount;
if (m_waitSet) {
m_waitSet->Signal();
m_waitSet = nil;
}
LeaveSpinLock(&m_spinLock);
}
/*****************************************************************************
*
* CEvent
*
***/
//============================================================================
CEvent::CEvent (
ECEventResetBehavior resetType,
bool initialSet
) {
m_handle = CreateEvent(
nil, // security attributes
(resetType == kEventManualReset) ? true : false,
initialSet,
nil // name
);
}
//============================================================================
CEvent::~CEvent () {
(void) CloseHandle(m_handle);
}
//============================================================================
void CEvent::Signal () {
SetEvent(m_handle);
}
//============================================================================
void CEvent::Reset () {
ResetEvent(m_handle);
}
//============================================================================
bool CEvent::Wait (unsigned waitMs) {
ThreadAssertCanBlock(__FILE__, __LINE__);
return WaitForSingleObject(m_handle, waitMs) == WAIT_OBJECT_0;
}
/****************************************************************************
*
* Exported functions
*
***/
//===========================================================================
long AtomicAdd (long * value, long increment) {
return InterlockedExchangeAdd(value, increment);
}
//===========================================================================
long AtomicSet (long * value, long set) {
return InterlockedExchange(value, set);
}

View File

@ -1,146 +1,146 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Time.cpp
*
***/
#include "../../Pch.h"
#pragma hdrstop
/*****************************************************************************
*
* Local functions
*
***/
//============================================================================
static void FormatTime (
qword time,
wchar const dateFmt[],
wchar const timeFmt[],
unsigned chars,
wchar * buffer
) {
COMPILER_ASSERT(sizeof(FILETIME) == sizeof(qword));
SYSTEMTIME sysTime;
FileTimeToSystemTime((FILETIME *)&time, &sysTime);
unsigned offset = GetDateFormatW(
LOCALE_SYSTEM_DEFAULT,
0,
&sysTime,
dateFmt,
buffer,
chars
);
if (timeFmt) {
// if we printed any characters, move offset back to overwrite the string terminator
if (offset)
--offset;
offset += GetTimeFormatW(
LOCALE_SYSTEM_DEFAULT,
0,
&sysTime,
timeFmt,
buffer + offset,
chars - offset
);
}
// if we didn't print any characters, NULL terminate the buffer
if (!offset && chars)
buffer[0] = 0;
}
/*****************************************************************************
*
* Exported functions
*
***/
#ifdef HS_BUILD_FOR_WIN32
//===========================================================================
void TimeGetDesc (
qword time,
TimeDesc * desc
) {
ASSERT(desc);
SYSTEMTIME sysTime;
COMPILER_ASSERT(sizeof(qword) == sizeof(FILETIME));
FileTimeToSystemTime((FILETIME *) &time, &sysTime);
desc->year = sysTime.wYear;
desc->month = sysTime.wMonth;
desc->day = sysTime.wDay;
desc->dayOfWeek = sysTime.wDayOfWeek;
desc->hour = sysTime.wHour;
desc->minute = sysTime.wMinute;
desc->second = sysTime.wSecond;
}
//============================================================================
qword TimeGetTime () {
qword time;
COMPILER_ASSERT(sizeof(qword) == sizeof(FILETIME));
GetSystemTimeAsFileTime((FILETIME *) &time);
return time;
}
//============================================================================
qword TimeGetLocalTime () {
qword time;
COMPILER_ASSERT(sizeof(qword) == sizeof(FILETIME));
GetSystemTimeAsFileTime((FILETIME *) &time);
FileTimeToLocalFileTime((FILETIME *) &time, (FILETIME *) &time);
return time;
}
//============================================================================
void TimePrettyPrint (
qword time,
unsigned chars,
wchar * buffer
) {
FormatTime(
time,
L"ddd MMM dd',' yyyy ",
L"hh':'mm':'ss tt",
chars,
buffer
);
}
#endif // HS_BUILD_FOR_WIN32
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Time.cpp
*
***/
#include "../../Pch.h"
#pragma hdrstop
/*****************************************************************************
*
* Local functions
*
***/
//============================================================================
static void FormatTime (
qword time,
wchar const dateFmt[],
wchar const timeFmt[],
unsigned chars,
wchar * buffer
) {
COMPILER_ASSERT(sizeof(FILETIME) == sizeof(qword));
SYSTEMTIME sysTime;
FileTimeToSystemTime((FILETIME *)&time, &sysTime);
unsigned offset = GetDateFormatW(
LOCALE_SYSTEM_DEFAULT,
0,
&sysTime,
dateFmt,
buffer,
chars
);
if (timeFmt) {
// if we printed any characters, move offset back to overwrite the string terminator
if (offset)
--offset;
offset += GetTimeFormatW(
LOCALE_SYSTEM_DEFAULT,
0,
&sysTime,
timeFmt,
buffer + offset,
chars - offset
);
}
// if we didn't print any characters, NULL terminate the buffer
if (!offset && chars)
buffer[0] = 0;
}
/*****************************************************************************
*
* Exported functions
*
***/
#ifdef HS_BUILD_FOR_WIN32
//===========================================================================
void TimeGetDesc (
qword time,
TimeDesc * desc
) {
ASSERT(desc);
SYSTEMTIME sysTime;
COMPILER_ASSERT(sizeof(qword) == sizeof(FILETIME));
FileTimeToSystemTime((FILETIME *) &time, &sysTime);
desc->year = sysTime.wYear;
desc->month = sysTime.wMonth;
desc->day = sysTime.wDay;
desc->dayOfWeek = sysTime.wDayOfWeek;
desc->hour = sysTime.wHour;
desc->minute = sysTime.wMinute;
desc->second = sysTime.wSecond;
}
//============================================================================
qword TimeGetTime () {
qword time;
COMPILER_ASSERT(sizeof(qword) == sizeof(FILETIME));
GetSystemTimeAsFileTime((FILETIME *) &time);
return time;
}
//============================================================================
qword TimeGetLocalTime () {
qword time;
COMPILER_ASSERT(sizeof(qword) == sizeof(FILETIME));
GetSystemTimeAsFileTime((FILETIME *) &time);
FileTimeToLocalFileTime((FILETIME *) &time, (FILETIME *) &time);
return time;
}
//============================================================================
void TimePrettyPrint (
qword time,
unsigned chars,
wchar * buffer
) {
FormatTime(
time,
L"ddd MMM dd',' yyyy ",
L"hh':'mm':'ss tt",
chars,
buffer
);
}
#endif // HS_BUILD_FOR_WIN32

View File

@ -1,171 +1,171 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Uuid.cpp
*
***/
#include "../../Pch.h"
#pragma hdrstop
#if 0
COMPILER_ASSERT(sizeof(Uuid) >= sizeof(GUID));
void Uuid::Clear()
{
UuidCreateNil( (GUID *)this );
}
int Uuid::CompareTo( const Uuid * v ) const
{
RPC_STATUS s;
return UuidCompare( (GUID *)this, (GUID *)v, &s );
}
bool Uuid::IsEqualTo( const Uuid * v ) const
{
return ( CompareTo( v )==0 );
}
void Uuid::CopyFrom( const Uuid * v )
{
memcpy( (void*)fData, (const void*)v->fData, sizeof(fData) );
}
bool Uuid::IsNull() const
{
RPC_STATUS s;
return 1 == UuidIsNil( (GUID *)this, &s );
}
bool Uuid::FromString( const char * str )
{
Clear();
if ( !str )
return false;
return RPC_S_OK == UuidFromString( (unsigned char *)str, (GUID *)this );
}
bool Uuid::ToString( std::string & out ) const
{
out = "";
unsigned char * ubuf;
RPC_STATUS s;
s = UuidToString( (GUID *) this, &ubuf );
bool success = ( s==RPC_S_OK );
if ( success )
out = (char*)ubuf;
RpcStringFree( &ubuf );
return success;
}
// static
Uuid Uuid::Generate()
{
Uuid result;
UuidCreate( (GUID *)&result );
return result;
}
#endif
#ifdef HS_BUILD_FOR_WIN32
/*****************************************************************************
*
* Exports
*
***/
COMPILER_ASSERT(sizeof(Uuid) >= sizeof(GUID));
//============================================================================
Uuid GuidGenerate () {
Uuid result;
UuidCreate( (GUID *)&result );
return result;
}
//============================================================================
void GuidClear (Uuid * uuid) {
UuidCreateNil((GUID *)uuid);
}
//============================================================================
bool GuidFromString (const wchar str[], Uuid * uuid) {
ASSERT(uuid);
COMPILER_ASSERT(sizeof(wchar) == sizeof(unsigned short));
return RPC_S_OK == UuidFromStringW((unsigned short *) str, (GUID *) uuid);
}
//============================================================================
bool GuidFromString (const char str[], Uuid * uuid) {
ASSERT(uuid);
return RPC_S_OK == UuidFromStringA((unsigned char *) str, (GUID *) uuid);
}
//============================================================================
int GuidCompare (const Uuid & a, const Uuid & b) {
RPC_STATUS s;
return UuidCompare((GUID *)&a, (GUID *)&b, &s);
}
//============================================================================
bool GuidIsNil (const Uuid & uuid) {
RPC_STATUS s;
return 1 == UuidIsNil((GUID *)&uuid, &s );
}
//============================================================================
const wchar * GuidToString (const Uuid & uuid, wchar * dst, unsigned chars) {
wchar * src;
RPC_STATUS s;
s = UuidToStringW( (GUID *) &uuid, (RPC_WSTR*)&src );
if (RPC_S_OK == s)
StrCopy(dst, src, chars);
else
StrCopy(dst, L"", chars);
RpcStringFreeW( (RPC_WSTR *)&src );
return dst;
}
//============================================================================
const char * GuidToString (const Uuid & uuid, char * dst, unsigned chars) {
byte * src;
RPC_STATUS s;
s = UuidToStringA( (GUID *) &uuid, &src );
if (RPC_S_OK == s)
StrCopy(dst, (char *)src, chars);
else
StrCopy(dst, "", chars);
RpcStringFreeA(&src);
return dst;
}
#endif // HS_BUILD_FOR_WIN32
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Uuid.cpp
*
***/
#include "../../Pch.h"
#pragma hdrstop
#if 0
COMPILER_ASSERT(sizeof(Uuid) >= sizeof(GUID));
void Uuid::Clear()
{
UuidCreateNil( (GUID *)this );
}
int Uuid::CompareTo( const Uuid * v ) const
{
RPC_STATUS s;
return UuidCompare( (GUID *)this, (GUID *)v, &s );
}
bool Uuid::IsEqualTo( const Uuid * v ) const
{
return ( CompareTo( v )==0 );
}
void Uuid::CopyFrom( const Uuid * v )
{
memcpy( (void*)fData, (const void*)v->fData, sizeof(fData) );
}
bool Uuid::IsNull() const
{
RPC_STATUS s;
return 1 == UuidIsNil( (GUID *)this, &s );
}
bool Uuid::FromString( const char * str )
{
Clear();
if ( !str )
return false;
return RPC_S_OK == UuidFromString( (unsigned char *)str, (GUID *)this );
}
bool Uuid::ToString( std::string & out ) const
{
out = "";
unsigned char * ubuf;
RPC_STATUS s;
s = UuidToString( (GUID *) this, &ubuf );
bool success = ( s==RPC_S_OK );
if ( success )
out = (char*)ubuf;
RpcStringFree( &ubuf );
return success;
}
// static
Uuid Uuid::Generate()
{
Uuid result;
UuidCreate( (GUID *)&result );
return result;
}
#endif
#ifdef HS_BUILD_FOR_WIN32
/*****************************************************************************
*
* Exports
*
***/
COMPILER_ASSERT(sizeof(Uuid) >= sizeof(GUID));
//============================================================================
Uuid GuidGenerate () {
Uuid result;
UuidCreate( (GUID *)&result );
return result;
}
//============================================================================
void GuidClear (Uuid * uuid) {
UuidCreateNil((GUID *)uuid);
}
//============================================================================
bool GuidFromString (const wchar str[], Uuid * uuid) {
ASSERT(uuid);
COMPILER_ASSERT(sizeof(wchar) == sizeof(unsigned short));
return RPC_S_OK == UuidFromStringW((unsigned short *) str, (GUID *) uuid);
}
//============================================================================
bool GuidFromString (const char str[], Uuid * uuid) {
ASSERT(uuid);
return RPC_S_OK == UuidFromStringA((unsigned char *) str, (GUID *) uuid);
}
//============================================================================
int GuidCompare (const Uuid & a, const Uuid & b) {
RPC_STATUS s;
return UuidCompare((GUID *)&a, (GUID *)&b, &s);
}
//============================================================================
bool GuidIsNil (const Uuid & uuid) {
RPC_STATUS s;
return 1 == UuidIsNil((GUID *)&uuid, &s );
}
//============================================================================
const wchar * GuidToString (const Uuid & uuid, wchar * dst, unsigned chars) {
wchar * src;
RPC_STATUS s;
s = UuidToStringW( (GUID *) &uuid, (RPC_WSTR*)&src );
if (RPC_S_OK == s)
StrCopy(dst, src, chars);
else
StrCopy(dst, L"", chars);
RpcStringFreeW( (RPC_WSTR *)&src );
return dst;
}
//============================================================================
const char * GuidToString (const Uuid & uuid, char * dst, unsigned chars) {
byte * src;
RPC_STATUS s;
s = UuidToStringA( (GUID *) &uuid, &src );
if (RPC_S_OK == s)
StrCopy(dst, (char *)src, chars);
else
StrCopy(dst, "", chars);
RpcStringFreeA(&src);
return dst;
}
#endif // HS_BUILD_FOR_WIN32