aboutsummaryrefslogtreecommitdiff
path: root/write_shared_mem.cc
diff options
context:
space:
mode:
authorFranz Zotter <fzotter@users.sourceforge.net>2006-02-22 12:48:15 +0000
committerFranz Zotter <fzotter@users.sourceforge.net>2006-02-22 12:48:15 +0000
commit97d9a1382b32a7055f407265d24f8dc900e04741 (patch)
treeb2804dbff72d634e2e0a38507e7c8c6c8768033a /write_shared_mem.cc
These is the beginning of a try to connect the pd to octave. Especially when using the iemmatrix features in pd, this feature becomes sensible. On the whole it shall enable the user to use the command line parser of octave.svn2git-root
The take-over strategy is bad at this starting point. No threading, no practical data transmission. Perhaps the common work on it can help. (Franz) svn path=/trunk/externals/iem/pdoctave/; revision=4611
Diffstat (limited to 'write_shared_mem.cc')
-rw-r--r--write_shared_mem.cc105
1 files changed, 105 insertions, 0 deletions
diff --git a/write_shared_mem.cc b/write_shared_mem.cc
new file mode 100644
index 0000000..2149e91
--- /dev/null
+++ b/write_shared_mem.cc
@@ -0,0 +1,105 @@
+#include <octave/oct.h>
+
+#include <unistd.h>
+#include <string.h>
+#include "pdoctave_dataframe.h"
+
+DatTyp classifyOctPDType (octave_value res)
+{
+ DatTyp pdtyp;
+ if (res.is_real_scalar())
+ pdtyp = FLOAT;
+ else if (res.is_real_matrix())
+ pdtyp = MATRIX;
+ else if (res.is_string())
+ pdtyp = SYMBOL;
+ else
+ pdtyp = UNKNOWN;
+}
+
+void writeOctMatrixIntoFloat (Matrix mtx, float *f)
+{
+ int n = mtx.rows();
+ int m = mtx.columns();
+ int i;
+ int j;
+
+ *f++ = n;
+ *f++ = m;
+
+ for (j = 0; j < m; j++)
+ for (i=0; i < n; i++)
+ *f++ = (float) mtx(i,j);
+}
+
+void writeOctScalarIntoFloat (double d, float *f)
+{
+ *f = (float) d;
+}
+void writeOctStringIntoString (char *s, char *c)
+{
+ strcpy (s,c);
+}
+
+
+DEFUN_DLD (write_shared_mem, args, , "returning an octave value to pd-value")
+{
+ SharedDataFrame *sdf;
+ int size;
+ void *data;
+ DatTyp pdtype;
+ int shmem_id = args(1).int_value();
+
+ if (shmem_id == -1) {
+ error("failed to get valid id\n");
+ return octave_value();
+ }
+ sdf = getSharedDataFrame (shmem_id);
+
+ if (!sdf) {
+ error("failed to attach memory!\n");
+ return octave_value();
+ }
+
+ sleepUntilWriteBlocked (sdf,STD_USLEEP_TIME);
+
+ if (args(0).is_string()) {
+ pdtype = SYMBOL;
+ }
+ else if (args(0).is_real_matrix()) {
+ pdtype = MATRIX;
+ size = args(0).columns() * args(0).rows()+2;
+ if (data = newSharedData (sdf, size, sizeof(float),pdtype)) {
+ writeOctMatrixIntoFloat (args(0).matrix_value(), (float *) data);
+ }
+ else {
+ error("failed to get new data memory!");
+ unBlockForWriting (sdf);
+ freeSharedDataFrame (&sdf);
+ return octave_value();
+ }
+ }
+ else if (args(0).is_real_scalar()) {
+ pdtype = FLOAT;
+ if (data = newSharedData (sdf, 1, sizeof(float), pdtype)) {
+ writeOctScalarIntoFloat(args(0).scalar_value(), (float *) data);
+ }
+ else {
+ error("failed to get new data memory!");
+ unBlockForWriting (sdf);
+ freeSharedDataFrame (&sdf);
+ return octave_value();
+ }
+ }
+ else
+ std::cout << " no mehtod for argument conversion" << std::endl;
+
+ unBlockForWriting (sdf);
+
+ freeSharedData (sdf, &data);
+ freeSharedDataFrame (&sdf);
+
+ return octave_value();
+}
+
+