added getter for memory info

develop
doomchild 2010-04-05 16:12:37 -05:00
parent b79c50d4b7
commit eb17353f3c
1 changed files with 36 additions and 0 deletions

@ -29,6 +29,7 @@ distribution.
#include <string>
#include "DFTypes.h"
#include "DFHackAPI.h"
#include "MemInfo.cpp"
using namespace std;
using namespace DFHack;
@ -36,6 +37,7 @@ using namespace DFHack;
struct DF_API
{
PyObject_HEAD
PyObject* mem_info;
DFHack::API* api_Ptr;
};
@ -59,6 +61,8 @@ static int DF_API_init(DF_API* self, PyObject* args, PyObject* kwds)
if(self->api_Ptr == NULL)
{
self->mem_info = NULL;
if(!PyArg_ParseTuple(args, "s", &memFileString))
return -1;
@ -82,6 +86,8 @@ static void DF_API_dealloc(DF_API* self)
self->api_Ptr = NULL;
}
Py_XDECREF(self->mem_info);
self->ob_type->tp_free((PyObject*)self);
}
}
@ -122,10 +128,40 @@ static PyObject* DF_API_getIsSuspended(DF_API* self, void* closure)
Py_RETURN_FALSE;
}
static PyObject* DF_API_getMemoryInfo(DF_API* self, void* closure)
{
if(self->mem_info != NULL)
return self->mem_info;
try
{
if(self->api_Ptr != NULL)
{
DFHack::memory_info* mem;
mem = self->api_Ptr->getMemoryInfo();
self->mem_info = _PyObject_New(&DF_MemInfo_type);
delete ((DF_MemInfo*)(self->mem_info))->mem_Ptr;
((DF_MemInfo*)(self->mem_info))->mem_Ptr = mem;
return self->mem_info;
}
}
catch(...)
{
PyErr_SetString(PyExc_ValueError, "Error trying to read memory info");
return NULL;
}
Py_RETURN_NONE;
}
static PyGetSetDef DF_API_getterSetters[] =
{
{"is_attached", (getter)DF_API_getIsAttached, NULL, "is_attached", NULL},
{"is_suspended", (getter)DF_API_getIsSuspended, NULL, "is_suspended", NULL},
{"memory_info", (getter)DF_API_getMemoryInfo, NULL, "memory_info", NULL},
{NULL} // Sentinel
};