Add create*Process functions to create process instances.

This allows us to remove friendship of DFProcessEnumerator for Process
subclasses.
develop
Tom Prince 2011-02-23 06:08:30 -05:00
parent 2927b08f93
commit 63ab8672d3
10 changed files with 105 additions and 43 deletions

@ -32,6 +32,7 @@ SET(PROJECT_HDRS_INTERNAL
private/SHMProcess.h
private/LinuxProcess.h
private/WindowsProcess.h
private/ProcessFactory.h
)
SET(PROJECT_HDRS

@ -23,6 +23,7 @@ distribution.
*/
#include "Internal.h"
#include "SHMProcess.h"
#include "ProcessFactory.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h"
#include "shms.h"
@ -30,6 +31,11 @@ distribution.
using namespace DFHack;
Process* DFHack::createSHMProcess(uint32_t pid, vector <VersionInfo *> & known_versions)
{
return new SHMProcess(pid, known_versions);
}
SHMProcess::SHMProcess(uint32_t PID, vector <VersionInfo *> & known_versions)
: d(new Private(this))
{

@ -23,6 +23,7 @@ distribution.
*/
#include "Internal.h"
#include "LinuxProcess.h"
#include "ProcessFactory.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h"
#include <errno.h>
@ -30,6 +31,31 @@ distribution.
#include <stdio.h>
using namespace DFHack;
namespace {
class WineProcess : public LinuxProcessBase
{
private:
uint32_t STLSTR_buf_off;
uint32_t STLSTR_size_off;
uint32_t STLSTR_cap_off;
public:
WineProcess(uint32_t pid, std::vector <VersionInfo *> & known_versions);
const std::string readSTLString (uint32_t offset);
size_t readSTLString (uint32_t offset, char * buffer, size_t bufcapacity);
void writeSTLString(const uint32_t address, const std::string writeString){};
// get class name of an object with rtti/type info
std::string readClassName(uint32_t vptr);
private:
bool validate(char * exe_file,uint32_t pid, char * memFile, vector <VersionInfo *> & known_versions);
};
}
Process* DFHack::createWineProcess(uint32_t pid, vector <VersionInfo *> & known_versions)
{
return new WineProcess(pid, known_versions);
}
WineProcess::WineProcess(uint32_t pid, vector <VersionInfo *> & known_versions) : LinuxProcessBase(pid)
{
char dir_name [256];

@ -23,12 +23,34 @@ distribution.
*/
#include "Internal.h"
#include "LinuxProcess.h"
#include "ProcessFactory.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h"
#include <errno.h>
#include <sys/ptrace.h>
using namespace DFHack;
namespace {
class NormalProcess : public LinuxProcessBase
{
public:
NormalProcess(uint32_t pid, std::vector <VersionInfo *> & known_versions);
const std::string readSTLString (uint32_t offset);
size_t readSTLString (uint32_t offset, char * buffer, size_t bufcapacity);
void writeSTLString(const uint32_t address, const std::string writeString){};
// get class name of an object with rtti/type info
std::string readClassName(uint32_t vptr);
private:
bool validate(char * exe_file,uint32_t pid, char * memFile, vector <VersionInfo *> & known_versions);
};
}
Process* DFHack::createNormalProcess(uint32_t pid, vector <VersionInfo *> & known_versions)
{
return new NormalProcess(pid, known_versions);
}
NormalProcess::NormalProcess(uint32_t pid, vector <VersionInfo *> & known_versions) : LinuxProcessBase(pid)
{
char dir_name [256];

@ -23,11 +23,17 @@ distribution.
*/
#include "Internal.h"
#include "WindowsProcess.h"
#include "ProcessFactory.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h"
#include <string.h>
using namespace DFHack;
Process* DFHack::createNormalProcess(uint32_t pid, vector <VersionInfo *> & known_versions)
{
return new NormalProcess(pid, known_versions);
}
class NormalProcess::Private
{
public:

@ -23,9 +23,7 @@ distribution.
*/
#include "Internal.h"
#include "SHMProcess.h"
#include "LinuxProcess.h"
#include "WindowsProcess.h"
#include "ProcessFactory.h"
#include "dfhack/VersionInfoFactory.h"
#include "dfhack/DFProcessEnumerator.h"
@ -122,19 +120,19 @@ Process * BadProcesses::operator[](uint32_t index)
Process *ProcessEnumerator::Private::GetProcessObject(ProcessID ID)
{
Process *p1 = new SHMProcess(ID.pid,meminfo->versions);
Process *p1 = createSHMProcess(ID.pid,meminfo->versions);
if(p1->isIdentified())
return p1;
else
delete p1;
Process *p2 = new NormalProcess(ID.pid,meminfo->versions);
Process *p2 = createNormalProcess(ID.pid,meminfo->versions);
if(p2->isIdentified())
return p2;
else
delete p2;
#ifdef LINUX_BUILD
Process *p3 = new WineProcess(ID.pid,meminfo->versions);
Process *p3 = createWineProcess(ID.pid,meminfo->versions);
if(p3->isIdentified())
return p3;
else

@ -90,39 +90,6 @@ namespace DFHack
bool SetAndWait (uint32_t state){return false;};
};
class DFHACK_EXPORT NormalProcess : public LinuxProcessBase
{
friend class ProcessEnumerator;
public:
NormalProcess(uint32_t pid, std::vector <VersionInfo *> & known_versions);
const std::string readSTLString (uint32_t offset);
size_t readSTLString (uint32_t offset, char * buffer, size_t bufcapacity);
void writeSTLString(const uint32_t address, const std::string writeString){};
// get class name of an object with rtti/type info
std::string readClassName(uint32_t vptr);
private:
bool validate(char * exe_file,uint32_t pid, char * memFile, vector <VersionInfo *> & known_versions);
};
class DFHACK_EXPORT WineProcess : public LinuxProcessBase
{
friend class ProcessEnumerator;
private:
uint32_t STLSTR_buf_off;
uint32_t STLSTR_size_off;
uint32_t STLSTR_cap_off;
public:
WineProcess(uint32_t pid, std::vector <VersionInfo *> & known_versions);
const std::string readSTLString (uint32_t offset);
size_t readSTLString (uint32_t offset, char * buffer, size_t bufcapacity);
void writeSTLString(const uint32_t address, const std::string writeString){};
// get class name of an object with rtti/type info
std::string readClassName(uint32_t vptr);
private:
bool validate(char * exe_file,uint32_t pid, char * memFile, vector <VersionInfo *> & known_versions);
};
}
#endif

@ -0,0 +1,38 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#ifndef PROCESS_FACTORY_H_INCLUDED
#define PROCESS_FACTORY_H_INCLUDED
#include "dfhack/DFProcess.h"
namespace DFHack
{
Process* createNormalProcess(uint32_t pid, std::vector <VersionInfo *> & known_versions);
Process* createSHMProcess(uint32_t pid, std::vector <VersionInfo *> & known_versions);
#ifdef LINUX_BUILD
Process* createWineProcess(uint32_t pid, std::vector <VersionInfo *> & known_versions);
#endif
}
#endif

@ -31,9 +31,8 @@ namespace DFHack
{
class DFHACK_EXPORT SHMProcess : public Process
{
friend class ProcessEnumerator;
class Private;
private:
class Private;
Private * const d;
public:

@ -30,9 +30,8 @@ distribution.
namespace DFHack
{
class DFHACK_EXPORT NormalProcess : public Process
class NormalProcess : public Process
{
friend class ProcessEnumerator;
class Private;
private:
Private * const d;