Revision: 10134 http://pure-data.svn.sourceforge.net/pure-data/?rev=10134&view=rev Author: zmoelnig Date: 2008-07-02 04:40:32 -0700 (Wed, 02 Jul 2008)
Log Message: ----------- made the threaded version the default; renamed the blocking version to [dmxout_b]
Modified Paths: -------------- trunk/externals/iem/dmx512/src/dmxout.c trunk/externals/iem/dmx512/src/dmxout_b.c
Modified: trunk/externals/iem/dmx512/src/dmxout.c =================================================================== --- trunk/externals/iem/dmx512/src/dmxout.c 2008-07-02 11:34:38 UTC (rev 10133) +++ trunk/externals/iem/dmx512/src/dmxout.c 2008-07-02 11:40:32 UTC (rev 10134) @@ -1,6 +1,6 @@ /****************************************************** * - * dmxout_threaded - implementation file + * dmxout - implementation file * * copyleft (c) IOhannes m zm\xF6lnig * @@ -23,8 +23,8 @@ #include <pthread.h>
-static t_class *dmxout_threaded_class; -static t_class *dmxout_threaded_class2; +static t_class *dmxout_class; +static t_class *dmxout_class2;
#define NUM_DMXVALUES 512
@@ -34,7 +34,7 @@ static int g_device; static int g_thread_running, g_thread_continue;
-typedef struct _dmxout_threaded +typedef struct _dmxout { t_object x_obj;
@@ -43,10 +43,10 @@ int x_portrange;
-} t_dmxout_threaded; +} t_dmxout;
-static void *dmxout_threaded_thread(void*you) +static void *dmxout_thread(void*you) { pthread_mutex_t *mutex=g_mutex; struct timeval timout; @@ -66,12 +66,11 @@ pthread_mutex_unlock(g_mutex); } g_thread_running=0; - printf("quit thread");
return NULL; }
-static void dmxout_threaded_close() +static void dmxout_close() { if(g_device>=0) { close(g_device); @@ -97,7 +96,7 @@ }
-static void dmxout_threaded_open(t_symbol*s_devname) +static void dmxout_open(t_symbol*s_devname) { int argc=2; const char *args[2] = {"--dmx", s_devname->s_name}; @@ -105,20 +104,20 @@ const char*devname=""; int fd;
- dmxout_threaded_close(); + dmxout_close();
if(s_devname && s_devname->s_name) devname=s_devname->s_name;
// strncpy(args[0], "--dmx", MAXPDSTRING); // strncpy(args[1], devname, MAXPDSTRING); - verbose(2, "[dmxout_threaded]: trying to open '%s'", args[1]); + verbose(2, "[dmxout]: trying to open '%s'", args[1]); devname=DMXdev(&argc, argv); if(!devname){ error("couldn't find DMX device"); return; } - verbose(1, "[dmxout_threaded] opening %s", devname); + verbose(1, "[dmxout] opening %s", devname);
fd = open (devname, O_WRONLY);
@@ -132,14 +131,14 @@ error("couldn't create mutex"); } else { g_thread_continue = 1; - pthread_create(&g_thread_id, 0, dmxout_threaded_thread, NULL); + pthread_create(&g_thread_id, 0, dmxout_thread, NULL); } } else { error("failed to open DMX-device '%s'",devname); } }
-static void dmxout_threaded_doout(t_dmxout_threaded*x) { +static void dmxout_doout(t_dmxout*x) { if(g_device<=0) { pd_error(x, "no DMX universe found"); return; @@ -147,14 +146,14 @@ }
-static void dmxout_threaded_doout1(t_dmxout_threaded*x, short port, unsigned char value) +static void dmxout_doout1(t_dmxout*x, short port, unsigned char value) { g_values[port]=value; - dmxout_threaded_doout(x); + dmxout_doout(x); }
-static void dmxout_threaded_float(t_dmxout_threaded*x, t_float f) +static void dmxout_float(t_dmxout*x, t_float f) { unsigned char val=(unsigned char)f; short port = (short)x->x_port; @@ -167,10 +166,10 @@ return; }
- dmxout_threaded_doout1(x, port, val); + dmxout_doout1(x, port, val); }
-static void dmxout_threaded_list(t_dmxout_threaded*x, t_symbol*s, int argc, t_atom*argv) +static void dmxout_list(t_dmxout*x, t_symbol*s, int argc, t_atom*argv) { int count=(argc<x->x_portrange)?argc:x->x_portrange; int i=0; @@ -195,10 +194,10 @@ pd_error(x, "%d valu%s out of bound [0..255]", errors, (1==errors)?"e":"es"); }
- dmxout_threaded_doout(x); + dmxout_doout(x); }
-static void dmxout_threaded_port(t_dmxout_threaded*x, t_float f_baseport, t_floatarg f_portrange) +static void dmxout_port(t_dmxout*x, t_float f_baseport, t_floatarg f_portrange) { short baseport =(short)f_baseport; short portrange=(short)f_portrange; @@ -224,23 +223,23 @@ x->x_portrange=portrange; }
-static void *dmxout_threaded_new(t_symbol*s, int argc, t_atom*argv) +static void *dmxout_new(t_symbol*s, int argc, t_atom*argv) { t_floatarg baseport=0.f, portrange=0.f; - t_dmxout_threaded *x = 0; + t_dmxout *x = 0;
switch(argc) { case 2: - x=(t_dmxout_threaded *)pd_new(dmxout_threaded_class2); + x=(t_dmxout *)pd_new(dmxout_class2); x->x_portinlet=inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("port")); baseport=atom_getfloat(argv); portrange=atom_getfloat(argv+1); - dmxout_threaded_port(x, baseport, portrange); + dmxout_port(x, baseport, portrange); break; case 1: baseport=atom_getfloat(argv); case 0: - x=(t_dmxout_threaded *)pd_new(dmxout_threaded_class); + x=(t_dmxout *)pd_new(dmxout_class); x->x_portinlet=floatinlet_new(&x->x_obj, &x->x_port); x->x_port = baseport; x->x_portrange = -1; @@ -251,12 +250,12 @@ return (x); }
-static void *dmxout_threaded_free(t_dmxout_threaded*x) +static void *dmxout_free(t_dmxout*x) { - // dmxout_threaded_close(); + // dmxout_close(); }
-static void dmxout_threaded_init(void) { +static void dmxout_init(void) { int i=0; g_thread_id=0; g_mutex=NULL; @@ -266,37 +265,35 @@ g_thread_running=0; g_thread_continue=0;
- dmxout_threaded_open(gensym("")); - - post("running thread %d for device %d", g_thread_id, g_device); + dmxout_open(gensym("")); }
-void dmxout_threaded_setup(void) +void dmxout_setup(void) {
#ifdef DMX4PD_POSTBANNER DMX4PD_POSTBANNER; #endif
- dmxout_threaded_class = class_new(gensym("dmxout_threaded"), (t_newmethod)dmxout_threaded_new, (t_method)dmxout_threaded_free, - sizeof(t_dmxout_threaded), + dmxout_class = class_new(gensym("dmxout"), (t_newmethod)dmxout_new, (t_method)dmxout_free, + sizeof(t_dmxout), 0, A_GIMME, A_NULL);
- class_addfloat(dmxout_threaded_class, dmxout_threaded_float); + class_addfloat(dmxout_class, dmxout_float);
- dmxout_threaded_class2 = class_new(gensym("dmxout_threaded"), (t_newmethod)dmxout_threaded_new, (t_method)dmxout_threaded_free, - sizeof(t_dmxout_threaded), + dmxout_class2 = class_new(gensym("dmxout"), (t_newmethod)dmxout_new, (t_method)dmxout_free, + sizeof(t_dmxout), 0, A_GIMME, A_NULL);
- class_addlist(dmxout_threaded_class2, dmxout_threaded_list); + class_addlist(dmxout_class2, dmxout_list);
- class_addmethod(dmxout_threaded_class2, (t_method)dmxout_threaded_port, gensym("port"), + class_addmethod(dmxout_class2, (t_method)dmxout_port, gensym("port"), A_FLOAT, A_DEFFLOAT, A_NULL);
- dmxout_threaded_init(); + dmxout_init(); }
Modified: trunk/externals/iem/dmx512/src/dmxout_b.c =================================================================== --- trunk/externals/iem/dmx512/src/dmxout_b.c 2008-07-02 11:34:38 UTC (rev 10133) +++ trunk/externals/iem/dmx512/src/dmxout_b.c 2008-07-02 11:40:32 UTC (rev 10134) @@ -1,7 +1,9 @@ /****************************************************** * - * dmxout - implementation file + * dmxout_b - implementation file * + * this is the "blocking" version + * * copyleft (c) IOhannes m zm\xF6lnig * * 0603:forum::f\xFCr::uml\xE4ute:2008 @@ -20,12 +22,12 @@ #include <string.h> #include <stdio.h>
-static t_class *dmxout_class; -static t_class *dmxout_class2; +static t_class *dmxout_b_class; +static t_class *dmxout_b_class2;
#define NUM_DMXVALUES 512
-typedef struct _dmxout +typedef struct _dmxout_b { t_object x_obj;
@@ -36,15 +38,15 @@ int x_portrange;
dmx_t x_values[NUM_DMXVALUES]; -} t_dmxout; +} t_dmxout_b;
-static void dmxout_clearbuf(t_dmxout*x) +static void dmxout_b_clearbuf(t_dmxout_b*x) { int i=0; for(i=0; i<NUM_DMXVALUES; i++) x->x_values[i]=0; }
-static void dmxout_close(t_dmxout*x) +static void dmxout_b_close(t_dmxout_b*x) { if(x->x_device>=0) { close(x->x_device); @@ -53,7 +55,7 @@ }
-static void dmxout_open(t_dmxout*x, t_symbol*s_devname) +static void dmxout_b_open(t_dmxout_b*x, t_symbol*s_devname) { int argc=2; const char *args[2] = {"--dmx", s_devname->s_name}; @@ -61,32 +63,30 @@ const char*devname=""; int fd;
- dmxout_close(x); + dmxout_b_close(x);
if(s_devname && s_devname->s_name) devname=s_devname->s_name;
- // strncpy(args[0], "--dmx", MAXPDSTRING); - // strncpy(args[1], devname, MAXPDSTRING); - verbose(2, "[dmxout]: trying to open '%s'", args[1]); + verbose(2, "[dmxout_b]: trying to open '%s'", args[1]); devname=DMXdev(&argc, argv); if(!devname){ pd_error(x, "couldn't find DMX device"); return; } - verbose(1, "[dmxout] opening %s", devname); + verbose(1, "[dmxout_b] opening %s", devname);
fd = open (devname, O_WRONLY | O_NONBLOCK);
if(fd!=-1) { x->x_device=fd; - dmxout_clearbuf(x); + dmxout_b_clearbuf(x); } else { pd_error(x, "failed to open DMX-device '%s'",devname); } }
-static void dmxout_doout(t_dmxout*x) { +static void dmxout_b_doout(t_dmxout_b*x) { int device = x->x_device; if(device<=0) { pd_error(x, "no DMX universe found"); @@ -98,14 +98,14 @@ }
-static void dmxout_doout1(t_dmxout*x, short port, unsigned char value) +static void dmxout_b_doout1(t_dmxout_b*x, short port, unsigned char value) { x->x_values[port]=value; - dmxout_doout(x); + dmxout_b_doout(x); }
-static void dmxout_float(t_dmxout*x, t_float f) +static void dmxout_b_float(t_dmxout_b*x, t_float f) { unsigned char val=(unsigned char)f; short port = (short)x->x_port; @@ -118,10 +118,10 @@ return; }
- dmxout_doout1(x, port, val); + dmxout_b_doout1(x, port, val); }
-static void dmxout_list(t_dmxout*x, t_symbol*s, int argc, t_atom*argv) +static void dmxout_b_list(t_dmxout_b*x, t_symbol*s, int argc, t_atom*argv) { int count=(argc<x->x_portrange)?argc:x->x_portrange; int i=0; @@ -146,10 +146,10 @@ pd_error(x, "%d valu%s out of bound [0..255]", errors, (1==errors)?"e":"es"); }
- dmxout_doout(x); + dmxout_b_doout(x); }
-static void dmxout_port(t_dmxout*x, t_float f_baseport, t_floatarg f_portrange) +static void dmxout_b_port(t_dmxout_b*x, t_float f_baseport, t_floatarg f_portrange) { short baseport =(short)f_baseport; short portrange=(short)f_portrange; @@ -175,23 +175,23 @@ x->x_portrange=portrange; }
-static void *dmxout_new(t_symbol*s, int argc, t_atom*argv) +static void *dmxout_b_new(t_symbol*s, int argc, t_atom*argv) { t_floatarg baseport=0.f, portrange=0.f; - t_dmxout *x = 0; + t_dmxout_b *x = 0;
switch(argc) { case 2: - x=(t_dmxout *)pd_new(dmxout_class2); + x=(t_dmxout_b *)pd_new(dmxout_b_class2); x->x_portinlet=inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("port")); baseport=atom_getfloat(argv); portrange=atom_getfloat(argv+1); - dmxout_port(x, baseport, portrange); + dmxout_b_port(x, baseport, portrange); break; case 1: baseport=atom_getfloat(argv); case 0: - x=(t_dmxout *)pd_new(dmxout_class); + x=(t_dmxout_b *)pd_new(dmxout_b_class); x->x_portinlet=floatinlet_new(&x->x_obj, &x->x_port); x->x_port = baseport; x->x_portrange = -1; @@ -201,40 +201,40 @@ } x->x_device=-1;
- dmxout_open(x, gensym("")); + dmxout_b_open(x, gensym("")); return (x); }
-static void *dmxout_free(t_dmxout*x) +static void *dmxout_b_free(t_dmxout_b*x) { - dmxout_close(x); + dmxout_b_close(x); }
-void dmxout_setup(void) +void dmxout_b_setup(void) { #ifdef DMX4PD_POSTBANNER DMX4PD_POSTBANNER; #endif
- dmxout_class = class_new(gensym("dmxout"), (t_newmethod)dmxout_new, (t_method)dmxout_free, - sizeof(t_dmxout), + dmxout_b_class = class_new(gensym("dmxout_b"), (t_newmethod)dmxout_b_new, (t_method)dmxout_b_free, + sizeof(t_dmxout_b), 0, A_GIMME, A_NULL);
- class_addfloat(dmxout_class, dmxout_float); - class_addmethod(dmxout_class, (t_method)dmxout_open, gensym("open"), A_SYMBOL, A_NULL); + class_addfloat(dmxout_b_class, dmxout_b_float); + class_addmethod(dmxout_b_class, (t_method)dmxout_b_open, gensym("open"), A_SYMBOL, A_NULL);
- dmxout_class2 = class_new(gensym("dmxout"), (t_newmethod)dmxout_new, (t_method)dmxout_free, - sizeof(t_dmxout), + dmxout_b_class2 = class_new(gensym("dmxout_b"), (t_newmethod)dmxout_b_new, (t_method)dmxout_b_free, + sizeof(t_dmxout_b), 0, A_GIMME, A_NULL);
- class_addlist(dmxout_class2, dmxout_list); + class_addlist(dmxout_b_class2, dmxout_b_list);
- class_addmethod(dmxout_class2, (t_method)dmxout_port, gensym("port"), + class_addmethod(dmxout_b_class2, (t_method)dmxout_b_port, gensym("port"), A_FLOAT, A_DEFFLOAT, A_NULL);
- class_addmethod(dmxout_class2, (t_method)dmxout_open, gensym("open"), A_SYMBOL, A_NULL); + class_addmethod(dmxout_b_class2, (t_method)dmxout_b_open, gensym("open"), A_SYMBOL, A_NULL); }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.