fifo: no CamelCase

Renamed types, functions and variables.
This commit is contained in:
Max Kellermann 2009-02-25 19:53:24 +01:00
parent ee7cf9c9b8
commit 74af4e4c3d
2 changed files with 52 additions and 45 deletions

View File

@ -34,19 +34,19 @@
#define FIFO_BUFFER_SIZE 65536 /* pipe capacity on Linux >= 2.6.11 */ #define FIFO_BUFFER_SIZE 65536 /* pipe capacity on Linux >= 2.6.11 */
typedef struct _FifoData { struct fifo_data {
char *path; char *path;
int input; int input;
int output; int output;
int created; int created;
Timer *timer; Timer *timer;
} FifoData; };
static FifoData *newFifoData(void) static struct fifo_data *fifo_data_new(void)
{ {
FifoData *ret; struct fifo_data *ret;
ret = g_new(FifoData, 1); ret = g_new(struct fifo_data, 1);
ret->path = NULL; ret->path = NULL;
ret->input = -1; ret->input = -1;
@ -56,13 +56,13 @@ static FifoData *newFifoData(void)
return ret; return ret;
} }
static void freeFifoData(FifoData *fd) static void fifo_data_free(struct fifo_data *fd)
{ {
g_free(fd->path); g_free(fd->path);
g_free(fd); g_free(fd);
} }
static void removeFifo(FifoData *fd) static void fifo_delete(struct fifo_data *fd)
{ {
g_debug("Removing FIFO \"%s\"", fd->path); g_debug("Removing FIFO \"%s\"", fd->path);
@ -75,7 +75,8 @@ static void removeFifo(FifoData *fd)
fd->created = 0; fd->created = 0;
} }
static void closeFifo(FifoData *fd) static void
fifo_close(struct fifo_data *fd)
{ {
struct stat st; struct stat st;
@ -90,10 +91,11 @@ static void closeFifo(FifoData *fd)
} }
if (fd->created && (stat(fd->path, &st) == 0)) if (fd->created && (stat(fd->path, &st) == 0))
removeFifo(fd); fifo_delete(fd);
} }
static int makeFifo(FifoData *fd) static int
fifo_make(struct fifo_data *fd)
{ {
if (mkfifo(fd->path, 0666) < 0) { if (mkfifo(fd->path, 0666) < 0) {
g_warning("Couldn't create FIFO \"%s\": %s", g_warning("Couldn't create FIFO \"%s\": %s",
@ -106,14 +108,15 @@ static int makeFifo(FifoData *fd)
return 0; return 0;
} }
static int checkFifo(FifoData *fd) static int
fifo_check(struct fifo_data *fd)
{ {
struct stat st; struct stat st;
if (stat(fd->path, &st) < 0) { if (stat(fd->path, &st) < 0) {
if (errno == ENOENT) { if (errno == ENOENT) {
/* Path doesn't exist */ /* Path doesn't exist */
return makeFifo(fd); return fifo_make(fd);
} }
g_warning("Failed to stat FIFO \"%s\": %s", g_warning("Failed to stat FIFO \"%s\": %s",
@ -130,16 +133,17 @@ static int checkFifo(FifoData *fd)
return 0; return 0;
} }
static bool openFifo(FifoData *fd) static bool
fifo_open(struct fifo_data *fd)
{ {
if (checkFifo(fd) < 0) if (fifo_check(fd) < 0)
return false; return false;
fd->input = open(fd->path, O_RDONLY|O_NONBLOCK); fd->input = open(fd->path, O_RDONLY|O_NONBLOCK);
if (fd->input < 0) { if (fd->input < 0) {
g_warning("Could not open FIFO \"%s\" for reading: %s", g_warning("Could not open FIFO \"%s\" for reading: %s",
fd->path, strerror(errno)); fd->path, strerror(errno));
closeFifo(fd); fifo_close(fd);
return false; return false;
} }
@ -147,7 +151,7 @@ static bool openFifo(FifoData *fd)
if (fd->output < 0) { if (fd->output < 0) {
g_warning("Could not open FIFO \"%s\" for writing: %s", g_warning("Could not open FIFO \"%s\" for writing: %s",
fd->path, strerror(errno)); fd->path, strerror(errno));
closeFifo(fd); fifo_close(fd);
return false; return false;
} }
@ -155,10 +159,10 @@ static bool openFifo(FifoData *fd)
} }
static void * static void *
fifo_initDriver(G_GNUC_UNUSED const struct audio_format *audio_format, fifo_output_init(G_GNUC_UNUSED const struct audio_format *audio_format,
const struct config_param *param) const struct config_param *param)
{ {
FifoData *fd; struct fifo_data *fd;
char *value, *path; char *value, *path;
value = config_dup_block_string(param, "path", NULL); value = config_dup_block_string(param, "path", NULL);
@ -173,45 +177,48 @@ fifo_initDriver(G_GNUC_UNUSED const struct audio_format *audio_format,
"at line %i", param->line); "at line %i", param->line);
} }
fd = newFifoData(); fd = fifo_data_new();
fd->path = path; fd->path = path;
if (!openFifo(fd)) { if (!fifo_open(fd)) {
freeFifoData(fd); fifo_data_free(fd);
return NULL; return NULL;
} }
return fd; return fd;
} }
static void fifo_finishDriver(void *data) static void
fifo_output_finish(void *data)
{ {
FifoData *fd = (FifoData *)data; struct fifo_data *fd = (struct fifo_data *)data;
closeFifo(fd); fifo_close(fd);
freeFifoData(fd); fifo_data_free(fd);
} }
static bool fifo_openDevice(void *data, static bool
struct audio_format *audio_format) fifo_output_open(void *data, struct audio_format *audio_format)
{ {
FifoData *fd = (FifoData *)data; struct fifo_data *fd = (struct fifo_data *)data;
fd->timer = timer_new(audio_format); fd->timer = timer_new(audio_format);
return true; return true;
} }
static void fifo_closeDevice(void *data) static void
fifo_output_close(void *data)
{ {
FifoData *fd = (FifoData *)data; struct fifo_data *fd = (struct fifo_data *)data;
timer_free(fd->timer); timer_free(fd->timer);
} }
static void fifo_dropBufferedAudio(void *data) static void
fifo_output_cancel(void *data)
{ {
FifoData *fd = (FifoData *)data; struct fifo_data *fd = (struct fifo_data *)data;
char buf[FIFO_BUFFER_SIZE]; char buf[FIFO_BUFFER_SIZE];
int bytes = 1; int bytes = 1;
@ -227,9 +234,9 @@ static void fifo_dropBufferedAudio(void *data)
} }
static size_t static size_t
fifo_playAudio(void *data, const void *chunk, size_t size) fifo_output_play(void *data, const void *chunk, size_t size)
{ {
FifoData *fd = (FifoData *)data; struct fifo_data *fd = (struct fifo_data *)data;
ssize_t bytes; ssize_t bytes;
if (!fd->timer->started) if (!fd->timer->started)
@ -248,7 +255,7 @@ fifo_playAudio(void *data, const void *chunk, size_t size)
switch (errno) { switch (errno) {
case EAGAIN: case EAGAIN:
/* The pipe is full, so empty it */ /* The pipe is full, so empty it */
fifo_dropBufferedAudio(fd); fifo_output_cancel(fd);
continue; continue;
case EINTR: case EINTR:
continue; continue;
@ -261,12 +268,12 @@ fifo_playAudio(void *data, const void *chunk, size_t size)
} }
} }
const struct audio_output_plugin fifoPlugin = { const struct audio_output_plugin fifo_output_plugin = {
.name = "fifo", .name = "fifo",
.init = fifo_initDriver, .init = fifo_output_init,
.finish = fifo_finishDriver, .finish = fifo_output_finish,
.open = fifo_openDevice, .open = fifo_output_open,
.play = fifo_playAudio, .close = fifo_output_close,
.cancel = fifo_dropBufferedAudio, .play = fifo_output_play,
.close = fifo_closeDevice, .cancel = fifo_output_cancel,
}; };

View File

@ -22,7 +22,7 @@
extern const struct audio_output_plugin shoutPlugin; extern const struct audio_output_plugin shoutPlugin;
extern const struct audio_output_plugin null_output_plugin; extern const struct audio_output_plugin null_output_plugin;
extern const struct audio_output_plugin fifoPlugin; extern const struct audio_output_plugin fifo_output_plugin;
extern const struct audio_output_plugin alsaPlugin; extern const struct audio_output_plugin alsaPlugin;
extern const struct audio_output_plugin ao_output_plugin; extern const struct audio_output_plugin ao_output_plugin;
extern const struct audio_output_plugin ossPlugin; extern const struct audio_output_plugin ossPlugin;
@ -37,7 +37,7 @@ const struct audio_output_plugin *audio_output_plugins[] = {
#endif #endif
&null_output_plugin, &null_output_plugin,
#ifdef HAVE_FIFO #ifdef HAVE_FIFO
&fifoPlugin, &fifo_output_plugin,
#endif #endif
#ifdef HAVE_ALSA #ifdef HAVE_ALSA
&alsaPlugin, &alsaPlugin,