Update of /cvsroot/pure-data/externals/iem/pdoctave In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6615
Modified Files: Makefile pdoctave-help.pd pdoctave.c pdoctave_dataframe.c pdoctave_dataframe.h pdoctave_get.c pdoctave_send.c read_shared_mem.cc write_shared_mem.cc Log Message: changed a lot: pdoctave_dataframe: sleepUntil changed. Doesn't work yet, perhaps will not work that way. Looking for a suitable solution... pdoctave.c: starting octave when loading lib. removed the pdoctave object. Started general chaos...
Index: read_shared_mem.cc =================================================================== RCS file: /cvsroot/pure-data/externals/iem/pdoctave/read_shared_mem.cc,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** read_shared_mem.cc 22 Feb 2006 12:48:15 -0000 1.1 --- read_shared_mem.cc 25 Mar 2006 13:14:59 -0000 1.2 *************** *** 59,64 **** return octave_value(); } ! sleepUntilWriteBlocked (sdf,STD_USLEEP_TIME); ! sleepUntilReadBlocked (sdf, STD_USLEEP_TIME);
data = getSharedData (sdf); --- 59,70 ---- return octave_value(); } ! if((sleepUntilWriteBlocked (sdf))==0) { ! error("read_shared_mem: pd and octave scheduling error, restart pd!"); ! return octave_value(); ! } ! if((sleepUntilReadBlocked (sdf))==0) { ! error("read_shared_mem: pd and octave scheduling error, restart pd!"); ! return octave_value(); ! }
data = getSharedData (sdf);
Index: pdoctave_dataframe.h =================================================================== RCS file: /cvsroot/pure-data/externals/iem/pdoctave/pdoctave_dataframe.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pdoctave_dataframe.h 22 Feb 2006 12:48:15 -0000 1.1 --- pdoctave_dataframe.h 25 Mar 2006 13:14:59 -0000 1.2 *************** *** 16,20 ****
#define STD_USLEEP_TIME 100 ! #define MAX_SLEEP_TIME 200000
typedef struct _SharedDataFrame_ SharedDataFrame; --- 16,20 ----
#define STD_USLEEP_TIME 100 ! #define MAX_SLEEP_TIME 2
typedef struct _SharedDataFrame_ SharedDataFrame; *************** *** 54,61 **** --- 54,67 ---- void blockForReading (SharedDataFrame *sdf); void blockForWriting (SharedDataFrame *sdf); + int sleepUntilReadUnBlocked (SharedDataFrame *sdf); + int sleepUntilReadBlocked (SharedDataFrame *sdf); + int sleepUntilWriteUnBlocked (SharedDataFrame *sdf); + int sleepUntilWriteBlocked (SharedDataFrame *sdf); + /* void sleepUntilReadUnBlocked (SharedDataFrame *sdf, int usleep_time); void sleepUntilReadBlocked (SharedDataFrame *sdf, int usleep_time); void sleepUntilWriteUnBlocked (SharedDataFrame *sdf, int usleep_time); void sleepUntilWriteBlocked (SharedDataFrame *sdf, int usleep_time); + */
Index: pdoctave_get.c =================================================================== RCS file: /cvsroot/pure-data/externals/iem/pdoctave/pdoctave_get.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** pdoctave_get.c 25 Mar 2006 10:53:13 -0000 1.2 --- pdoctave_get.c 25 Mar 2006 13:14:59 -0000 1.3 *************** *** 146,150 **** sdf = pdoctget_obj->sdf;
! sleepUntilReadUnBlocked (sdf,STD_USLEEP_TIME); blockForReading (sdf);
--- 146,153 ---- sdf = pdoctget_obj->sdf;
! if((sleepUntilReadUnBlocked (sdf))==0) { ! error("pdoctave_get: pd and octave scheduling error, restart pd!"); ! return; ! } blockForReading (sdf);
*************** *** 152,156 **** blockForWriting (sdf); pDOctaveGetCommand (pdoctget_obj); ! sleepUntilWriteUnBlocked (sdf,STD_USLEEP_TIME);
// waiting for results --- 155,162 ---- blockForWriting (sdf); pDOctaveGetCommand (pdoctget_obj); ! if((sleepUntilWriteUnBlocked (sdf))==0) { ! error("pdoctave_get: pd and octave scheduling error, restart pd!"); ! return; ! }
// waiting for results
Index: pdoctave_dataframe.c =================================================================== RCS file: /cvsroot/pure-data/externals/iem/pdoctave/pdoctave_dataframe.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pdoctave_dataframe.c 22 Feb 2006 12:48:15 -0000 1.1 --- pdoctave_dataframe.c 25 Mar 2006 13:14:59 -0000 1.2 *************** *** 1,3 **** --- 1,4 ---- #include "pdoctave_dataframe.h" + static int scheduling_ok = 1;
SharedDataFrame *newSharedDataFrame () *************** *** 204,207 **** --- 205,240 ---- sdf->block_for_write = 1; } + + int sleepUntilReadUnBlocked (SharedDataFrame *sdf) + { + alarm(MAX_SLEEP_TIME); + while ((sdf->block_for_read!=0)&&scheduling_ok) + sched_yield(); + return scheduling_ok; + } + + int sleepUntilReadBlocked (SharedDataFrame *sdf) + { + alarm(MAX_SLEEP_TIME); + while ((sdf->block_for_read==0)&&scheduling_ok) + sched_yield(); + return scheduling_ok; + } + + int sleepUntilWriteUnBlocked (SharedDataFrame *sdf) + { + alarm(MAX_SLEEP_TIME); + while ((sdf->block_for_write!=0)&&scheduling_ok) + sched_yield(); + return scheduling_ok; + } + int sleepUntilWriteBlocked (SharedDataFrame *sdf) + { + alarm(MAX_SLEEP_TIME); + while ((sdf->block_for_write==0)&&scheduling_ok) + sched_yield(); + return scheduling_ok; + } + /* void sleepUntilReadUnBlocked (SharedDataFrame *sdf, int usleep_time) { *************** *** 247,249 **** } } ! --- 280,282 ---- } } ! */
Index: Makefile =================================================================== RCS file: /cvsroot/pure-data/externals/iem/pdoctave/Makefile,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Makefile 20 Mar 2006 09:32:59 -0000 1.1 --- Makefile 25 Mar 2006 13:14:59 -0000 1.2 *************** *** 63,77 **** cc $(CFLAGS) $(INCLUDE) -c -o $*.o $*.c
! read_shared_mem.oct: read_shared_mem.cc mkoctfile read_shared_mem.cc -c -o read_shared_mem.o mkoctfile read_shared_mem.o pdoctave_dataframe.o -o read_shared_mem.oct
! write_shared_mem.oct: write_shared_mem.cc mkoctfile write_shared_mem.cc -c -o write_shared_mem.o mkoctfile write_shared_mem.o pdoctave_dataframe.o -o write_shared_mem.oct
! pdoctave_send.o: pdoctave_send.c
! pdoctave_command.o: pdoctave_command.c
! pdoctave_get.o: pdoctave_get.c --- 63,79 ---- cc $(CFLAGS) $(INCLUDE) -c -o $*.o $*.c
! pdoctave_dataframe.o: pdoctave_dataframe.h pdoctave_dataframe.c ! ! read_shared_mem.oct: read_shared_mem.cc pdoctave_dataframe.o mkoctfile read_shared_mem.cc -c -o read_shared_mem.o mkoctfile read_shared_mem.o pdoctave_dataframe.o -o read_shared_mem.oct
! write_shared_mem.oct: write_shared_mem.cc pdoctave_dataframe.o mkoctfile write_shared_mem.cc -c -o write_shared_mem.o mkoctfile write_shared_mem.o pdoctave_dataframe.o -o write_shared_mem.oct
! pdoctave_send.o: pdoctave_dataframe.o pdoctave_send.c
! pdoctave_command.o: pdoctave_dataframe.o pdoctave_command.c
! pdoctave_get.o: pdoctave_dataframe.o pdoctave_get.c
Index: pdoctave_send.c =================================================================== RCS file: /cvsroot/pure-data/externals/iem/pdoctave/pdoctave_send.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** pdoctave_send.c 25 Mar 2006 10:53:13 -0000 1.2 --- pdoctave_send.c 25 Mar 2006 13:14:59 -0000 1.3 *************** *** 97,101 **** sdf = pdoctsnd_obj->sdf;
! sleepUntilWriteUnBlocked (sdf, STD_USLEEP_TIME); blockForWriting (sdf);
--- 97,105 ---- sdf = pdoctsnd_obj->sdf;
! //sleepUntilWriteUnBlocked (sdf, STD_USLEEP_TIME); ! if ((sleepUntilWriteUnBlocked (sdf))==0) { ! error("pdoctave_send: pd and octave scheduling error, restart pd"); ! return; ! } blockForWriting (sdf);
*************** *** 129,133 **** freeSharedData (sdf, &(pdoctsnd_obj->data)); pDOctaveSendBang (pdoctsnd_obj); ! sleepUntilReadUnBlocked (sdf,STD_USLEEP_TIME); unBlockForWriting (sdf); } --- 133,140 ---- freeSharedData (sdf, &(pdoctsnd_obj->data)); pDOctaveSendBang (pdoctsnd_obj); ! if ((sleepUntilReadUnBlocked (sdf))==0) { ! error("pdoctave_send: pd and octave scheduling error, restart pd"); ! return; ! } unBlockForWriting (sdf); }
Index: pdoctave-help.pd =================================================================== RCS file: /cvsroot/pure-data/externals/iem/pdoctave/pdoctave-help.pd,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** pdoctave-help.pd 25 Mar 2006 10:08:01 -0000 1.2 --- pdoctave-help.pd 25 Mar 2006 13:14:59 -0000 1.3 *************** *** 1,3 **** --- 1,6 ---- #N canvas 82 58 809 670 10; + #X text 32 22 pdoctave - a pd interface to octave; + #X text 32 38 2006 , Franz Zotter , IEM Graz; + #X text 30 87 See also the iemmatrix externals !; #X msg 401 209 list 1 2 3 4 5; #X msg 410 230 matrix 2 2 1 2 3 4; *************** *** 6,15 **** #X obj 430 290 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; - #X obj 68 162 pdoctave; #X obj 401 365 pdoctave_send a; #X obj 39 493 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; #X obj 62 518 pdoctave_command b=[1:5 ; 1 , 2 , 3 , 4 , 0]; - #X obj 398 511 pdoctave_get a; #X obj 398 488 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; --- 9,16 ---- *************** *** 34,41 **** #X obj 552 511 pdoctave_get b; #X text 372 457 get variables from octave to pd:; - #X text 32 22 pdoctave - a pd interface to octave; - #X text 32 38 2006 , Franz Zotter , IEM Graz; - #X text 33 141 open pipe to octave:; - #X text 30 87 See also the iemmatrix externals !; #X text 30 357 with ben bogarts entry external:; #X obj 35 598 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 --- 35,38 ---- *************** *** 45,66 **** #X msg 384 189 symbol hello; #X text 365 613 (help-patch provided by Georg Holzmann); ! #X connect 0 0 6 0; ! #X connect 1 0 6 0; ! #X connect 2 0 6 0; ! #X connect 3 0 6 0; ! #X connect 4 0 23 0; ! #X connect 7 0 8 0; ! #X connect 9 0 11 0; ! #X connect 10 0 9 0; ! #X connect 12 0 6 0; ! #X connect 13 0 12 0; ! #X connect 14 0 17 0; #X connect 15 0 18 0; ! #X connect 16 0 18 0; ! #X connect 18 0 8 0; ! #X connect 19 0 17 0; ! #X connect 23 0 6 0; ! #X connect 24 0 26 0; ! #X connect 26 0 25 0; ! #X connect 33 0 34 0; ! #X connect 36 0 6 0; --- 42,64 ---- #X msg 384 189 symbol hello; #X text 365 613 (help-patch provided by Georg Holzmann); ! #X obj 398 511 pdoctave_get a; ! #X connect 3 0 8 0; ! #X connect 4 0 8 0; ! #X connect 5 0 8 0; ! #X connect 6 0 8 0; ! #X connect 7 0 24 0; ! #X connect 9 0 10 0; ! #X connect 11 0 35 0; ! #X connect 13 0 8 0; ! #X connect 14 0 13 0; #X connect 15 0 18 0; ! #X connect 16 0 19 0; ! #X connect 17 0 19 0; ! #X connect 19 0 10 0; ! #X connect 20 0 18 0; ! #X connect 24 0 8 0; ! #X connect 25 0 27 0; ! #X connect 27 0 26 0; ! #X connect 30 0 31 0; ! #X connect 33 0 8 0; ! #X connect 35 0 12 0;
Index: write_shared_mem.cc =================================================================== RCS file: /cvsroot/pure-data/externals/iem/pdoctave/write_shared_mem.cc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** write_shared_mem.cc 24 Mar 2006 21:44:48 -0000 1.2 --- write_shared_mem.cc 25 Mar 2006 13:14:59 -0000 1.3 *************** *** 62,68 **** }
! sleepUntilWriteBlocked (sdf,STD_USLEEP_TIME); ! ! if (args(0).is_string()) { pdtype = SYMBOL; size = args(0).string_value().size(); --- 62,74 ---- }
! if((sleepUntilWriteBlocked (sdf))==0) { ! error("write_shared_mem: pd and octave scheduling error, restart pd!"); ! return octave_value(); ! } ! if (args(0).is_empty()) { ! pdtype = UNKNOWN; ! return octave_value(); ! } ! else if (args(0).is_string()) { pdtype = SYMBOL; size = args(0).string_value().size();
Index: pdoctave.c =================================================================== RCS file: /cvsroot/pure-data/externals/iem/pdoctave/pdoctave.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** pdoctave.c 24 Mar 2006 19:23:35 -0000 1.2 --- pdoctave.c 25 Mar 2006 13:14:59 -0000 1.3 *************** *** 73,77 **** }
! static void *newPDOctave (t_symbol *s, int argc, t_atom *argv) { --- 73,77 ---- }
! /* static void *newPDOctave (t_symbol *s, int argc, t_atom *argv) { *************** *** 86,90 **** }
! if ((octave_pid = fork()) == 0) { /* child process */ // execution of octave and pipe to octave stdin close(fd[1]); --- 86,91 ---- }
! if ((octave_pid = fork()) == 0) { ! //child process // execution of octave and pipe to octave stdin close(fd[1]); *************** *** 103,107 **** } else if (octave_pid == -1) { // Error handling ! } else { /* parent process */ close(fd[0]); // waiting for the child process having the octave pipe --- 104,109 ---- } else if (octave_pid == -1) { // Error handling ! } else { ! //parent process close(fd[0]); // waiting for the child process having the octave pipe *************** *** 112,119 **** return ((void *) pdoctave_obj); }
void pdoctave_setup (void) { ! pdoctave_class = class_new (gensym("pdoctave"), (t_newmethod) newPDOctave, --- 114,159 ---- return ((void *) pdoctave_obj); } + */ + static void openPDOctave () + { + if (!obj_instances++) { + + if (pipe(fd) == -1) { + post("Error creating pipe."); + } + + if ((octave_pid = fork()) == 0) { + //child process + // execution of octave and pipe to octave stdin + close(fd[1]); + + if (dup2(fd[0], STDIN_FILENO) == -1) { + post("error duplicating filedescriptor to STDIN"); + exit(1); + return; + } + + close(fd[0]); + execlp("octave", "octave", "-i", NULL); + // this is only reached, when the octave process is + // dying before the pdoctave object + post("shell command ``octave'' could not be executed"); + } else if (octave_pid == -1) { + // Error handling + } else { + //parent process + close(fd[0]); + // waiting for the child process having the octave pipe + // and process properly set up + sleep(1); + } + } + } +
void pdoctave_setup (void) { ! /* ! pdoctave_class = class_new (gensym("pdoctave"), (t_newmethod) newPDOctave, *************** *** 122,125 **** --- 162,167 ---- CLASS_NOINLET, 0); class_sethelpsymbol(pdoctave_class, gensym("pdoctave-help.pd")); + */ + openPDOctave(); post("pdoctave successfully loaded!"); pdoctave_send_setup ();