Changeset 118
- Timestamp:
- 05/31/07 22:54:44 (2 years ago)
- Files:
-
- branches/cwiidpy/Makefile (deleted)
- branches/dev (copied) (copied from trunk)
- branches/dev/ChangeLog (modified) (1 diff)
- branches/dev/Makefile.in (modified) (4 diffs)
- branches/dev/common/include/app.mak (modified) (1 diff)
- branches/dev/common/include/lib.mak.in (modified) (1 diff)
- branches/dev/common/include/plugin.mak (modified) (1 diff)
- branches/dev/configure.ac (modified) (3 diffs)
- branches/dev/defs.mak.in (modified) (1 diff)
- branches/dev/doc/Makefile.in (modified) (1 diff)
- branches/dev/man/Makefile.in (modified) (1 diff)
- branches/dev/python (copied) (copied from branches/cwiidpy)
- branches/dev/python/Makefile.in (added)
- branches/dev/python/Wiimote.c (modified) (10 diffs)
- branches/dev/python/cwiidmodule.c (modified) (4 diffs)
- branches/dev/python/setup.py (added)
- branches/dev/wminput/Makefile.in (modified) (1 diff)
- branches/dev/wminput/conf.c (modified) (13 diffs)
- branches/dev/wminput/conf.h (modified) (2 diffs)
- branches/dev/wminput/main.c (modified) (11 diffs)
- branches/dev/wminput/plugins/acc/acc.c (modified) (8 diffs)
- branches/dev/wminput/plugins/ir_ptr/ir_ptr.c (modified) (5 diffs)
- branches/dev/wminput/plugins/nunchuk_acc/nunchuk_acc.c (modified) (9 diffs)
- branches/dev/wminput/pyplugin.c (added)
- branches/dev/wminput/pyplugin.h (added)
- branches/dev/wminput/uinput.c (modified) (1 diff)
- branches/dev/wminput/wmplugin.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dev/ChangeLog
r116 r118 1 2007-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 12 2007-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 22 2007-05-27 Arthur Peters <amp@singingwizard.org> 23 python 24 * removed set_mesg_callback from methods table 25 1 26 2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 2 27 libcwiid branches/dev/Makefile.in
r83 r118 6 6 BIN_DIRS = wmgui wminput lswm 7 7 DOC_DIRS = man doc 8 BIND_DIRS = python 9 10 SUB_DIRS = $(LIB_DIRS) $(BIN_DIRS) $(DOC_DIRS) $(BIND_DIRS) wmdemo 8 11 9 12 all install clean distclean uninstall: TARGET += $(MAKECMDGOALS) 10 13 11 all install clean distclean uninstall: $(BIN_DIRS) $(LIB_DIRS) 14 all install clean distclean uninstall: $(BIN_DIRS) $(LIB_DIRS) $(BIND_DIRS) 12 15 13 16 install uninstall distclean: $(DOC_DIRS) … … 17 20 ifneq ($(MAKECMDGOALS),clean) 18 21 ifneq ($(MAKECMDGOALS),distclean) 19 $(BIN_DIRS) : $(LIB_DIRS)22 $(BIN_DIRS) $(BIND_DIRS): $(LIB_DIRS) 20 23 endif 21 24 endif … … 25 28 endif 26 29 27 $( LIB_DIRS) $(BIN_DIRS) $(DOC_DIRS) wmdemo:30 $(SUB_DIRS): 28 31 $(MAKE) $(TARGET) -C $@ 29 32 … … 44 47 rm -rf $(CWIID_CONFIG_DIR) 45 48 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) 48 50 49 51 .NOTPARALLEL: branches/dev/common/include/app.mak
r52 r118 6 6 INST_DIR ?= /usr/local/bin 7 7 8 DEST_INST_DIR = $( DESTDIR)/$(INST_DIR)8 DEST_INST_DIR = $(ROOTDIR)$(INST_DIR) 9 9 10 10 all: $(APP_NAME) branches/dev/common/include/lib.mak.in
r52 r118 8 8 SO_NAME = $(LINK_NAME).$(MAJOR_VER) 9 9 SHARED_LIB = $(SO_NAME).$(MINOR_VER) 10 DEST_INC_INST_DIR = $( DESTDIR)/$(INC_INST_DIR)11 DEST_LIB_INST_DIR = $( DESTDIR)/$(LIB_INST_DIR)10 DEST_INC_INST_DIR = $(ROOTDIR)$(INC_INST_DIR) 11 DEST_LIB_INST_DIR = $(ROOTDIR)$(LIB_INST_DIR) 12 12 13 13 OBJECTS = $(SOURCES:.c=.o) branches/dev/common/include/plugin.mak
r52 r118 8 8 CFLAGS += -fpic 9 9 10 #TODO:unify the way DESTDIR is handled11 #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, 12 12 #so we don't do it here 13 #DEST_INST_DIR = $( DESTDIR)/$(INST_DIR)13 #DEST_INST_DIR = $(ROOTDIR)/$(INST_DIR) 14 14 DEST_INST_DIR = $(INST_DIR) 15 15 branches/dev/configure.ac
r83 r118 1 1 # ChangeLog: 2 # 2007-05-30 L. Donnie Smith <cwiid@abstrakraft.org> 3 # * added python/Makefile 4 # * added PYTHON_VERSION variable 5 # 2 6 # 2007-04-09 L. Donnie Smith <cwiid@abstrakraft.org> 3 7 # * updated for libcwiid rename … … 32 36 AC_MSG_ERROR([bison not found]) 33 37 fi 38 39 PYTHON_VERSION=[`python -c 'import sys; print sys.version[:3]'`] 40 AC_SUBST(PYTHON_VERSION) 34 41 35 42 AC_CHECK_LIB([pthread], [pthread_create],, … … 105 112 [wminput/plugins/nunchuk_acc/Makefile] 106 113 [lswm/Makefile] 114 [python/Makefile] 107 115 ) 108 116 branches/dev/defs.mak.in
r72 r118 24 24 COMMON = @abs_top_builddir@/common 25 25 26 CWIID_CONFIG_DIR = $(DESTDIR)/@CWIID_CONFIG_DIR@ 27 CWIID_PLUGINS_DIR = $(DESTDIR)/@CWIID_PLUGINS_DIR@ 26 ifdef DESTDIR 27 ROOTDIR = $(DESTDIR:%/=%) 28 endif 29 30 CWIID_CONFIG_DIR = $(ROOTDIR)@CWIID_CONFIG_DIR@ 31 CWIID_PLUGINS_DIR = $(ROOTDIR)@CWIID_PLUGINS_DIR@ 28 32 29 33 DEBUGFLAGS = -g branches/dev/doc/Makefile.in
r56 r118 5 5 docfiles = Xmodmap wminput.list 6 6 7 DEST_DOC_DIR = $( DESTDIR)/$(docdir)7 DEST_DOC_DIR = $(ROOTDIR)$(docdir) 8 8 9 9 all: branches/dev/man/Makefile.in
r56 r118 3 3 include @top_builddir@/defs.mak 4 4 5 DEST_MAN_DIR = $( DESTDIR)/$(mandir)5 DEST_MAN_DIR = $(ROOTDIR)$(mandir) 6 6 7 7 all: branches/dev/python/Wiimote.c
r117 r118 20 20 * 21 21 * 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 * 22 28 * 2007-05-22 L. Donnie Smith <cwiid@abstrakraft.org> 23 29 * * changed disconnect to close … … 26 32 * * fixed memory leak in get_mesg 27 33 * * added function names to argument parsing errors 34 * * changed to processMesg to ConvertMesgArray with global visibility 28 35 * 29 36 * 2007-05-15 L. Donnie Smith <cwiid@abstrakraft.org> … … 73 80 74 81 /* helper prototypes */ 75 static cwiid_mesg_callback_t callbackBridge; 76 static PyObject *processMesgs(int mesg_count, union cwiid_mesg mesg[]); 82 static cwiid_mesg_callback_t CallbackBridge; 83 PyObject *ConvertMesgArray(int mesg_count, union cwiid_mesg mesg[]); 84 PyObject *Wiimote_FromC(cwiid_wiimote_t *wiimote); 77 85 static int cwiid_start(Wiimote *self, int flags); 78 86 … … 85 93 {"disable", (PyCFunction)Wiimote_disable, METH_VARARGS | METH_KEYWORDS, 86 94 "disable flags on wiimote"}, 87 {"set_mesg_callback", (PyCFunction)Wiimote_set_mesg_callback,88 METH_VARARGS | METH_KEYWORDS, "setup a mesg processing callback"},89 95 {"get_mesg", (PyCFunction)Wiimote_get_mesg, METH_NOARGS, 90 96 "blocking call to get messages"}, … … 271 277 272 278 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)) { 274 280 PyErr_SetString(PyExc_IOError, "set callback error"); 275 281 return -1; … … 307 313 } 308 314 309 PyMesg = processMesgs(mesg_count, mesg);315 PyMesg = ConvertMesgArray(mesg_count, mesg); 310 316 311 317 free(mesg); … … 609 615 610 616 static void 611 callbackBridge(cwiid_wiimote_t *wiimote, int mesg_count,617 CallbackBridge(cwiid_wiimote_t *wiimote, int mesg_count, 612 618 union cwiid_mesg mesg[], struct timespec *t) 613 619 { … … 618 624 gstate = PyGILState_Ensure(); 619 625 620 ArgTuple = processMesgs(mesg_count, mesg);626 ArgTuple = ConvertMesgArray(mesg_count, mesg); 621 627 622 628 /* Put id and the list of messages as the arguments to the callback */ … … 626 632 Py_XDECREF(ArgTuple); 627 633 PyGILState_Release(gstate); 634 } 635 636 PyObject *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; 628 650 } 629 651 … … 648 670 * (CWIID_ERROR_MESG,error)] 649 671 */ 650 static PyObject *processMesgs(int mesg_count, union cwiid_mesg mesg[])672 PyObject *ConvertMesgArray(int mesg_count, union cwiid_mesg mesg[]) 651 673 { 652 674 PyObject *mesglist; /* List of message tuples */ branches/dev/python/cwiidmodule.c
r117 r118 20 20 * 21 21 * ChangeLog: 22 * 2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 23 * * added CObjects for Wiimote_FromC and ConvertMesgArray 24 * 22 25 * 2007-05-22 L. Donnie Smith <cwiid@abstrakraft.org> 23 26 * * clarified variable names … … 70 73 /* externally defined types */ 71 74 extern PyTypeObject Wiimote_Type; 75 extern PyObject *ConvertMesgArray(int, union cwiid_mesg []); 76 extern PyObject *Wiimote_FromC(cwiid_wiimote_t *); 72 77 73 78 /* cwiid module initializer */ … … 167 172 { 168 173 PyObject *Module; 174 PyObject *CObj; 169 175 int i; 170 176 … … 189 195 cwiid_constants[i].value); 190 196 } 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); 191 207 } 208 branches/dev/wminput/Makefile.in
r83 r118 5 5 APP_NAME = wminput 6 6 7 SOURCES = main.c conf.c uinput.c action_enum.c parser.c lexer.c util.c7 SOURCES = main.c conf.c pyplugin.c uinput.c action_enum.c parser.c lexer.c util.c 8 8 9 9 WMINPUT_CONFIG_DIR = $(CWIID_CONFIG_DIR)/wminput 10 CFLAGS += -I@top_builddir@/libcwiid \10 CFLAGS += -I@top_builddir@/libcwiid -I/usr/include/python@PYTHON_VERSION@ \ 11 11 -DWMINPUT_CONFIG_DIR=\"$(WMINPUT_CONFIG_DIR)\" \ 12 12 -DCWIID_PLUGINS_DIR=\"$(CWIID_PLUGINS_DIR)\" 13 LDLIBS += -lcwiid -ldl 13 LDLIBS += -lcwiid -ldl -lpython@PYTHON_VERSION@ 14 14 LDFLAGS += -L@top_builddir@/libcwiid -rdynamic 15 15 INST_DIR = @bindir@ branches/dev/wminput/conf.c
r91 r118 16 16 * 17 17 * ChangeLog: 18 * 2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 19 * * added python plugin support 20 * * changed param interface (pass pointers) 21 * 18 22 * 2007-04-15 <work.eric@gmail.com> 19 23 * * fixed classic controller configuration bug … … 28 32 */ 29 33 34 #include "Python.h" 35 30 36 #include <stdint.h> 31 37 #include <stdio.h> … … 41 47 #include "util.h" 42 48 #include "y.tab.h" 49 #include "pyplugin.h" 43 50 44 51 extern FILE *yyin; … … 85 92 if (conf->plugins[i].name) { 86 93 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 } 88 107 } 89 108 else { … … 309 328 int i; 310 329 unsigned char param_found = 0; 330 PyObject *PyObj; 311 331 312 332 if ((plugin = get_plugin(conf, name)) == NULL) { … … 326 346 } 327 347 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 } 339 387 } 340 388 … … 348 396 int i; 349 397 unsigned char param_found = 0; 398 PyObject *PyObj; 350 399 351 400 if ((plugin = get_plugin(conf, name)) == NULL) { … … 365 414 } 366 415 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 } 380 459 } 381 460 … … 454 533 for (i=0; i < CONF_MAX_PLUGINS; i++) { 455 534 conf->plugins[i].name = NULL; 535 conf->plugins[i].PyInfo = NULL; 456 536 conf->plugins[i].rpt_mode_flags = 0; 457 537 conf->plugins[i].prev_buttons = 0; … … 563 643 struct plugin *plugin; 564 644 struct stat buf; 565 wmplugin_info_t *info; 566 645 void *info; 646 647 /* TODO: replace PyErr_Print with wminput_err */ 567 648 for (i=0; i < CONF_MAX_PLUGINS; i++) { 568 649 if (!conf->plugins[i].name) { … … 589 670 wminput_err(dlerror()); 590 671 } 672 else { 673 plugin->type = PLUGIN_C; 674 } 591 675 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 */ 592 683 } 593 684 } … … 599 690 return NULL; 600 691 } 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; 631 807 } 632 808 } … … 634 810 return plugin; 635 811 } 636 branches/dev/wminput/conf.h
r83 r118 16 16 * 17 17 * ChangeLog: 18 * 2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 19 * * added python plugin support 20 * 18 21 * 2007-04-09 L. Donnie Smith <cwiid@abstrakraft.org> 19 22 * * updated for libcwiid rename … … 133 136 }; 134 137 138 enum plugin_type { 139 PLUGIN_C, 140 PLUGIN_PYTHON 141 }; 142 135 143 struct plugin { 136 144 char *name; 137 145 struct wmplugin_info *info; 146 struct wmplugin_data *data; 147 void *PyInfo; 148 enum plugin_type type; 138 149 void *handle; 139 wmplugin_init_t*init;140 wmplugin_exec_t*exec;150 void *init; 151 void *exec; 141 152 uint8_t rpt_mode_flags; 142 153 uint16_t prev_buttons; branches/dev/wminput/main.c
r116 r118 16 16 * 17 17 * 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 * 18 22 * 2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 19 23 * * changed cwiid_{connect,disconnect,command} to … … 37 41 */ 38 42 43 #include "Python.h" 44 39 45 #include <stdint.h> 40 46 #include <stdio.h> … … 51 57 #include "util.h" 52 58 #include "wmplugin.h" 59 #include "pyplugin.h" 53 60 54 61 struct conf conf; … … 69 76 /* Globals */ 70 77 cwiid_wiimote_t *wiimote; 78 PyObject *PyCWiidModule; 79 PyObject *PyWiimote; 80 static PyObject *(*ConvertMesgArray)(int, union cwiid_mesg[]); 71 81 char init; 72 82 … … 91 101 struct uinput_listen_data uinput_listen_data; 92 102 pthread_t uinput_listen_thread; 103 PyObject *PyCObj; 104 PyObject *(*Wiimote_FromC)(cwiid_wiimote_t *); 93 105 94 106 init = 1; … … 113 125 } 114 126 } 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); 115 152 116 153 /* Load Config */ … … 180 217 } 181 218 219 if (!(PyWiimote = Wiimote_FromC(wiimote))) { 220 PyErr_Print(); 221 conf_unload(&conf); 222 return -1; 223 } 224 182 225 /* init plugins */ 183 226 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);
