mirror of
https://github.com/SWG-Source/src.git
synced 2026-07-29 23:15:56 -04:00
readd some win32 files so that we can more easily run static analyzers
that are windows only against the source
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
// CentralServerPrecompiledHeader.cpp
|
||||
// copyright 2001 Verant Interactive
|
||||
// Author: Justin Randall
|
||||
|
||||
#include "FirstCentralServer.h"
|
||||
@@ -0,0 +1,84 @@
|
||||
#include "FirstCentralServer.h"
|
||||
#include "ConfigCentralServer.h"
|
||||
#include "CentralServer.h"
|
||||
|
||||
#include "sharedCompression/SetupSharedCompression.h"
|
||||
#include "sharedDebug/SetupSharedDebug.h"
|
||||
#include "sharedFile/SetupSharedFile.h"
|
||||
#include "sharedFoundation/SetupSharedFoundation.h"
|
||||
#include "sharedNetworkMessages/SetupSharedNetworkMessages.h"
|
||||
#include "sharedRandom/SetupSharedRandom.h"
|
||||
#include "sharedThread/SetupSharedThread.h"
|
||||
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
|
||||
//_____________________________________________________________________
|
||||
/*
|
||||
int WINAPI WinMain(
|
||||
HINSTANCE hInstance, // handle to current instance
|
||||
HINSTANCE hPrevInstance, // handle to previous instance
|
||||
LPSTR lpCmdLine, // pointer to command line
|
||||
int nCmdShow // show state of window
|
||||
)
|
||||
*/
|
||||
int main(int argc, char ** argv)
|
||||
{ //lint !e1065 //WinMain conflicts with clib
|
||||
int i = 0;
|
||||
|
||||
// UNREF(hPrevInstance);
|
||||
// UNREF(nCmdShow);
|
||||
|
||||
SetupSharedThread::install();
|
||||
SetupSharedDebug::install(1024);
|
||||
|
||||
//-- setup foundation
|
||||
SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game);
|
||||
|
||||
// command line hack
|
||||
std::string cmdLine;
|
||||
for(i = 1; i < argc; ++i)
|
||||
{
|
||||
cmdLine += argv[i];
|
||||
if(i + 1 < argc)
|
||||
{
|
||||
cmdLine += " ";
|
||||
}
|
||||
}
|
||||
// setupFoundationData.hInstance = hInstance;
|
||||
setupFoundationData.commandLine = cmdLine.c_str();
|
||||
setupFoundationData.createWindow = false;
|
||||
setupFoundationData.clockUsesSleep = true;
|
||||
|
||||
SetupSharedFoundation::install (setupFoundationData);
|
||||
|
||||
SetupSharedCompression::install();
|
||||
|
||||
SetupSharedFile::install(false);
|
||||
|
||||
SetupSharedNetworkMessages::install();
|
||||
|
||||
ConfigCentralServer::install();
|
||||
|
||||
cmdLine = "";
|
||||
// now, the real command line
|
||||
for(i = 0; i < argc; ++i)
|
||||
{
|
||||
cmdLine += argv[i];
|
||||
if(i + 1 < argc)
|
||||
{
|
||||
cmdLine += " ";
|
||||
}
|
||||
}
|
||||
|
||||
CentralServer::getInstance().setCommandLine(cmdLine);
|
||||
|
||||
//-- run game
|
||||
SetupSharedFoundation::callbackWithExceptionHandling(CentralServer::run);
|
||||
|
||||
SetupSharedFoundation::remove();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________
|
||||
@@ -0,0 +1,42 @@
|
||||
#include "FirstChatServer.h"
|
||||
#include "ConfigChatServer.h"
|
||||
#include "ChatServer.h"
|
||||
#include "sharedCompression/SetupSharedCompression.h"
|
||||
#include "sharedDebug/SetupSharedDebug.h"
|
||||
#include "sharedFoundation/SetupSharedFoundation.h"
|
||||
#include "sharedNetworkMessages/SetupSharedNetworkMessages.h"
|
||||
#include "sharedThread/SetupSharedThread.h"
|
||||
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
|
||||
int main( int argc, char ** argv )
|
||||
{
|
||||
SetupSharedThread::install();
|
||||
SetupSharedDebug::install(1024);
|
||||
|
||||
//-- setup foundation
|
||||
SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game);
|
||||
|
||||
//setupFoundationData.hInstance = hInstance;
|
||||
setupFoundationData.argc = argc;
|
||||
setupFoundationData.argv = argv;
|
||||
setupFoundationData.createWindow = false;
|
||||
setupFoundationData.clockUsesSleep = true;
|
||||
|
||||
SetupSharedFoundation::install (setupFoundationData);
|
||||
|
||||
SetupSharedCompression::install();
|
||||
|
||||
SetupSharedNetworkMessages::install();
|
||||
|
||||
//-- setup game server
|
||||
ConfigChatServer::install ();
|
||||
|
||||
//-- run game
|
||||
SetupSharedFoundation::callbackWithExceptionHandling(ChatServer::run);
|
||||
|
||||
SetupSharedFoundation::remove();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
#include "FirstConnectionServer.h"
|
||||
@@ -0,0 +1,58 @@
|
||||
#include "FirstConnectionServer.h"
|
||||
#include "ConfigConnectionServer.h"
|
||||
#include "ConnectionServer.h"
|
||||
|
||||
#include "sharedCompression/SetupSharedCompression.h"
|
||||
#include "sharedDebug/SetupSharedDebug.h"
|
||||
#include "sharedFile/SetupSharedFile.h"
|
||||
#include "sharedFoundation/PerThreadData.h"
|
||||
#include "sharedFoundation/SetupSharedFoundation.h"
|
||||
#include "sharedNetworkMessages/SetupSharedNetworkMessages.h"
|
||||
#include "sharedRandom/SetupSharedRandom.h"
|
||||
#include "sharedThread/SetupSharedThread.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
// command line hack
|
||||
std::string cmdLine;
|
||||
for(int i = 1; i < argc; ++i)
|
||||
{
|
||||
cmdLine += argv[i];
|
||||
if(i + 1 < argc)
|
||||
{
|
||||
cmdLine += " ";
|
||||
}
|
||||
}
|
||||
|
||||
SetupSharedThread::install();
|
||||
SetupSharedDebug::install(1024);
|
||||
|
||||
//-- setup foundation
|
||||
SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game);
|
||||
|
||||
// setupFoundationData.hInstance = hInstance;
|
||||
setupFoundationData.commandLine = cmdLine.c_str();
|
||||
setupFoundationData.createWindow = false;
|
||||
setupFoundationData.clockUsesSleep = true;
|
||||
|
||||
SetupSharedFoundation::install (setupFoundationData);
|
||||
SetupSharedFile::install(false);
|
||||
SetupSharedCompression::install();
|
||||
|
||||
SetupSharedNetworkMessages::install();
|
||||
SetupSharedRandom::install(int(time(NULL)));
|
||||
|
||||
//-- setup game server
|
||||
ConfigConnectionServer::install ();
|
||||
|
||||
ConnectionServer::install();
|
||||
//-- run game
|
||||
SetupSharedFoundation::callbackWithExceptionHandling(ConnectionServer::run);
|
||||
ConnectionServer::remove();
|
||||
ConfigConnectionServer::remove();
|
||||
SetupSharedFoundation::remove();
|
||||
PerThreadData::threadRemove();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// LoggingServerApiWrapper.cpp
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
// This is a wrapper cpp to workaround PCH and RSP's. While a DSP
|
||||
// may exclude a single file from using precompiled headers, the
|
||||
// dsp builder has no way (I know of) to honor this behavior.
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "FirstLogServer.h"
|
||||
//#include "LoggingServerApi.cpp"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// WinMain.cpp
|
||||
//
|
||||
// Copyright 2002 Sony Online Entertainment
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include "FirstLogServer.h"
|
||||
#include "sharedFoundation/FirstSharedFoundation.h"
|
||||
#include "LogServer.h"
|
||||
|
||||
#include "sharedCompression/SetupSharedCompression.h"
|
||||
#include "sharedDebug/SetupSharedDebug.h"
|
||||
#include "sharedFile/SetupSharedFile.h"
|
||||
#include "sharedFoundation/SetupSharedFoundation.h"
|
||||
#include "sharedNetworkMessages/SetupSharedNetworkMessages.h"
|
||||
#include "sharedThread/SetupSharedThread.h"
|
||||
|
||||
// ======================================================================
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
SetupSharedThread::install();
|
||||
SetupSharedDebug::install(1024);
|
||||
|
||||
//-- setup foundation
|
||||
SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game);
|
||||
|
||||
setupFoundationData.argc = argc;
|
||||
setupFoundationData.argv = argv;
|
||||
setupFoundationData.createWindow = false;
|
||||
setupFoundationData.clockUsesSleep = true;
|
||||
|
||||
SetupSharedFoundation::install(setupFoundationData);
|
||||
|
||||
SetupSharedCompression::install();
|
||||
|
||||
SetupSharedFile::install(false);
|
||||
SetupSharedNetworkMessages::install();
|
||||
|
||||
//-- setup server
|
||||
LogServer::install();
|
||||
|
||||
//-- run server
|
||||
SetupSharedFoundation::callbackWithExceptionHandling(LogServer::run);
|
||||
|
||||
LogServer::remove();
|
||||
SetupSharedFoundation::remove();
|
||||
SetupSharedThread::remove();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ======================================================================
|
||||
@@ -0,0 +1 @@
|
||||
#include "FirstLoginServer.h"
|
||||
@@ -0,0 +1,46 @@
|
||||
#include "FirstLoginServer.h"
|
||||
#include "ConfigLoginServer.h"
|
||||
#include "LoginServer.h"
|
||||
|
||||
#include "sharedCompression/SetupSharedCompression.h"
|
||||
#include "sharedDebug/SetupSharedDebug.h"
|
||||
#include "sharedFile/SetupSharedFile.h"
|
||||
#include "sharedFoundation/SetupSharedFoundation.h"
|
||||
#include "sharedNetworkMessages/SetupSharedNetworkMessages.h"
|
||||
#include "sharedRandom/SetupSharedRandom.h"
|
||||
#include "sharedThread/SetupSharedThread.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
SetupSharedThread::install();
|
||||
SetupSharedDebug::install(1024);
|
||||
|
||||
//-- setup foundation
|
||||
SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game);
|
||||
|
||||
setupFoundationData.argc = argc;
|
||||
setupFoundationData.argv = argv;
|
||||
setupFoundationData.createWindow = false;
|
||||
|
||||
SetupSharedFoundation::install (setupFoundationData);
|
||||
SetupSharedNetworkMessages::install();
|
||||
|
||||
SetupSharedCompression::install();
|
||||
|
||||
SetupSharedFile::install(false);
|
||||
|
||||
SetupSharedRandom::install(time(NULL));
|
||||
|
||||
//-- setup game server
|
||||
ConfigLoginServer::install ();
|
||||
|
||||
//-- run game
|
||||
SetupSharedFoundation::callbackWithExceptionHandling(LoginServer::run);
|
||||
|
||||
SetupSharedFoundation::remove();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
#include "sharedFoundation/FirstSharedFoundation.h"
|
||||
|
||||
#include "ConfigMetricsServer.h"
|
||||
#include "MetricsServer.h"
|
||||
|
||||
#include "sharedCompression/SetupSharedCompression.h"
|
||||
#include "sharedDebug/SetupSharedDebug.h"
|
||||
#include "sharedFile/SetupSharedFile.h"
|
||||
#include "sharedFoundation/Os.h"
|
||||
#include "sharedFoundation/SetupSharedFoundation.h"
|
||||
#include "sharedNetwork/NetworkHandler.h"
|
||||
#include "sharedNetwork/SetupSharedNetwork.h"
|
||||
#include "sharedNetworkMessages/SetupSharedNetworkMessages.h"
|
||||
#include "sharedRandom/SetupSharedRandom.h"
|
||||
#include "sharedThread/SetupSharedThread.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
// ======================================================================
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
SetupSharedThread::install();
|
||||
SetupSharedDebug::install(1024);
|
||||
|
||||
//-- setup foundation
|
||||
SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game);
|
||||
|
||||
// command line hack
|
||||
std::string cmdLine;
|
||||
for(int i = 1; i < argc; ++i)
|
||||
{
|
||||
cmdLine += argv[i];
|
||||
if(i + 1 < argc)
|
||||
{
|
||||
cmdLine += " ";
|
||||
}
|
||||
}
|
||||
|
||||
setupFoundationData.commandLine = cmdLine.c_str();
|
||||
setupFoundationData.createWindow = false;
|
||||
setupFoundationData.clockUsesSleep = true;
|
||||
|
||||
SetupSharedFoundation::install (setupFoundationData);
|
||||
|
||||
{
|
||||
//SetupSharedObject::Data data;
|
||||
//SetupSharedObject::setupDefaultGameData(data);
|
||||
//SetupSharedObject::install(data);
|
||||
}
|
||||
SetupSharedCompression::install();
|
||||
SetupSharedFile::install(true, 32);
|
||||
|
||||
SetupSharedNetwork::SetupData networkSetupData;
|
||||
SetupSharedNetwork::getDefaultServerSetupData(networkSetupData);
|
||||
SetupSharedNetwork::install(networkSetupData);
|
||||
|
||||
SetupSharedRandom::install(static_cast<uint32>(time(NULL))); //lint !e1924 !e64 // NULL is a C-Style cast?
|
||||
|
||||
//Os::setProgramName("MetricsServer");
|
||||
//setup the server
|
||||
ConfigMetricsServer::install();
|
||||
|
||||
//set command line
|
||||
cmdLine = setupFoundationData.commandLine;
|
||||
size_t firstArg = cmdLine.find(" ", 0);
|
||||
size_t lastSlash = 0;
|
||||
size_t nextSlash = 0;
|
||||
while(nextSlash < firstArg)
|
||||
{
|
||||
nextSlash = cmdLine.find("/", lastSlash);
|
||||
if(nextSlash == cmdLine.npos || nextSlash >= firstArg) //lint !e1705 static class members may be accessed by the scoping operator (huh?)
|
||||
break;
|
||||
lastSlash = nextSlash + 1;
|
||||
}
|
||||
cmdLine = cmdLine.substr(lastSlash);
|
||||
MetricsServer::setCommandLine(cmdLine);
|
||||
|
||||
|
||||
//-- run game
|
||||
NetworkHandler::install();
|
||||
MetricsServer::install();
|
||||
MetricsServer::run();
|
||||
MetricsServer::remove();
|
||||
NetworkHandler::remove();
|
||||
SetupSharedFoundation::remove();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// FirstPlanetServer.cpp
|
||||
// copyright (c) 2001 Sony Online Entertainment
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include "FirstPlanetServer.h"
|
||||
@@ -0,0 +1,67 @@
|
||||
#include "FirstPlanetServer.h"
|
||||
#include "ConfigPlanetServer.h"
|
||||
#include "PlanetServer.h"
|
||||
|
||||
#include "sharedCompression/SetupSharedCompression.h"
|
||||
#include "sharedDebug/SetupSharedDebug.h"
|
||||
#include "sharedFile/SetupSharedFile.h"
|
||||
#include "sharedFoundation/Os.h"
|
||||
#include "sharedFoundation/SetupSharedFoundation.h"
|
||||
#include "sharedLog/SetupSharedLog.h"
|
||||
#include "sharedNetwork/SetupSharedNetwork.h"
|
||||
#include "sharedNetworkMessages/SetupSharedNetworkMessages.h"
|
||||
#include "sharedRandom/SetupSharedRandom.h"
|
||||
#include "sharedThread/SetupSharedThread.h"
|
||||
#include "sharedUtility/SetupSharedUtility.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
//_____________________________________________________________________
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
SetupSharedThread::install();
|
||||
SetupSharedDebug::install(1024);
|
||||
|
||||
//-- setup foundation
|
||||
SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game);
|
||||
|
||||
setupFoundationData.argc = argc;
|
||||
setupFoundationData.argv = argv;
|
||||
setupFoundationData.createWindow = false;
|
||||
setupFoundationData.clockUsesSleep = true;
|
||||
|
||||
SetupSharedFoundation::install (setupFoundationData);
|
||||
|
||||
SetupSharedCompression::install();
|
||||
SetupSharedFile::install(false);
|
||||
|
||||
SetupSharedNetwork::SetupData networkSetupData;
|
||||
SetupSharedNetwork::getDefaultServerSetupData(networkSetupData);
|
||||
SetupSharedNetwork::install(networkSetupData);
|
||||
|
||||
SetupSharedNetworkMessages::install();
|
||||
|
||||
SetupSharedRandom::install(int(time(NULL)));
|
||||
|
||||
SetupSharedUtility::Data sharedUtilityData;
|
||||
SetupSharedUtility::setupGameData (sharedUtilityData);
|
||||
SetupSharedUtility::install (sharedUtilityData);
|
||||
|
||||
//-- setup server
|
||||
ConfigPlanetServer::install ();
|
||||
|
||||
char tmp[92];
|
||||
sprintf(tmp, "PlanetServer:%d", Os::getProcessId());
|
||||
SetupSharedLog::install(tmp);
|
||||
|
||||
//-- run server
|
||||
SetupSharedFoundation::callbackWithExceptionHandling(PlanetServer::run);
|
||||
|
||||
SetupSharedLog::remove();
|
||||
SetupSharedFoundation::remove();
|
||||
SetupSharedThread::remove();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________
|
||||
@@ -0,0 +1,59 @@
|
||||
// main.cpp
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "FirstServerConsole.h"
|
||||
|
||||
#include "sharedFoundation/FirstSharedFoundation.h"
|
||||
#include "sharedCompression/SetupSharedCompression.h"
|
||||
#include "sharedDebug/SetupSharedDebug.h"
|
||||
#include "sharedFile/SetupSharedFile.h"
|
||||
#include "sharedFoundation/ConfigFile.h"
|
||||
#include "sharedFoundation/SetupSharedFoundation.h"
|
||||
#include "sharedNetwork/SetupSharedNetwork.h"
|
||||
#include "sharedNetwork/NetworkHandler.h"
|
||||
#include "sharedNetworkMessages/SetupSharedNetworkMessages.h"
|
||||
#include "sharedThread/SetupSharedThread.h"
|
||||
#include "ServerConsole.h"
|
||||
#include "ConfigServerConsole.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
SetupSharedThread::install();
|
||||
SetupSharedDebug::install(1024);
|
||||
|
||||
//-- setup foundation
|
||||
SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game);
|
||||
|
||||
setupFoundationData.argc = argc;
|
||||
setupFoundationData.argv = argv;
|
||||
setupFoundationData.clockUsesSleep = true;
|
||||
setupFoundationData.createWindow = false;
|
||||
SetupSharedFoundation::install (setupFoundationData);
|
||||
|
||||
SetupSharedCompression::install();
|
||||
SetupSharedNetworkMessages::install();
|
||||
|
||||
SetupSharedNetwork::SetupData networkSetupData;
|
||||
SetupSharedNetwork::getDefaultClientSetupData(networkSetupData);
|
||||
SetupSharedNetwork::install(networkSetupData);
|
||||
NetworkHandler::install();
|
||||
|
||||
ConfigServerConsole::install();
|
||||
|
||||
//-- run server
|
||||
SetupSharedFoundation::callbackWithExceptionHandling(ServerConsole::run);
|
||||
|
||||
NetworkHandler::remove();
|
||||
SetupSharedFoundation::remove();
|
||||
SetupSharedThread::remove();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// ConsoleInput.cpp
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "FirstTaskManager.h"
|
||||
#include "Console.h"
|
||||
#include <conio.h>
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
const char Console::getNextChar()
|
||||
{
|
||||
char result = 0;
|
||||
if(_kbhit())
|
||||
result = static_cast<char>(_getche());
|
||||
return result;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#include "FirstTaskManager.h"
|
||||
|
||||
namespace EnvironmentVariable
|
||||
{
|
||||
bool addToEnvironmentVariable(const char* key, const char* value)
|
||||
{
|
||||
bool retval = false;
|
||||
char oldValue[256];
|
||||
DWORD tmp = GetEnvironmentVariable(key, oldValue, sizeof(oldValue));
|
||||
if (tmp != 0)
|
||||
{
|
||||
std::string s(oldValue);
|
||||
s += ";";
|
||||
s += value;
|
||||
|
||||
//Bad things happen if the first character happens to be ; (ie from an empty environment string)
|
||||
const char* newValue = s.c_str();
|
||||
if (newValue[0] == ';')
|
||||
++newValue;
|
||||
|
||||
retval = (SetEnvironmentVariable(key, newValue) != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = (SetEnvironmentVariable(key, value) != 0);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
bool setEnvironmentVariable(const char* key, const char* value)
|
||||
{
|
||||
return (SetEnvironmentVariable(key, value) != 0);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,153 @@
|
||||
#include "FirstTaskManager.h"
|
||||
#include "sharedFoundation/FirstSharedFoundation.h"
|
||||
#include "ProcessSpawner.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "TaskManager.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
uint32 ProcessSpawner::prefix;
|
||||
std::map<uint32, HANDLE> procById;
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool tokenize (const std::string & str, std::vector<std::string> & result)
|
||||
{
|
||||
size_t end_pos = 0;
|
||||
size_t start_pos = 0;
|
||||
|
||||
result.clear ();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (end_pos >= str.size ())
|
||||
break;
|
||||
|
||||
start_pos = str.find_first_not_of (' ', end_pos);
|
||||
|
||||
if (start_pos == str.npos)
|
||||
break;
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
if (str [start_pos] == '\"')
|
||||
{
|
||||
if (++start_pos >= str.size ())
|
||||
break;
|
||||
end_pos = str.find_first_of ('\"', start_pos);
|
||||
}
|
||||
else
|
||||
end_pos = str.find_first_of (' ', start_pos);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
if (start_pos == end_pos)
|
||||
break;
|
||||
|
||||
if (end_pos == str.npos)
|
||||
{
|
||||
result.push_back (str.substr (start_pos));
|
||||
break;
|
||||
}
|
||||
else
|
||||
result.push_back (str.substr (start_pos, end_pos - start_pos));
|
||||
|
||||
++start_pos;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32 ProcessSpawner::execute(const std::string & processName, const std::vector<std::string> & parameters)
|
||||
{
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
char cmd[1024] = {"\0"};
|
||||
std::string cmdLine;
|
||||
|
||||
cmdLine = processName.c_str();
|
||||
cmdLine += " ";
|
||||
std::vector<std::string>::const_iterator i;
|
||||
for(i = parameters.begin(); i != parameters.end(); ++i)
|
||||
{
|
||||
cmdLine += (*i).c_str();
|
||||
cmdLine += " ";
|
||||
}
|
||||
|
||||
_snprintf(cmd, 1024, "%s.exe", processName.c_str());
|
||||
// _snprintf(cmd, 1024, "%s", processName.c_str());
|
||||
memset(&si, 0, sizeof(si));
|
||||
memset(&pi, 0, sizeof(pi));
|
||||
|
||||
si.cb = sizeof(si);
|
||||
|
||||
const int result = CreateProcess(cmd, const_cast<char *>(cmdLine.c_str()), NULL, NULL, false, 0, 0, 0, &si, &pi);
|
||||
UNREF (result);
|
||||
|
||||
#ifdef _DEBUG
|
||||
if (!result)
|
||||
{
|
||||
DWORD iErr = GetLastError();
|
||||
char * errStr = strerror(iErr);
|
||||
DEBUG_REPORT_LOG(true, ("ProcessSpawner: %s - %s\n", cmd, errStr));
|
||||
}
|
||||
#endif
|
||||
|
||||
procById.insert(std::pair<uint32, HANDLE>(pi.dwProcessId, pi.hProcess));
|
||||
return pi.dwProcessId;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
uint32 ProcessSpawner::execute(const std::string & cmd)
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
size_t firstArg = cmd.find_first_of(" ");
|
||||
std::string processName;
|
||||
if(firstArg < cmd.size())
|
||||
{
|
||||
std::string a = cmd.substr(firstArg + 1);
|
||||
tokenize(a, args);
|
||||
processName = cmd.substr(0, firstArg);
|
||||
}
|
||||
else
|
||||
{
|
||||
processName = cmd;
|
||||
}
|
||||
return execute(processName, args);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool ProcessSpawner::isProcessActive(uint32 pid)
|
||||
{
|
||||
bool result = false;
|
||||
std::map<uint32, HANDLE>::const_iterator f = procById.find(pid);
|
||||
if(f != procById.end())
|
||||
{
|
||||
DWORD exitCode;
|
||||
GetExitCodeProcess((*f).second, &exitCode);
|
||||
result = (exitCode == STILL_ACTIVE);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ProcessSpawner::kill(uint32 pid)
|
||||
{
|
||||
HANDLE p = OpenProcess(PROCESS_TERMINATE, false, (DWORD)pid);
|
||||
if(p)
|
||||
TerminateProcess(p, 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ProcessSpawner::forceCore(const unsigned long pid)
|
||||
{
|
||||
ProcessSpawner::kill(pid);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
// TaskManagerSysInfo.cpp
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "FirstTaskManager.h"
|
||||
#include "TaskManagerSysInfo.h"
|
||||
#pragma warning ( disable : 4201)
|
||||
#include <windows.h>
|
||||
#include <tlhelp32.h>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
TaskManagerSysInfo::TaskManagerSysInfo() :
|
||||
averageScore()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
TaskManagerSysInfo::TaskManagerSysInfo(const TaskManagerSysInfo &)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
TaskManagerSysInfo::~TaskManagerSysInfo()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
TaskManagerSysInfo & TaskManagerSysInfo::operator = (const TaskManagerSysInfo & rhs)
|
||||
{
|
||||
if(this != &rhs)
|
||||
{
|
||||
// make assignments if right hand side is not this instance
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
const float TaskManagerSysInfo::getScore() const
|
||||
{
|
||||
std::list<float>::const_iterator i;
|
||||
float avg = 0.0f;
|
||||
for(i = averageScore.begin(); i != averageScore.end(); ++i)
|
||||
{
|
||||
avg += (*i);
|
||||
}
|
||||
avg = avg / averageScore.size();
|
||||
return avg;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void TaskManagerSysInfo::update()
|
||||
{
|
||||
static int64 activeTime[2] = {0};
|
||||
static int64 currentTime[2] = {0};
|
||||
|
||||
float currentScore = 0.0f;
|
||||
activeTime[0] = activeTime[1];
|
||||
currentTime[0] = currentTime[1];
|
||||
activeTime[1] = 0;
|
||||
|
||||
HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
|
||||
double procAvg = 0.0f;
|
||||
|
||||
MEMORYSTATUS memStat;
|
||||
GlobalMemoryStatus(&memStat);
|
||||
|
||||
currentScore = static_cast<float>(static_cast<float>(memStat.dwMemoryLoad) * 0.005f);
|
||||
if(hProcessSnap != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
PROCESSENTRY32 pe32 = {0};
|
||||
pe32.dwSize = sizeof(PROCESSENTRY32);
|
||||
if (Process32First(hProcessSnap, &pe32))
|
||||
{
|
||||
do
|
||||
{
|
||||
HANDLE proc = OpenProcess(PROCESS_QUERY_INFORMATION, false, pe32.th32ProcessID);
|
||||
// some stuf with the enumerated processes
|
||||
FILETIME createTime = {0};
|
||||
FILETIME exitTime = {0};
|
||||
FILETIME kernelTime = {0};
|
||||
FILETIME userTime = {0};
|
||||
GetProcessTimes(proc, &createTime, &exitTime, &kernelTime, &userTime);
|
||||
int64 totals;
|
||||
|
||||
// SDK docs say:
|
||||
// It is not recommended that you add and subtract values
|
||||
// from the FILETIME structure to obtain relative times. Instead, you should
|
||||
// Copy the resulting FILETIME structure to a ULARGE_INTEGER structure.
|
||||
// Use normal 64-bit arithmetic on the ULARGE_INTEGER value.
|
||||
int64 c;
|
||||
int64 e;
|
||||
int64 k;
|
||||
int64 u;
|
||||
memcpy(&c, &createTime, sizeof(int64));
|
||||
memcpy(&e, &exitTime, sizeof(int64));
|
||||
memcpy(&k, &kernelTime, sizeof(int64));
|
||||
memcpy(&u, &userTime, sizeof(int64));
|
||||
|
||||
totals = k + u;
|
||||
|
||||
FILETIME fst;
|
||||
SYSTEMTIME st;
|
||||
GetSystemTime(&st);
|
||||
SystemTimeToFileTime(&st, &fst);
|
||||
|
||||
int64 runTime;
|
||||
memcpy(&runTime, &fst, sizeof(int64));
|
||||
runTime = runTime - c;
|
||||
|
||||
if(c || e || k || u)
|
||||
{
|
||||
activeTime[1] += k + e;
|
||||
}
|
||||
|
||||
}
|
||||
while (Process32Next(hProcessSnap, &pe32));
|
||||
}
|
||||
}
|
||||
|
||||
FILETIME fst;
|
||||
SYSTEMTIME st;
|
||||
GetSystemTime(&st);
|
||||
SystemTimeToFileTime(&st, &fst);
|
||||
memcpy(¤tTime[1], &fst, sizeof(int64));
|
||||
int64 timeSlice = currentTime[1] - currentTime[0];
|
||||
int64 activeSlice = activeTime[1] - activeTime[0];
|
||||
procAvg = static_cast<double>(static_cast<double>(activeSlice) / timeSlice);
|
||||
//REPORT_LOG(true, ("%f\n", procAvg));
|
||||
currentScore = currentScore + static_cast<float>(procAvg * 0.5);
|
||||
|
||||
averageScore.insert(averageScore.end(), currentScore);
|
||||
|
||||
if(averageScore.size() > 100)
|
||||
averageScore.erase(averageScore.begin());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#include "FirstTaskManager.h"
|
||||
|
||||
#include "sharedFoundation/FirstSharedFoundation.h"
|
||||
#include "sharedCompression/SetupSharedCompression.h"
|
||||
#include "sharedDebug/SetupSharedDebug.h"
|
||||
#include "sharedFile/SetupSharedFile.h"
|
||||
#include "sharedFoundation/ConfigFile.h"
|
||||
#include "sharedFoundation/SetupSharedFoundation.h"
|
||||
#include "sharedNetworkMessages/SetupSharedNetworkMessages.h"
|
||||
#include "sharedRandom/SetupSharedRandom.h"
|
||||
#include "sharedThread/SetupSharedThread.h"
|
||||
#include "TaskManager.h"
|
||||
#include "ConfigTaskManager.h"
|
||||
|
||||
//=====================================================================
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
SetupSharedThread::install();
|
||||
SetupSharedDebug::install(1024);
|
||||
|
||||
//-- setup foundation
|
||||
SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game);
|
||||
|
||||
setupFoundationData.argc = argc;
|
||||
setupFoundationData.argv = argv;
|
||||
setupFoundationData.createWindow = false;
|
||||
setupFoundationData.clockUsesSleep = true;
|
||||
SetupSharedFoundation::install (setupFoundationData);
|
||||
|
||||
SetupSharedCompression::install();
|
||||
SetupSharedFile::install(false);
|
||||
SetupSharedNetworkMessages::install();
|
||||
SetupSharedRandom::install(static_cast<uint32>(time(NULL))); //lint !e1924 !e64 // NULL is a C-Style cast?
|
||||
|
||||
ConfigTaskManager::install();
|
||||
|
||||
TaskManager::install();
|
||||
|
||||
//-- run server
|
||||
SetupSharedFoundation::callbackWithExceptionHandling(TaskManager::run);
|
||||
|
||||
TaskManager::remove();
|
||||
SetupSharedFoundation::remove();
|
||||
SetupSharedThread::remove();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
Reference in New Issue
Block a user