source: roaraudio/roard/commands.c @ 100:fea0dd940215

Last change on this file since 100:fea0dd940215 was 100:fea0dd940215, checked in by phi, 16 years ago

added basic declarations for reading meta data

File size: 2.2 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
11  {ROAR_CMD_SET_META,     "SET_META",     req_on_set_meta},
12  {ROAR_CMD_GET_META,     "GET_META",     req_on_get_meta},
13
14  {ROAR_CMD_EXEC_STREAM,  "EXEC_STREAM",  req_on_exec_stream},
15  {ROAR_CMD_QUIT,         "QUIT",         clients_delete},
16
17  {ROAR_CMD_CON_STREAM,   "CON_STREAM",   req_on_con_stream},
18
19  {ROAR_CMD_SERVER_OINFO, "SERVER_OINFO", req_on_server_oinfo},
20  {ROAR_CMD_GET_STANDBY,  "GET_STANDBY",  req_on_get_standby},
21  {ROAR_CMD_SET_STANDBY,  "SET_STANDBY",  req_on_set_standby},
22  {ROAR_CMD_EXIT,         "EXIT",         req_on_exit},
23
24  {ROAR_CMD_LIST_CLIENTS, "LIST_CLIENTS", req_on_list_clients},
25  {ROAR_CMD_LIST_STREAMS, "LIST_STREAMS", req_on_list_streams},
26  {ROAR_CMD_GET_CLIENT,   "GET_CLIENT",   req_on_get_client},
27  {ROAR_CMD_GET_STREAM,   "GET_STREAM",   req_on_get_stream},
28  {ROAR_CMD_KICK,         "KICK",         req_on_kick},
29  {ROAR_CMD_SET_VOL,      "SET_VOL",      req_on_set_vol},
30  {ROAR_CMD_GET_VOL,      "GET_VOL",      req_on_get_vol},
31
32  {ROAR_CMD_ADD_DATA,     "ADD_DATA",     req_on_add_data},
33
34  {ROAR_CMD_EOL,          "END OF LIST",  NULL}
35 };
36
37int command_get_id_by_cmd (int command) {
38 int i;
39 int cmd;
40
41 for (i = 0; i < COMMAND_MAX_COMMANDS; i++) {
42  if ( (cmd = g_commands[i].cmd) == ROAR_CMD_EOL )
43   break;
44
45  if ( cmd == command )
46   return i;
47 }
48
49 return -1;
50}
51
52int command_exec (int client, struct roar_message * mes, char * data) {
53 int cmd = command_get_id_by_cmd(mes->cmd);
54 int (*func)(int client, struct roar_message * mes, char * data);
55
56 if ( cmd == -1 )
57  return -1;
58
59 if ( (func = g_commands[cmd].handler) == NULL )
60  return -1;
61
62 ROAR_DBG("command_exec(*): Execing command %i(%s) via %p", cmd, g_commands[cmd].name, func);
63
64 return func(client, mes, data);
65}
66
67int command_get_name (int command, char ** name) {
68 int cmd = command_get_id_by_cmd(command);
69
70 if ( cmd == -1 ) {
71  *name = NULL;
72  return -1;
73 }
74
75 *name = g_commands[cmd].name;
76
77 return 0;
78}
79
80
81//ll
Note: See TracBrowser for help on using the repository browser.