From ff98ee6f9e66ba850274463ca7f125c01a02d73e Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Fri, 10 Jan 2014 21:07:58 +0100 Subject: mplayer_server: change the type of callback_t we need to access the opcode of the callbacks from outside of the server (i.e. in the future clients). the type callback_t is now a pointer to function and can be accessed using callbacks_g[opcode] where the opcodes are enumerated in request.h a new file named pub_callbacks.h has been added. it will be used later by the client and must not be server dependant closes #1 --- callbacks.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'callbacks.c') diff --git a/callbacks.c b/callbacks.c index e41fe8b..c0b6dce 100644 --- a/callbacks.c +++ b/callbacks.c @@ -16,20 +16,20 @@ CB(mute); extern FILE *stream_g; -typedef struct { - int opcode; - int (*cb)(const byte *, int); -} callback_t; - -static callback_t callbacks_g[] = { - {0, callback_load_url}, - {1, callback_pause}, - {2, callback_quit}, - {3, callback_snd_up}, - {4, callback_snd_down}, - {5, callback_fullscreen}, - {6, callback_mute}, -}; +static callback_t callbacks_g[CALLBACK_COUNT] = {NULL}; + +int callbacks_init(void) +{ + callbacks_g[CALLBACK_LOAD_URL] = callback_load_url; + callbacks_g[CALLBACK_PAUSE] = callback_pause; + callbacks_g[CALLBACK_QUIT] = callback_quit; + callbacks_g[CALLBACK_SND_DOWN] = callback_snd_down; + callbacks_g[CALLBACK_SND_UP] = callback_snd_up; + callbacks_g[CALLBACK_FULLSCREEN] = callback_fullscreen; + callbacks_g[CALLBACK_MUTE] = callback_mute; + + return 0; +} /* * returns a new malloced() null terminated escaped string @@ -40,10 +40,8 @@ char *real_escape_string(const byte *buf, int size); void *get_assoc_cb(int opcode) { - for (size_t i = 0; i < sizeof(callbacks_g) / sizeof(callbacks_g[0]); ++i) { - if (callbacks_g[i].opcode == opcode) { - return callbacks_g[i].cb; - } + if (opcode >= 0 && opcode < CALLBACK_COUNT) { + return callbacks_g[opcode]; } return NULL; -- cgit v1.2.3