--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "proxy.h"
+#include "logger.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#define DEFAULT_MAX_STREAMS_PER_POOL_CNT 25
+#define MICROSECS_PER_MILLISEC 1000
+
+#define MAX_POOL_CNT 100
+static sound_pool_h pools[MAX_POOL_CNT] = { NULL };
+
+/* Messages to be used for callbacks output (for pool state changing) */
+static char *messages[MAX_POOL_CNT] = { NULL };
+/* Scripts will be launched from callbacks (for stream state changing) */
+static char *scripts[MAX_POOL_CNT] = { NULL };
+
+#define MAX_STREAM_CNT 1000
+/* Messages to be used for callbacks output (for pool state changing) */
+static char *stream_messages[MAX_POOL_CNT][MAX_STREAM_CNT] = { NULL };
+/* Messages to be used for callbacks output (for stream state changing) */
+static char *stream_scripts[MAX_POOL_CNT][MAX_STREAM_CNT] = { NULL };
+
+static int __proxy_sound_pool_execute_script(const char *pars);
+
+const char *__stringify_sound_pool_error(sound_pool_error_e error)
+{
+ switch (error) {
+ case SOUND_POOL_ERROR_NONE:
+ return "SOUND_POOL_ERROR_NONE";
+ break;
+ case SOUND_POOL_ERROR_NOT_SUPPORTED:
+ return "SOUND_POOL_ERROR_NOT_SUPPORTED";
+ break;
+ case SOUND_POOL_ERROR_MSG_TOO_LONG:
+ return "SOUND_POOL_ERROR_MSG_TOO_LONG";
+ break;
+ case SOUND_POOL_ERROR_NO_DATA:
+ return "SOUND_POOL_ERROR_NO_DATA";
+ break;
+ case SOUND_POOL_ERROR_KEY_NOT_AVAILABLE:
+ return "SOUND_POOL_ERROR_KEY_NOT_AVAILABLE";
+ break;
+ case SOUND_POOL_ERROR_OUT_OF_MEMORY:
+ return "SOUND_POOL_ERROR_OUT_OF_MEMORY";
+ break;
+ case SOUND_POOL_ERROR_INVALID_PARAMETER:
+ return "SOUND_POOL_ERROR_INVALID_PARAMETER";
+ break;
+ case SOUND_POOL_ERROR_INVALID_OPERATION:
+ return "SOUND_POOL_ERROR_INVALID_OPERATION";
+ break;
+ case SOUND_POOL_ERROR_PERMISSION_DENIED:
+ return "SOUND_POOL_ERROR_PERMISSION_DENIED";
+ break;
+ default:
+ return "";
+ break;
+ }
+
+ return NULL;
+}
+
+const char *__stringify_stream_state(sound_pool_stream_state_e state)
+{
+ switch (state) {
+ case SOUND_POOL_STREAM_STATE_NONE:
+ return "SOUND_POOL_STREAM_STATE_NONE";
+ break;
+ case SOUND_POOL_STREAM_STATE_PLAYING:
+ return "SOUND_POOL_STREAM_STATE_PLAYING";
+ break;
+ case SOUND_POOL_STREAM_STATE_PAUSED:
+ return "SOUND_POOL_STREAM_STATE_PAUSED";
+ break;
+ case SOUND_POOL_STREAM_STATE_SUSPENDED:
+ return "SOUND_POOL_STREAM_STATE_SUSPENDED";
+ break;
+ case SOUND_POOL_STREAM_STATE_STOPPED:
+ return "SOUND_POOL_STREAM_STATE_STOPPED";
+ break;
+ case SOUND_POOL_STREAM_STATE_FINISHED:
+ return "SOUND_POOL_STREAM_STATE_FINISHED";
+ break;
+ default:
+ return "";
+ break;
+ }
+
+ return NULL;
+}
+
+static void __sp_cb_msg(sound_pool_h pool, sound_pool_state_e prev_state,
+ sound_pool_state_e cur_state, void *data)
+{
+ const char *msg = (const char *)data;
+ _logger_log_info("Sound pool state was changing from %s to %s: %s",
+ prev_state == SOUND_POOL_STATE_ACTIVE ?
+ "SOUND_POOL_STATE_ACTIVE" : "SOUND_POOL_STATE_INACTIVE",
+ cur_state == SOUND_POOL_STATE_ACTIVE ?
+ "SOUND_POOL_STATE_ACTIVE" : "SOUND_POOL_STATE_INACTIVE",
+ msg ? msg : "No message");
+}
+
+static void __sp_cb_scr(sound_pool_h pool, sound_pool_state_e prev_state,
+ sound_pool_state_e cur_state, void *data)
+{
+ const char *scr = (const char *)data;
+ _logger_log_info("Sound pool state was changing from %s to %s; "
+ "Executing: %s...",
+ prev_state == SOUND_POOL_STATE_ACTIVE ? "SOUND_POOL_STATE_ACTIVE" :
+ "SOUND_POOL_STATE_INACTIVE",
+ cur_state == SOUND_POOL_STATE_ACTIVE ? "SOUND_POOL_STATE_ACTIVE" :
+ "SOUND_POOL_STATE_INACTIVE",
+ scr ? scr : "No script");
+ __proxy_sound_pool_execute_script(scr);
+}
+
+static void __s_cb_msg(sound_pool_h pool, const char *tag, unsigned id,
+ sound_pool_stream_state_e prev_state,
+ sound_pool_stream_state_e cur_state, void *data)
+{
+ const char *msg = (const char *)data;
+ _logger_log_info("Stream state was changing from %s to %s: %s",
+ __stringify_stream_state(prev_state),
+ __stringify_stream_state(cur_state),
+ msg ? msg : "No message");
+}
+
+static void __s_cb_scr(sound_pool_h pool, const char *tag, unsigned id,
+ sound_pool_stream_state_e prev_state,
+ sound_pool_stream_state_e cur_state, void *data)
+{
+ const char *scr = (const char *)data;
+ _logger_log_info("Sound pool state was changing from %s to %s; "
+ "Executing: %s...", __stringify_stream_state(prev_state),
+ __stringify_stream_state(cur_state),
+ scr ? scr : "No script");
+ __proxy_sound_pool_execute_script(scr);
+}
+
+/* CMD_EXIT */
+static int __exit()
+{
+ return EXIT;
+}
+
+/* CMD_HELP */
+static int __print_cmd_help_msg()
+{
+ printf("\nTest suite usage help:\n");
+
+ printf(CMD_HELP "\n");
+ printf("\t- Shows this help.\n");
+
+ printf(CMD_CREATE_POOL "\n");
+ printf("\t- creates pool with specific identifier.\n");
+
+ printf(CMD_DESTROY_POOL "\n");
+ printf("\t- destroys pool with specific identifier.\n");
+
+ printf(CMD_ACTIVATE_POOL "\n");
+ printf("\t- activates pool with specific identifier.\n");
+
+ printf(CMD_DEACTIVATE_POOL "\n");
+ printf("\t- deactivates pool with specific identifier.\n");
+
+ printf(CMD_GET_POOL_STATE "\n");
+ printf("\t- shows state of the pool with specific identifier.\n");
+
+ printf(CMD_SET_POOL_VOLUME "\n");
+ printf("\t- use this command to set volume for the specific sound pool.\n");
+
+ printf(CMD_GET_POOL_VOLUME "\n");
+ printf("\t- shows volume of the sound pool with specific identifier.\n");
+
+ printf(CMD_SET_POOL_CB_MSG "\n");
+ printf("\t- sets callback which will show the message when sound pool "
+ "state is changed.\n");
+
+ printf(CMD_SET_POOL_CB_SCRIPT "\n");
+ printf("\t- sets callback which will execute the script when sound pool "
+ "state is changed.\n");
+
+ printf(CMD_UNSET_POOL_CB "\n");
+ printf("\t- unsets the callback for the sound pool.\n");
+
+ printf(CMD_LIST_POOL "\n");
+ printf("\t- shows ids of all pools had been created and their states.\n");
+
+ printf(CMD_LOAD_SOURCE "\n");
+ printf("\t- loads the source with specific source tag.\n");
+
+ printf(CMD_UNLOAD_SOURCE "\n");
+ printf("\t- unloads the source with specific source tag.\n");
+
+ printf(CMD_PLAY_STREAM "\n");
+ printf("\t- creates the stream with unique identifier and starts playback.\n"
+ "\t Source tag to be used for stream creation should be specified.\n");
+
+ printf(CMD_STOP_STREAM "\n");
+ printf("\t- stops the stream playback. Stream unique identifier should be\n"
+ "\t specified after command. After stopping the stream became invalid.\n");
+
+ printf(CMD_PAUSE_STREAM "\n");
+ printf("\t- pauses the stream playback. Stream unique identifier should be\n"
+ "\t specified after command.\n");
+
+ printf(CMD_RESUME_STREAM "\n");
+ printf("\t- resumes the stream was paused before. Stream unique identifier\n"
+ "\t should be specified after command.\n");
+
+ printf(CMD_SET_STREAM_VOLUME "\n");
+ printf("\t- use this command to set volume parameter of the stream.\n");
+
+ printf(CMD_GET_STREAM_VOLUME "\n");
+ printf("\t- shows volume of the stream in the pool with specified "
+ "identifiers.\n");
+
+ printf(CMD_SET_STREAM_LOOP "\n");
+ printf("\t- use this command to set loop parameter of the stream.\n");
+
+ printf(CMD_GET_STREAM_LOOP "\n");
+ printf("\t- shows loop count of the stream in the pool with specified "
+ "identifiers.\n");
+
+ printf(CMD_SET_STREAM_PRIORITY "\n");
+ printf("\t- use this command to set priority parameter of the stream.\n");
+
+ printf(CMD_GET_STREAM_PRIORITY "\n");
+ printf("\t- shows priority rank of the stream in the pool with specified "
+ "identifiers.\n");
+
+ printf(CMD_GET_STREAM_STATE "\n");
+ printf("\t- shows state of the stream in the pool with specified "
+ "identifiers.\n");
+
+ printf(CMD_SET_STREAM_CB_MSG "\n");
+ printf("\t- sets callback which will show the message when sound stream "
+ "state is changed.\n");
+
+ printf(CMD_SET_STREAM_CB_SCRIPT "\n");
+ printf("\t- sets callback which will execute the script (from file) when "
+ "sound stream state is changed.\n");
+
+ printf(CMD_UNSET_STREAM_CB "\n");
+ printf("\t- unsets the callback for the sound stream.\n");
+
+ printf(CMD_EXECUTE_SCRIPT "\n");
+ printf("\t- executes the script from the file in filesystem. Script has to\n"
+ "\t be compiled with commands supported by testsuite, one command\n"
+ "\t per single line.\n");
+
+ printf(CMD_SLEEP "\n");
+ printf("\t- suspends execution of the main thread for the specific amount "
+ "of milleseconds.\n");
+
+ printf(CMD_EXIT "\n");
+ printf("\t- exits from the test suite.\n");
+
+ printf("\n");
+
+ return OK;
+}
+
+/* CMD_CREATE_POOL */
+static int __proxy_sound_pool_create(const char *pars)
+{
+ _logger_log_info(CMD_CREATE_POOL " command was called");
+
+ unsigned int max_streams = DEFAULT_MAX_STREAMS_PER_POOL_CNT;
+ if (pars != NULL)
+ sscanf(pars, " %u", &max_streams);
+
+ _logger_log_info("Creating the pool...");
+
+ sound_pool_h pool = NULL;
+ int ret = sound_pool_create(max_streams, &pool);
+
+ if (ret == SOUND_POOL_ERROR_NONE) {
+ _logger_log_info("sound_pool_create(%u, pool) returned %s value",
+ max_streams, __stringify_sound_pool_error(ret));
+
+ size_t idx = 0;
+ while (idx < MAX_POOL_CNT) {
+ if (pools[idx++] == NULL) {
+ pools[--idx] = pool;
+ break;
+ }
+ }
+
+ if (idx == MAX_POOL_CNT) {
+ _printf(CMD_COLOR_RED, "Limit of possible pools is exceeded. Destroy "
+ "some pools before creating of new ones.\n");
+
+ _logger_log_warn("Pool can't be created due to test suite "
+ "restrictions. Destroying the pool...");
+
+ ret = sound_pool_destroy(pool);
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_destroy(pool) returned %s value",
+ __stringify_sound_pool_error(ret));
+ else
+ _logger_log_err("sound_pool_destroy(pool) returned %s value",
+ __stringify_sound_pool_error(ret));
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+ }
+
+ if (!pool)
+ _logger_log_warn("Created pool is NULL");
+ else
+ _logger_log_info("Identifier of the pool has been created is %zu", idx);
+ } else {
+ _logger_log_err("sound_pool_create(%u, pool) returned %s value",
+ max_streams, __stringify_sound_pool_error(ret));
+ }
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_DESTROY_POOL */
+static int __proxy_sound_pool_destroy(const char *pars)
+{
+ int ret = SOUND_POOL_ERROR_NONE;
+ size_t idx = 0;
+ if ((pars == NULL) || (sscanf(pars, " %zu", &idx) < 1)) {
+ _printf(CMD_COLOR_RED, "You have to specify identifier of the pool to be "
+ "destroyed after command! Format: " CMD_DESTROY_POOL " <id>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ _logger_log_info(CMD_DESTROY_POOL " command was called");
+ _logger_log_info("Destroying the pool by %zu identifier...", idx);
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool to be destroyed is NULL");
+
+ ret = sound_pool_destroy(pools[idx]);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_destroy(pool) returned %s value",
+ __stringify_sound_pool_error(ret));
+ else
+ _logger_log_err("sound_pool_destroy(pool) returned %s value",
+ __stringify_sound_pool_error(ret));
+
+ pools[idx] = NULL;
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_ACTIVATE_POOL */
+static int __proxy_sound_pool_activate(const char *pars)
+{
+ int ret = SOUND_POOL_ERROR_NONE;
+ size_t idx = 0;
+ if ((pars == NULL) || (sscanf(pars, " %zu", &idx) < 1)) {
+ _printf(CMD_COLOR_RED, "You have to specify identifier of the pool "
+ "to be activated after command name! Format: "
+ CMD_ACTIVATE_POOL " <id>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ _logger_log_info(CMD_ACTIVATE_POOL " command was called");
+ _logger_log_info("Activating the pool by %zu identifier...", idx);
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool to be activated is NULL");
+
+ ret = sound_pool_activate(pools[idx]);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_set_state(pool, "
+ "SOUND_POOL_STATE_ACTIVE) returned %s value",
+ __stringify_sound_pool_error(ret));
+ else
+ _logger_log_err("sound_pool_set_state(pool, "
+ "SOUND_POOL_STATE_ACTIVE) returned %s value",
+ __stringify_sound_pool_error(ret));
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_DEACTIVATE_POOL */
+static int __proxy_sound_pool_deactivate(const char *pars)
+{
+ size_t idx = 0;
+ if ((pars == NULL) || (sscanf(pars, " %zu", &idx) < 1)) {
+ _printf(CMD_COLOR_RED, "You have to specify identifier of the pool "
+ "to be deactivated after command name! Format: "
+ CMD_DEACTIVATE_POOL " <id>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ _logger_log_info(CMD_DEACTIVATE_POOL " command was called");
+ _logger_log_info("Deactivating the pool by %zu identifier...", idx);
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool to be deactivated is NULL");
+
+ int ret = sound_pool_deactivate(pools[idx]);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_set_state(pool, "
+ "SOUND_POOL_STATE_INACTIVE) returned %s value",
+ __stringify_sound_pool_error(ret));
+ else
+ _logger_log_err("sound_pool_set_state(pool, "
+ "SOUND_POOL_STATE_INACTIVE) returned %s value",
+ __stringify_sound_pool_error(ret));
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_GET_POOL_STATE */
+static int __proxy_sound_pool_get_state(const char *pars)
+{
+ size_t idx = 0;
+ if ((pars == NULL) || (sscanf(pars, " %zu", &idx) < 1)) {
+ _printf(CMD_COLOR_RED, "You have to specify identifier of the pool "
+ "to get state for, after command name! Format: "
+ CMD_GET_POOL_STATE " <id>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ _logger_log_info(CMD_GET_POOL_STATE " command was called");
+ _logger_log_info("Getting the pool state by %zu identifier...", idx);
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool to get state for is NULL");
+
+ sound_pool_state_e state = SOUND_POOL_STATE_INACTIVE;
+ int ret = sound_pool_get_state(pools[idx], &state);
+
+ const char *str_state = (state == SOUND_POOL_STATE_ACTIVE ?
+ "SOUND_POOL_STATE_ACTIVE" : "SOUND_POOL_STATE_INACTIVE");
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_get_state(pool, state) returned %s value,"
+ " state is %s", __stringify_sound_pool_error(ret), str_state);
+ else
+ _logger_log_err("sound_pool_get_state(pool, state) returned %s value,"
+ " state is %s", __stringify_sound_pool_error(ret), str_state);
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_SET_POOL_VOLUME */
+static int __proxy_sound_pool_set_volume(const char *pars)
+{
+ size_t idx = 0;
+ float volume = .0f;
+ if ((pars == NULL) || (sscanf(pars, " %zu %f", &idx, &volume) < 2)) {
+ _printf(CMD_COLOR_RED, "You have to specify both identifier of the "
+ "pool and new volume float value to set volume for whole pool! "
+ "Format: " CMD_SET_POOL_VOLUME " <id> <volume>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ _logger_log_info(CMD_SET_POOL_VOLUME " command was called");
+ _logger_log_info("Set %f volume value for pool with %zu identifier...",
+ volume, idx);
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool to get state for is NULL");
+
+ if (volume < .0f || volume > 1.0f)
+ _logger_log_warn("Volume is set as %f, not in [0, 1.0] range", volume);
+
+ int ret = sound_pool_set_volume(pools[idx], volume);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_set_global_volume(pool, %f) "
+ "returned %s value", volume, __stringify_sound_pool_error(ret));
+ else
+ _logger_log_err("sound_pool_set_global_volume(pool, %f) "
+ "returned %s value", volume, __stringify_sound_pool_error(ret));
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_GET_POOL_VOLUME */
+static int __proxy_sound_pool_get_volume(const char *pars)
+{
+ size_t idx = 0;
+ if ((pars == NULL) || (sscanf(pars, " %zu", &idx) < 1)) {
+ _printf(CMD_COLOR_RED, "You have to specify identifier of the pool "
+ "to get volume for, after command name! Format: "
+ CMD_GET_POOL_VOLUME " <id>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ _logger_log_info(CMD_GET_POOL_VOLUME " command was called");
+ _logger_log_info("Getting the pool global volume for pool with %zu "
+ "identifier...", idx);
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool to get state for is NULL");
+
+ float volume = .0f;
+ int ret = sound_pool_get_volume(pools[idx], &volume);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_get_global_volume(pool, volume) returned "
+ "%s value, volume is %f", __stringify_sound_pool_error(ret),
+ volume);
+ else
+ _logger_log_err("sound_pool_get_global_volume(pool, volume) returned "
+ "%s value, volume is %f", __stringify_sound_pool_error(ret),
+ volume);
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_SET_POOL_CB_MSG */
+static int __proxy_sound_pool_set_state_change_callback_message(const char *pars)
+{
+ size_t idx = 0;
+
+ char msg[MAX_MSG_LEN] = { '\0' };
+
+ if ((pars == NULL) || (sscanf(pars, " %zu %"MAX_MSG_LEN_STR"[^ ]", &idx, msg) < 2)) {
+ _printf(CMD_COLOR_RED, "You have to specify both identifier of the "
+ "pool and message to be shown each time when state of the pool "
+ " is changed! Message should be a single word. Format: "
+ CMD_SET_POOL_CB_MSG " <id> <message>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ _logger_log_info(CMD_SET_POOL_CB_MSG " command was called");
+ _logger_log_info("Set state changing callback (%s message) for pool with "
+ "%zu identifier...", msg, idx);
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool to set callback for is NULL");
+
+ if (messages[idx])
+ free(messages[idx]);
+ messages[idx] = strndup(msg, MAX_MSG_LEN);
+
+ int ret = sound_pool_set_state_change_callback(pools[idx], __sp_cb_msg,
+ messages[idx]);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_set_state_change_callback(pool, cb, "
+ "\"%s\") returned %s value", msg, __stringify_sound_pool_error(ret));
+ else
+ _logger_log_err("sound_pool_set_state_change_callback(pool, cb, "
+ "\"%s\") returned %s value", msg, __stringify_sound_pool_error(ret));
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_SET_POOL_CB_SCRIPT */
+static int __proxy_sound_pool_set_state_change_callback_script(const char *pars)
+{
+ size_t idx = 0;
+
+ char scr[MAX_MSG_LEN] = { '\0' };
+
+ if ((pars == NULL) || (sscanf(pars, " %zu %"MAX_MSG_LEN_STR"[^ ]", &idx, scr) < 2)) {
+ _printf(CMD_COLOR_RED, "You have to specify both identifier of the "
+ "pool and script file name to be executed each time when state "
+ "of the pool will be changed! Format: "
+ CMD_SET_POOL_CB_SCRIPT " <id> <script file>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ _logger_log_info(CMD_SET_POOL_CB_SCRIPT " command was called");
+ _logger_log_info("Set state changing callback (%s script) for pool with "
+ "%zu identifier...", scr, idx);
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool to set callback for is NULL");
+
+ if (scripts[idx])
+ free(scripts[idx]);
+ scripts[idx] = strndup(scr, MAX_MSG_LEN);
+
+ int ret = sound_pool_set_state_change_callback(pools[idx], __sp_cb_scr,
+ scripts[idx]);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_set_state_change_callback(pool, cb, "
+ "\"%s\") returned %s value", scr, __stringify_sound_pool_error(ret));
+ else
+ _logger_log_err("sound_pool_set_state_change_callback(pool, cb, "
+ "\"%s\") returned %s value", scr, __stringify_sound_pool_error(ret));
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_UNSET_POOL_CB */
+static int __proxy_sound_pool_unset_state_change_callback(const char *pars)
+{
+ size_t idx = 0;
+ if ((pars == NULL) || (sscanf(pars, " %zu", &idx) < 1)) {
+ _printf(CMD_COLOR_RED, "You have to specify identifier of the pool! "
+ "Format: " CMD_UNSET_POOL_CB " <id>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ _logger_log_info(CMD_UNSET_POOL_CB " command was called");
+ _logger_log_info("Unset state changing callback for pool with "
+ "%zu identifier...", idx);
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool to unset callback for is NULL");
+
+ int ret = sound_pool_unset_state_change_callback(pools[idx]);
+
+ if (messages[idx] != NULL)
+ free(messages[idx]);
+ messages[idx] = NULL;
+
+ if (scripts[idx] != NULL)
+ free(scripts[idx]);
+ scripts[idx] = NULL;
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_unset_state_change_callback(pool) "
+ "returned %s value", __stringify_sound_pool_error(ret));
+ else
+ _logger_log_err("sound_pool_unset_state_change_callback(pool) "
+ "returned %s value", __stringify_sound_pool_error(ret));
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_LIST_POOL */
+static int __proxy_sound_pool_list()
+{
+ _logger_log_info("Getting the pool identifiers...");
+
+ const size_t buffer_size = 1024;
+ char buffer[buffer_size];
+ buffer[0] = '\0';
+
+ size_t idx = 0;
+ size_t len = 0;
+ while (idx < MAX_POOL_CNT) {
+ len = strnlen(buffer, buffer_size);
+ if (pools[idx++] != NULL) {
+ size_t add_len = 1;
+ size_t id = idx - 1;
+ do
+ add_len++;
+ while ((id = id / 10) > 0);
+ id = idx - 1;
+ if (len + add_len + 1 > buffer_size)
+ break;
+ snprintf(buffer + len, buffer_size, "%zu ", id);
+ }
+ }
+
+ _printf(CMD_COLOR_GREEN, "Pools identifiers: %s\n", buffer);
+ _logger_log_info("Pools identifiers: %s", buffer);
+
+ _logger_log_info("Pool identifiers were retrieved...");
+
+ return OK;
+}
+
+/* CMD_LOAD_SOURCE */
+static int __proxy_sound_pool_load_source_from_file(const char *pars)
+{
+ size_t idx = 0;
+
+ char fname[MAX_PATH_LEN] = {'\0'};
+ char tag[MAX_PATH_LEN] = {'\0'};
+
+ if ((pars == NULL) || sscanf(pars, " %zu %"MAX_PATH_LEN_STR"[^ ] "
+ "%"MAX_PATH_LEN_STR"[^ ]", &idx, fname, tag) < 2) {
+ _printf(CMD_COLOR_RED, "You have to specify at least pool identifier and "
+ "file name to be loaded! Format: " CMD_LOAD_SOURCE " <pool id> "
+ "<file name> <source tag>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool with specified identifier is NULL");
+
+ /* If tag wasn't specified by the user, we will use file path as a tag */
+ if (tag[0] == '\0')
+ strncpy(tag, fname, MAX_PATH_LEN);
+
+ _logger_log_info(CMD_LOAD_SOURCE " command was called");
+ _logger_log_info("Loading source to the pool with %zu identifier from %s file. "
+ "Tag '%s' will be assigned for the loaded source...", idx, fname, tag);
+
+ int ret = sound_pool_load_source_from_file(pools[idx], fname, tag);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_load_source_from_file(pool, \"%s\", "
+ "\"%s\") returned %s value", fname, tag,
+ __stringify_sound_pool_error(ret));
+ else
+ _logger_log_err("sound_pool_load_source_from_file(pool, \"%s\", "
+ "\"%s\") returned %s value", fname, tag,
+ __stringify_sound_pool_error(ret));
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_UNLOAD_SOURCE */
+static int __proxy_sound_pool_unload_source(const char *pars)
+{
+ size_t idx = 0;
+
+ char tag[MAX_PATH_LEN] = {'\0'};
+
+ if ((pars == NULL) || sscanf(pars, " %zu %"MAX_PATH_LEN_STR"[^ ]", &idx, tag) < 2) {
+ _printf(CMD_COLOR_RED, "You have to specify both pool identifier and "
+ "source tag to be unloaded! Format: " CMD_UNLOAD_SOURCE
+ " <pool id> <source tag>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool with specified identifier is NULL");
+
+ _logger_log_info(CMD_UNLOAD_SOURCE " command was called");
+ _logger_log_info("Unloading source by '%s' tag from the pool with %zu "
+ "identifier...", tag, idx);
+
+ int ret = sound_pool_unload_source(pools[idx], tag);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_unload_source(pool, \"%s\") returned "
+ "%s value", tag, __stringify_sound_pool_error(ret));
+ else
+ _logger_log_err("sound_pool_unload_source(pool, \"%s\") returned "
+ "%s value", tag, __stringify_sound_pool_error(ret));
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_PLAY_STREAM */
+static int __proxy_sound_pool_play_stream(const char *pars)
+{
+ size_t idx = 0;
+ int loop = 0;
+ float volume = 1.0f;
+ int rank = 0;
+
+ char tag[MAX_PATH_LEN] = {'\0'};
+
+ if ((pars == NULL) || sscanf(pars, " %zu %"MAX_PATH_LEN_STR"[^ ] %i %f %i",
+ &idx, tag, &loop, &volume, &rank) < 2) {
+ _printf(CMD_COLOR_RED, "You have to specify at least pool identifier and "
+ "source tag to be played in stream! Format: " CMD_PLAY_STREAM
+ " <pool id> <source tag> <loop> <volume> <priority rank>... \n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool with specified identifier is NULL");
+
+ _logger_log_info(CMD_PLAY_STREAM " command was called");
+ _logger_log_info("Playing stream based on source with '%s' tag from the pool "
+ "with %zu identifier...", tag, idx);
+
+ int stream_idx = 0;
+ int ret = sound_pool_stream_play(pools[idx], tag, loop, volume, rank, NULL,
+ NULL, &stream_idx);
+
+ if (ret == SOUND_POOL_ERROR_NONE) {
+ _logger_log_info("sound_pool_play_stream(pool, \"%s\", %i, %f, %i,"
+ " NULL, NULL, &stream_idx) returned %s value. "
+ "Generated identifier is %i", tag, loop, volume, rank,
+ __stringify_sound_pool_error(ret), stream_idx);
+ _printf(CMD_COLOR_GREEN, "Generated stream identifier is %i\n", stream_idx);
+ } else {
+ _logger_log_err("sound_pool_play_stream(pool, \"%s\", %i, %f, %i,"
+ " NULL, NULL, &stream_idx) returned %s value",
+ tag, loop, volume, rank, __stringify_sound_pool_error(ret));
+ }
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_PAUSE_STREAM */
+static int __proxy_sound_pool_pause_stream(const char *pars)
+{
+ size_t idx = 0;
+ size_t stream_idx = 0;
+
+ if ((pars == NULL) || (sscanf(pars, " %zu %i", &idx, &stream_idx) < 2)) {
+ _printf(CMD_COLOR_RED, "You have to specify both pool identifier and "
+ "stream to be paused identifier! Format: " CMD_PAUSE_STREAM
+ " <pool id> <stream id>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool with specified identifier is NULL");
+
+ _logger_log_info(CMD_PAUSE_STREAM " command was called");
+
+ int ret = sound_pool_stream_pause(pools[idx], stream_idx);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_pause_stream(pool, %i) returned %s "
+ "value", stream_idx, __stringify_sound_pool_error(ret));
+ else
+ _logger_log_err("sound_pool_pause_stream(pool, %i) returned %s "
+ "value", stream_idx, __stringify_sound_pool_error(ret));
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_RESUME_STREAM */
+static int __proxy_sound_pool_resume_stream(const char *pars)
+{
+ size_t idx = 0;
+ size_t stream_idx = 0;
+
+ if ((pars == NULL) || (sscanf(pars, " %zu %i", &idx, &stream_idx) < 2)) {
+ _printf(CMD_COLOR_RED, "You have to specify both pool identifier and "
+ "stream to be resumed identifier! Format: " CMD_RESUME_STREAM
+ " <pool id> <stream id>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool with specified identifier is NULL");
+
+ _logger_log_info(CMD_RESUME_STREAM " command was called");
+
+ int ret = sound_pool_stream_resume(pools[idx], stream_idx);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_resume_stream(pool, %i) returned %s "
+ "value", stream_idx, __stringify_sound_pool_error(ret));
+ else
+ _logger_log_err("sound_pool_resume_stream(pool, %i) returned %s "
+ "value", stream_idx, __stringify_sound_pool_error(ret));
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_STOP_STREAM */
+static int __proxy_sound_pool_stop_stream(const char *pars)
+{
+ size_t idx = 0;
+ size_t stream_idx = 0;
+
+ if ((pars == NULL) || (sscanf(pars, " %zu %zu", &idx, &stream_idx) < 2)) {
+ _printf(CMD_COLOR_RED, "You have to specify both pool identifier and "
+ "stream to be stopped identifier! Format: " CMD_STOP_STREAM
+ " <pool id> <stream id>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool with specified identifier is NULL");
+
+ _logger_log_info(CMD_STOP_STREAM " command was called");
+
+ int ret = sound_pool_stream_stop(pools[idx], stream_idx);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_stop_stream(pool, %i) returned %s "
+ "value", stream_idx, __stringify_sound_pool_error(ret));
+ else
+ _logger_log_err("sound_pool_stop_stream(pool, %i) returned %s "
+ "value", stream_idx, __stringify_sound_pool_error(ret));
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_SET_STREAM_VOLUME */
+static int __proxy_sound_pool_stream_set_volume(const char *pars)
+{
+ size_t idx = 0;
+ size_t stream_idx = 0;
+ float volume_val = 1.0f;
+
+ if ((pars == NULL)
+ || (sscanf(pars, " %zu %zu %f", &idx, &stream_idx, &volume_val) < 3)) {
+ _printf(CMD_COLOR_RED, "You have to specify all following parameters: "
+ "pool identifier, stream identifier! Format: "
+ CMD_SET_STREAM_VOLUME " <pool id> <stream id> <volume>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool with specified identifier is NULL");
+
+ if (volume_val < .0f || volume_val > 1.0f)
+ _logger_log_warn("Volume has to be specified in 0.0~1.0 range");
+
+ _logger_log_info(CMD_SET_STREAM_VOLUME " command was called");
+
+ int ret = sound_pool_stream_set_volume(pools[idx], stream_idx, volume_val);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_stream_set_volume(pool, %i, %f) "
+ "returned %s value", stream_idx, volume_val,
+ __stringify_sound_pool_error(ret));
+ else
+ _logger_log_err("sound_pool_stream_set_volume(pool, %i, %f) "
+ "returned %s value", stream_idx, volume_val,
+ __stringify_sound_pool_error(ret));
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_GET_STREAM_VOLUME */
+static int __proxy_sound_pool_stream_get_volume(const char *pars)
+{
+ size_t idx = 0;
+ size_t stream_idx = 0;
+ if ((pars == NULL) || (sscanf(pars, " %zu %zu", &idx, &stream_idx) < 2)) {
+ _printf(CMD_COLOR_RED, "You have to specify both pool and stream "
+ "identifiers after command name! Format: "
+ CMD_GET_STREAM_VOLUME " <pool id> <stream id>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ _logger_log_info(CMD_GET_STREAM_VOLUME " command was called");
+ _logger_log_info("Getting the %zu stream from %zu pool volume value...",
+ stream_idx, idx);
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool to get state for is NULL");
+
+ float volume = .0f;
+ int ret = sound_pool_stream_get_volume(pools[idx], stream_idx, &volume);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_stream_get_volume(pool, %zu, volume) "
+ "returned %s value, volume is %f", stream_idx,
+ __stringify_sound_pool_error(ret), volume);
+ else
+ _logger_log_err("sound_pool_stream_get_volume(pool, %zu, volume) "
+ "returned %s value, volume is %f", stream_idx,
+ __stringify_sound_pool_error(ret), volume);
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_SET_STREAM_LOOP */
+static int __proxy_sound_pool_stream_set_loop(const char *pars)
+{
+ size_t idx = 0;
+ size_t stream_idx = 0;
+ int loop_val = 1;
+
+ if ((pars == NULL)
+ || (sscanf(pars, " %zu %zu %i", &idx, &stream_idx, &loop_val) < 3)) {
+ _printf(CMD_COLOR_RED, "You have to specify all following parameters: "
+ "pool identifier, stream identifier, and loop number! Format: "
+ CMD_SET_STREAM_LOOP " <pool id> <stream id> <loop num>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool with specified identifier is NULL");
+
+ if (loop_val < 0)
+ _logger_log_warn("Loop number should to be greater than 0, but it's"
+ "value is %i", loop_val);
+
+ _logger_log_info(CMD_SET_STREAM_LOOP " command was called");
+
+ int ret = sound_pool_stream_set_loop(pools[idx], stream_idx, loop_val);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_stream_set_loop(pool, %zu, %i) "
+ "returned %s value", stream_idx, loop_val,
+ __stringify_sound_pool_error(ret));
+ else
+ _logger_log_err("sound_pool_stream_set_loop(pool, %zu, %i) "
+ "returned %s value", stream_idx, loop_val,
+ __stringify_sound_pool_error(ret));
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_GET_STREAM_LOOP */
+static int __proxy_sound_pool_stream_get_loop(const char *pars)
+{
+ size_t idx = 0;
+ size_t stream_idx = 0;
+ if ((pars == NULL) || (sscanf(pars, " %zu %zu", &idx, &stream_idx) < 2)) {
+ _printf(CMD_COLOR_RED, "You have to specify both pool and stream "
+ "identifiers after command name! Format: "
+ CMD_GET_STREAM_LOOP " <pool id> <stream id>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ _logger_log_info(CMD_GET_STREAM_LOOP " command was called");
+ _logger_log_info("Getting the stream state by %zu identifier in %zu "
+ "pool...", stream_idx, idx);
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool where stream should be located is NULL");
+
+ unsigned loop = 0;
+ int ret = sound_pool_stream_get_loop(pools[idx], stream_idx, &loop);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_stream_get_loop(pool, %zu, loop) "
+ "returned %s value, loop value is %i", stream_idx,
+ __stringify_sound_pool_error(ret), loop);
+ else
+ _logger_log_err("sound_pool_stream_get_loop(pool, %zu, loop) "
+ "returned %s value, loop value is %i", stream_idx,
+ __stringify_sound_pool_error(ret), loop);
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_SET_STREAM_PRIORITY */
+static int __proxy_sound_pool_stream_set_priority(const char *pars)
+{
+ size_t idx = 0;
+ size_t stream_idx = 0;
+ int rank_val = 0;
+
+ if ((pars == NULL)
+ || (sscanf(pars, " %zu %zu %i", &idx, &stream_idx, &rank_val) < 3)) {
+ _printf(CMD_COLOR_RED, "You have to specify all following parameters: "
+ "pool identifier, stream identifier, and priority rank! Format: "
+ CMD_SET_STREAM_PRIORITY " <pool id> <stream id> <rank>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool with specified identifier is NULL");
+
+ if (rank_val < 0)
+ _logger_log_warn("Priority rank should to be greater or equal 0, but "
+ "it's value is %i", rank_val);
+
+ _logger_log_info(CMD_SET_STREAM_PRIORITY " command was called");
+
+ int ret = sound_pool_stream_set_priority(pools[idx], stream_idx, rank_val);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_stream_set_priority(pool, %zu, %i) "
+ "returned %s value", stream_idx, rank_val,
+ __stringify_sound_pool_error(ret));
+ else
+ _logger_log_err("sound_pool_stream_set_priority(pool, %zu, %i) "
+ "returned %s value", stream_idx, rank_val,
+ __stringify_sound_pool_error(ret));
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_GET_STREAM_PRIORITY */
+static int __proxy_sound_pool_stream_get_priority(const char *pars)
+{
+ size_t idx = 0;
+ size_t stream_idx = 0;
+ if ((pars == NULL) || (sscanf(pars, " %zu %zu", &idx, &stream_idx) < 2)) {
+ _printf(CMD_COLOR_RED, "You have to specify both pool and stream "
+ "identifiers after command name! Format: "
+ CMD_GET_STREAM_PRIORITY " <pool id> <stream id>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ _logger_log_info(CMD_GET_STREAM_PRIORITY " command was called");
+ _logger_log_info("Getting the stream priority rank by %zu identifier in "
+ "%zu pool...", stream_idx, idx);
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool where stream should be located is NULL");
+
+ unsigned rank = 0;
+ int ret = sound_pool_stream_get_priority(pools[idx], stream_idx, &rank);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_stream_get_priority(pool, %zu, rank) "
+ "returned %s value, rank value is %i", stream_idx,
+ __stringify_sound_pool_error(ret), rank);
+ else
+ _logger_log_err("sound_pool_stream_get_priority(pool, %zu, rank) "
+ "returned %s value, rank value is %i", stream_idx,
+ __stringify_sound_pool_error(ret), rank);
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_GET_STREAM_STATE */
+static int __proxy_sound_pool_get_stream_state(const char *pars)
+{
+ size_t idx = 0;
+ size_t stream_idx = 0;
+ if ((pars == NULL) || (sscanf(pars, " %zu %zu", &idx, &stream_idx) < 2)) {
+ _printf(CMD_COLOR_RED, "You have to specify both pool and stream "
+ "identifiers after command name! Format: "
+ CMD_GET_STREAM_STATE " <pool id> <stream id>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ _logger_log_info(CMD_GET_STREAM_STATE " command was called");
+ _logger_log_info("Getting the stream state by %zu identifier in %zu "
+ "pool...", stream_idx, idx);
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool where stream should be located is NULL");
+
+ sound_pool_stream_state_e state = SOUND_POOL_STREAM_STATE_NONE;
+ int ret = sound_pool_stream_get_state(pools[idx], stream_idx, &state);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_get_stream_state(pool, %zu, state) "
+ "returned %s value, state is %s", stream_idx,
+ __stringify_sound_pool_error(ret),
+ __stringify_stream_state(state));
+ else
+ _logger_log_err("sound_pool_get_stream_state(pool, %zu, state) "
+ "returned %s value, state is %s", stream_idx,
+ __stringify_sound_pool_error(ret),
+ __stringify_stream_state(state));
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_SET_STREAM_CB_MSG */
+static int __proxy_sound_pool_set_stream_state_change_callback_message(const char *pars)
+{
+ size_t idx = 0;
+ size_t stream_idx = 0;
+
+ char msg[MAX_MSG_LEN] = { '\0' };
+
+ if ((pars == NULL) || sscanf(pars, " %zu %zu %"MAX_MSG_LEN_STR"[^ ]",
+ &idx, &stream_idx, msg) < 3) {
+ _printf(CMD_COLOR_RED, "You have to specify both identifier of the "
+ "pool and stream, plus message to be shown each time when "
+ "state of the stream is changed! Message should be a single "
+ "word. Format: "
+ CMD_SET_STREAM_CB_MSG " <pool id> <stream id> <message>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ if (stream_idx > (MAX_STREAM_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Stream identifier value can't be greater than %d\n",
+ MAX_STREAM_CNT - 1);
+ return FAIL;
+ }
+
+ _logger_log_info(CMD_SET_STREAM_CB_MSG " command was called");
+ _logger_log_info("Set state changing callback (%s message) for stream %zu "
+ "in pool with %zu identifier...", msg, stream_idx, idx);
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool with stream to set callback for is NULL");
+
+ if (stream_messages[idx][stream_idx])
+ free(stream_messages[idx][stream_idx]);
+ stream_messages[idx][stream_idx] = strndup(msg, MAX_MSG_LEN);
+
+ int ret = sound_pool_stream_set_state_change_callback(pools[idx], stream_idx,
+ __s_cb_msg, stream_messages[idx][stream_idx]);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_set_stream_state_change_callback(pool, "
+ "%zu, cb, \"%s\") returned %s value", stream_idx, msg,
+ __stringify_sound_pool_error(ret));
+ else
+ _logger_log_err("sound_pool_set_stream_state_change_callback(pool, "
+ "%zu, cb, \"%s\") returned %s value", stream_idx, msg,
+ __stringify_sound_pool_error(ret));
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_SET_STREAM_CB_SCRIPT */
+static int __proxy_sound_pool_set_stream_state_change_callback_script(const char *pars)
+{
+ size_t idx = 0;
+ size_t stream_idx = 0;
+
+ char scr[MAX_MSG_LEN] = { '\0' };
+
+ if ((pars == NULL) || sscanf(pars, " %zu %zu %"MAX_MSG_LEN_STR"[^ ]",
+ &idx, &stream_idx, scr) < 3) {
+ _printf(CMD_COLOR_RED, "You have to specify both identifier of the "
+ "pool and stream, plus file with script to be executed each "
+ "time when state of the stream is changed! Message should be a "
+ "single word. Format: " CMD_SET_STREAM_CB_SCRIPT
+ " <pool id> <stream id> <script file>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ if (stream_idx > (MAX_STREAM_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Stream identifier value can't be greater than %d\n",
+ MAX_STREAM_CNT - 1);
+ return FAIL;
+ }
+
+ _logger_log_info(CMD_SET_STREAM_CB_SCRIPT " command was called");
+ _logger_log_info("Set state changing callback (%s script) for stream %zu "
+ "in pool with %zu identifier...", scr, stream_idx, idx);
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool with stream to set callback for is NULL");
+
+ if (stream_scripts[idx][stream_idx])
+ free(stream_scripts[idx][stream_idx]);
+ stream_scripts[idx][stream_idx] = strndup(scr, MAX_MSG_LEN);
+
+ int ret = sound_pool_stream_set_state_change_callback(pools[idx], stream_idx,
+ __s_cb_scr, stream_scripts[idx][stream_idx]);
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_set_stream_state_change_callback(pool, "
+ "%zu, cb, \"%s\") returned %s value", stream_idx, scr,
+ __stringify_sound_pool_error(ret));
+ else
+ _logger_log_err("sound_pool_set_stream_state_change_callback(pool, "
+ "%zu, cb, \"%s\") returned %s value", stream_idx, scr,
+ __stringify_sound_pool_error(ret));
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_UNSET_STREAM_CB */
+static int __proxy_sound_pool_unset_stream_state_change_callback(const char *pars)
+{
+ size_t idx = 0;
+ size_t stream_idx = 0;
+ if ((pars == NULL) || (sscanf(pars, " %zu %zu", &idx, &stream_idx) < 2)) {
+ _printf(CMD_COLOR_RED, "You have to specify both identifier of the "
+ " pool and stream! Format: " CMD_UNSET_STREAM_CB
+ " <pool id> <stream id>\n");
+ return FAIL;
+ }
+
+ if (idx > (MAX_POOL_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Pool identifier value can't be greater than %d\n",
+ MAX_POOL_CNT - 1);
+ return FAIL;
+ }
+
+ _logger_log_info(CMD_UNSET_STREAM_CB " command was called");
+ _logger_log_info("Unset state changing callback for the stream %zu in pool "
+ "with %zu identifier...", stream_idx, idx);
+
+ if (pools[idx] == NULL)
+ _logger_log_warn("Pool to unset callback for is NULL");
+
+ int ret = sound_pool_stream_unset_state_change_callback(pools[idx], stream_idx);
+
+ if (stream_idx > (MAX_STREAM_CNT - 1)) {
+ _printf(CMD_COLOR_RED, "Stream identifier value can't be greater than %d\n",
+ MAX_STREAM_CNT - 1);
+ return FAIL;
+ }
+
+ if (stream_messages[idx][stream_idx] != NULL)
+ free(stream_messages[idx][stream_idx]);
+ stream_messages[idx][stream_idx] = NULL;
+
+ if (stream_scripts[idx][stream_idx] != NULL)
+ free(stream_scripts[idx][stream_idx]);
+ stream_scripts[idx][stream_idx] = NULL;
+
+ if (ret == SOUND_POOL_ERROR_NONE)
+ _logger_log_info("sound_pool_unset_stream_state_change_callback(pool, "
+ "%zu) returned %s value", stream_idx,
+ __stringify_sound_pool_error(ret));
+ else
+ _logger_log_info("sound_pool_unset_stream_state_change_callback(pool, "
+ "%zu) returned %s value", stream_idx,
+ __stringify_sound_pool_error(ret));
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_SLEEP */
+static int __proxy_sleep(const char *pars)
+{
+ int ret = SOUND_POOL_ERROR_NONE;
+
+ useconds_t stime = 0;
+
+ if ((pars == NULL) || (sscanf(pars, " %u", &stime) < 1)) {
+ _printf(CMD_COLOR_RED, "You have to specify number of milliseconds "
+ "for the pause duration! Format: " CMD_SLEEP " <millisecs>\n");
+ return FAIL;
+ }
+
+ _logger_log_info(CMD_SLEEP " command was called");
+ _logger_log_info("Start main thread sleep for %u milliseconds...", stime);
+ stime *= MICROSECS_PER_MILLISEC;
+ usleep(stime);
+ _logger_log_info("Main thread sleep has been finished...", stime);
+
+ return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
+}
+
+/* CMD_EXECUTE_SCRIPT */
+static int __proxy_sound_pool_execute_script(const char *pars)
+{
+ char script_file[MAX_PATH_LEN] = {'\0'};
+
+ if ((pars == NULL) || (sscanf(pars, " %"MAX_PATH_LEN_STR"[^ ]", script_file) < 1)) {
+ _printf(CMD_COLOR_RED, "You have to specify script file name to be "
+ "executed after command name! Format: " CMD_EXECUTE_SCRIPT " "
+ "<script file>\n");
+ return FAIL;
+ }
+
+ _logger_log_info(CMD_EXECUTE_SCRIPT " command was called");
+ _logger_log_info("Loading script from file...");
+ FILE *fd = fopen(script_file, "r");
+
+ if (fd) {
+ _logger_log_info("File has been loaded...");
+ _logger_log_info("Reading lines...");
+ size_t line_len = 0;
+ char *line = NULL;
+ while ((line_len = getline(&line, &line_len, fd)) != -1) {
+ line[strnlen(line, MAX_COMMAND_LINE_LEN) - 1] = '\0';
+ _logger_log_info("Executing line: %s", line);
+ if (_exec_cmd(line) != OK)
+ _logger_log_warn("Unknown or unsupported command! "
+ "Line was skipped.");
+ }
+ _logger_log_info("Lines were read...");
+ } else {
+ _logger_log_err("File wasn't loaded...");
+ return FAIL;
+ }
+
+ _logger_log_info("Close file...");
+
+ if (fd)
+ fclose(fd);
+
+ return OK;
+}
+
+/* Number of parameters supported by each command */
+static int cmd_pars[MAX_COMMAND_LINE_LEN] = { /* CMD_EXIT */ 0,
+ /* CMD_HELP */ 0, /* CMD_CREATE_POOL */ 1, /* CMD_DESTROY_POOL */ 1,
+ /* CMD_ACTIVATE_POOL */ 1, /* CMD_DEACTIVATE_POOL */ 1,
+ /* CMD_GET_POOL_STATE */ 1, /* CMD_SET_POOL_VOLUME */ 2,
+ /* CMD_GET_POOL_VOLUME */ 2, /* CMD_SET_POOL_CB_MSG */ 2,
+ /* CMD_SET_POOL_CB_SCRIPT */ 2, /* CMD_UNSET_POOL_CB */ 1,
+ /* CMD_LIST_POOL */ 0, /* CMD_LOAD_SOURCE */ 3,
+ /* CMD_LOAD_MEDIA_PACKAGE */ 3, /* CMD_UNLOAD_SOURCE */ 2,
+ /* CMD_PLAY_STREAM */ 5, /* CMD_STOP_STREAM */ 2,
+ /* CMD_PAUSE_STREAM */ 2, /* CMD_RESUME_STREAM */ 2,
+ /* CMD_SET_STREAM_VOLUME */ 3, /* CMD_GET_STREAM_VOLUME */ 2,
+ /* CMD_SET_STREAM_LOOP */ 3, /* CMD_GET_STREAM_LOOP */ 2,
+ /* CMD_SET_STREAM_PRIORITY */ 3, /* CMD_GET_STREAM_PRIORITY */ 2,
+ /* CMD_GET_STREAM_STATE */ 2, /* CMD_SET_STREAM_CB_MSG */ 3,
+ /* CMD_SET_STREAM_CB_SCRIPT */ 3, /* CMD_UNSET_STREAM_CB */ 2,
+ /* CMD_EXECUTE_SCRIPT */ 1, /* CMD_SLEEP */ 1 };
+
+/* Command -> Function mapping */
+static int (*cmd_fcns[MAX_COMMAND_LINE_LEN])() = {
+ /* CMD_EXIT */ __exit,
+ /* CMD_HELP */ __print_cmd_help_msg,
+ /* CMD_CREATE_POOL */ __proxy_sound_pool_create,
+ /* CMD_DESTROY_POOL */ __proxy_sound_pool_destroy,
+ /* CMD_ACTIVATE_POOL */ __proxy_sound_pool_activate,
+ /* CMD_DEACTIVATE_POOL */ __proxy_sound_pool_deactivate,
+ /* CMD_GET_POOL_STATE */ __proxy_sound_pool_get_state,
+ /* CMD_SET_POOL_VOLUME */ __proxy_sound_pool_set_volume,
+ /* CMD_GET_POOL_VOLUME */ __proxy_sound_pool_get_volume,
+ /* CMD_SET_POOL_CB_MSG */ __proxy_sound_pool_set_state_change_callback_message,
+ /* CMD_SET_POOL_CB_SCRIPT */ __proxy_sound_pool_set_state_change_callback_script,
+ /* CMD_UNSET_POOL_CB */ __proxy_sound_pool_unset_state_change_callback,
+ /* CMD_LIST_POOL */ __proxy_sound_pool_list,
+ /* CMD_LOAD_SOURCE */ __proxy_sound_pool_load_source_from_file,
+ /* CMD_LOAD_MEDIA_PACKAGE */ NULL,
+ /* CMD_UNLOAD_SOURCE */ __proxy_sound_pool_unload_source,
+ /* CMD_PLAY_STREAM */ __proxy_sound_pool_play_stream,
+ /* CMD_STOP_STREAM */ __proxy_sound_pool_stop_stream,
+ /* CMD_PAUSE_STREAM */ __proxy_sound_pool_pause_stream,
+ /* CMD_RESUME_STREAM */ __proxy_sound_pool_resume_stream,
+ /* CMD_SET_STREAM_VOLUME */ __proxy_sound_pool_stream_set_volume,
+ /* CMD_GET_STREAM_VOLUME */ __proxy_sound_pool_stream_get_volume,
+ /* CMD_SET_STREAM_LOOP */ __proxy_sound_pool_stream_set_loop,
+ /* CMD_GET_STREAM_LOOP */ __proxy_sound_pool_stream_get_loop,
+ /* CMD_SET_STREAM_PRIORITY */ __proxy_sound_pool_stream_set_priority,
+ /* CMD_GET_STREAM_PRIORITY */ __proxy_sound_pool_stream_get_priority,
+ /* CMD_GET_STREAM_STATE */ __proxy_sound_pool_get_stream_state,
+ /* CMD_SET_STREAM_CB_MSG */ __proxy_sound_pool_set_stream_state_change_callback_message,
+ /* CMD_SET_STREAM_CB_SCRIPT */ __proxy_sound_pool_set_stream_state_change_callback_script,
+ /* CMD_UNSET_STREAM_CB */ __proxy_sound_pool_unset_stream_state_change_callback,
+ /* CMD_EXECUTE_SCRIPT */ __proxy_sound_pool_execute_script,
+ /* CMD_SLEEP */ __proxy_sleep };
+
+int _exec_cmd(const char *cmd_line)
+{
+ /* User just pressed enter: */
+ if (strlen(cmd_line) == 0) return OK;
+
+ size_t trim_len = 0;
+ while((cmd_line + trim_len)[0] == ' ')
+ trim_len++;
+
+ char *cmd = cmd_line + trim_len;
+
+ /* Macro for checking command correctness */
+# define CHECK_CMD(ccmd, line) \
+ (strncmp(ccmd, line, strnlen(ccmd, MAX_COMMAND_LINE_LEN)) == 0)
+
+ int idx = 0;
+ for (; idx < CMD_COUNT; ++idx) {
+ if (CHECK_CMD(cmd_list[idx], cmd)) {
+ if (cmd_pars[idx] > 0) {
+ if (cmd_fcns[idx])
+ return cmd_fcns[idx](cmd + strlen(cmd_list[idx]));
+ } else {
+ return cmd_fcns[idx]();
+ }
+ }
+ }
+
+ return UCMD;
+}