r4211 - developers/werner/ahrt/host/tmc
werner at sita.openmoko.org
werner at sita.openmoko.org
Sat Mar 15 04:23:02 CET 2008
Author: werner
Date: 2008-03-15 04:22:57 +0100 (Sat, 15 Mar 2008)
New Revision: 4211
Modified:
developers/werner/ahrt/host/tmc/python.c
developers/werner/ahrt/host/tmc/tmc.c
developers/werner/ahrt/host/tmc/tmc.h
Log:
- tmc.c (tmc_stop): close the asynchronous file handler
- tmc.c (struct tmc_dsc, tmc_start, tmc_stop, launch), tmc.h (tmc_start),
python.c (tmc_py_start): added optional second argument with a command to
send to restart asynchronous read
Modified: developers/werner/ahrt/host/tmc/python.c
===================================================================
--- developers/werner/ahrt/host/tmc/python.c 2008-03-14 15:54:29 UTC (rev 4210)
+++ developers/werner/ahrt/host/tmc/python.c 2008-03-15 03:22:57 UTC (rev 4211)
@@ -27,6 +27,9 @@
};
+/*
+ * @@@FIXME: how to _properly_ deallocate these strings ?
+ */
static char **make_argv(int skip, PyObject *args, int *argc)
{
@@ -154,18 +157,32 @@
}
-static PyObject *tmc_py_start(PyObject *self, PyObject *arg)
+static PyObject *tmc_py_start(PyObject *self, PyObject *args)
{
struct py_instr *s = (struct py_instr *) self;
+ char **argv;
+ int argc;
if (!s->instr) {
ERROR;
return NULL;
}
- if (tmc_start(s->instr, PyString_AsString(arg))) {
+ argv = make_argv(0, args, &argc);
+ if (!argv) {
ERROR;
return NULL;
}
+ if (argc < 1 || argc > 2) {
+ ERROR;
+ fprintf(stderr, "usage: filename [, command]\n");
+ free(argv);
+ return NULL;
+ }
+ if (tmc_start(s->instr, argv[0], argc == 2 ? argv[1] : NULL)) {
+ ERROR;
+ return NULL;
+ }
+ free(argv);
return Py_BuildValue("");
}
Modified: developers/werner/ahrt/host/tmc/tmc.c
===================================================================
--- developers/werner/ahrt/host/tmc/tmc.c 2008-03-14 15:54:29 UTC (rev 4210)
+++ developers/werner/ahrt/host/tmc/tmc.c 2008-03-15 03:22:57 UTC (rev 4211)
@@ -25,8 +25,9 @@
const struct proto_ops *ops; /* protocol operations */
void *proto_dsc; /* protocol descriptor */
void *io_dsc; /* I/O descriptor */
- int running;
- pthread_t thread;
+ int running; /* asynchronous streaming is running */
+ pthread_t thread; /* streaming thread */
+ char *repeat; /* command to send to repeat async. */
};
@@ -94,12 +95,21 @@
{
struct tmc_dsc *dsc = arg;
- dsc->ops->read(dsc->proto_dsc, io_push_async, dsc->io_dsc);
+ while (1) {
+ if (dsc->ops->read(dsc->proto_dsc, io_push_async, dsc->io_dsc)
+ < 0)
+ return NULL;
+ if (!dsc->repeat)
+ return NULL;
+ if (dsc->ops->write(dsc->proto_dsc, dsc->repeat,
+ strlen(dsc->repeat)))
+ return NULL;
+ }
return NULL;
}
-int tmc_start(struct tmc_dsc *dsc, const char *file)
+int tmc_start(struct tmc_dsc *dsc, const char *file, const char *repeat)
{
if (dsc->running) {
fprintf(stderr, "tmc_start: already running\n");
@@ -108,6 +118,15 @@
dsc->io_dsc = io_setup_async(file);
if (!dsc->io_dsc)
return -1;
+ if (!repeat)
+ dsc->repeat = NULL;
+ else {
+ dsc->repeat = strdup(repeat);
+ if (!dsc->repeat) {
+ io_end_async(dsc->io_dsc);
+ return -1;
+ }
+ }
dsc->running = 1;
pthread_create(&dsc->thread, NULL, launch, dsc);
return 0;
@@ -127,6 +146,8 @@
fprintf(stderr, "pthread_cancel: %s\n", strerror(err));
}
dsc->running = 0;
+ io_end_async(dsc->io_dsc);
+ free(dsc->repeat);
dsc->ops->dci(dsc->proto_dsc);
return 0;
}
Modified: developers/werner/ahrt/host/tmc/tmc.h
===================================================================
--- developers/werner/ahrt/host/tmc/tmc.h 2008-03-14 15:54:29 UTC (rev 4210)
+++ developers/werner/ahrt/host/tmc/tmc.h 2008-03-15 03:22:57 UTC (rev 4211)
@@ -26,7 +26,7 @@
int tmc_close(struct tmc_dsc *dsc);
int tmc_send(struct tmc_dsc *dsc, int argc, const char **argv);
int tmc_read(struct tmc_dsc *dsc, void *buf, ssize_t size);
-int tmc_start(struct tmc_dsc *dsc, const char *file);
+int tmc_start(struct tmc_dsc *dsc, const char *file, const char *repeat);
int tmc_stop(struct tmc_dsc *dsc);
/*
More information about the commitlog
mailing list