diff options
| author | Jeff Armstrong <jeffrey.armstrong@approximatrix.com> | 2011-07-12 23:02:14 -0400 |
|---|---|---|
| committer | Jeff Armstrong <jeffrey.armstrong@approximatrix.com> | 2011-07-12 23:02:14 -0400 |
| commit | 33346eaee2add1bf9c801cf92f19664ffaa71f2b (patch) | |
| tree | 5c12daa2aeb41d40e00333bb79518af852d6870f /lib | |
| parent | 020592344c70c1b287e52729086a493211daea5a (diff) | |
| download | gempy-33346eaee2add1bf9c801cf92f19664ffaa71f2b.tar.gz gempy-33346eaee2add1bf9c801cf92f19664ffaa71f2b.zip | |
Added appl_write and basic resource functions.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/gem.c | 38 | ||||
| -rw-r--r-- | lib/ldg_Python.h | 41 | ||||
| -rw-r--r-- | lib/py_aes.c | 49 | ||||
| -rw-r--r-- | lib/py_aes.h | 30 |
4 files changed, 126 insertions, 32 deletions
@@ -8,24 +8,42 @@ #include "py_aes.h" +/* --- A GEM exception --- */ +static PyObject *GEMError; + /* --- Python-C API Calls --- */ static void *pycallbacks[PY_API_FCOUNT]; /* --- Python API Bookkeeping --- */ static PyMethodDef GemMethods[] = { + /* AES Application Library */ {"appl_init", py_appl_init, METH_VARARGS, "Initialize a GEM application"}, {"appl_exit", py_appl_exit, METH_VARARGS, "Exit a GEM application"}, + {"appl_write", py_appl_write, METH_VARARGS, "Send a message to a GEM application"}, + + /* AES Forms Library */ {"form_alert", py_form_alert, METH_VARARGS, "Display a GEM alert dialog"}, + + /* AES Resource Library */ + {"rsrc_load", py_rsrc_load, METH_VARARGS, "Load a resource into memory"}, + {"rsrc_gaddr", py_rsrc_gaddr, METH_VARARGS, "Return an encapsulated memory address of a resource component"}, {NULL,NULL,0,NULL} }; PyMODINIT_FUNC __CDECL initgem(void) { +PyObject *m; - printf("Welcome to shared init.\nStandby...\n"); + //printf("Welcome to shared init.\nStandby...\n"); //LPy_InitModule("gem",GemMethods,NULL,NULL); - ldg_callback(pycallbacks[0],"gem",GemMethods,NULL,NULL); + + m = Py_InitModule("_gem",GemMethods); + + GEMError = PyErr_NewException("_gem.error",NULL,NULL); + Py_INCREF(GEMError); + PyModule_AddObject(m,"error",GEMError); + return; } /* --- End Python API Bookkeeping --- */ @@ -43,18 +61,28 @@ int i; PROC LibFunc[] = { "assign_pycalls", "Assigns Python callbacks", assign_pycalls, "initgem", "Internal\n", initgem, - "py_form_alert", "Internal\n", py_form_alert, + + /* AES Application Library */ "py_appl_exit", "Internal\n", py_appl_exit, - "py_appl_init", "Internal\n", py_appl_init + "py_appl_init", "Internal\n", py_appl_init, + "py_appl_write", "Internal\n", py_appl_write, + + /* AES Forms Library */ + "py_form_alert", "Internal\n", py_form_alert, + + /* AES Resource Library */ + "py_rsrc_load", "Internal\n", py_rsrc_load, + "py_rsrc_gaddr", "Internal\n", py_rsrc_gaddr }; LDGLIB LibLdg[] = { - 0x0001, 5, LibFunc, "GEM Extensions for Python", 0 + 0x0001, 8, LibFunc, "GEM Extensions for Python", 0 }; int main( void) { if( ldg_init( LibLdg) == -1) { + printf("*** %s ***\n",LibLdg[0].infos); printf("This program is a shared library.\n"); } return 0; diff --git a/lib/ldg_Python.h b/lib/ldg_Python.h index 1a79e18..0f21960 100644 --- a/lib/ldg_Python.h +++ b/lib/ldg_Python.h @@ -1,16 +1,27 @@ -#ifndef __LDG_PYTHON_HEADERS
-#define __LDG_PYTHON_HEADERS
-
-#include <Python.h>
-
-#define PY_API_FCOUNT 3
-
-#ifndef LDG_INTERNAL
-extern void *pycallbacks[PY_API_FCOUNT];
-#endif
-
-#define Py_InitModule(name,methods) ldg_callback(pycallbacks[0],name,methods,NULL,NULL)
-#define PyArg_ParseTuple(tpl,...) ldg_callback(pycallbacks[1],tpl,##__VA_ARGS__)
-#define Py_BuildValue(fmt,...) ldg_callback(pycallbacks[2],fmt,##__VA_ARGS__)
-
+#ifndef __LDG_PYTHON_HEADERS +#define __LDG_PYTHON_HEADERS + +#include <Python.h> +#include <ldg.h> + +#define PY_API_FCOUNT 8 + +#ifndef LDG_INTERNAL +extern void *pycallbacks[PY_API_FCOUNT]; +#endif + +#ifdef Py_REF_DEBUG +#error Cannot build LDG Python exceptions with reference debugging +#endif + +#define Py_InitModule(name,methods) ldg_callback(pycallbacks[0],name,methods,NULL,NULL) +#define PyArg_ParseTuple(tpl,...) ldg_callback(pycallbacks[1],tpl,##__VA_ARGS__) +#define Py_BuildValue(fmt,...) ldg_callback(pycallbacks[2],fmt,##__VA_ARGS__) +#define PyErr_NewException(obj,pt1,pt2) ldg_callback(pycallbacks[3],obj,pt1,pt2) +#define PyErr_SetString(obj,s) ldg_callback(pycallbacks[4],obj,s) +#define PyModule_AddObject(m,s,o) ldg_callback(pycallbacks[5],m,s,o) +#define PyCapsule_New(pt,s,de) ldg_callback(pycallbacks[6],pt,s,de) +#define PyCapsule_GetPointer(c,s) ldg_callback(pycallbacks[7],c.s) +//#define Py_INCREF(obj) ldg_callback(pycallbacks[4],obj) + #endif /*__LDG_PYTHON_HEADERS */
\ No newline at end of file diff --git a/lib/py_aes.c b/lib/py_aes.c index e97f4d5..d4d315b 100644 --- a/lib/py_aes.c +++ b/lib/py_aes.c @@ -1,6 +1,8 @@ #include "ldg_Python.h" #include <gem.h> +extern PyObject *GEMError; + /* --- Application Library --- */ static PyObject* __CDECL py_appl_init(PyObject *self, PyObject *args) { @@ -18,6 +20,20 @@ int ret; return Py_BuildValue("i",ret); } +static PyObject* __CDECL py_appl_write(PyObject *self, PyObject *args) +{ +int ret; +int app_id; +char *message; +int msg_length; + + if(!PyArg_ParseTuple(args,"iiy*",&app_id,&msg_length,&message)) + return NULL; + + ret = appl_write(app_id,msg_length,message); + return Py_BuildValue("i",ret); +} + /* --- Forms Library --- */ static PyObject* __CDECL py_form_alert(PyObject *self, PyObject *args) { @@ -30,3 +46,36 @@ int x; x = form_alert(x,text); return Py_BuildValue("i",x); } + +/* --- Resources Library --- */ +static void __CDECL py_rsrc_load(PyObject *self, PyObject *args) +{ +char *file; +int x; + + if(!PyArg_ParseTuple(args,"s",&file)) + return NULL; + + if(rsrc_load(file) == 0) { + PyErr_SetString(GEMError,"Resource failed to load"); + return NULL; + } + return Py_BuildValue("i",x); +} + +static PyObject* __CDECL py_rsrc_gaddr(PyObject *self, PyObject *args) +{ +char *file; +int type, index; +void *gaddr; + + if(!PyArg_ParseTuple(args,"ii",&type,&index)) + return NULL; + + if(rsrc_gaddr(type,index,&gaddr) == 0) { + PyErr_SetString(GEMError,"Resource item was not found"); + return NULL; + } + + return PyCapsule_New(gaddr,NULL,NULL); +} diff --git a/lib/py_aes.h b/lib/py_aes.h index 9336169..921b82c 100644 --- a/lib/py_aes.h +++ b/lib/py_aes.h @@ -1,12 +1,18 @@ -#ifndef __PY_AES_HEADERS
-#define __PY_AES_HEADERS
-
-#include "ldg_Python.h"
-
-static PyObject* __CDECL py_appl_init(PyObject *self, PyObject *args);
-
-static PyObject* __CDECL py_appl_exit(PyObject *self, PyObject *args);
-
-static PyObject* __CDECL py_form_alert(PyObject *self, PyObject *args);
-
-#endif /* __PY_AES_HEADERS */
+#ifndef __PY_AES_HEADERS +#define __PY_AES_HEADERS + +#include "ldg_Python.h" + +static PyObject* __CDECL py_appl_init(PyObject *self, PyObject *args); + +static PyObject* __CDECL py_appl_exit(PyObject *self, PyObject *args); + +static PyObject* __CDECL py_appl_write(PyObject *self, PyObject *args) + +static PyObject* __CDECL py_form_alert(PyObject *self, PyObject *args); + + +static void __CDECL py_rsrc_load(PyObject *self, PyObject *args); +static PyObject* __CDECL py_rsrc_gaddr(PyObject *self, PyObject *args); + +#endif /* __PY_AES_HEADERS */ |
