Changeset 118

Show
Ignore:
Timestamp:
05/31/07 22:54:44 (2 years ago)
Author:
dsmith
Message:

Create dev branch (currently contains experimental python plugins)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dev/ChangeLog

    r116 r118  
     12007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 
     2        python 
     3        * added Wiimote_FromC 
     4        * exported Wiimote_FromC and ConvertMesgArray as CObjects 
     5 
     6        wminput 
     7        * added pyplugin.c, pyplugin.h 
     8        * changed wmplugin_exec prototype (&mesg->mesg) 
     9        * changed param format (pass pointers) 
     10        * added python plugin support (experimental) 
     11 
     122007-05-30 L. Donnie Smith <cwiid@abstrakraft.org> 
     13        configure.ac 
     14        * added python/Makefile and PYTHON_VERSION variable 
     15 
     16        build system 
     17        * added ROOTDIR (massaged DESTDIR) 
     18 
     19        python 
     20        * added directory 
     21 
     222007-05-27 Arthur Peters <amp@singingwizard.org> 
     23        python 
     24        * removed set_mesg_callback from methods table 
     25 
    1262007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 
    227        libcwiid 
  • branches/dev/Makefile.in

    r83 r118  
    66BIN_DIRS = wmgui wminput lswm 
    77DOC_DIRS = man doc 
     8BIND_DIRS = python 
     9 
     10SUB_DIRS = $(LIB_DIRS) $(BIN_DIRS) $(DOC_DIRS) $(BIND_DIRS) wmdemo 
    811 
    912all install clean distclean uninstall: TARGET += $(MAKECMDGOALS) 
    1013 
    11 all install clean distclean uninstall: $(BIN_DIRS) $(LIB_DIRS) 
     14all install clean distclean uninstall: $(BIN_DIRS) $(LIB_DIRS) $(BIND_DIRS) 
    1215 
    1316install uninstall distclean: $(DOC_DIRS) 
     
    1720ifneq ($(MAKECMDGOALS),clean) 
    1821ifneq ($(MAKECMDGOALS),distclean) 
    19 $(BIN_DIRS): $(LIB_DIRS) 
     22$(BIN_DIRS) $(BIND_DIRS): $(LIB_DIRS) 
    2023endif 
    2124endif 
     
    2528endif 
    2629 
    27 $(LIB_DIRS) $(BIN_DIRS) $(DOC_DIRS) wmdemo
     30$(SUB_DIRS)
    2831        $(MAKE) $(TARGET) -C $@ 
    2932 
     
    4447        rm -rf $(CWIID_CONFIG_DIR) 
    4548 
    46 .PHONY: all install clean distclean uninstall uninstall_config $(LIB_DIRS) \ 
    47         $(BIN_DIRS) $(DOC_DIRS) wmdemo 
     49.PHONY: all install clean distclean uninstall uninstall_config $(SUB_DIRS) 
    4850 
    4951.NOTPARALLEL: 
  • branches/dev/common/include/app.mak

    r52 r118  
    66INST_DIR ?= /usr/local/bin 
    77 
    8 DEST_INST_DIR = $(DESTDIR)/$(INST_DIR) 
     8DEST_INST_DIR = $(ROOTDIR)$(INST_DIR) 
    99 
    1010all: $(APP_NAME) 
  • branches/dev/common/include/lib.mak.in

    r52 r118  
    88SO_NAME    = $(LINK_NAME).$(MAJOR_VER) 
    99SHARED_LIB = $(SO_NAME).$(MINOR_VER) 
    10 DEST_INC_INST_DIR = $(DESTDIR)/$(INC_INST_DIR) 
    11 DEST_LIB_INST_DIR = $(DESTDIR)/$(LIB_INST_DIR) 
     10DEST_INC_INST_DIR = $(ROOTDIR)$(INC_INST_DIR) 
     11DEST_LIB_INST_DIR = $(ROOTDIR)$(LIB_INST_DIR) 
    1212 
    1313OBJECTS = $(SOURCES:.c=.o) 
  • branches/dev/common/include/plugin.mak

    r52 r118  
    88CFLAGS += -fpic 
    99 
    10 #TODO:unify the way DESTDIR is handled 
    11 #Currently, defs.mak adds DESTDIR to the plugin INST_DIR, 
     10#TODO:unify the way ROOTDIR is handled 
     11#Currently, defs.mak adds ROOTDIR to the plugin INST_DIR, 
    1212#so we don't do it here 
    13 #DEST_INST_DIR = $(DESTDIR)/$(INST_DIR) 
     13#DEST_INST_DIR = $(ROOTDIR)/$(INST_DIR) 
    1414DEST_INST_DIR = $(INST_DIR) 
    1515 
  • branches/dev/configure.ac

    r83 r118  
    11# ChangeLog: 
     2# 2007-05-30 L. Donnie Smith <cwiid@abstrakraft.org> 
     3# * added python/Makefile 
     4# * added PYTHON_VERSION variable 
     5# 
    26# 2007-04-09 L. Donnie Smith <cwiid@abstrakraft.org> 
    37# * updated for libcwiid rename 
     
    3236        AC_MSG_ERROR([bison not found]) 
    3337fi 
     38 
     39PYTHON_VERSION=[`python -c 'import sys; print sys.version[:3]'`] 
     40AC_SUBST(PYTHON_VERSION) 
    3441 
    3542AC_CHECK_LIB([pthread], [pthread_create],, 
     
    105112        [wminput/plugins/nunchuk_acc/Makefile] 
    106113        [lswm/Makefile] 
     114        [python/Makefile] 
    107115        ) 
    108116 
  • branches/dev/defs.mak.in

    r72 r118  
    2424COMMON = @abs_top_builddir@/common 
    2525 
    26 CWIID_CONFIG_DIR = $(DESTDIR)/@CWIID_CONFIG_DIR@ 
    27 CWIID_PLUGINS_DIR = $(DESTDIR)/@CWIID_PLUGINS_DIR@ 
     26ifdef DESTDIR 
     27        ROOTDIR = $(DESTDIR:%/=%) 
     28endif 
     29 
     30CWIID_CONFIG_DIR = $(ROOTDIR)@CWIID_CONFIG_DIR@ 
     31CWIID_PLUGINS_DIR = $(ROOTDIR)@CWIID_PLUGINS_DIR@ 
    2832 
    2933DEBUGFLAGS = -g 
  • branches/dev/doc/Makefile.in

    r56 r118  
    55docfiles = Xmodmap wminput.list 
    66 
    7 DEST_DOC_DIR = $(DESTDIR)/$(docdir) 
     7DEST_DOC_DIR = $(ROOTDIR)$(docdir) 
    88 
    99all: 
  • branches/dev/man/Makefile.in

    r56 r118  
    33include @top_builddir@/defs.mak 
    44 
    5 DEST_MAN_DIR = $(DESTDIR)/$(mandir) 
     5DEST_MAN_DIR = $(ROOTDIR)$(mandir) 
    66 
    77all: 
  • branches/dev/python/Wiimote.c

    r117 r118  
    2020 * 
    2121 * ChangeLog: 
     22 * 2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 
     23 * * added Wiimote_FromC 
     24 * 
     25 * 2007-05-27 Arthur Peters <amp@singingwizard.org> 
     26 * * removed set_mesg_callback from methods table 
     27 * 
    2228 * 2007-05-22 L. Donnie Smith <cwiid@abstrakraft.org> 
    2329 * * changed disconnect to close 
     
    2632 * * fixed memory leak in get_mesg 
    2733 * * added function names to argument parsing errors 
     34 * * changed to processMesg to ConvertMesgArray with global visibility 
    2835 * 
    2936 * 2007-05-15 L. Donnie Smith <cwiid@abstrakraft.org> 
     
    7380 
    7481/* helper prototypes */ 
    75 static cwiid_mesg_callback_t callbackBridge; 
    76 static PyObject *processMesgs(int mesg_count, union cwiid_mesg mesg[]); 
     82static cwiid_mesg_callback_t CallbackBridge; 
     83PyObject *ConvertMesgArray(int mesg_count, union cwiid_mesg mesg[]); 
     84PyObject *Wiimote_FromC(cwiid_wiimote_t *wiimote); 
    7785static int cwiid_start(Wiimote *self, int flags); 
    7886 
     
    8593        {"disable", (PyCFunction)Wiimote_disable, METH_VARARGS | METH_KEYWORDS, 
    8694         "disable flags on wiimote"}, 
    87         {"set_mesg_callback", (PyCFunction)Wiimote_set_mesg_callback, 
    88          METH_VARARGS | METH_KEYWORDS, "setup a mesg processing callback"}, 
    8995        {"get_mesg", (PyCFunction)Wiimote_get_mesg, METH_NOARGS, 
    9096         "blocking call to get messages"}, 
     
    271277 
    272278        if ((OldCallback == Py_None) && (NewCallback != Py_None)) { 
    273                 if (cwiid_set_mesg_callback(self->wiimote, callbackBridge)) { 
     279                if (cwiid_set_mesg_callback(self->wiimote, CallbackBridge)) { 
    274280                        PyErr_SetString(PyExc_IOError, "set callback error"); 
    275281                        return -1; 
     
    307313        } 
    308314 
    309         PyMesg = processMesgs(mesg_count, mesg); 
     315        PyMesg = ConvertMesgArray(mesg_count, mesg); 
    310316 
    311317        free(mesg); 
     
    609615 
    610616static void 
    611         callbackBridge(cwiid_wiimote_t *wiimote, int mesg_count, 
     617        CallbackBridge(cwiid_wiimote_t *wiimote, int mesg_count, 
    612618                       union cwiid_mesg mesg[], struct timespec *t) 
    613619{ 
     
    618624        gstate = PyGILState_Ensure(); 
    619625 
    620         ArgTuple = processMesgs(mesg_count, mesg); 
     626        ArgTuple = ConvertMesgArray(mesg_count, mesg); 
    621627 
    622628        /* Put id and the list of messages as the arguments to the callback */ 
     
    626632        Py_XDECREF(ArgTuple); 
    627633        PyGILState_Release(gstate); 
     634} 
     635 
     636PyObject *Wiimote_FromC(cwiid_wiimote_t *wiimote) 
     637{ 
     638        Wiimote *PyWiimote; 
     639 
     640        if (!(PyWiimote = (Wiimote *)PyObject_CallMethod((PyObject *)&Wiimote_Type, 
     641                                                         "__new__", "(O)", 
     642                                                         &Wiimote_Type))) { 
     643                return NULL; 
     644        } 
     645 
     646        cwiid_set_data(wiimote, PyWiimote); 
     647        PyWiimote->wiimote = wiimote; 
     648 
     649        return (PyObject *)PyWiimote; 
    628650} 
    629651 
     
    648670 *          (CWIID_ERROR_MESG,error)] 
    649671 */ 
    650 static PyObject *processMesgs(int mesg_count, union cwiid_mesg mesg[]) 
     672PyObject *ConvertMesgArray(int mesg_count, union cwiid_mesg mesg[]) 
    651673{ 
    652674        PyObject *mesglist; /* List of message tuples */ 
  • branches/dev/python/cwiidmodule.c

    r117 r118  
    2020 * 
    2121 * ChangeLog: 
     22 * 2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 
     23 * * added CObjects for Wiimote_FromC and ConvertMesgArray 
     24 * 
    2225 * 2007-05-22 L. Donnie Smith <cwiid@abstrakraft.org> 
    2326 * * clarified variable names 
     
    7073/* externally defined types */ 
    7174extern PyTypeObject Wiimote_Type; 
     75extern PyObject *ConvertMesgArray(int, union cwiid_mesg []); 
     76extern PyObject *Wiimote_FromC(cwiid_wiimote_t *); 
    7277 
    7378/* cwiid module initializer */ 
     
    167172{ 
    168173        PyObject *Module; 
     174        PyObject *CObj; 
    169175        int i; 
    170176 
     
    189195                                        cwiid_constants[i].value); 
    190196        } 
     197 
     198        if (!(CObj = PyCObject_FromVoidPtr(ConvertMesgArray, NULL))) { 
     199                return; 
     200        } 
     201        PyModule_AddObject(Module, "ConvertMesgArray", CObj); 
     202 
     203        if (!(CObj = PyCObject_FromVoidPtr(Wiimote_FromC, NULL))) { 
     204                return; 
     205        } 
     206        PyModule_AddObject(Module, "Wiimote_FromC", CObj); 
    191207} 
     208 
  • branches/dev/wminput/Makefile.in

    r83 r118  
    55APP_NAME = wminput 
    66 
    7 SOURCES = main.c conf.c uinput.c action_enum.c parser.c lexer.c util.c 
     7SOURCES = main.c conf.c pyplugin.c uinput.c action_enum.c parser.c lexer.c util.c 
    88 
    99WMINPUT_CONFIG_DIR = $(CWIID_CONFIG_DIR)/wminput 
    10 CFLAGS += -I@top_builddir@/libcwiid
     10CFLAGS += -I@top_builddir@/libcwiid -I/usr/include/python@PYTHON_VERSION@
    1111        -DWMINPUT_CONFIG_DIR=\"$(WMINPUT_CONFIG_DIR)\" \ 
    1212        -DCWIID_PLUGINS_DIR=\"$(CWIID_PLUGINS_DIR)\" 
    13 LDLIBS += -lcwiid -ldl 
     13LDLIBS += -lcwiid -ldl -lpython@PYTHON_VERSION@ 
    1414LDFLAGS += -L@top_builddir@/libcwiid -rdynamic 
    1515INST_DIR = @bindir@ 
  • branches/dev/wminput/conf.c

    r91 r118  
    1616 * 
    1717 *  ChangeLog: 
     18 *  2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * added python plugin support 
     20 *  * changed param interface (pass pointers) 
     21 * 
    1822 *  2007-04-15 <work.eric@gmail.com> 
    1923 *  * fixed classic controller configuration bug 
     
    2832 */ 
    2933 
     34#include "Python.h" 
     35 
    3036#include <stdint.h> 
    3137#include <stdio.h> 
     
    4147#include "util.h" 
    4248#include "y.tab.h" 
     49#include "pyplugin.h" 
    4350 
    4451extern FILE *yyin; 
     
    8592                if (conf->plugins[i].name) { 
    8693                        free(conf->plugins[i].name); 
    87                         dlclose(conf->plugins[i].handle); 
     94                        switch (conf->plugins[i].type) { 
     95                        case PLUGIN_C: 
     96                                dlclose(conf->plugins[i].handle); 
     97                                break; 
     98                        case PLUGIN_PYTHON: 
     99                                free(conf->plugins[i].info); 
     100                                free(conf->plugins[i].data); 
     101                                Py_DECREF((PyObject *)conf->plugins[i].PyInfo); 
     102                                Py_DECREF((PyObject *)conf->plugins[i].init); 
     103                                Py_DECREF((PyObject *)conf->plugins[i].exec); 
     104                                Py_DECREF((PyObject *)conf->plugins[i].handle); 
     105                                break; 
     106                        } 
    88107                } 
    89108                else { 
     
    309328        int i; 
    310329        unsigned char param_found = 0; 
     330        PyObject *PyObj; 
    311331 
    312332        if ((plugin = get_plugin(conf, name)) == NULL) { 
     
    326346        } 
    327347 
    328         switch (plugin->info->param_info[i].type) { 
    329         case WMPLUGIN_PARAM_INT: 
    330                 plugin->info->param_info[i].value.Int = value; 
    331                 break; 
    332         case WMPLUGIN_PARAM_FLOAT: 
    333                 plugin->info->param_info[i].value.Float = (float) value; 
    334                 break; 
    335         default: 
    336                 wminput_err("unknown parameter type: %s.%s", name, param); 
    337                 return -1; 
    338                 break; 
     348        switch (plugin->type) { 
     349        case PLUGIN_C: 
     350                switch (plugin->info->param_info[i].type) { 
     351                case WMPLUGIN_PARAM_INT: 
     352                        *(int *)plugin->info->param_info[i].ptr = value; 
     353                        break; 
     354                case WMPLUGIN_PARAM_FLOAT: 
     355                        *(float *)plugin->info->param_info[i].ptr = value; 
     356                        break; 
     357                default: 
     358                        wminput_err("unknown parameter type: %s.%s", name, param); 
     359                        return -1; 
     360                        break; 
     361                } 
     362        case PLUGIN_PYTHON: 
     363                switch (plugin->info->param_info[i].type) { 
     364                case WMPLUGIN_PARAM_INT: 
     365                        PyObj = PyInt_FromLong(value); 
     366                        if (PyObject_SetAttrString(plugin->handle, 
     367                                                   plugin->info->param_info[i].name, 
     368                                                   PyObj)) { 
     369                                PyErr_Print(); 
     370                                return -1; 
     371                        } 
     372                        break; 
     373                case WMPLUGIN_PARAM_FLOAT: 
     374                        PyObj = PyFloat_FromDouble((double)value); 
     375                        if (PyObject_SetAttrString(plugin->handle, 
     376                                                   plugin->info->param_info[i].name, 
     377                                                   PyObj)) { 
     378                                PyErr_Print(); 
     379                                return -1; 
     380                        } 
     381                        break; 
     382                default: 
     383                        wminput_err("unknown parameter type: %s.%s", name, param); 
     384                        return -1; 
     385                        break; 
     386                } 
    339387        } 
    340388 
     
    348396        int i; 
    349397        unsigned char param_found = 0; 
     398        PyObject *PyObj; 
    350399 
    351400        if ((plugin = get_plugin(conf, name)) == NULL) { 
     
    365414        } 
    366415 
    367         switch (plugin->info->param_info[i].type) { 
    368         case WMPLUGIN_PARAM_INT: 
    369                 wminput_err("possible loss of precision: %s.%s (cast float to int)", 
    370                             name, param); 
    371                 plugin->info->param_info[i].value.Int = value; 
    372                 break; 
    373         case WMPLUGIN_PARAM_FLOAT: 
    374                 plugin->info->param_info[i].value.Float = value; 
    375                 break; 
    376         default: 
    377                 wminput_err("unknown parameter type: %s.%s", name, param); 
    378                 return -1; 
    379                 break; 
     416        switch (plugin->type) { 
     417        case PLUGIN_C: 
     418                switch (plugin->info->param_info[i].type) { 
     419                case WMPLUGIN_PARAM_INT: 
     420                        wminput_err("possible loss of precision: %s.%s " 
     421                                    "(cast float to int)", name, param); 
     422                        *(int *)plugin->info->param_info[i].ptr = value; 
     423                        break; 
     424                case WMPLUGIN_PARAM_FLOAT: 
     425                        *(float *)plugin->info->param_info[i].ptr = value; 
     426                        break; 
     427                default: 
     428                        wminput_err("unknown parameter type: %s.%s", name, param); 
     429                        return -1; 
     430                        break; 
     431                } 
     432        case PLUGIN_PYTHON: 
     433                switch (plugin->info->param_info[i].type) { 
     434                case WMPLUGIN_PARAM_INT: 
     435                        wminput_err("possible loss of precision: %s.%s " 
     436                                    "(cast float to int)", name, param); 
     437                        PyObj = PyInt_FromLong((int)value); 
     438                        if (PyObject_SetAttrString(plugin->handle, 
     439                                                   plugin->info->param_info[i].name, 
     440                                                   PyObj)) { 
     441                                PyErr_Print(); 
     442                                return -1; 
     443                        } 
     444                        break; 
     445                case WMPLUGIN_PARAM_FLOAT: 
     446                        PyObj = PyFloat_FromDouble((double)value); 
     447                        if (PyObject_SetAttrString(plugin->handle, 
     448                                                   plugin->info->param_info[i].name, 
     449                                                   PyObj)) { 
     450                                PyErr_Print(); 
     451                                return -1; 
     452                        } 
     453                        break; 
     454                default: 
     455                        wminput_err("unknown parameter type: %s.%s", name, param); 
     456                        return -1; 
     457                        break; 
     458                } 
    380459        } 
    381460 
     
    454533        for (i=0; i < CONF_MAX_PLUGINS; i++) { 
    455534                conf->plugins[i].name = NULL; 
     535                conf->plugins[i].PyInfo = NULL; 
    456536                conf->plugins[i].rpt_mode_flags = 0; 
    457537                conf->plugins[i].prev_buttons = 0; 
     
    563643        struct plugin *plugin; 
    564644        struct stat buf; 
    565         wmplugin_info_t *info; 
    566  
     645        void *info; 
     646 
     647        /* TODO: replace PyErr_Print with wminput_err */ 
    567648        for (i=0; i < CONF_MAX_PLUGINS; i++) { 
    568649                if (!conf->plugins[i].name) { 
     
    589670                                        wminput_err(dlerror()); 
    590671                                } 
     672                                else { 
     673                                        plugin->type = PLUGIN_C; 
     674                                } 
    591675                                break; 
     676                        } 
     677                        if (!chdir(conf->plugin_search_dirs[i])) { 
     678                                if ((plugin->handle = PyImport_ImportModule((char *)name))) { 
     679                                        plugin->type = PLUGIN_PYTHON; 
     680                                        break; 
     681                                } 
     682                                /* TODO: restore directory */ 
    592683                        } 
    593684                } 
     
    599690                        return NULL; 
    600691                } 
    601                 else if ((info = dlsym(plugin->handle, "wmplugin_info")) == 
    602                          NULL) { 
    603                         wminput_err("Unable to load plugin info function: %s", dlerror()); 
    604                         free(plugin->name); 
    605                         plugin->name = NULL; 
    606                         dlclose(plugin->handle); 
    607                         return NULL; 
    608                 } 
    609                 else if ((plugin->info = (*info)()) == NULL) { 
    610                         wminput_err("Invalid plugin info from %s", plugin->name); 
    611                         free(plugin->name); 
    612                         plugin->name = NULL; 
    613                         dlclose(plugin->handle); 
    614                         return NULL; 
    615                 } 
    616                 else if ((plugin->init = dlsym(plugin->handle, "wmplugin_init")) == 
    617                          NULL) { 
    618                         wminput_err("Unable to load plugin init function: %s", dlerror()); 
    619                         free(plugin->name); 
    620                         plugin->name = NULL; 
    621                         dlclose(plugin->handle); 
    622                         return NULL; 
    623                 } 
    624                 else if ((plugin->exec = dlsym(plugin->handle, "wmplugin_exec")) == 
    625                          NULL) { 
    626                         wminput_err("Unable to load plugin exec function: %s", dlerror()); 
    627                         free(plugin->name); 
    628                         plugin->name = NULL; 
    629                         dlclose(plugin->handle); 
    630                         return NULL; 
     692 
     693                switch (plugin->type) { 
     694                case PLUGIN_C: 
     695                        if (!(info = dlsym(plugin->handle, "wmplugin_info"))) { 
     696                                wminput_err("Unable to load plugin info function: %s", 
     697                                            dlerror()); 
     698                                free(plugin->name); 
     699                                plugin->name = NULL; 
     700                                dlclose(plugin->handle); 
     701                                return NULL; 
     702                        } 
     703                        if (!(plugin->info = (*(wmplugin_info_t *)info)())) { 
     704                                wminput_err("Invalid plugin info from %s", plugin->name); 
     705                                free(plugin->name); 
     706                                plugin->name = NULL; 
     707                                dlclose(plugin->handle); 
     708                                return NULL; 
     709                        } 
     710                        if (!(plugin->init = dlsym(plugin->handle, "wmplugin_init"))) { 
     711                                wminput_err("Unable to load plugin init function: %s", 
     712                                            dlerror()); 
     713                                free(plugin->name); 
     714                                plugin->name = NULL; 
     715                                dlclose(plugin->handle); 
     716                                return NULL; 
     717                        } 
     718                        if (!(plugin->exec = dlsym(plugin->handle, "wmplugin_exec"))) { 
     719                                wminput_err("Unable to load plugin exec function: %s", 
     720                                            dlerror()); 
     721                                free(plugin->name); 
     722                                plugin->name = NULL; 
     723                                dlclose(plugin->handle); 
     724                                return NULL; 
     725                        } 
     726                        break; 
     727                case PLUGIN_PYTHON: 
     728                        if (!(info = PyObject_GetAttrString(plugin->handle, 
     729                                                            "wmplugin_info"))) { 
     730                                PyErr_Print(); 
     731                                Py_DECREF((PyObject *)plugin->handle); 
     732                                free(plugin->name); 
     733                                plugin->name = NULL; 
     734                                return NULL; 
     735                        } 
     736                        if (!PyCallable_Check(info)) { 
     737                                wminput_err("Unable to load plugin info function: " 
     738                                            "not callable"); 
     739                                Py_DECREF((PyObject *)info); 
     740                                Py_DECREF((PyObject *)plugin->handle); 
     741                                free(plugin->name); 
     742                                plugin->name = NULL; 
     743                                return NULL; 
     744                        } 
     745                        if (!(plugin->init = PyObject_GetAttrString(plugin->handle, 
     746                                                                    "wmplugin_init"))) { 
     747                                PyErr_Print(); 
     748                                Py_DECREF((PyObject *)info); 
     749                                Py_DECREF((PyObject *)plugin->handle); 
     750                                free(plugin->name); 
     751                                plugin->name = NULL; 
     752                                return NULL; 
     753                        } 
     754                        if (!PyCallable_Check(plugin->init)) { 
     755                                wminput_err("Unable to load plugin init function: " 
     756                                            "not callable"); 
     757                                Py_DECREF((PyObject *)info); 
     758                                Py_DECREF((PyObject *)plugin->init); 
     759                                Py_DECREF((PyObject *)plugin->handle); 
     760                                free(plugin->name); 
     761                                plugin->name = NULL; 
     762                                return NULL; 
     763                        } 
     764                        if (!(plugin->exec = PyObject_GetAttrString(plugin->handle, 
     765                                                                    "wmplugin_exec"))) { 
     766                                PyErr_Print(); 
     767                                Py_DECREF((PyObject *)info); 
     768                                Py_DECREF((PyObject *)plugin->init); 
     769                                Py_DECREF((PyObject *)plugin->handle); 
     770                                free(plugin->name); 
     771                                plugin->name = NULL; 
     772                                return NULL; 
     773                        } 
     774                        if (!PyCallable_Check(plugin->exec)) { 
     775                                wminput_err("Unable to load plugin exec function: " 
     776                                            "not callable"); 
     777                                Py_DECREF((PyObject *)info); 
     778                                Py_DECREF((PyObject *)plugin->init); 
     779                                Py_DECREF((PyObject *)plugin->exec); 
     780                                Py_DECREF((PyObject *)plugin->handle); 
     781                                free(plugin->name); 
     782                                plugin->name = NULL; 
     783                                return NULL; 
     784                        } 
     785                        if (python_info(info, plugin)) { 
     786                                wminput_err("python_info error"); 
     787                                Py_DECREF((PyObject *)info); 
     788                                Py_DECREF((PyObject *)plugin->init); 
     789                                Py_DECREF((PyObject *)plugin->exec); 
     790                                Py_DECREF((PyObject *)plugin->handle); 
     791                                free(plugin->name); 
     792                                plugin->name = NULL; 
     793                                return NULL; 
     794                        } 
     795                        if (!(plugin->data = malloc(sizeof &plugin->data))) { 
     796                                wminput_err("malloc error"); 
     797                                Py_DECREF((PyObject *)info); 
     798                                Py_DECREF((PyObject *)plugin->init); 
     799                                Py_DECREF((PyObject *)plugin->exec); 
     800                                Py_DECREF((PyObject *)plugin->handle); 
     801                                free(plugin->name); 
     802                                plugin->name = NULL; 
     803                                return NULL; 
     804                        } 
     805                        Py_DECREF((PyObject *)info); 
     806                        break; 
    631807                } 
    632808        } 
     
    634810        return plugin; 
    635811} 
    636  
  • branches/dev/wminput/conf.h

    r83 r118  
    1616 * 
    1717 *  ChangeLog: 
     18 *  2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * added python plugin support 
     20 * 
    1821 *  2007-04-09 L. Donnie Smith <cwiid@abstrakraft.org> 
    1922 *  * updated for libcwiid rename 
     
    133136}; 
    134137 
     138enum plugin_type { 
     139        PLUGIN_C, 
     140        PLUGIN_PYTHON 
     141}; 
     142 
    135143struct plugin { 
    136144        char *name; 
    137145        struct wmplugin_info *info; 
     146        struct wmplugin_data *data; 
     147        void *PyInfo; 
     148        enum plugin_type type; 
    138149        void *handle; 
    139         wmplugin_init_t *init; 
    140         wmplugin_exec_t *exec; 
     150        void *init; 
     151        void *exec; 
    141152        uint8_t rpt_mode_flags; 
    142153        uint16_t prev_buttons; 
  • branches/dev/wminput/main.c

    r116 r118  
    1616 * 
    1717 *  ChangeLog: 
     18 *  2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * added python plugin support 
     20 *  * pass mesg instead of &mesg to wmplugin_exec 
     21 * 
    1822 *  2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 
    1923 *  * changed cwiid_{connect,disconnect,command} to 
     
    3741 */ 
    3842 
     43#include "Python.h" 
     44 
    3945#include <stdint.h> 
    4046#include <stdio.h> 
     
    5157#include "util.h" 
    5258#include "wmplugin.h" 
     59#include "pyplugin.h" 
    5360 
    5461struct conf conf; 
     
    6976/* Globals */ 
    7077cwiid_wiimote_t *wiimote; 
     78PyObject *PyCWiidModule; 
     79PyObject *PyWiimote; 
     80static PyObject *(*ConvertMesgArray)(int, union cwiid_mesg[]); 
    7181char init; 
    7282 
     
    91101        struct uinput_listen_data uinput_listen_data; 
    92102        pthread_t uinput_listen_thread; 
     103        PyObject *PyCObj; 
     104        PyObject *(*Wiimote_FromC)(cwiid_wiimote_t *); 
    93105 
    94106        init = 1; 
     
    113125                } 
    114126        } 
     127 
     128        /* Python Init */ 
     129        /* TODO: DECREF global objects and finalize on error and exit */ 
     130        Py_Initialize(); 
     131        if (initwmplugin()) { 
     132                return -1; 
     133        } 
     134        PyRun_SimpleString("import sys; sys.path.append('.')"); 
     135        if (!(PyCWiidModule = PyImport_ImportModule("cwiid"))) { 
     136                PyErr_Print(); 
     137                return -1; 
     138        } 
     139 
     140        if (!(PyCObj = PyObject_GetAttrString(PyCWiidModule, "Wiimote_FromC"))) { 
     141                PyErr_Print(); 
     142                return -1; 
     143        } 
     144        Wiimote_FromC = PyCObject_AsVoidPtr(PyCObj); 
     145 
     146        if (!(PyCObj = PyObject_GetAttrString(PyCWiidModule, 
     147                                              "ConvertMesgArray"))) { 
     148                PyErr_Print(); 
     149                return -1; 
     150        } 
     151        ConvertMesgArray = PyCObject_AsVoidPtr(PyCObj); 
    115152 
    116153        /* Load Config */ 
     
    180217        } 
    181218 
     219        if (!(PyWiimote = Wiimote_FromC(wiimote))) { 
     220                PyErr_Print(); 
     221                conf_unload(&conf); 
     222                return -1; 
     223        } 
     224 
    182225        /* init plugins */ 
    183226        for (i=0; (i < CONF_MAX_PLUGINS) && conf.plugins[i].name; i++) { 
    184                 if ((*conf.plugins[i].init)(i, wiimote)) { 
    185                         wminput_err("error on %s init", conf.plugins[i].name); 
    186                         conf_unload(&conf); 
    187                         cwiid_close(wiimote); 
    188                         return -1; 
     227                switch (conf.plugins[i].type) { 
     228                case PLUGIN_C: 
     229                        if ((*(wmplugin_init_t *)conf.plugins[i].init)(i, wiimote)) { 
     230                                wminput_err("error on %s init", conf.plugins[i].name); 
     231                                conf_unload(&conf); 
     232                                cwiid_close(wiimote); 
     233                                return -1; 
     234                        } 
     235                        break; 
     236                case PLUGIN_PYTHON: 
     237                        if (python_init(&conf.plugins[i], i, PyWiimote)) { 
     238                                wminput_err("error %s init", conf.plugins[i].name); 
     239                                conf_unload(&conf);