[0] | 1 | //commands.c: |
---|
| 2 | |
---|
[668] | 3 | /* |
---|
[3811] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 |
---|
[668] | 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 |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[668] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
[0] | 26 | #include "roard.h" |
---|
| 27 | |
---|
[1502] | 28 | #if !defined(ROAR_TARGET_MICROCONTROLLER) && !defined(ROAR_MINIMAL) |
---|
[1497] | 29 | #define _NAME(x) (x) |
---|
| 30 | #else |
---|
| 31 | #define _NAME(x) ((char*)NULL) |
---|
| 32 | #endif |
---|
| 33 | |
---|
[0] | 34 | struct roar_command g_commands[COMMAND_MAX_COMMANDS] = { |
---|
[1497] | 35 | {ROAR_CMD_NOOP, _NAME("NOOP"), req_on_noop}, |
---|
| 36 | {ROAR_CMD_IDENTIFY, _NAME("IDENTIFY"), req_on_identify}, |
---|
| 37 | {ROAR_CMD_AUTH, _NAME("AUTH"), req_on_auth}, |
---|
| 38 | {ROAR_CMD_WHOAMI, _NAME("WHOAMI"), req_on_whoami}, |
---|
[1162] | 39 | |
---|
| 40 | |
---|
[1497] | 41 | {ROAR_CMD_NEW_STREAM, _NAME("NEW_STREAM"), req_on_new_stream}, |
---|
[100] | 42 | |
---|
[1497] | 43 | #ifdef ROAR_SUPPORT_META |
---|
| 44 | {ROAR_CMD_SET_META, _NAME("SET_META"), req_on_set_meta}, |
---|
| 45 | {ROAR_CMD_GET_META, _NAME("GET_META"), req_on_get_meta}, |
---|
| 46 | {ROAR_CMD_LIST_META, _NAME("LIST_META"), req_on_list_meta}, |
---|
| 47 | #endif |
---|
[0] | 48 | |
---|
[1497] | 49 | {ROAR_CMD_EXEC_STREAM, _NAME("EXEC_STREAM"), req_on_exec_stream}, |
---|
[3926] | 50 | {ROAR_CMD_QUIT, _NAME("QUIT"), (int(*)(int client, struct roar_message * mes, char ** data, uint32_t flags[2]))clients_delete}, |
---|
[1497] | 51 | |
---|
| 52 | {ROAR_CMD_CON_STREAM, _NAME("CON_STREAM"), req_on_con_stream}, |
---|
| 53 | {ROAR_CMD_PASSFH, _NAME("PASSFH"), req_on_passfh}, |
---|
[77] | 54 | |
---|
[1497] | 55 | {ROAR_CMD_SERVER_OINFO, _NAME("SERVER_OINFO"), req_on_server_oinfo}, |
---|
| 56 | {ROAR_CMD_GET_STANDBY, _NAME("GET_STANDBY"), req_on_get_standby}, |
---|
| 57 | {ROAR_CMD_SET_STANDBY, _NAME("SET_STANDBY"), req_on_set_standby}, |
---|
| 58 | {ROAR_CMD_EXIT, _NAME("EXIT"), req_on_exit}, |
---|
[0] | 59 | |
---|
[1497] | 60 | {ROAR_CMD_LIST_CLIENTS, _NAME("LIST_CLIENTS"), req_on_list_clients}, |
---|
| 61 | {ROAR_CMD_LIST_STREAMS, _NAME("LIST_STREAMS"), req_on_list_streams}, |
---|
| 62 | {ROAR_CMD_GET_CLIENT, _NAME("GET_CLIENT"), req_on_get_client}, |
---|
| 63 | {ROAR_CMD_GET_STREAM, _NAME("GET_STREAM"), req_on_get_stream}, |
---|
| 64 | {ROAR_CMD_KICK, _NAME("KICK"), req_on_kick}, |
---|
| 65 | {ROAR_CMD_ATTACH, _NAME("ATTACH"), req_on_attach}, |
---|
| 66 | {ROAR_CMD_SET_VOL, _NAME("SET_VOL"), req_on_set_vol}, |
---|
| 67 | {ROAR_CMD_GET_VOL, _NAME("GET_VOL"), req_on_get_vol}, |
---|
| 68 | {ROAR_CMD_GET_STREAM_PARA, _NAME("GET_STREAM_PARA"), req_on_get_stream_para}, |
---|
| 69 | {ROAR_CMD_SET_STREAM_PARA, _NAME("SET_STREAM_PARA"), req_on_set_stream_para}, |
---|
[0] | 70 | |
---|
[1497] | 71 | {ROAR_CMD_ADD_DATA, _NAME("ADD_DATA"), req_on_add_data}, |
---|
[0] | 72 | |
---|
[3574] | 73 | {ROAR_CMD_BEEP, _NAME("BEEP"), req_on_beep}, |
---|
| 74 | |
---|
[4343] | 75 | {ROAR_CMD_WAIT, _NAME("WAIT"), req_on_wait}, |
---|
| 76 | |
---|
[1497] | 77 | {ROAR_CMD_EOL, _NAME("END OF LIST"), NULL} |
---|
[0] | 78 | }; |
---|
| 79 | |
---|
| 80 | int command_get_id_by_cmd (int command) { |
---|
| 81 | int i; |
---|
| 82 | int cmd; |
---|
| 83 | |
---|
| 84 | for (i = 0; i < COMMAND_MAX_COMMANDS; i++) { |
---|
| 85 | if ( (cmd = g_commands[i].cmd) == ROAR_CMD_EOL ) |
---|
| 86 | break; |
---|
| 87 | |
---|
| 88 | if ( cmd == command ) |
---|
| 89 | return i; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | return -1; |
---|
| 93 | } |
---|
| 94 | |
---|
[3926] | 95 | int command_exec (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) { |
---|
[0] | 96 | int cmd = command_get_id_by_cmd(mes->cmd); |
---|
[3926] | 97 | int (*func)(int client, struct roar_message * mes, char ** data, uint32_t flags[2]); |
---|
[4298] | 98 | #ifdef DEBUG |
---|
| 99 | int ret; |
---|
| 100 | #endif |
---|
[0] | 101 | |
---|
| 102 | if ( cmd == -1 ) |
---|
| 103 | return -1; |
---|
| 104 | |
---|
[4279] | 105 | if ( (func = g_commands[cmd].handler) == NULL ) { |
---|
| 106 | ROAR_WARN("command_exec(client=%i, mes=%p{.cmd=%i,...}, data=%p, flags=%p) = -1 // unknown command", client, mes, (int)mes->cmd, data, flags); |
---|
[0] | 107 | return -1; |
---|
[4279] | 108 | } |
---|
[0] | 109 | |
---|
| 110 | ROAR_DBG("command_exec(*): Execing command %i(%s) via %p", cmd, g_commands[cmd].name, func); |
---|
| 111 | |
---|
[4298] | 112 | #ifdef DEBUG |
---|
| 113 | 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); |
---|
| 114 | ret = func(client, mes, data, flags); |
---|
| 115 | 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); |
---|
| 116 | return ret; |
---|
| 117 | #else |
---|
[3926] | 118 | return func(client, mes, data, flags); |
---|
[4298] | 119 | #endif |
---|
[0] | 120 | } |
---|
| 121 | |
---|
| 122 | int command_get_name (int command, char ** name) { |
---|
| 123 | int cmd = command_get_id_by_cmd(command); |
---|
| 124 | |
---|
| 125 | if ( cmd == -1 ) { |
---|
| 126 | *name = NULL; |
---|
| 127 | return -1; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | *name = g_commands[cmd].name; |
---|
| 131 | |
---|
| 132 | return 0; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | //ll |
---|