source: roaraudio/roard/commands.c @ 5910:cb47378a0e0b

roaraudio init
Last change on this file since 5910:cb47378a0e0b was 0:2a41d2f42394, checked in by phi, 16 years ago

Initial revision

File size: 2.0 KB
Line 
1//commands.c:
2
3#include "roard.h"
4
5struct roar_command g_commands[COMMAND_MAX_COMMANDS] = {
6  {ROAR_CMD_NOOP,         "NOOP",         req_on_noop},
7  {ROAR_CMD_IDENTIFY,     "IDENTIFY",     req_on_identify},
8  {ROAR_CMD_AUTH,         "AUTH",         req_on_auth},
9  {ROAR_CMD_NEW_STREAM,   "NEW_STREAM",   req_on_new_stream},
10  {ROAR_CMD_SET_META,     "SET_META",     req_on_set_meta},
11  {ROAR_CMD_EXEC_STREAM,  "EXEC_STREAM",  req_on_exec_stream},
12  {ROAR_CMD_QUIT,         "QUIT",         clients_delete},
13
14  {ROAR_CMD_SERVER_OINFO, "SERVER_OINFO", req_on_server_oinfo},
15  {ROAR_CMD_GET_STANDBY,  "GET_STANDBY",  req_on_get_standby},
16  {ROAR_CMD_SET_STANDBY,  "SET_STANDBY",  req_on_set_standby},
17  {ROAR_CMD_EXIT,         "EXIT",         req_on_exit},
18
19  {ROAR_CMD_LIST_CLIENTS, "LIST_CLIENTS", req_on_list_clients},
20  {ROAR_CMD_LIST_STREAMS, "LIST_STREAMS", req_on_list_streams},
21  {ROAR_CMD_GET_CLIENT,   "GET_CLIENT",   req_on_get_client},
22  {ROAR_CMD_GET_STREAM,   "GET_STREAM",   req_on_get_stream},
23  {ROAR_CMD_KICK,         "KICK",         req_on_kick},
24
25  {ROAR_CMD_ADD_DATA,     "ADD_DATA",     req_on_add_data},
26
27  {ROAR_CMD_EOL,          "END OF LIST",  NULL}
28 };
29
30int command_get_id_by_cmd (int command) {
31 int i;
32 int cmd;
33
34 for (i = 0; i < COMMAND_MAX_COMMANDS; i++) {
35  if ( (cmd = g_commands[i].cmd) == ROAR_CMD_EOL )
36   break;
37
38  if ( cmd == command )
39   return i;
40 }
41
42 return -1;
43}
44
45int command_exec (int client, struct roar_message * mes, char * data) {
46 int cmd = command_get_id_by_cmd(mes->cmd);
47 int (*func)(int client, struct roar_message * mes, char * data);
48
49 if ( cmd == -1 )
50  return -1;
51
52 if ( (func = g_commands[cmd].handler) == NULL )
53  return -1;
54
55 ROAR_DBG("command_exec(*): Execing command %i(%s) via %p", cmd, g_commands[cmd].name, func);
56
57 return func(client, mes, data);
58}
59
60int command_get_name (int command, char ** name) {
61 int cmd = command_get_id_by_cmd(command);
62
63 if ( cmd == -1 ) {
64  *name = NULL;
65  return -1;
66 }
67
68 *name = g_commands[cmd].name;
69
70 return 0;
71}
72
73
74//ll
Note: See TracBrowser for help on using the repository browser.