2000-11-14 15:52:10 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include <Python.h>
|
|
|
|
|
|
|
|
|
|
#include "Python_API.h"
|
2000-11-17 00:18:32 +00:00
|
|
|
#include "Thing.h"
|
2000-11-14 15:52:10 +00:00
|
|
|
|
2000-11-17 00:18:32 +00:00
|
|
|
static PyObject * object_new(PyObject * self, PyObject * args)
|
2000-11-16 16:35:03 +00:00
|
|
|
{
|
2000-11-17 00:18:32 +00:00
|
|
|
AtlasObject *o;
|
2000-11-16 16:35:03 +00:00
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "")) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2000-11-17 00:18:32 +00:00
|
|
|
o = newAtlasObject(args);
|
2000-11-16 16:35:03 +00:00
|
|
|
if ( o == NULL ) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2000-11-17 00:18:32 +00:00
|
|
|
o->m_obj = new Object;
|
2000-11-16 16:35:03 +00:00
|
|
|
return (PyObject *)o;
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-17 00:18:32 +00:00
|
|
|
static PyObject * cppthing_new(PyObject * self, PyObject * args)
|
2000-11-16 16:35:03 +00:00
|
|
|
{
|
2000-11-17 00:18:32 +00:00
|
|
|
ThingObject *o;
|
2000-11-16 16:35:03 +00:00
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "")) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2000-11-17 00:18:32 +00:00
|
|
|
o = newThingObject(args);
|
2000-11-16 16:35:03 +00:00
|
|
|
if ( o == NULL ) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2000-11-17 00:18:32 +00:00
|
|
|
//o->m_thing = new Thing;
|
2000-11-16 16:35:03 +00:00
|
|
|
return (PyObject *)o;
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-14 15:52:10 +00:00
|
|
|
static PyObject * operation_new(PyObject * self, PyObject * args)
|
|
|
|
|
{
|
|
|
|
|
RootOperationObject * op;
|
|
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "")) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
op = newAtlasRootOperation(args);
|
|
|
|
|
if (op == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
op->operation = new RootOperation;
|
|
|
|
|
*op->operation = RootOperation::Instantiate();
|
|
|
|
|
return (PyObject *)op;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyMethodDef cyphesis_methods[] = {
|
|
|
|
|
/* {"system", spam_system, METH_VARARGS}, */
|
|
|
|
|
{"Operation", operation_new, METH_VARARGS},
|
2000-11-16 16:35:03 +00:00
|
|
|
{"Object", object_new, METH_VARARGS},
|
|
|
|
|
{"cppThing", cppthing_new, METH_VARARGS},
|
2000-11-14 15:52:10 +00:00
|
|
|
{NULL, NULL} /* Sentinel */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void init_python_api()
|
|
|
|
|
{
|
|
|
|
|
char * cwd;
|
|
|
|
|
|
|
|
|
|
if ((cwd = getcwd(NULL, 0)) != NULL) {
|
2000-11-17 00:18:32 +00:00
|
|
|
size_t len = strlen(cwd) + 12;
|
|
|
|
|
char * pypath = (char *)malloc(len);
|
|
|
|
|
strcpy(pypath, cwd);
|
|
|
|
|
strcat(pypath, "/rulesets/basic");
|
|
|
|
|
setenv("PYTHONPATH", pypath, 1);
|
2000-11-14 15:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Py_Initialize();
|
|
|
|
|
|
|
|
|
|
if (Py_InitModule("cyphesis", cyphesis_methods) == NULL) {
|
|
|
|
|
printf("Failed to Create cyphesis thing\n");
|
|
|
|
|
} else {
|
|
|
|
|
printf("Created cyphesis thing\n");
|
|
|
|
|
}
|
|
|
|
|
}
|