view src/cs/services/buzm/buzm_api.c @ 297:8dfdf88d632f

BUZM SWE initial implementation
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 29 Mar 2022 03:45:41 +0000
parents
children
line wrap: on
line source

/*
 * The implementation of our external API functions lives here.
 */

#include "buzm/buzm_api.h"
#include "buzm/buzm_env.h"
#include "buzm/buzm_messages_i.h"
#include "rv/rv_general.h"
#include "rvf/rvf_api.h"
#include "rvm/rvm_use_id_list.h"
#include "ffs/ffs_api.h"

T_RV_RET buzm_play_melody(const char *pathname, UINT8 volume, BOOL loop)
{
	struct buzm_start_msg *msg;
	T_FFS_FD fd;

	if (!buzm_env)
		return RV_NOT_READY;
	if (volume < BUZM_VOLUME_MIN || volume > BUZM_VOLUME_MAX)
		return RV_INVALID_PARAMETER;
	fd = ffs_open(pathname, FFS_O_RDONLY);
	if (fd <= 0)
		return RV_INVALID_PARAMETER;
	if (rvf_get_buf(buzm_env->prim_id, sizeof(struct buzm_start_msg),
			(T_RVF_BUFFER **)&msg) == RVF_RED) {
		rvf_send_trace(
			"rvf_get_buf() failed in buzm_play_melody()", 42,
			NULL_PARAM, RV_TRACE_LEVEL_ERROR, BUZM_USE_ID);
		ffs_close(fd);
		return RV_MEMORY_ERR;
	}
	msg->hdr.msg_id        = BUZM_START_REQ;
	msg->hdr.src_addr_id   = buzm_env->addr_id;
	msg->hdr.dest_addr_id  = buzm_env->addr_id;
	msg->hdr.callback_func = NULL;
	msg->fd = fd;
	msg->volume = volume;
	msg->loop = loop;
	if (rvf_send_msg(buzm_env->addr_id, msg) != RV_OK) {
		rvf_send_trace("buzm_play_melody(): Send failed!", 32,
				NULL_PARAM, RV_TRACE_LEVEL_ERROR, BUZM_USE_ID);
		rvf_free_buf(msg);
		ffs_close(fd);
		return RV_INTERNAL_ERR;
	}
	return RV_OK;
}

T_RV_RET buzm_stop_melody(void)
{
	struct buzm_stop_msg *msg;

	if (!buzm_env)
		return RV_NOT_READY;
	if (rvf_get_buf(buzm_env->prim_id, sizeof(struct buzm_stop_msg),
			(T_RVF_BUFFER **)&msg) == RVF_RED) {
		rvf_send_trace(
			"rvf_get_buf() failed in buzm_stop_melody()", 42,
			NULL_PARAM, RV_TRACE_LEVEL_ERROR, BUZM_USE_ID);
		return RV_MEMORY_ERR;
	}
	msg->hdr.msg_id        = BUZM_STOP_REQ;
	msg->hdr.src_addr_id   = buzm_env->addr_id;
	msg->hdr.dest_addr_id  = buzm_env->addr_id;
	msg->hdr.callback_func = NULL;
	if (rvf_send_msg(buzm_env->addr_id, msg) != RV_OK) {
		rvf_send_trace("buzm_stop_melody(): Send failed!", 32,
				NULL_PARAM, RV_TRACE_LEVEL_ERROR, BUZM_USE_ID);
		rvf_free_buf(msg);
		return RV_INTERNAL_ERR;
	}
	return RV_OK;
}