1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
/* $Id$ */
/*
* (C) Copyright 2004-2005 Leszek Krupiski <leafnode@pld-linux.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "ekg2.h"
#include "python.h"
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <Python.h>
#include "python.h"
#include "python-plugin.h"
// * ***************************************************************************
// *
// * plugin object
// *
// * ***************************************************************************
/**
* ekg_plugin_init()
*
* initialization of plugin object
*
*/
int ekg_plugin_init(ekg_pluginObj *self, PyObject *args, PyObject *kwds)
{
PyObject * name;
PyObject * prio;
static char *kwlist[] = {"name", "prio", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kwds, "si", kwlist,
&name, &prio))
return -1;
self->name = PyString_AsString(name);
self->prio = (int)PyInt_AsLong(prio);
return 0;
}
/**
* ekg_plugin_get_attr()
*
* get attribute from plugin object
*
*/
PyObject *ekg_plugin_get_attr(ekg_pluginObj * self, char * attr)
{
return Py_FindMethod(ekg_plugin_methods, (PyObject *) self, attr);
}
/**
* ekg_plugin_dealloc()
*
* deallocation of plugin object
*
*/
void ekg_plugin_dealloc(ekg_pluginObj * o)
{
xfree(o->name);
}
/**
* ekg_plugin_load()
*
* load plugin
*
*/
PyObject *ekg_plugin_load(ekg_pluginObj * self, PyObject *args)
{
int prio;
if (!PyArg_ParseTuple(args, "i", &prio))
return NULL;
debug("[python] Loading plugin '%s' with prio %i\n", self->name, prio);
if (plugin_find(self->name)) {
PyErr_SetString(PyExc_RuntimeError, "Plugin already loaded");
return NULL;
}
if (plugin_load(self->name, prio, 0) == -1) {
Py_RETURN_FALSE;
} else {
self->loaded = 1;
Py_RETURN_TRUE;
}
Py_INCREF(Py_None);
return Py_None;
}
/**
* ekg_plugin_is_loaded()
*
* load plugin
*
*/
PyObject *ekg_plugin_is_loaded(ekg_pluginObj * self, PyObject *args)
{
debug("[python] Checking if '%s' plugin is loaded\n", self->name);
if (plugin_find(self->name)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/**
* ekg_plugin_unload()
*
* unload plugin
*
*/
PyObject *ekg_plugin_unload(ekg_pluginObj * self, PyObject *args)
{
debug("[python] Unloading plugin '%s'\n", self->name);
if (plugin_unload(plugin_find(self->name)) == -1) {
Py_RETURN_FALSE;
} else {
self->loaded = 0;
Py_RETURN_TRUE;
}
}
/*
* Local Variables:
* mode: c
* c-file-style: "k&r"
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
* vim: sts=8 sw=8
*/
|