diff options
| author | Xanadu <none@none> | 2010-07-20 02:49:28 +0200 |
|---|---|---|
| committer | Xanadu <none@none> | 2010-07-20 02:49:28 +0200 |
| commit | 79622802f397258ee0f34327ba3ae6977ca3e7ff (patch) | |
| tree | 1868946c234ab9ee256a6b7766a15713eae94235 /src/server/shared | |
| parent | 7dd2dc91816ab8b3bc3b99a1b1c99c7ea314d5a8 (diff) | |
| parent | f906976837502fa5aa81b982b901d1509f5aa0c4 (diff) | |
Merge. Revision history for source files should be all back now.
--HG--
branch : trunk
rename : sql/CMakeLists.txt => sql/tools/CMakeLists.txt
rename : src/server/game/Pools/PoolHandler.cpp => src/server/game/Pools/PoolMgr.cpp
rename : src/server/game/Pools/PoolHandler.h => src/server/game/Pools/PoolMgr.h
rename : src/server/game/PrecompiledHeaders/NixCorePCH.cpp => src/server/game/PrecompiledHeaders/gamePCH.cpp
rename : src/server/game/PrecompiledHeaders/NixCorePCH.h => src/server/game/PrecompiledHeaders/gamePCH.h
Diffstat (limited to 'src/server/shared')
58 files changed, 343 insertions, 1058 deletions
diff --git a/src/server/shared/CMakeLists.txt b/src/server/shared/CMakeLists.txt index ed43a4eb6cd..2c474e61693 100644 --- a/src/server/shared/CMakeLists.txt +++ b/src/server/shared/CMakeLists.txt @@ -1,42 +1,125 @@ -add_subdirectory(vmap) -add_subdirectory(Auth) -add_subdirectory(Config) -add_subdirectory(Database) - -########### next target ############### - -SET(shared_STAT_SRCS - ByteBuffer.h - Common.cpp - Common.h - DelayExecutor.cpp - DelayExecutor.h - Errors.h - Log.cpp - Log.h - ProgressBar.cpp - ProgressBar.h - SignalHandler.h - Threading.cpp - Timer.h - Util.cpp - Util.h - WorldPacket.h - SystemConfig.h +# Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +########### shared ############### + +set(shared_STAT_SRCS + Logging/Log.cpp + Threading/DelayExecutor.cpp + Threading/Threading.cpp + Utilities/ProgressBar.cpp + Utilities/Util.cpp + Utilities/EventProcessor.cpp + Common.cpp ) +# Windows specific files +if(WIN32) + set(shared_STAT_SRCS + ${shared_STAT_SRCS} + Debugging/WheatyExceptionReport.cpp + Utilities/ServiceWin32.cpp + ) +endif() + include_directories( ${ACE_INCLUDE_DIR} ${CMAKE_BINARY_DIR} - ${CMAKE_SOURCE_DIR}/dep/include - ${CMAKE_SOURCE_DIR}/dep/include/sockets - ${CMAKE_SOURCE_DIR}/src/server/framework + ${CMAKE_SOURCE_DIR}/externals/mersennetwister + ${CMAKE_SOURCE_DIR}/externals/SFMT + ${CMAKE_SOURCE_DIR}/externals/sockets/include + ${CMAKE_SOURCE_DIR}/externals/utf8cpp ${CMAKE_SOURCE_DIR}/src/server/shared + ${CMAKE_SOURCE_DIR}/src/server/shared/Configuration + ${CMAKE_SOURCE_DIR}/src/server/shared/Cryptography + ${CMAKE_SOURCE_DIR}/src/server/shared/Database + ${CMAKE_SOURCE_DIR}/src/server/shared/DataStores + ${CMAKE_SOURCE_DIR}/src/server/shared/Debugging + ${CMAKE_SOURCE_DIR}/src/server/shared/Dynamic + ${CMAKE_SOURCE_DIR}/src/server/shared/Logging + ${CMAKE_SOURCE_DIR}/src/server/shared/Packets + ${CMAKE_SOURCE_DIR}/src/server/shared/Threading + ${CMAKE_SOURCE_DIR}/src/server/shared/Utilities ${MYSQL_INCLUDE_DIR} ) add_library(shared STATIC ${shared_STAT_SRCS}) + +if(WIN32) +target_link_libraries( + shared + ace +) +else() target_link_libraries( -shared -${ACE_LIBRARY} + shared + ${ACE_LIBRARY} +) +endif() + +########### trinityconfig ############### + +set(trinityconfig_STAT_SRCS + Configuration/dotconfpp/dotconfpp.cpp + Configuration/dotconfpp/mempool.cpp + Configuration/Config.cpp +) + +include_directories( + ${ACE_INCLUDE_DIR} + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/src/server/shared +) + +add_library(trinityconfig STATIC ${trinityconfig_STAT_SRCS}) + +########### trinityauth ############### + +set(trinityauth_STAT_SRCS + Cryptography/Authentication/AuthCrypt.cpp + Cryptography/BigNumber.cpp + Cryptography/HMACSHA1.cpp + Cryptography/SHA1.cpp + Cryptography/MD5.c + Cryptography/ARC4.cpp ) + +include_directories( + ${ACE_INCLUDE_DIR} + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/src/server/shared + ${MYSQL_INCLUDE_DIR} +) + +add_library(trinityauth STATIC ${trinityauth_STAT_SRCS}) + +########### trinitydatabase ############### + +set(trinitydatabase_STAT_SRCS + DataStores/DBCFileLoader.cpp + Database/Database.cpp + Database/Field.cpp + Database/QueryResult.cpp + Database/SQLStorage.cpp + Database/SqlDelayThread.cpp + Database/SqlOperations.cpp + Database/PreparedStatements.cpp +) + +include_directories( + ${ACE_INCLUDE_DIR} + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/src/server/shared + ${CMAKE_SOURCE_DIR}/src/server/shared/Database + ${CMAKE_SOURCE_DIR}/src/server/game/Entities/Object + ${MYSQL_INCLUDE_DIR} +) + +add_library(trinitydatabase STATIC ${trinitydatabase_STAT_SRCS}) diff --git a/src/server/shared/Common.h b/src/server/shared/Common.h index 4a6aac43390..f7407e78aac 100644 --- a/src/server/shared/Common.h +++ b/src/server/shared/Common.h @@ -59,7 +59,7 @@ #undef VERSION #endif //HAVE_CONFIG_H -#include "Platform/Define.h" +#include "Define.h" #if COMPILER == COMPILER_MICROSOFT # pragma warning(disable:4996) // 'function': was declared deprecated @@ -76,7 +76,7 @@ #endif // __SHOW_STUPID_WARNINGS__ #endif // __GNUC__ -#include "Utilities/UnorderedMap.h" +#include "Dynamic/UnorderedMap.h" #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -100,8 +100,8 @@ #include <sstream> #include <algorithm> -#include "LockedQueue.h" -#include "Threading.h" +#include "Threading/LockedQueue.h" +#include "Threading/Threading.h" #include <ace/Basic_Types.h> #include <ace/Guard_T.h> @@ -168,7 +168,7 @@ enum TimeConstants WEEK = DAY*7, MONTH = DAY*30, YEAR = MONTH*12, - IN_MILISECONDS = 1000 + IN_MILLISECONDS = 1000 }; enum AccountTypes diff --git a/src/server/shared/CompilerDefs.h b/src/server/shared/CompilerDefs.h index fb7dbfe4caa..d2d470e2097 100644 --- a/src/server/shared/CompilerDefs.h +++ b/src/server/shared/CompilerDefs.h @@ -26,7 +26,7 @@ #define PLATFORM_APPLE 2 #define PLATFORM_INTEL 3 -// must be first (win 64 also define WIN32) +// must be first (win 64 also define _WIN32) #if defined( _WIN64 ) # define PLATFORM PLATFORM_WINDOWS #elif defined( __WIN32__ ) || defined( WIN32 ) || defined( _WIN32 ) diff --git a/src/server/shared/Configuration/CMakeLists.txt b/src/server/shared/Configuration/CMakeLists.txt deleted file mode 100644 index da1c2e8aa3b..00000000000 --- a/src/server/shared/Configuration/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ - -########### next target ############### - -SET(trinityconfig_STAT_SRCS - dotconfpp/dotconfpp.cpp - dotconfpp/dotconfpp.h - dotconfpp/mempool.cpp - dotconfpp/mempool.h - Config.cpp - Config.h - ConfigEnv.h -) - -include_directories( - ${ACE_INCLUDE_DIR} - ${CMAKE_BINARY_DIR} - ${CMAKE_SOURCE_DIR}/src/server/shared - ${CMAKE_SOURCE_DIR}/src/server/framework -) - -add_library(trinityconfig STATIC ${trinityconfig_STAT_SRCS}) - diff --git a/src/server/shared/Configuration/Config.cpp b/src/server/shared/Configuration/Config.cpp index 39830104a7c..3979cbc36aa 100644 --- a/src/server/shared/Configuration/Config.cpp +++ b/src/server/shared/Configuration/Config.cpp @@ -19,9 +19,6 @@ */ #include "ConfigEnv.h" -#include "Policies/SingletonImp.h" - -INSTANTIATE_SINGLETON_1(Config); Config::Config() : mIgnoreCase(true), mConf(NULL) { diff --git a/src/server/shared/Configuration/Config.h b/src/server/shared/Configuration/Config.h index ccc76073e46..50cd4609b25 100644 --- a/src/server/shared/Configuration/Config.h +++ b/src/server/shared/Configuration/Config.h @@ -21,15 +21,16 @@ #ifndef CONFIG_H #define CONFIG_H -#include <Policies/Singleton.h> -#include "Platform/Define.h" +#include <ace/Singleton.h> +#include "Define.h" class DOTCONFDocument; class Config { + friend class ACE_Singleton<Config, ACE_Null_Mutex>; + Config(); public: - Config(); ~Config(); bool SetSource(const char *file, bool ignorecase = true); @@ -47,7 +48,7 @@ class Config DOTCONFDocument *mConf; }; -#define sConfig Trinity::Singleton<Config>::Instance() +#define sConfig (*ACE_Singleton<Config, ACE_Null_Mutex>::instance()) #endif diff --git a/src/server/shared/Cryptography/ARC4.cpp b/src/server/shared/Cryptography/ARC4.cpp index 80cad4991e9..8427640ba2a 100644 --- a/src/server/shared/Cryptography/ARC4.cpp +++ b/src/server/shared/Cryptography/ARC4.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "Auth/SARC4.h" +#include "ARC4.h" #include <openssl/sha.h> SARC4::SARC4(uint8 len) diff --git a/src/server/shared/Cryptography/Authentication/AuthCrypt.cpp b/src/server/shared/Cryptography/Authentication/AuthCrypt.cpp index b34b922b16a..2dfcebfa932 100644 --- a/src/server/shared/Cryptography/Authentication/AuthCrypt.cpp +++ b/src/server/shared/Cryptography/Authentication/AuthCrypt.cpp @@ -19,9 +19,9 @@ */ #include "AuthCrypt.h" -#include "Hmac.h" -#include "Log.h" -#include "BigNumber.h" +#include "Cryptography/HMACSHA1.h" +#include "Logging/Log.h" +#include "Cryptography/BigNumber.h" AuthCrypt::AuthCrypt() : _clientDecrypt(SHA_DIGEST_LENGTH), _serverEncrypt(SHA_DIGEST_LENGTH) { diff --git a/src/server/shared/Cryptography/Authentication/AuthCrypt.h b/src/server/shared/Cryptography/Authentication/AuthCrypt.h index 6695dc580cc..5a2430611a4 100644 --- a/src/server/shared/Cryptography/Authentication/AuthCrypt.h +++ b/src/server/shared/Cryptography/Authentication/AuthCrypt.h @@ -22,7 +22,7 @@ #define _AUTHCRYPT_H #include <Common.h> -#include "SARC4.h" +#include "Cryptography/ARC4.h" class BigNumber; diff --git a/src/server/shared/Cryptography/BigNumber.cpp b/src/server/shared/Cryptography/BigNumber.cpp index 64e9ef21ccc..c05258c73a0 100644 --- a/src/server/shared/Cryptography/BigNumber.cpp +++ b/src/server/shared/Cryptography/BigNumber.cpp @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "Auth/BigNumber.h" +#include "Cryptography/BigNumber.h" #include <openssl/bn.h> #include <algorithm> diff --git a/src/server/shared/Cryptography/CMakeLists.txt b/src/server/shared/Cryptography/CMakeLists.txt deleted file mode 100644 index 6e5d10d40e5..00000000000 --- a/src/server/shared/Cryptography/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ - -########### next target ############### - -SET(trinityauth_STAT_SRCS - AuthCrypt.cpp - AuthCrypt.h - BigNumber.cpp - BigNumber.h - Hmac.cpp - Hmac.h - Sha1.cpp - Sha1.h - md5.c - md5.h - SARC4.cpp - SARC4.h -) - -include_directories( - ${ACE_INCLUDE_DIR} - ${CMAKE_BINARY_DIR} - ${CMAKE_SOURCE_DIR}/src/server/shared - ${CMAKE_SOURCE_DIR}/src/server/framework - ${MYSQL_INCLUDE_DIR} -) - -add_library(trinityauth STATIC ${trinityauth_STAT_SRCS}) diff --git a/src/server/shared/Cryptography/HMACSHA1.cpp b/src/server/shared/Cryptography/HMACSHA1.cpp index a30f1b2d1e2..aed8940372b 100644 --- a/src/server/shared/Cryptography/HMACSHA1.cpp +++ b/src/server/shared/Cryptography/HMACSHA1.cpp @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "Auth/Hmac.h" +#include "HMACSHA1.h" #include "BigNumber.h" HmacHash::HmacHash(uint32 len, uint8 *seed) diff --git a/src/server/shared/Cryptography/MD5.c b/src/server/shared/Cryptography/MD5.c index 3e9735e2dbb..45897503455 100644 --- a/src/server/shared/Cryptography/MD5.c +++ b/src/server/shared/Cryptography/MD5.c @@ -51,7 +51,7 @@ self-checking. 1999-05-03 lpd Original version. */ -#include "md5.h" +#include "MD5.h" #include <string.h> #undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */ diff --git a/src/server/shared/Cryptography/SHA1.cpp b/src/server/shared/Cryptography/SHA1.cpp index b63deb2c5f3..b50f72af4d3 100644 --- a/src/server/shared/Cryptography/SHA1.cpp +++ b/src/server/shared/Cryptography/SHA1.cpp @@ -18,8 +18,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "Auth/Sha1.h" -#include "Auth/BigNumber.h" +#include "SHA1.h" +#include "BigNumber.h" #include <stdarg.h> Sha1Hash::Sha1Hash() diff --git a/src/server/shared/DataStores/DBCFileLoader.h b/src/server/shared/DataStores/DBCFileLoader.h index a97ab4d60fa..f59ad038ce0 100644 --- a/src/server/shared/DataStores/DBCFileLoader.h +++ b/src/server/shared/DataStores/DBCFileLoader.h @@ -18,7 +18,7 @@ #ifndef DBC_FILE_LOADER_H #define DBC_FILE_LOADER_H -#include "Platform/Define.h" +#include "Define.h" #include "Utilities/ByteConverter.h" #include <cassert> diff --git a/src/server/shared/DataStores/DBCStore.h b/src/server/shared/DataStores/DBCStore.h index 61e2f7a6d06..cd1d1881d68 100644 --- a/src/server/shared/DataStores/DBCStore.h +++ b/src/server/shared/DataStores/DBCStore.h @@ -20,7 +20,7 @@ #define DBCSTORE_H #include "DBCFileLoader.h" -#include "Log.h" +#include "Logging/Log.h" struct SqlDbc { diff --git a/src/server/shared/Database/CMakeLists.txt b/src/server/shared/Database/CMakeLists.txt deleted file mode 100644 index e30c8ae3ca2..00000000000 --- a/src/server/shared/Database/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -SET(trinitydatabase_STAT_SRCS - DBCFileLoader.cpp - DBCFileLoader.h - DBCStore.h - Database.cpp - Database.h - DatabaseEnv.h - DatabaseImpl.h - Field.cpp - Field.h - QueryResult.cpp - QueryResult.h - SQLStorage.cpp - SQLStorage.h - SqlDelayThread.cpp - SqlDelayThread.h - SqlOperations.cpp - SqlOperations.h -) - -include_directories( - ${ACE_INCLUDE_DIR} - ${CMAKE_BINARY_DIR} - ${CMAKE_SOURCE_DIR}/src/server/shared - ${CMAKE_SOURCE_DIR}/src/server/shared/Database - ${CMAKE_SOURCE_DIR}/src/server/framework - ${CMAKE_SOURCE_DIR}/src/server/game/Entities/Object - ${MYSQL_INCLUDE_DIR} -) - -add_library(trinitydatabase STATIC ${trinitydatabase_STAT_SRCS}) diff --git a/src/server/shared/Database/Database.cpp b/src/server/shared/Database/Database.cpp index 7646a451eb4..1fb2f831a9f 100644 --- a/src/server/shared/Database/Database.cpp +++ b/src/server/shared/Database/Database.cpp @@ -19,18 +19,17 @@ */ #include "DatabaseEnv.h" -#include "Config/ConfigEnv.h" +#include "Configuration/ConfigEnv.h" #include "Common.h" -#include "UpdateFields.h" +#include "Updates/UpdateFields.h" -#include "Util.h" -#include "Policies/SingletonImp.h" -#include "Platform/Define.h" -#include "Threading.h" +#include "Utilities/Util.h" +#include "Define.h" +#include "Threading/Threading.h" #include "Database/SqlDelayThread.h" #include "Database/SqlOperations.h" -#include "Timer.h" +#include "Utilities/Timer.h" #include <ctime> @@ -113,7 +112,7 @@ bool Database::Initialize(const char *infoString) database = *iter++; mysql_options(mysqlInit, MYSQL_SET_CHARSET_NAME, "utf8"); - #ifdef WIN32 + #ifdef _WIN32 if (host==".") // named pipe use option (Windows) { unsigned int opt = MYSQL_PROTOCOL_PIPE; diff --git a/src/server/shared/Database/Database.h b/src/server/shared/Database/Database.h index 4ad5d29c993..762abfd2ede 100644 --- a/src/server/shared/Database/Database.h +++ b/src/server/shared/Database/Database.h @@ -21,14 +21,13 @@ #ifndef DATABASE_H #define DATABASE_H -#include "Threading.h" -#include "Utilities/UnorderedMap.h" +#include "Threading/Threading.h" +#include "Dynamic/UnorderedMap.h" #include "Database/SqlDelayThread.h" -#include "Policies/Singleton.h" #include "ace/Thread_Mutex.h" #include "ace/Guard_T.h" -#ifdef WIN32 +#ifdef _WIN32 #define FD_SETSIZE 1024 #include <winsock2.h> #include <mysql/mysql.h> @@ -117,7 +116,7 @@ class Database bool _UpdateDataBlobValue(const uint32 guid, const uint32 field, const int32 value); bool _SetDataBlobValue(const uint32 guid, const uint32 field, const uint32 value); - // Writes SQL commands to a LOG file (see Trinityd.conf "LogSQL") + // Writes SQL commands to a LOG file (see worldserver.conf "LogSQL") bool PExecuteLog(const char *format,...) ATTR_PRINTF(2,3); bool BeginTransaction(); diff --git a/src/server/shared/Database/DatabaseEnv.h b/src/server/shared/Database/DatabaseEnv.h index 69236b076e9..15c1b1c599e 100644 --- a/src/server/shared/Database/DatabaseEnv.h +++ b/src/server/shared/Database/DatabaseEnv.h @@ -22,8 +22,8 @@ #define DATABASEENV_H #include "Common.h" -#include "Log.h" -#include "Errors.h" +#include "Logging/Log.h" +#include "Debugging/Errors.h" #include "Database/Field.h" #include "Database/QueryResult.h" diff --git a/src/server/shared/Database/PreparedStatements.cpp b/src/server/shared/Database/PreparedStatements.cpp new file mode 100644 index 00000000000..40a910acf9e --- /dev/null +++ b/src/server/shared/Database/PreparedStatements.cpp @@ -0,0 +1,93 @@ +#include "PreparedStatements.h" + +void PreparedStatementHolder::_prepareStatement(const char* name, const char* sql, Database *db, uint32 &count) +{ + const char prefix[] = "PREPARE "; + size_t querySize = 8 + strlen(name) + 6 + strlen(sql) + 2 + 1; + char* query = new char[querySize]; + strcpy(query, prefix); + strcat(query, name); + strcat(query, " FROM "); + strcat(query, "'"); + strcat(query, sql); + strcat(query, "'"); + + DEBUG_LOG("Preparing statement: %s", query); + db->Execute(query); + + delete[] query; + ++count; +} + +void PreparedStatementHolder::LoadAuthserver(Database *db, uint32 &count) +{ + _prepareStatement("auth_ping", "SELECT 1 FROM realmlist LIMIT 1", db, count); +}; + +void PreparedStatementHolder::Execute(Database *db, const char *name) +{ + const char prefix[] = "EXECUTE "; + size_t querySize = 8 + strlen(name) + 1; + char* query = new char[querySize]; + strcpy(query, prefix); + strcat(query, name); + + DEBUG_LOG("Prepared statement: %s", query); + db->Execute(query); + delete[] query; +} + +void PreparedStatementHolder::PExecute(Database *db, const char *name, const char* args) +{ + // NOTE: if args == NULL, we're crashing here. No need to waste performance on checking; + // devs must make sure they use PExecute for args and Execute for no args. + + const char prefix[] = "EXECUTE "; + size_t querySize = 8 + strlen(name) + 7 + strlen(args) + 1; + char* query = new char[querySize]; + strcpy(query, prefix); + strcat(query, name); + strcat(query, " USING "); + strcat(query, args); + + DEBUG_LOG("Prepared statement (parsed args): %s", query); + db->Execute(query); + delete[] query; +} + +QueryResult_AutoPtr PreparedStatementHolder::Query(Database *db, const char *name) +{ + QueryResult_AutoPtr _return = QueryResult_AutoPtr(NULL); + + const char prefix[] = "EXECUTE "; + size_t querySize = 8 + strlen(name) + 1; + char* query = new char[querySize]; + strcpy(query, prefix); + strcat(query, name); + + DEBUG_LOG("Prepared statement with resultset: %s", query); + _return = db->Query(query); + delete[] query; + return _return; +} + +QueryResult_AutoPtr PreparedStatementHolder::PQuery(Database *db, const char *name, const char *args) +{ + // NOTE: if args == NULL, we're crashing here. No need to waste performance on checking; + // devs must make sure they use PQuery for args and Query for no args. + + QueryResult_AutoPtr _return = QueryResult_AutoPtr(NULL); + + const char prefix[] = "EXECUTE "; + size_t querySize = 8 + strlen(name) + 7 + strlen(args) + 1; + char* query = new char[querySize]; + strcpy(query, prefix); + strcat(query, name); + strcat(query, " USING "); + strcat(query, args); + + DEBUG_LOG("Prepared statement with resultset (parsed args): %s", query); + _return = db->Query(query); + delete[] query; + return _return; +}
\ No newline at end of file diff --git a/src/server/shared/Database/PreparedStatements.h b/src/server/shared/Database/PreparedStatements.h new file mode 100644 index 00000000000..c19119dcb3d --- /dev/null +++ b/src/server/shared/Database/PreparedStatements.h @@ -0,0 +1,30 @@ +#ifndef sPreparedStatement + +#include "ace/Singleton.h" +#include "Database/DatabaseEnv.h" + +class PreparedStatementHolder +{ + public: + ///- Load prepare statements on database $db and increase $count for every statement + void LoadCharacters(Database *db, uint32 &count); + void LoadAuthserver(Database *db, uint32 &count); + void LoadWorldserver(Database *db, uint32 &count); + + ///- Executes prepared statement that doesn't require feedback with name $name on database $db + void Execute(Database *db, const char* name); + ///- Executes prepared statement that doesn't require feedback with name $name and args $args + ///- on database $db + void PExecute(Database *db, const char* name, const char* args); + + ///- Executes a prepared statement without args on db $db with name $name and puts the result set in a pointer. + QueryResult_AutoPtr Query(Database* db, const char* name); + ///- Executes a prepared statement with args $args on db $db with name $name and put the result set in a pointer. + QueryResult_AutoPtr PQuery(Database* db, const char* name, const char* args); + + private: + void _prepareStatement(const char* name, const char* sql, Database *db, uint32 &count); + +}; +#define sPreparedStatement (*ACE_Singleton<PreparedStatementHolder, ACE_Null_Mutex>::instance()) +#endif
\ No newline at end of file diff --git a/src/server/shared/Database/QueryResult.h b/src/server/shared/Database/QueryResult.h index 4eec9915362..5562a9abfa4 100644 --- a/src/server/shared/Database/QueryResult.h +++ b/src/server/shared/Database/QueryResult.h @@ -26,7 +26,7 @@ #include "Field.h" -#ifdef WIN32 +#ifdef _WIN32 #define FD_SETSIZE 1024 #include <winsock2.h> #include <mysql/mysql.h> diff --git a/src/server/shared/Database/SQLStorageImpl.h b/src/server/shared/Database/SQLStorageImpl.h index c74be48c34c..b3d06484e2e 100644 --- a/src/server/shared/Database/SQLStorageImpl.h +++ b/src/server/shared/Database/SQLStorageImpl.h @@ -16,9 +16,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "ProgressBar.h" -#include "Log.h" -#include "DBCFileLoader.h" +#include "Utilities/ProgressBar.h" +#include "Logging/Log.h" +#include "DataStores/DBCFileLoader.h" template<class T> template<class S, class D> diff --git a/src/server/shared/Database/SqlDelayThread.h b/src/server/shared/Database/SqlDelayThread.h index d603813c8fa..4ef9c67aa5b 100644 --- a/src/server/shared/Database/SqlDelayThread.h +++ b/src/server/shared/Database/SqlDelayThread.h @@ -23,7 +23,7 @@ #include "ace/Thread_Mutex.h" #include "ace/Activation_Queue.h" -#include "Threading.h" +#include "Threading/Threading.h" class Database; class SqlOperation; diff --git a/src/server/shared/Database/SqlOperations.h b/src/server/shared/Database/SqlOperations.h index f2e09c0c921..eb28a2c0790 100644 --- a/src/server/shared/Database/SqlOperations.h +++ b/src/server/shared/Database/SqlOperations.h @@ -25,9 +25,9 @@ #include "ace/Thread_Mutex.h" #include "ace/Method_Request.h" -#include "LockedQueue.h" +#include "Threading/LockedQueue.h" #include <queue> -#include "Utilities/Callback.h" +#include "Threading/Callback.h" #include "QueryResult.h" /// ---- BASE --- diff --git a/src/server/shared/Debugging/MemoryLeaks.cpp b/src/server/shared/Debugging/MemoryLeaks.cpp index ef7e36c3b57..c591dabb866 100644 --- a/src/server/shared/Debugging/MemoryLeaks.cpp +++ b/src/server/shared/Debugging/MemoryLeaks.cpp @@ -17,9 +17,6 @@ */ #include "MemoryLeaks.h" -#include "Policies/SingletonImp.h" - -INSTANTIATE_SINGLETON_1( MemoryManager ) ; MemoryManager::MemoryManager( ) { diff --git a/src/server/shared/Debugging/MemoryLeaks.h b/src/server/shared/Debugging/MemoryLeaks.h index c8b8fb8e1b1..4b13e4d3d90 100644 --- a/src/server/shared/Debugging/MemoryLeaks.h +++ b/src/server/shared/Debugging/MemoryLeaks.h @@ -19,7 +19,7 @@ #ifndef TRINITYSERVER_MEMORY_H #define TRINITYSERVER_MEMORY_H -#include "Platform/CompilerDefs.h" +#include "shared/CompilerDefs.h" #if COMPILER == COMPILER_MICROSOFT @@ -39,10 +39,11 @@ #endif -#include "Policies/Singleton.h" +#include "ace/Singleton.h" -struct MemoryManager : public Trinity::Singleton < MemoryManager > +struct MemoryManager { MemoryManager(); }; +#define sMemoryManager ACE_Singleton<MemoryManager, ACE_Null_Mutex>::instance() #endif diff --git a/src/server/shared/Define.h b/src/server/shared/Define.h index 9285bf289f9..980cf9023e1 100644 --- a/src/server/shared/Define.h +++ b/src/server/shared/Define.h @@ -26,7 +26,7 @@ #include <ace/Basic_Types.h> #include <ace/ACE_export.h> -#include "Platform/CompilerDefs.h" +#include "CompilerDefs.h" #define TRINITY_LITTLEENDIAN 0 #define TRINITY_BIGENDIAN 1 diff --git a/src/server/shared/Dynamic/CountedReference/Reference.h b/src/server/shared/Dynamic/CountedReference/Reference.h deleted file mode 100644 index d3cfe55ffc0..00000000000 --- a/src/server/shared/Dynamic/CountedReference/Reference.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_REFERENCE_H -#define TRINITY_REFERENCE_H - -/** - * Referencer<T> - * Referencer is an object that holds a reference holder that hold a reference - * counted object. When an object's reference count drop to zero, it removes - * the object. This is a non intrusive mechanism and any object at any point - * in time can be referenced. When and object is reference counted, do not - * pass the object directly to other methods but rather, pass its - * reference around. Objects can be reference counted in both single threaded - * model and multi-threaded model - */ - -#include <stdexcept> -#include "Platform/Define.h" -#include "Policies/ThreadingModel.h" -#include "ReferenceHolder.h" - -template -< -typename T, -class THREADING_MODEL = Trinity::SingleThreaded<T> -> -class Referencer -{ - typedef typename THREADING_MODEL::Lock Lock; - typedef ReferenceHolder<T, THREADING_MODEL> ReferenceeHolder; - public: - - /// Constructs a referencer. - Referencer(T *ref = NULL); - - /// Copy constructor - Referencer(const Referencer &obj) : i_holder(NULL) { *this = obj; } - - /// Destructor - ~Referencer(); - - /// Referencee accessor - T* referencee(void) { return (i_holder == NULL ? NULL : i_holder->i_referencee); } - const T* referencee(void) const { return (i_holder == NULL ? NULL : i_holder->i_referencee); } - - //T& referencee(void){ return _referencee(); } - //const T& referencee(void) const { return const_cast<Referencer *>(this)->_referencee(); } - operator T&(void) { return _referencee(); } - operator const T&(void) const { return *const_cast<Referencer *>(this)->_referencee(); } - - /// cast operators - T* operator*() { return (i_holder == NULL ? NULL : i_holder->i_referencee); } - T const * operator*() const { return (i_holder == NULL ? NULL : i_holder->i_referencee); } - - /// overload operators - T* operator->() { return (i_holder == NULL ? NULL : i_holder->i_referencee); } - const T * operator->() const { return (i_holder == NULL ? NULL : i_holder->i_referencee); } - - /// operator = - Referencer& operator=(const Referencer &obj); - Referencer& operator=(T *); - - /// returns true if i_referencee is null - bool isNull(void) const { return i_holder == NULL; } - - private: - - T& _referencee(void) - { - if( i_holder == NULL ) - throw std::runtime_error("Invalid access to null pointer"); - return *i_holder->i_referencee; - } - - void deReference(ReferenceeHolder *); - void addReference(ReferenceeHolder *); - - // private data - ReferenceeHolder *i_holder; -}; -#endif - diff --git a/src/server/shared/Dynamic/CountedReference/ReferenceHolder.h b/src/server/shared/Dynamic/CountedReference/ReferenceHolder.h deleted file mode 100644 index 597e9854be0..00000000000 --- a/src/server/shared/Dynamic/CountedReference/ReferenceHolder.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_REFERENCEHOLDER_H -#define TRINITY_REFERENCEHOLDER_H - -/** ReferenceHolder holds the actualy referenced obejct as well the refence - count. The ReferenecHolder implements as a policy base object and - will decided by the Reference class to be consnsitent. - */ - -template -< -typename T, -class THREADING_MODEL -> -struct ReferenceHolder : public THREADING_MODEL -{ - explicit ReferenceHolder(T *ref) : i_referencee(ref), i_referenceCount(0) {} - T *i_referencee; - unsigned int i_referenceCount; - typedef typename THREADING_MODEL::Lock Lock; -}; -#endif - diff --git a/src/server/shared/Dynamic/CountedReference/ReferenceImpl.h b/src/server/shared/Dynamic/CountedReference/ReferenceImpl.h deleted file mode 100644 index cde330179e3..00000000000 --- a/src/server/shared/Dynamic/CountedReference/ReferenceImpl.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_REFERENCEIMPL_H -#define TRINITY_REFERENCEIMPL_H - -#include "Reference.h" - -template -< -typename T, -class THREADING_MODEL -> -Referencer<T, THREADING_MODEL>::Referencer(T *ref) -: i_holder(NULL) -{ - if( ref != NULL ) - { - i_holder = new ReferenceeHolder(ref); - ++i_holder->i_referenceCount; - } -} - -template -< -typename T, -class THREADING_MODEL -> -Referencer<T, THREADING_MODEL>::~Referencer() -{ - if( i_holder != NULL ) - deReference(i_holder); - i_holder = NULL; -} - -template -< -typename T, -class THREADING_MODEL -> -Referencer<T, THREADING_MODEL>& -Referencer<T, THREADING_MODEL>::operator=(const Referencer<T, THREADING_MODEL> &obj) -{ - if( i_holder != NULL ) - deReference(i_holder); - if( obj.i_holder != NULL ) - addReference(obj.i_holder); - i_holder = obj.i_holder; - return *this; -} - -template -< -typename T, -class THREADING_MODEL -> -Referencer<T, THREADING_MODEL>& -Referencer<T, THREADING_MODEL>::operator=(T *ref) -{ - if( i_holder != NULL ) - deReference(i_holder); - i_holder = NULL; - if( ref != NULL ) - { - i_holder = new ReferenceeHolder(ref); - ++i_holder->i_referenceCount; - } - - return *this; -} - -template -< -typename T, -class THREADING_MODEL -> -void -Referencer<T, THREADING_MODEL>::deReference(ReferenceHolder<T, THREADING_MODEL> *holder) -{ - assert( holder != NULL && holder->i_referenceCount > 0); - bool delete_object = false; - - { - // The guard is within the scope due to the guard - // must release earlier than expected. - Lock guard(*holder); - Guard(&guard); - - --holder->i_referenceCount; - if( holder->i_referenceCount == 0 ) - delete_object = true; - } - - if( delete_object ) - { - delete holder->i_referencee; - delete holder; - } -} - -template -< -typename T, -class THREADING_MODEL -> -void -Referencer<T, THREADING_MODEL>::addReference(ReferenceHolder<T, THREADING_MODEL> *holder) -{ - assert( i_holder != NULL ); - Lock guard(*holder); - Guard(&guard); - - ++holder->i_referenceCount; -} -#endif - diff --git a/src/server/shared/Dynamic/FactoryHolder.h b/src/server/shared/Dynamic/FactoryHolder.h index 282968d6097..096bdad1783 100644 --- a/src/server/shared/Dynamic/FactoryHolder.h +++ b/src/server/shared/Dynamic/FactoryHolder.h @@ -21,10 +21,9 @@ #ifndef TRINITY_FACTORY_HOLDER #define TRINITY_FACTORY_HOLDER -#include "Platform/Define.h" -#include "Utilities/TypeList.h" +#include "Define.h" +#include "Dynamic/TypeList.h" #include "ObjectRegistry.h" -#include "Policies/SingletonImp.h" /** FactoryHolder holds a factory object of a specific type */ @@ -33,14 +32,15 @@ class FactoryHolder { public: typedef ObjectRegistry<FactoryHolder<T, Key >, Key > FactoryHolderRegistry; - typedef Trinity::Singleton<FactoryHolderRegistry > FactoryHolderRepository; + friend class ACE_Singleton<FactoryHolderRegistry, ACE_Null_Mutex>; + typedef ACE_Singleton<FactoryHolderRegistry, ACE_Null_Mutex> FactoryHolderRepository; FactoryHolder(Key k) : i_key(k) {} virtual ~FactoryHolder() {} inline Key key() const { return i_key; } - void RegisterSelf(void) { FactoryHolderRepository::Instance().InsertItem(this, i_key); } - void DeregisterSelf(void) { FactoryHolderRepository::Instance().RemoveItem(this, false); } + void RegisterSelf(void) { FactoryHolderRepository::instance()->InsertItem(this, i_key); } + void DeregisterSelf(void) { FactoryHolderRepository::instance()->RemoveItem(this, false); } /// Abstract Factory create method virtual T* Create(void *data = NULL) const = 0; diff --git a/src/server/shared/Dynamic/LinkedReference/RefManager.h b/src/server/shared/Dynamic/LinkedReference/RefManager.h index 7e294b4f5f0..ea79d5e1784 100644 --- a/src/server/shared/Dynamic/LinkedReference/RefManager.h +++ b/src/server/shared/Dynamic/LinkedReference/RefManager.h @@ -22,8 +22,8 @@ #define _REFMANAGER_H //===================================================== -#include "Utilities/LinkedList.h" -#include "Utilities/LinkedReference/Reference.h" +#include "Dynamic/LinkedList.h" +#include "Dynamic/LinkedReference/Reference.h" template <class TO, class FROM> class RefManager : public LinkedListHead { diff --git a/src/server/shared/Dynamic/LinkedReference/Reference.h b/src/server/shared/Dynamic/LinkedReference/Reference.h index 4a1545f8f12..8891199a5eb 100644 --- a/src/server/shared/Dynamic/LinkedReference/Reference.h +++ b/src/server/shared/Dynamic/LinkedReference/Reference.h @@ -21,7 +21,7 @@ #ifndef _REFERENCE_H #define _REFERENCE_H -#include "Utilities/LinkedList.h" +#include "Dynamic/LinkedList.h" //===================================================== diff --git a/src/server/shared/Dynamic/ObjectRegistry.h b/src/server/shared/Dynamic/ObjectRegistry.h index e6619427885..11052a9f0a7 100644 --- a/src/server/shared/Dynamic/ObjectRegistry.h +++ b/src/server/shared/Dynamic/ObjectRegistry.h @@ -21,9 +21,9 @@ #ifndef TRINITY_OBJECTREGISTRY_H #define TRINITY_OBJECTREGISTRY_H -#include "Platform/Define.h" -#include "Utilities/UnorderedMap.h" -#include "Policies/Singleton.h" +#include "Define.h" +#include "Dynamic/UnorderedMap.h" +#include "ace/Singleton.h" #include <string> #include <vector> @@ -94,11 +94,6 @@ class ObjectRegistry return i_registeredObjects; } - private: - RegistryMapType i_registeredObjects; - friend class Trinity::OperatorNew<ObjectRegistry<T, Key> >; - - // protected for friend use since it should be a singleton ObjectRegistry() {} ~ObjectRegistry() { @@ -106,6 +101,9 @@ class ObjectRegistry delete iter->second; i_registeredObjects.clear(); } + private: + RegistryMapType i_registeredObjects; + }; #endif diff --git a/src/server/shared/Dynamic/TypeContainer.h b/src/server/shared/Dynamic/TypeContainer.h index c2c9b4fcdea..4ed07431ee3 100644 --- a/src/server/shared/Dynamic/TypeContainer.h +++ b/src/server/shared/Dynamic/TypeContainer.h @@ -28,9 +28,9 @@ #include <map> #include <vector> -#include "Platform/Define.h" -#include "Utilities/TypeList.h" -#include "GameSystem/GridRefManager.h" +#include "Define.h" +#include "Dynamic/TypeList.h" +#include "GridRefManager.h" /* * @class ContainerMapList is a mulit-type container for map elements diff --git a/src/server/shared/Dynamic/TypeContainerFunctions.h b/src/server/shared/Dynamic/TypeContainerFunctions.h index edfbb40e659..7ab2151461e 100644 --- a/src/server/shared/Dynamic/TypeContainerFunctions.h +++ b/src/server/shared/Dynamic/TypeContainerFunctions.h @@ -27,8 +27,8 @@ * to access or mutate the container. */ -#include "Platform/Define.h" -#include "Utilities/TypeList.h" +#include "Define.h" +#include "Dynamic/TypeList.h" #include <map> namespace Trinity diff --git a/src/server/shared/Dynamic/TypeContainerVisitor.h b/src/server/shared/Dynamic/TypeContainerVisitor.h index f15075e5afd..6057eb32fc3 100644 --- a/src/server/shared/Dynamic/TypeContainerVisitor.h +++ b/src/server/shared/Dynamic/TypeContainerVisitor.h @@ -27,8 +27,8 @@ * to overload its types as a visit method is called. */ -#include "Platform/Define.h" -#include "TypeContainer.h" +#include "Define.h" +#include "Dynamic/TypeContainer.h" // forward declaration template<class T, class Y> class TypeContainerVisitor; diff --git a/src/server/shared/Dynamic/UnorderedMap.h b/src/server/shared/Dynamic/UnorderedMap.h index fce5ec82bfc..d9f41fe4ab8 100644 --- a/src/server/shared/Dynamic/UnorderedMap.h +++ b/src/server/shared/Dynamic/UnorderedMap.h @@ -21,8 +21,8 @@ #ifndef TRINITY_UNORDERED_MAP_H #define TRINITY_UNORDERED_MAP_H -#include "Platform/CompilerDefs.h" -#include "Platform/Define.h" +#include "CompilerDefs.h" +#include "Define.h" #if COMPILER == COMPILER_INTEL #include <ext/hash_map> @@ -62,7 +62,13 @@ namespace __gnu_cxx { size_t operator()(T * const &__x) const { return (size_t)__x; } }; - + template<> struct hash<std::string> + { + size_t operator()(const std::string &__x) const + { + return hash<const char *>()(__x.c_str()); + } + }; }; #else diff --git a/src/server/shared/Logging/Log.cpp b/src/server/shared/Logging/Log.cpp index 187b9eaa79b..7a34eaa0c0d 100644 --- a/src/server/shared/Logging/Log.cpp +++ b/src/server/shared/Logging/Log.cpp @@ -20,15 +20,12 @@ #include "Common.h" #include "Log.h" -#include "Policies/SingletonImp.h" -#include "Config/ConfigEnv.h" +#include "Configuration/ConfigEnv.h" #include "Util.h" #include <stdarg.h> #include <stdio.h> -INSTANTIATE_SINGLETON_1( Log ); - Log::Log() : raLogfile(NULL), logfile(NULL), gmLogfile(NULL), charLogfile(NULL), dberLogfile(NULL), chatLogfile(NULL), m_gmlog_per_account(false), @@ -450,7 +447,7 @@ void Log::outCrash(const char * err, ...) va_list ap; va_start(ap, err); - vutf8printf(stdout, err, &ap); + vutf8printf(stderr, err, &ap); va_end(ap); if (m_colored) @@ -530,7 +527,6 @@ void Log::outArena(const char * str, ...) va_end(ap); fflush(arenaLogFile); } - fflush(stdout); } void Log::outErrorDb(const char * err, ...) @@ -902,7 +898,6 @@ void Log::outRemote(const char * str, ...) va_end(ap); fflush(raLogfile); } - fflush(stdout); } void Log::outChat(const char * str, ...) @@ -930,76 +925,4 @@ void Log::outChat(const char * str, ...) fflush(chatLogfile); va_end(ap); } - fflush(stdout); -} - -void outstring_log(const char * str, ...) -{ - if (!str) - return; - - char buf[256]; - va_list ap; - va_start(ap, str); - vsnprintf(buf,256, str, ap); - va_end(ap); - - Trinity::Singleton<Log>::Instance().outString(buf); -} - -void detail_log(const char * str, ...) -{ - if (!str) - return; - - char buf[256]; - va_list ap; - va_start(ap, str); - vsnprintf(buf,256, str, ap); - va_end(ap); - - Trinity::Singleton<Log>::Instance().outDetail(buf); -} - -void debug_log(const char * str, ...) -{ - if (!str) - return; - - char buf[256]; - va_list ap; - va_start(ap, str); - vsnprintf(buf,256, str, ap); - va_end(ap); - - Trinity::Singleton<Log>::Instance().outDebug(buf); -} - -void error_log(const char * str, ...) -{ - if (!str) - return; - - char buf[256]; - va_list ap; - va_start(ap, str); - vsnprintf(buf,256, str, ap); - va_end(ap); - - Trinity::Singleton<Log>::Instance().outError(buf); -} - -void error_db_log(const char * str, ...) -{ - if (!str) - return; - - char buf[256]; - va_list ap; - va_start(ap, str); - vsnprintf(buf,256, str, ap); - va_end(ap); - - Trinity::Singleton<Log>::Instance().outErrorDb(buf); } - diff --git a/src/server/shared/Logging/Log.h b/src/server/shared/Logging/Log.h index deb6c55e4e0..fb584d42c27 100644 --- a/src/server/shared/Logging/Log.h +++ b/src/server/shared/Logging/Log.h @@ -22,7 +22,7 @@ #define TRINITYCORE_LOG_H #include "Common.h" -#include "Policies/Singleton.h" +#include <ace/Singleton.h> #include "Database/DatabaseEnv.h" class Config; @@ -82,9 +82,9 @@ enum ColorTypes const int Colors = int(WHITE)+1; -class Log : public Trinity::Singleton<Log, Trinity::ClassLevelLockable<Log, ACE_Thread_Mutex> > +class Log { - friend class Trinity::OperatorNew<Log>; + friend class ACE_Singleton<Log, ACE_Thread_Mutex>; Log(); ~Log(); @@ -172,19 +172,13 @@ class Log : public Trinity::Singleton<Log, Trinity::ClassLevelLockable<Log, ACE_ std::string m_dumpsDir; }; -#define sLog Trinity::Singleton<Log>::Instance() +#define sLog (*ACE_Singleton<Log, ACE_Thread_Mutex>::instance()) #ifdef TRINITY_DEBUG -#define DEBUG_LOG Trinity::Singleton<Log>::Instance().outDebug +#define DEBUG_LOG sLog.outDebug #else #define DEBUG_LOG #endif -// primary for script library -void outstring_log(const char * str, ...) ATTR_PRINTF(1,2); -void detail_log(const char * str, ...) ATTR_PRINTF(1,2); -void debug_log(const char * str, ...) ATTR_PRINTF(1,2); -void error_log(const char * str, ...) ATTR_PRINTF(1,2); -void error_db_log(const char * str, ...) ATTR_PRINTF(1,2); #endif diff --git a/src/server/shared/Packets/ByteBuffer.h b/src/server/shared/Packets/ByteBuffer.h index ba0240fb58b..98709a5b0e0 100644 --- a/src/server/shared/Packets/ByteBuffer.h +++ b/src/server/shared/Packets/ByteBuffer.h @@ -22,8 +22,8 @@ #define _BYTEBUFFER_H #include "Common.h" -#include "Errors.h" -#include "Log.h" +#include "Debugging/Errors.h" +#include "Logging/Log.h" #include "Utilities/ByteConverter.h" class ByteBufferException diff --git a/src/server/shared/Policies/CreationPolicy.h b/src/server/shared/Policies/CreationPolicy.h deleted file mode 100644 index 8552ce7da52..00000000000 --- a/src/server/shared/Policies/CreationPolicy.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_CREATIONPOLICY_H -#define TRINITY_CREATIONPOLICY_H - -#include <stdlib.h> -#include "Platform/Define.h" - -namespace Trinity -{ - /** - * OperatorNew policy creates an object on the heap using new. - */ - template <class T> - class OperatorNew - { - public: - static T* Create(void) { return (new T); } - static void Destroy(T *obj) { delete obj; } - }; - - /** - * LocalStaticCreation policy creates an object on the stack - * the first time call Create. - */ - template <class T> - class LocalStaticCreation - { - union MaxAlign - { - char t_[sizeof(T)]; - short int shortInt_; - int int_; - long int longInt_; - float float_; - double double_; - long double longDouble_; - struct Test; - int Test::* pMember_; - int (Test::*pMemberFn_)(int); - }; - public: - static T* Create(void) - { - static MaxAlign si_localStatic; - return new(&si_localStatic) T; - } - - static void Destroy(T *obj) { obj->~T(); } - }; - - /** - * CreateUsingMalloc by pass the memory manger. - */ - template<class T> - class CreateUsingMalloc - { - public: - static T* Create() - { - void* p = ::malloc(sizeof(T)); - if (!p) return 0; - return new(p) T; - } - - static void Destroy(T* p) - { - p->~T(); - ::free(p); - } - }; - - /** - * CreateOnCallBack creates the object base on the call back. - */ - template<class T, class CALL_BACK> - class CreateOnCallBack - { - public: - static T* Create() - { - return CALL_BACK::createCallBack(); - } - - static void Destroy(T *p) - { - CALL_BACK::destroyCallBack(p); - } - }; -} -#endif - diff --git a/src/server/shared/Policies/ObjectLifeTime.cpp b/src/server/shared/Policies/ObjectLifeTime.cpp deleted file mode 100644 index fd16873ae92..00000000000 --- a/src/server/shared/Policies/ObjectLifeTime.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <cstdlib> -#include "ObjectLifeTime.h" - -namespace Trinity -{ - extern "C" void external_wrapper(void *p) - { - std::atexit( (void (*)())p ); - } - - void at_exit( void (*func)() ) - { - external_wrapper((void*)func); - } -} - diff --git a/src/server/shared/Policies/ObjectLifeTime.h b/src/server/shared/Policies/ObjectLifeTime.h deleted file mode 100644 index 61b90b59f6e..00000000000 --- a/src/server/shared/Policies/ObjectLifeTime.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_OBJECTLIFETIME_H -#define TRINITY_OBJECTLIFETIME_H - -#include <stdexcept> -#include "Platform/Define.h" - -typedef void (* Destroyer)(void); - -namespace Trinity -{ - void at_exit( void (*func)() ); - - template <class T> - class ObjectLifeTime - { - public: - static void ScheduleCall(void (*destroyer)() ) - { - at_exit( destroyer ); - } - - DECLSPEC_NORETURN static void OnDeadReference(void) ATTR_NORETURN; - - }; - - template <class T> - void ObjectLifeTime<T>::OnDeadReference(void) // We don't handle Dead Reference for now - { - throw std::runtime_error("Dead Reference"); - } -} -#endif - diff --git a/src/server/shared/Policies/Singleton.h b/src/server/shared/Policies/Singleton.h deleted file mode 100644 index da898558ca5..00000000000 --- a/src/server/shared/Policies/Singleton.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_SINGLETON_H -#define TRINITY_SINGLETON_H - -/** - * @brief class Singleton - */ - -#include "CreationPolicy.h" -#include "ThreadingModel.h" -#include "ObjectLifeTime.h" - -namespace Trinity -{ - template - < - typename T, - class ThreadingModel = Trinity::SingleThreaded<T>, - class CreatePolicy = Trinity::OperatorNew<T>, - class LifeTimePolicy = Trinity::ObjectLifeTime<T> - > - class Singleton - { - public: - static T& Instance(); - - protected: - Singleton() {}; - - private: - - // Prohibited actions...this does not prevent hijacking. - Singleton(const Singleton &); - Singleton& operator=(const Singleton &); - - // Singleton Helpers - static void DestroySingleton(); - - // data structure - typedef typename ThreadingModel::Lock Guard; - static T *si_instance; - static bool si_destroyed; - }; -} -#endif - diff --git a/src/server/shared/Policies/SingletonImp.h b/src/server/shared/Policies/SingletonImp.h deleted file mode 100644 index 3e985cd5c64..00000000000 --- a/src/server/shared/Policies/SingletonImp.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_SINGLETONIMPL_H -#define TRINITY_SINGLETONIMPL_H - -#include "Singleton.h" - -// avoid the using namespace here cuz -// its a .h file afterall - -template -< -typename T, -class ThreadingModel, -class CreatePolicy, -class LifeTimePolicy -> -T& -Trinity::Singleton<T, ThreadingModel, CreatePolicy, LifeTimePolicy >::Instance() -{ - if( !si_instance ) - { - // double-checked Locking pattern - Guard(); - if( !si_instance ) - { - if( si_destroyed ) - { - si_destroyed = false; - LifeTimePolicy::OnDeadReference(); - } - si_instance = CreatePolicy::Create(); - LifeTimePolicy::ScheduleCall(&DestroySingleton); - } - } - - return *si_instance; -} - -template -< -typename T, -class ThreadingModel, -class CreatePolicy, -class LifeTimePolicy -> -void -Trinity::Singleton<T, ThreadingModel, CreatePolicy, LifeTimePolicy>::DestroySingleton() -{ - CreatePolicy::Destroy(si_instance); - si_instance = NULL; - si_destroyed = true; -} - -#define INSTANTIATE_SINGLETON_1(TYPE) \ - template class Trinity::Singleton<TYPE, Trinity::SingleThreaded<TYPE>, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >; \ - template<> TYPE* Trinity::Singleton<TYPE, Trinity::SingleThreaded<TYPE>, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >::si_instance = 0; \ - template<> bool Trinity::Singleton<TYPE, Trinity::SingleThreaded<TYPE>, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >::si_destroyed = false - -#define INSTANTIATE_SINGLETON_2(TYPE, THREADINGMODEL) \ - template class Trinity::Singleton<TYPE, THREADINGMODEL, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >; \ - template<> TYPE* Trinity::Singleton<TYPE, THREADINGMODEL, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >::si_instance = 0; \ - template<> bool Trinity::Singleton<TYPE, THREADINGMODEL, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >::si_destroyed = false - -#define INSTANTIATE_SINGLETON_3(TYPE, THREADINGMODEL, CREATIONPOLICY ) \ - template class Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, Trinity::ObjectLifeTime<TYPE> >; \ - template<> TYPE* Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, Trinity::ObjectLifeTime<TYPE> >::si_instance = 0; \ - template<> bool Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, Trinity::ObjectLifeType<TYPE> >::si_destroyed = false - -#define INSTANTIATE_SINGLETON_4(TYPE, THREADINGMODEL, CREATIONPOLICY, OBJECTLIFETIME) \ - template class Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, OBJECTLIFETIME >; \ - template<> TYPE* Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, OBJECTLIFETIME >::si_instance = 0; \ - template<> bool Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, OBJECTLIFETIME >::si_destroyed = false -#endif - diff --git a/src/server/shared/Policies/ThreadingModel.h b/src/server/shared/Policies/ThreadingModel.h deleted file mode 100644 index d4c5e9a2333..00000000000 --- a/src/server/shared/Policies/ThreadingModel.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_THREADINGMODEL_H -#define TRINITY_THREADINGMODEL_H - -/** - * @class ThreadingModel<T> - * - */ - -#include "Platform/Define.h" - -namespace Trinity -{ - inline void Guard(void *) {} - - template<typename MUTEX> class GeneralLock - { - public: - GeneralLock(MUTEX &m) : i_mutex(m) - { - i_mutex.acquire(); - } - - ~GeneralLock() - { - i_mutex.release(); - } - private: - GeneralLock(const GeneralLock &); - GeneralLock& operator=(const GeneralLock &); - MUTEX &i_mutex; - }; - - template <class T> - class SingleThreaded - { - public: - - struct Lock // empty object - { - Lock() {} - Lock(const T &) {} - Lock(const SingleThreaded<T> &) // for single threaded we ignore this - { - } - }; - - typedef T VolatileType; - }; - - // object level lockable - template<class T, class MUTEX> - class ObjectLevelLockable - { - public: - ObjectLevelLockable() : i_mtx() {} - - friend class Lock; - - class Lock - { - public: - Lock(ObjectLevelLockable<T, MUTEX> &host) : i_lock(host.i_mtx) - { - } - - private: - GeneralLock<MUTEX> i_lock; - }; - - typedef volatile T VolatileType; - - private: - // prevent the compiler creating a copy construct - ObjectLevelLockable(const ObjectLevelLockable<T, MUTEX> &); - ObjectLevelLockable<T, MUTEX>& operator=(const ObjectLevelLockable<T, MUTEX> &); - - MUTEX i_mtx; - }; - - template<class T, class MUTEX> - class ClassLevelLockable - { - public: - class Lock; - friend class Lock; - typedef volatile T VolatileType; - - ClassLevelLockable() {} - - class Lock - { - public: - Lock(T& /*host*/) { ClassLevelLockable<T, MUTEX>::si_mtx.acquire(); } - Lock(ClassLevelLockable<T, MUTEX> &) { ClassLevelLockable<T, MUTEX>::si_mtx.acquire(); } - Lock() { ClassLevelLockable<T, MUTEX>::si_mtx.acquire(); } - ~Lock() { ClassLevelLockable<T, MUTEX>::si_mtx.release(); } - }; - - private: - static MUTEX si_mtx; - }; - -} - -template<class T, class MUTEX> MUTEX Trinity::ClassLevelLockable<T, MUTEX>::si_mtx; - -#define INSTANTIATE_CLASS_MUTEX(CTYPE,MUTEX) \ - template class Trinity::ClassLevelLockable<CTYPE, MUTEX > -#endif - diff --git a/src/server/shared/SystemConfig.h b/src/server/shared/SystemConfig.h index ac531cbbc94..fd380d72b79 100644 --- a/src/server/shared/SystemConfig.h +++ b/src/server/shared/SystemConfig.h @@ -24,7 +24,7 @@ #ifndef TRINITY_SYSTEMCONFIG_H #define TRINITY_SYSTEMCONFIG_H -#include "Platform/Define.h" +#include "Define.h" #include "revision.h" #define _PACKAGENAME "TrinityCore " diff --git a/src/server/shared/Threading/LockedQueue.h b/src/server/shared/Threading/LockedQueue.h index 9f8afae6c14..ff6056350f3 100644 --- a/src/server/shared/Threading/LockedQueue.h +++ b/src/server/shared/Threading/LockedQueue.h @@ -23,7 +23,7 @@ #include <ace/Thread_Mutex.h> #include <deque> #include <assert.h> -#include "Errors.h" +#include "Debugging/Errors.h" namespace ACE_Based { diff --git a/src/server/shared/Utilities/ByteConverter.h b/src/server/shared/Utilities/ByteConverter.h index f8b6bd72498..24a89f464b8 100644 --- a/src/server/shared/Utilities/ByteConverter.h +++ b/src/server/shared/Utilities/ByteConverter.h @@ -25,7 +25,7 @@ for cross platform where they have different endians. */ -#include<Platform/Define.h> +#include "Define.h" #include<algorithm> namespace ByteConverter diff --git a/src/server/shared/Utilities/EventProcessor.h b/src/server/shared/Utilities/EventProcessor.h index 2712967e1b7..421f88b659a 100644 --- a/src/server/shared/Utilities/EventProcessor.h +++ b/src/server/shared/Utilities/EventProcessor.h @@ -21,7 +21,7 @@ #ifndef __EVENTPROCESSOR_H #define __EVENTPROCESSOR_H -#include "Platform/Define.h" +#include "Define.h" #include<map> diff --git a/src/server/shared/Utilities/ProgressBar.h b/src/server/shared/Utilities/ProgressBar.h index e7565590278..cae23254f30 100644 --- a/src/server/shared/Utilities/ProgressBar.h +++ b/src/server/shared/Utilities/ProgressBar.h @@ -20,7 +20,7 @@ #ifndef TRINITYCORE_PROGRESSBAR_H #define TRINITYCORE_PROGRESSBAR_H -#include "Platform/Define.h" +#include "Define.h" class barGoLink { diff --git a/src/server/shared/Utilities/ServiceWin32.cpp b/src/server/shared/Utilities/ServiceWin32.cpp index 2c1df2ff483..a50a4f9d039 100644 --- a/src/server/shared/Utilities/ServiceWin32.cpp +++ b/src/server/shared/Utilities/ServiceWin32.cpp @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifdef WIN32 +#ifdef _WIN32 #include "Common.h" #include "Log.h" @@ -26,6 +26,11 @@ #include <windows.h> #include <winsvc.h> +// stupid ACE define +#ifdef main +#undef main +#endif //main + #if !defined(WINADVAPI) #if !defined(_ADVAPI32_) #define WINADVAPI DECLSPEC_IMPORT diff --git a/src/server/shared/Utilities/ServiceWin32.h b/src/server/shared/Utilities/ServiceWin32.h index ddac785a0fb..4dbd329a5fa 100644 --- a/src/server/shared/Utilities/ServiceWin32.h +++ b/src/server/shared/Utilities/ServiceWin32.h @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifdef WIN32 +#ifdef _WIN32 #ifndef _WIN32_SERVICE_ #define _WIN32_SERVICE_ @@ -27,5 +27,5 @@ bool WinServiceUninstall(); bool WinServiceRun(); #endif // _WIN32_SERVICE_ -#endif // WIN32 +#endif // _WIN32 diff --git a/src/server/shared/Utilities/Timer.h b/src/server/shared/Utilities/Timer.h index 3e0a369b655..326df71bf50 100644 --- a/src/server/shared/Utilities/Timer.h +++ b/src/server/shared/Utilities/Timer.h @@ -21,7 +21,7 @@ #ifndef TRINITY_TIMER_H #define TRINITY_TIMER_H -#include "Platform/CompilerDefs.h" +#include "CompilerDefs.h" #if PLATFORM == PLATFORM_WINDOWS # include <ace/config-all.h> diff --git a/src/server/shared/Utilities/Util.cpp b/src/server/shared/Utilities/Util.cpp index a3c017fdbfd..97dfde6c92b 100644 --- a/src/server/shared/Utilities/Util.cpp +++ b/src/server/shared/Utilities/Util.cpp @@ -20,9 +20,10 @@ #include "Util.h" -#include "sockets/socket_include.h" -#include "utf8cpp/utf8.h" -#include "mersennetwister/MersenneTwister.h" +#include "socket_include.h" +#include "utf8.h" +//#include "SFMT.h" +#include "MersenneTwister.h" #include <ace/TSS_T.h> typedef ACE_TSS<MTRand> MTRandTSS; @@ -194,7 +195,7 @@ uint32 CreatePIDFile(const std::string& filename) if (pid_file == NULL) return 0; -#ifdef WIN32 +#ifdef _WIN32 DWORD pid = GetCurrentProcessId(); #else pid_t pid = getpid(); |
