Added an early binding for the Config API (incomplete, untested)
This commit is contained in:
parent
47baa4f84a
commit
c90d082b6c
|
@ -22,21 +22,33 @@
|
|||
/* libSystem */
|
||||
/* private */
|
||||
/* constants */
|
||||
static char const _libsystem_config_name[] = "libSystem::Config";
|
||||
static char const _libsystem_event_name[] = "libSystem::Event";
|
||||
|
||||
|
||||
/* prototypes */
|
||||
/* Config */
|
||||
static PyObject * _libsystem_config_new(PyObject * self, PyObject * args);
|
||||
static void _libsystem_config_delete(PyObject * self);
|
||||
|
||||
static PyObject * _libsystem_config_get(PyObject * self, PyObject * args);
|
||||
static PyObject * _libsystem_config_set(PyObject * self, PyObject * args);
|
||||
|
||||
/* Event */
|
||||
static PyObject * _libsystem_event_new(PyObject * self, PyObject * args);
|
||||
static void _libsystem_event_delete(PyObject * self);
|
||||
|
||||
/* useful */
|
||||
static PyObject * _libsystem_event_loop(PyObject * self, PyObject * args);
|
||||
|
||||
|
||||
/* variables */
|
||||
static PyMethodDef _libsystem_methods[] =
|
||||
{
|
||||
{ "config_new", _libsystem_config_new, METH_VARARGS,
|
||||
"Instantiates a Config object." },
|
||||
{ "config_get", _libsystem_config_get, METH_VARARGS,
|
||||
"Obtains a value from the Config object." },
|
||||
{ "config_set", _libsystem_config_set, METH_VARARGS,
|
||||
"Sets a value in the Config object." },
|
||||
{ "event_new", _libsystem_event_new, METH_VARARGS,
|
||||
"Instantiates an Event object." },
|
||||
{ "event_loop", _libsystem_event_loop, METH_VARARGS,
|
||||
|
@ -60,6 +72,70 @@ PyMODINIT_FUNC init_libSystem(void)
|
|||
|
||||
/* private */
|
||||
/* functions */
|
||||
/* Config */
|
||||
/* libsystem_config_new */
|
||||
static PyObject * _libsystem_config_new(PyObject * self, PyObject * args)
|
||||
{
|
||||
Config * config;
|
||||
|
||||
if(!PyArg_ParseTuple(args, ""))
|
||||
return NULL;
|
||||
if((config = config_new()) == NULL)
|
||||
return NULL;
|
||||
return PyCapsule_New(config, _libsystem_config_name,
|
||||
_libsystem_config_delete);
|
||||
}
|
||||
|
||||
|
||||
/* libsystem_config_delete */
|
||||
static void _libsystem_config_delete(PyObject * self)
|
||||
{
|
||||
Config * config;
|
||||
|
||||
if((config = PyCapsule_GetPointer(self, _libsystem_config_name))
|
||||
== NULL)
|
||||
return;
|
||||
config_delete(config);
|
||||
}
|
||||
|
||||
|
||||
/* libsystem_config_get */
|
||||
static PyObject * _libsystem_config_get(PyObject * self, PyObject * args)
|
||||
{
|
||||
Config * config;
|
||||
char const * ret;
|
||||
char const * section;
|
||||
char const * variable;
|
||||
|
||||
if((config = PyCapsule_GetPointer(self, _libsystem_config_name))
|
||||
== NULL)
|
||||
return NULL;
|
||||
if(!PyArg_ParseTuple(args, "ss", §ion, &variable))
|
||||
return NULL;
|
||||
ret = config_get(config, section, variable);
|
||||
return Py_BuildValue("s", ret);
|
||||
}
|
||||
|
||||
|
||||
/* libsystem_config_set */
|
||||
static PyObject * _libsystem_config_set(PyObject * self, PyObject * args)
|
||||
{
|
||||
Config * config;
|
||||
int ret;
|
||||
char const * section;
|
||||
char const * variable;
|
||||
char const * value;
|
||||
|
||||
if((config = PyCapsule_GetPointer(self, _libsystem_config_name))
|
||||
== NULL)
|
||||
return NULL;
|
||||
if(!PyArg_ParseTuple(args, "sss", §ion, &variable, &value))
|
||||
return NULL;
|
||||
ret = config_set(config, section, variable, value);
|
||||
return Py_BuildValue("i", ret);
|
||||
}
|
||||
|
||||
|
||||
/* Event */
|
||||
/* libsystem_event_new */
|
||||
static PyObject * _libsystem_event_new(PyObject * self, PyObject * args)
|
||||
|
|
|
@ -19,6 +19,17 @@
|
|||
import _libSystem
|
||||
|
||||
|
||||
#Config
|
||||
class Config:
|
||||
def __init__(self):
|
||||
self.config = _libSystem.config_new()
|
||||
|
||||
def get(self, section, variable):
|
||||
return _libSystem.config_get(self.config, section, variable)
|
||||
|
||||
def set(self, section, variable, value):
|
||||
return _libSystem.config_set(self.config, section, variable,
|
||||
value)
|
||||
#Event
|
||||
class Event:
|
||||
def __init__(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user