aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranz Zotter <fzotter@users.sourceforge.net>2006-03-25 13:14:59 +0000
committerFranz Zotter <fzotter@users.sourceforge.net>2006-03-25 13:14:59 +0000
commit6b079b5df20a90500294e2f1a58912b32074cd82 (patch)
tree23bdb7515ac1a6ae6343bf1a85904057ea396388
parent47979e4af5ff135984a22d5ecb6ef7acb69f6f0f (diff)
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... svn path=/trunk/externals/iem/pdoctave/; revision=4766
-rw-r--r--Makefile12
-rw-r--r--pdoctave-help.pd48
-rw-r--r--pdoctave.c50
-rw-r--r--pdoctave_dataframe.c35
-rw-r--r--pdoctave_dataframe.h8
-rw-r--r--pdoctave_get.c10
-rw-r--r--pdoctave_send.c11
-rw-r--r--read_shared_mem.cc10
-rw-r--r--write_shared_mem.cc12
9 files changed, 151 insertions, 45 deletions
diff --git a/Makefile b/Makefile
index c3aaacf..d337179 100644
--- a/Makefile
+++ b/Makefile
@@ -62,16 +62,18 @@ $(OBJ) : %.o : %.c
#touch $*.c
cc $(CFLAGS) $(INCLUDE) -c -o $*.o $*.c
-read_shared_mem.oct: read_shared_mem.cc
+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
+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_send.c
+pdoctave_send.o: pdoctave_dataframe.o pdoctave_send.c
-pdoctave_command.o: pdoctave_command.c
+pdoctave_command.o: pdoctave_dataframe.o pdoctave_command.c
-pdoctave_get.o: pdoctave_get.c
+pdoctave_get.o: pdoctave_dataframe.o pdoctave_get.c
diff --git a/pdoctave-help.pd b/pdoctave-help.pd
index 1bd25dd..e316b3f 100644
--- a/pdoctave-help.pd
+++ b/pdoctave-help.pd
@@ -1,16 +1,17 @@
#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;
#X msg 437 331 2;
#X floatatom 473 343 5 0 0 0 - - -;
#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;
#X obj 398 536 print;
@@ -33,10 +34,6 @@ objects !) :;
#X obj 552 536 print;
#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
-1;
@@ -44,23 +41,24 @@ objects !) :;
#X text 32 575 use gnuplot to plot a matrix:;
#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 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 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;
+#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;
diff --git a/pdoctave.c b/pdoctave.c
index d1f5189..171d1fb 100644
--- a/pdoctave.c
+++ b/pdoctave.c
@@ -72,7 +72,7 @@ static void deletePDOctave (PDOctave *pdoctave_obj)
}
}
-
+/*
static void *newPDOctave (t_symbol *s, int argc, t_atom *argv)
{
PDOctave * pdoctave_obj;
@@ -85,7 +85,8 @@ static void *newPDOctave (t_symbol *s, int argc, t_atom *argv)
post("Error creating pipe.");
}
- if ((octave_pid = fork()) == 0) { /* child process */
+ if ((octave_pid = fork()) == 0) {
+ //child process
// execution of octave and pipe to octave stdin
close(fd[1]);
@@ -102,7 +103,8 @@ static void *newPDOctave (t_symbol *s, int argc, t_atom *argv)
post("shell command ``octave'' could not be executed");
} else if (octave_pid == -1) {
// Error handling
- } else { /* parent process */
+ } else {
+ //parent process
close(fd[0]);
// waiting for the child process having the octave pipe
// and process properly set up
@@ -111,16 +113,56 @@ static void *newPDOctave (t_symbol *s, int argc, t_atom *argv)
}
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
+/*
+ pdoctave_class = class_new
(gensym("pdoctave"),
(t_newmethod) newPDOctave,
(t_method) deletePDOctave,
sizeof (PDOctave),
CLASS_NOINLET, 0);
class_sethelpsymbol(pdoctave_class, gensym("pdoctave-help.pd"));
+ */
+ openPDOctave();
post("pdoctave successfully loaded!");
pdoctave_send_setup ();
pdoctave_command_setup ();
diff --git a/pdoctave_dataframe.c b/pdoctave_dataframe.c
index 7193c62..1ff6f09 100644
--- a/pdoctave_dataframe.c
+++ b/pdoctave_dataframe.c
@@ -1,4 +1,5 @@
#include "pdoctave_dataframe.h"
+static int scheduling_ok = 1;
SharedDataFrame *newSharedDataFrame ()
{
@@ -203,6 +204,38 @@ void blockForWriting (SharedDataFrame *sdf)
if (sdf)
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)
{
int timer = 0;
@@ -246,4 +279,4 @@ void sleepUntilWriteBlocked (SharedDataFrame *sdf, int usleep_time)
}
}
-
+ */
diff --git a/pdoctave_dataframe.h b/pdoctave_dataframe.h
index 53a21cc..c20ee45 100644
--- a/pdoctave_dataframe.h
+++ b/pdoctave_dataframe.h
@@ -15,7 +15,7 @@ extern "C" {
#include "pdoctave_datatypes.h"
#define STD_USLEEP_TIME 100
-#define MAX_SLEEP_TIME 200000
+#define MAX_SLEEP_TIME 2
typedef struct _SharedDataFrame_ SharedDataFrame;
@@ -53,10 +53,16 @@ void unBlockForReading (SharedDataFrame *sdf);
void unBlockForWriting (SharedDataFrame *sdf);
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);
+*/
#ifdef __cplusplus
diff --git a/pdoctave_get.c b/pdoctave_get.c
index d0e2394..8177c8c 100644
--- a/pdoctave_get.c
+++ b/pdoctave_get.c
@@ -145,13 +145,19 @@ static void pDOctaveGetBang (PDOctaveGet *pdoctget_obj)
sdf = pdoctget_obj->sdf;
- sleepUntilReadUnBlocked (sdf,STD_USLEEP_TIME);
+ if((sleepUntilReadUnBlocked (sdf))==0) {
+ error("pdoctave_get: pd and octave scheduling error, restart pd!");
+ return;
+ }
blockForReading (sdf);
// sending read command
blockForWriting (sdf);
pDOctaveGetCommand (pdoctget_obj);
- sleepUntilWriteUnBlocked (sdf,STD_USLEEP_TIME);
+ if((sleepUntilWriteUnBlocked (sdf))==0) {
+ error("pdoctave_get: pd and octave scheduling error, restart pd!");
+ return;
+ }
// waiting for results
pdoctget_obj->data = getSharedData (sdf);
diff --git a/pdoctave_send.c b/pdoctave_send.c
index 8492120..0ad0f2f 100644
--- a/pdoctave_send.c
+++ b/pdoctave_send.c
@@ -96,7 +96,11 @@ static void pDOctaveSend (PDOctaveSend *pdoctsnd_obj,
sdf = pdoctsnd_obj->sdf;
- sleepUntilWriteUnBlocked (sdf, STD_USLEEP_TIME);
+ //sleepUntilWriteUnBlocked (sdf, STD_USLEEP_TIME);
+ if ((sleepUntilWriteUnBlocked (sdf))==0) {
+ error("pdoctave_send: pd and octave scheduling error, restart pd");
+ return;
+ }
blockForWriting (sdf);
if (pdoctsnd_obj->data)
@@ -128,7 +132,10 @@ static void pDOctaveSend (PDOctaveSend *pdoctsnd_obj,
blockForReading (sdf);
freeSharedData (sdf, &(pdoctsnd_obj->data));
pDOctaveSendBang (pdoctsnd_obj);
- sleepUntilReadUnBlocked (sdf,STD_USLEEP_TIME);
+ if ((sleepUntilReadUnBlocked (sdf))==0) {
+ error("pdoctave_send: pd and octave scheduling error, restart pd");
+ return;
+ }
unBlockForWriting (sdf);
}
diff --git a/read_shared_mem.cc b/read_shared_mem.cc
index 446ee0f..1fec260 100644
--- a/read_shared_mem.cc
+++ b/read_shared_mem.cc
@@ -58,8 +58,14 @@ DEFUN_DLD (read_shared_mem, args, , "reading and returning a pd-value in octave"
error("failed to attach memory!\n");
return octave_value();
}
- sleepUntilWriteBlocked (sdf,STD_USLEEP_TIME);
- sleepUntilReadBlocked (sdf, STD_USLEEP_TIME);
+ 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);
if (!data) {
diff --git a/write_shared_mem.cc b/write_shared_mem.cc
index ac9f98f..fc9107e 100644
--- a/write_shared_mem.cc
+++ b/write_shared_mem.cc
@@ -61,9 +61,15 @@ DEFUN_DLD (write_shared_mem, args, , "returning an octave value to pd-value")
return octave_value();
}
- sleepUntilWriteBlocked (sdf,STD_USLEEP_TIME);
-
- if (args(0).is_string()) {
+ 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();
if (data = newSharedData (sdf, size, sizeof(char),pdtype)) {