\documentclass[a4paper,10pt]{report} \usepackage[francais]{babel} \usepackage[utf8]{inputenc} \usepackage{xspace} \usepackage{makeidx} \usepackage{listings} \makeindex \lstset{basicstyle=\ttfamily\small} \lstset{aboveskip=1em,belowskip=1em} \title {Myrycast source code} \author{tTh} \begin{document} \maketitle \section{worker.c} \index{worker.c} \begin{lstlisting}[language=C] /* * worker.c - 16 juillet 2014 - mixart myrys */ #include #include #include #include #include "audio.h" #include "worker.h" #include "sendwave.h" /* ------------------------------------------------------- casting --- */ static FILE *worker_log; static int fd_rxcmd; /* from pipe from main loop */ /* ------------------------------------------------------- casting --- */ int worker_init(int mode) { #if DEBUG_LEVEL fprintf(stderr, "%s:%s > %d %d\n", __FILE__, __func__, mode, WORKER_H); #endif if (NULL != worker_log) { fprintf(stderr, "\nin %s:%s worker_log is not NULL\n", __FILE__, __func__); abort(); } if ( NULL==(worker_log=fopen("worker.log", "w")) ) { perror("open worker logfile"); abort(); } setlinebuf(worker_log); fprintf(worker_log, "%s pid=%d, fdrx=%d\n", __func__, getpid(), fd_rxcmd); return -1000; } /* ------------------------------------------------------- casting --- */ /* this is the main thread function for the worker */ void * worker_main_loop(void *vptr) { int loop, foo; worker_cmd cmd; char *cptr; #if DEBUG_LEVEL fprintf(stderr, "%s:%s > %p\n", __FILE__, __func__, vptr); #endif for (loop=0; loop<1000; loop++) { fprintf(stderr, "**** boucle %d du worker\n", loop); /* trying to read a command from outside world */ foo = read(fd_rxcmd, &cmd, sizeof(cmd)); fprintf(stderr, "worker received %d bytes\n", foo); if (-1 == foo) { perror("read cmd"); abort(); } #if DEBUG_LEVEL fprintf(stderr, "received command #%d\n", cmd.command); #endif fprintf(worker_log, "%04x %04x : %d\n", cmd.command, cmd.code, cmd.value); if (cmd.value & 1) cptr = "plopcast2.wav"; else cptr = "dtmf.wav"; fprintf(worker_log, " %s\n", cptr); foo = blast_a_wav_file(cptr, 1, 0); if (foo) { fprintf(stderr, "***** blast a wave -> %d\n", foo); sleep(15); } } return NULL; } /* ------------------------------------------------------- casting --- */ /* some private vars */ static pthread_t thread; int worker_demarrage(int fdrx) { int foo; #if DEBUG_LEVEL fprintf(stderr, "%s:%s > %d\n", __FILE__, __func__, fdrx); #endif fd_rxcmd = fdrx; foo = worker_init(42); #if DEBUG_LEVEL fprintf(stderr, "retour init worker = %d\n", foo); #endif foo = pthread_create(&thread, NULL, worker_main_loop, NULL); fprintf(worker_log, "creating worker thread -> %d\n", foo); return -1001; } /* ------------------------------------------------------- casting --- */ end{lstlisting} \printindex \end{document}