source: roaraudio/roard/commands.c @ 3358:7f9d211148e0

Last change on this file since 3358:7f9d211148e0 was 1502:09c7a94d4e49, checked in by phi, 15 years ago

exclude names on ROAR_MINIMAL, too

File size: 3.9 KB
Line 
1//commands.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is part of roard a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "roard.h"
26
27#if !defined(ROAR_TARGET_MICROCONTROLLER) && !defined(ROAR_MINIMAL)
28#define _NAME(x) (x)
29#else
30#define _NAME(x) ((char*)NULL)
31#endif
32
33struct roar_command g_commands[COMMAND_MAX_COMMANDS] = {
34  {ROAR_CMD_NOOP,         _NAME("NOOP"),         req_on_noop},
35  {ROAR_CMD_IDENTIFY,     _NAME("IDENTIFY"),     req_on_identify},
36  {ROAR_CMD_AUTH,         _NAME("AUTH"),         req_on_auth},
37  {ROAR_CMD_WHOAMI,       _NAME("WHOAMI"),       req_on_whoami},
38
39
40  {ROAR_CMD_NEW_STREAM,   _NAME("NEW_STREAM"),   req_on_new_stream},
41
42#ifdef ROAR_SUPPORT_META
43  {ROAR_CMD_SET_META,     _NAME("SET_META"),     req_on_set_meta},
44  {ROAR_CMD_GET_META,     _NAME("GET_META"),     req_on_get_meta},
45  {ROAR_CMD_LIST_META,    _NAME("LIST_META"),    req_on_list_meta},
46#endif
47
48  {ROAR_CMD_EXEC_STREAM,  _NAME("EXEC_STREAM"),  req_on_exec_stream},
49  {ROAR_CMD_QUIT,         _NAME("QUIT"),         (int(*)(int client, struct roar_message * mes, char * data))clients_delete},
50
51  {ROAR_CMD_CON_STREAM,   _NAME("CON_STREAM"),   req_on_con_stream},
52  {ROAR_CMD_PASSFH,       _NAME("PASSFH"),       req_on_passfh},
53
54  {ROAR_CMD_SERVER_OINFO, _NAME("SERVER_OINFO"), req_on_server_oinfo},
55  {ROAR_CMD_GET_STANDBY,  _NAME("GET_STANDBY"),  req_on_get_standby},
56  {ROAR_CMD_SET_STANDBY,  _NAME("SET_STANDBY"),  req_on_set_standby},
57  {ROAR_CMD_EXIT,         _NAME("EXIT"),         req_on_exit},
58
59  {ROAR_CMD_LIST_CLIENTS, _NAME("LIST_CLIENTS"), req_on_list_clients},
60  {ROAR_CMD_LIST_STREAMS, _NAME("LIST_STREAMS"), req_on_list_streams},
61  {ROAR_CMD_GET_CLIENT,   _NAME("GET_CLIENT"),   req_on_get_client},
62  {ROAR_CMD_GET_STREAM,   _NAME("GET_STREAM"),   req_on_get_stream},
63  {ROAR_CMD_KICK,         _NAME("KICK"),         req_on_kick},
64  {ROAR_CMD_ATTACH,       _NAME("ATTACH"),       req_on_attach},
65  {ROAR_CMD_SET_VOL,      _NAME("SET_VOL"),      req_on_set_vol},
66  {ROAR_CMD_GET_VOL,      _NAME("GET_VOL"),      req_on_get_vol},
67  {ROAR_CMD_GET_STREAM_PARA, _NAME("GET_STREAM_PARA"), req_on_get_stream_para},
68  {ROAR_CMD_SET_STREAM_PARA, _NAME("SET_STREAM_PARA"), req_on_set_stream_para},
69
70  {ROAR_CMD_ADD_DATA,     _NAME("ADD_DATA"),     req_on_add_data},
71
72  {ROAR_CMD_EOL,          _NAME("END OF LIST"),  NULL}
73 };
74
75int command_get_id_by_cmd (int command) {
76 int i;
77 int cmd;
78
79 for (i = 0; i < COMMAND_MAX_COMMANDS; i++) {
80  if ( (cmd = g_commands[i].cmd) == ROAR_CMD_EOL )
81   break;
82
83  if ( cmd == command )
84   return i;
85 }
86
87 return -1;
88}
89
90int command_exec (int client, struct roar_message * mes, char * data) {
91 int cmd = command_get_id_by_cmd(mes->cmd);
92 int (*func)(int client, struct roar_message * mes, char * data);
93
94 if ( cmd == -1 )
95  return -1;
96
97 if ( (func = g_commands[cmd].handler) == NULL )
98  return -1;
99
100 ROAR_DBG("command_exec(*): Execing command %i(%s) via %p", cmd, g_commands[cmd].name, func);
101
102 return func(client, mes, data);
103}
104
105int command_get_name (int command, char ** name) {
106 int cmd = command_get_id_by_cmd(command);
107
108 if ( cmd == -1 ) {
109  *name = NULL;
110  return -1;
111 }
112
113 *name = g_commands[cmd].name;
114
115 return 0;
116}
117
118
119//ll
Note: See TracBrowser for help on using the repository browser.