source: roaraudio/roard/commands.c @ 4500:07a9fe743aa1

Last change on this file since 4500:07a9fe743aa1 was 4500:07a9fe743aa1, checked in by phi, 14 years ago

done some basic work for stds listing

File size: 6.1 KB
Line 
1//commands.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010
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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include "roard.h"
27
28#if !defined(ROAR_TARGET_MICROCONTROLLER) && !defined(ROAR_MINIMAL)
29#define _NAME(x) (x)
30#else
31#define _NAME(x) ((char*)NULL)
32#endif
33
34struct roar_command g_commands[COMMAND_MAX_COMMANDS] = {
35  {ROAR_CMD_NOOP,         _NAME("NOOP"),         req_on_noop,         ACCLEV_NONE},
36  {ROAR_CMD_IDENTIFY,     _NAME("IDENTIFY"),     req_on_identify,     ACCLEV_NONE},
37  {ROAR_CMD_AUTH,         _NAME("AUTH"),         req_on_auth,         ACCLEV_IDENTED},
38  {ROAR_CMD_WHOAMI,       _NAME("WHOAMI"),       req_on_whoami,       ACCLEV_NONE},
39
40
41  {ROAR_CMD_NEW_STREAM,   _NAME("NEW_STREAM"),   req_on_new_stream,   ACCLEV_USER},
42
43#ifdef ROAR_SUPPORT_META
44  {ROAR_CMD_SET_META,     _NAME("SET_META"),     req_on_set_meta,     ACCLEV_PWRUSER},
45  {ROAR_CMD_GET_META,     _NAME("GET_META"),     req_on_get_meta,     ACCLEV_GUEST},
46  {ROAR_CMD_LIST_META,    _NAME("LIST_META"),    req_on_list_meta,    ACCLEV_GUEST},
47#endif
48
49  {ROAR_CMD_EXEC_STREAM,  _NAME("EXEC_STREAM"),  req_on_exec_stream,  ACCLEV_PWRUSER},
50  {ROAR_CMD_QUIT,         _NAME("QUIT"),         (int(*)(int client, struct roar_message * mes, char ** data, uint32_t flags[2]))clients_delete, ACCLEV_NONE},
51
52  {ROAR_CMD_CON_STREAM,   _NAME("CON_STREAM"),   req_on_con_stream,   ACCLEV_PWRUSER},
53  {ROAR_CMD_PASSFH,       _NAME("PASSFH"),       req_on_passfh,       ACCLEV_PWRUSER},
54
55  {ROAR_CMD_SERVER_INFO,  _NAME("SERVER_INFO"),  req_on_server_info,  ACCLEV_IDENTED}, // allow this early so the client
56                                                                                       // can device ealry if this server
57                                                                                       // provieds all needed features
58  {ROAR_CMD_SERVER_OINFO, _NAME("SERVER_OINFO"), req_on_server_oinfo, ACCLEV_IDENTED}, // same as above
59  {ROAR_CMD_CAPS,         _NAME("CAPS"),         req_on_caps,         ACCLEV_IDENTED}, // and again the same
60  {ROAR_CMD_GET_STANDBY,  _NAME("GET_STANDBY"),  req_on_get_standby,  ACCLEV_GUEST},
61  {ROAR_CMD_SET_STANDBY,  _NAME("SET_STANDBY"),  req_on_set_standby,  ACCLEV_PWRUSER}, // should this be set to ACCLEV_ALL?
62  {ROAR_CMD_EXIT,         _NAME("EXIT"),         req_on_exit,         ACCLEV_ALL},
63
64  {ROAR_CMD_LIST_CLIENTS, _NAME("LIST_CLIENTS"), req_on_list_clients, ACCLEV_GUEST},
65  {ROAR_CMD_LIST_STREAMS, _NAME("LIST_STREAMS"), req_on_list_streams, ACCLEV_GUEST},
66  {ROAR_CMD_GET_CLIENT,   _NAME("GET_CLIENT"),   req_on_get_client,   ACCLEV_GUEST},
67  {ROAR_CMD_GET_STREAM,   _NAME("GET_STREAM"),   req_on_get_stream,   ACCLEV_GUEST},
68  {ROAR_CMD_KICK,         _NAME("KICK"),         req_on_kick,         ACCLEV_PWRUSER},
69  {ROAR_CMD_ATTACH,       _NAME("ATTACH"),       req_on_attach,       ACCLEV_PWRUSER},
70  {ROAR_CMD_SET_VOL,      _NAME("SET_VOL"),      req_on_set_vol,      ACCLEV_PWRUSER},
71  {ROAR_CMD_GET_VOL,      _NAME("GET_VOL"),      req_on_get_vol,      ACCLEV_GUEST},
72  {ROAR_CMD_GET_STREAM_PARA, _NAME("GET_STREAM_PARA"), req_on_get_stream_para, ACCLEV_GUEST},
73  {ROAR_CMD_SET_STREAM_PARA, _NAME("SET_STREAM_PARA"), req_on_set_stream_para, ACCLEV_PWRUSER},
74
75  {ROAR_CMD_ADD_DATA,     _NAME("ADD_DATA"),     req_on_add_data,     ACCLEV_PWRUSER},
76
77  {ROAR_CMD_BEEP,         _NAME("BEEP"),         req_on_beep,         ACCLEV_USER},
78
79  {ROAR_CMD_WAIT,         _NAME("WAIT"),         req_on_wait,         ACCLEV_USER},
80
81  {ROAR_CMD_EOL,          _NAME("END OF LIST"),  NULL,                ACCLEV_NONE}
82 };
83
84int command_get_id_by_cmd (int command) {
85 int i;
86 int cmd;
87
88 for (i = 0; i < COMMAND_MAX_COMMANDS; i++) {
89  if ( (cmd = g_commands[i].cmd) == ROAR_CMD_EOL )
90   break;
91
92  if ( cmd == command )
93   return i;
94 }
95
96 return -1;
97}
98
99int command_exec (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
100 int cmd = command_get_id_by_cmd(mes->cmd);
101 int (*func)(int client, struct roar_message * mes, char ** data, uint32_t flags[2]);
102#ifdef DEBUG
103 int ret;
104#endif
105
106 if ( cmd == -1 )
107  return -1;
108
109 // NOTE: This is optimized for speed here, so we do notc al clients_get().
110 // we maybe should do but current just don't. /client/ must be valid anyway.
111 if ( g_commands[cmd].minacclev > g_clients[client]->acclev ) {
112  ROAR_WARN("command_exec(client=%i, mes=%p{.cmd=%i,...}, data=%p, flags=%p) = -1 // client not allowed to use command %s", client, mes, (int)mes->cmd, data, flags, g_commands[cmd].name);
113  return -1;
114 }
115
116 if ( (func = g_commands[cmd].handler) == NULL ) {
117  ROAR_WARN("command_exec(client=%i, mes=%p{.cmd=%i,...}, data=%p, flags=%p) = -1 // unknown command", client, mes, (int)mes->cmd, data, flags);
118  return -1;
119 }
120
121 ROAR_DBG("command_exec(*): Execing command %i(%s) via %p", cmd, g_commands[cmd].name, func);
122
123#ifdef DEBUG
124 ROAR_DBG("command_exec(client=%i, mes=%p{.cmd=%i,...}, data=%p{%p}, flags=%p): func=%p", client, mes, (int)mes->cmd, data, *data, flags, func);
125 ret = func(client, mes, data, flags);
126 ROAR_DBG("command_exec(client=%i, mes=%p{.cmd=%i,...}, data=%p{%p}, flags=%p) = %i", client, mes, (int)mes->cmd, data, *data, flags, ret);
127 return ret;
128#else
129 return func(client, mes, data, flags);
130#endif
131}
132
133int command_get_name (int command, char ** name) {
134 int cmd = command_get_id_by_cmd(command);
135
136 if ( cmd == -1 ) {
137  *name = NULL;
138  return -1;
139 }
140
141 *name = g_commands[cmd].name;
142
143 return 0;
144}
145
146
147//ll
Note: See TracBrowser for help on using the repository browser.