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/SHMProcess.h
private/LinuxProcess.h private/LinuxProcess.h
private/WindowsProcess.h private/WindowsProcess.h
private/ProcessFactory.h
) )
SET(PROJECT_HDRS SET(PROJECT_HDRS

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

@ -23,6 +23,7 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include "LinuxProcess.h" #include "LinuxProcess.h"
#include "ProcessFactory.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
#include <errno.h> #include <errno.h>
@ -30,6 +31,31 @@ distribution.
#include <stdio.h> #include <stdio.h>
using namespace DFHack; 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) WineProcess::WineProcess(uint32_t pid, vector <VersionInfo *> & known_versions) : LinuxProcessBase(pid)
{ {
char dir_name [256]; char dir_name [256];

@ -23,12 +23,34 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include "LinuxProcess.h" #include "LinuxProcess.h"
#include "ProcessFactory.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
#include <errno.h> #include <errno.h>
#include <sys/ptrace.h> #include <sys/ptrace.h>
using namespace DFHack; 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) NormalProcess::NormalProcess(uint32_t pid, vector <VersionInfo *> & known_versions) : LinuxProcessBase(pid)
{ {
char dir_name [256]; char dir_name [256];

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

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

@ -90,39 +90,6 @@ namespace DFHack
bool SetAndWait (uint32_t state){return false;}; 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 #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 class DFHACK_EXPORT SHMProcess : public Process
{ {
friend class ProcessEnumerator;
class Private;
private: private:
class Private;
Private * const d; Private * const d;
public: public:

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