#include "include/mm_sound_common.h"
#include "include/mm_sound_focus_socket.h"
-#define FILL_SOCKET_PARAM(x_param, x_func_name, x_instance, x_id, x_focus_type, x_option, x_ext_info, x_is_in_thread, x_is_for_session) \
+#define _FILL_SOCKET_PARAM(x_param, x_func_name, x_pid) \
do { \
MMSOUND_STRNCPY(x_param.func_name, x_func_name, MM_SOUND_NAME_NUM); \
- x_param.pid = x_instance; \
+ x_param.pid = x_pid; \
+} while (0) \
+
+#define _FILL_SOCKET_PARAM_WITH_HANDLE(x_param, x_func_name, x_pid, x_id) \
+do { \
+ _FILL_SOCKET_PARAM(x_param, x_func_name, x_pid); \
x_param.handle_id = x_id; \
+} while (0) \
+
+#define FILL_SOCKET_PARAM_REGISTER(x_param, x_func_name, x_pid, x_stream_type) \
+do { \
+ _FILL_SOCKET_PARAM(x_param, x_func_name, x_pid); \
+ MMSOUND_STRNCPY(x_param.stream_type, x_stream_type, MM_SOUND_NAME_NUM); \
+} while (0) \
+
+#define FILL_SOCKET_PARAM_UNREGISTER(x_param, x_func_name, x_pid, x_id) \
+do { \
+ _FILL_SOCKET_PARAM_WITH_HANDLE(x_param, x_func_name, x_pid, x_id); \
+} while (0) \
+
+#define FILL_SOCKET_PARAM_ADD_WATCH(x_param, x_func_name, x_pid, x_focus_type) \
+do { \
+ _FILL_SOCKET_PARAM(x_param, x_func_name, x_pid); \
x_param.focus_type = x_focus_type; \
- x_param.option = x_option; \
- MMSOUND_STRNCPY(x_param.ext_info, x_ext_info, MM_SOUND_NAME_NUM); \
- x_param.is_in_thread = x_is_in_thread; \
- x_param.is_for_session = x_is_for_session; \
-} while(0) \
+} while (0) \
-static int _convert_error_from_string(const char *error_string)
-{
- int ret = MM_ERROR_NONE;
+#define FILL_SOCKET_PARAM_REMOVE_WATCH(x_param, x_func_name, x_pid, x_id) \
+do { \
+ _FILL_SOCKET_PARAM_WITH_HANDLE(x_param, x_func_name, x_pid, x_id); \
+} while (0) \
- if (error_string == NULL) {
- debug_error("error_string is null");
- return MM_ERROR_INVALID_ARGUMENT;
- }
+#define FILL_SOCKET_PARAM_SET_REACQUISITION(x_param, x_func_name, x_pid, x_id, x_reacquisition) \
+do { \
+ _FILL_SOCKET_PARAM_WITH_HANDLE(x_param, x_func_name, x_pid, x_id); \
+ x_param.reacquisition = x_reacquisition; \
+} while (0) \
- if (!strncmp(error_string, FOCUS_ERROR_NONE, MAX_ERROR_LEN))
- ret = MM_ERROR_NONE;
- else if (!strncmp(error_string, FOCUS_ERROR_INVALID_PARAMETER, MAX_ERROR_LEN))
- ret = MM_ERROR_INVALID_ARGUMENT;
- else if (!strncmp(error_string, FOCUS_ERROR_POLICY, MAX_ERROR_LEN))
- ret = MM_ERROR_POLICY_BLOCKED;
- else if (!strncmp(error_string, FOCUS_ERROR_INVALID_STATE, MAX_ERROR_LEN))
- ret = MM_ERROR_SOUND_INVALID_STATE;
- else if (!strncmp(error_string, FOCUS_ERROR_INTERNAL, MAX_ERROR_LEN))
- ret = MM_ERROR_SOUND_INTERNAL;
- else
- ret = MM_ERROR_SOUND_INTERNAL;
+#define FILL_SOCKET_PARAM_DELIVER(x_param, x_func_name, x_pid, x_src_id, x_dst_id, x_focus_type) \
+do { \
+ _FILL_SOCKET_PARAM_WITH_HANDLE(x_param, x_func_name, x_pid, x_src_id); \
+ x_param.handle_id_dst = x_dst_id; \
+ x_param.focus_type = x_focus_type; \
+} while (0) \
- debug_msg("error_string[%s], ret[0x%x]", error_string, ret);
+#define FILL_SOCKET_PARAM_GET_ACQUIRED(x_param, x_func_name, x_focus_type) \
+do { \
+ MMSOUND_STRNCPY(x_param.func_name, x_func_name, MM_SOUND_NAME_NUM); \
+ x_param.focus_type = x_focus_type; \
+} while (0) \
- return ret;
-}
+#define FILL_SOCKET_PARAM(x_param, x_func_name, x_pid, x_id, x_focus_type, x_option, x_ext_info, x_is_in_thread) \
+do { \
+ _FILL_SOCKET_PARAM_WITH_HANDLE(x_param, x_func_name, x_pid, x_id); \
+ x_param.focus_type = x_focus_type; \
+ x_param.option = x_option; \
+ MMSOUND_STRNCPY(x_param.ext_info, x_ext_info, MM_SOUND_NAME_NUM); \
+ x_param.is_in_thread = x_is_in_thread; \
+} while (0) \
static int _get_client_socket_fd(int *fd)
{
return MM_ERROR_NONE;
}
-static int _send_data_to_server(int fd, _mm_sound_mgr_focus_socket_param_t *data)
+static int _send_data_to_server(int fd, _mm_sound_focus_socket_param_t *data, _mm_sound_focus_socket_result_t *result)
{
char str_error[MAX_ERROR_LEN] = {'\0',};
- char ret_buf[MAX_ERROR_LEN] = {'\0',};
int rval = 0;
if (fd < 0 || data == NULL) {
return MM_ERROR_INVALID_ARGUMENT;
}
- if (write(fd, data, sizeof(_mm_sound_mgr_focus_socket_param_t)) < 0) {
+ if (write(fd, data, sizeof(_mm_sound_focus_socket_param_t)) < 0) {
strerror_r(errno, str_error, sizeof(str_error));
debug_error("failed to write(), err: %s", str_error);
return MM_ERROR_SOUND_INTERNAL;
}
/* return message from server */
- if ((rval = read(fd, ret_buf, sizeof(ret_buf))) < 0) {
+ if ((rval = read(fd, result, sizeof(_mm_sound_focus_socket_result_t))) < 0) {
strerror_r(errno, str_error, sizeof(str_error));
debug_error("failed to read(), err: %s", str_error);
return MM_ERROR_SOUND_INTERNAL;
}
- debug_log("rval[%d], ret_buf[%s]", rval, ret_buf);
+ debug_log("func_name[%s], rval[%d], ret[0x%x]", data->func_name, rval, result->ret);
- return _convert_error_from_string(ret_buf);
+ return result->ret;
}
EXPORT_API
-int mm_sound_focus_socket_acquire(int instance, int id, mm_sound_focus_type_e focus_type, int option, const char *ext_info, bool is_in_thread, bool is_for_session)
+int mm_sound_focus_socket_register(int pid, const char *stream_type, int *client_fd, int *server_fd)
{
int ret = MM_ERROR_NONE;
- int fd = -1;
- _mm_sound_mgr_focus_socket_param_t data;
+ _mm_sound_focus_socket_param_t data;
+ _mm_sound_focus_socket_result_t result;
debug_fenter();
- if (instance <= 0 || id < 0 || option < 0) {
- debug_error("invalid parameter, instance[%d], id[%d], option[%d]", instance, id, option);
+ if (!stream_type || !client_fd || !server_fd)
return MM_ERROR_INVALID_ARGUMENT;
+
+ if ((ret = _get_client_socket_fd(client_fd))) {
+ debug_error("failed to _get_client_socket_fd()");
+ return MM_ERROR_SOUND_INTERNAL;
}
- if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
- debug_error("focus type[%d] is not valid", focus_type);
- return MM_ERROR_INVALID_ARGUMENT;
+ if ((ret = _connect_socket_fd(*client_fd))) {
+ debug_error("failed to _connect_socket_fd()");
+ close(*client_fd);
+ return MM_ERROR_SOUND_INTERNAL;
}
- if ((ret = _get_client_socket_fd(&fd))) {
+ /* get accepted fd from server */
+ memset(&data, 0x00, sizeof(_mm_sound_focus_socket_param_t));
+ memset(&result, 0x00, sizeof(_mm_sound_focus_socket_result_t));
+ FILL_SOCKET_PARAM_REGISTER(data, FOCUS_FUNC_NAME_REGISTER, pid, stream_type);
+ if ((ret = _send_data_to_server(*client_fd, &data, &result))) {
+ debug_error("failed to _send_data_to_server(), ret[0x%x]", ret);
+ close(*client_fd);
+ return ret;
+ }
+
+ debug_msg("CONNECTED : client fd[%d], server fd[%d]", *client_fd, result.handle_id);
+ *server_fd = result.handle_id;
+
+ debug_fleave();
+
+ return ret;
+}
+
+EXPORT_API
+int mm_sound_focus_socket_unregister(int pid, int client_fd, int server_fd)
+{
+ int ret = MM_ERROR_NONE;
+ _mm_sound_focus_socket_param_t data;
+ _mm_sound_focus_socket_result_t result;
+
+ debug_fenter();
+
+ debug_msg("DISCONNECTING : client fd[%d], server fd[%d]", client_fd, server_fd);
+
+ memset(&data, 0x00, sizeof(_mm_sound_focus_socket_param_t));
+ memset(&result, 0x00, sizeof(_mm_sound_focus_socket_result_t));
+ FILL_SOCKET_PARAM_UNREGISTER(data, FOCUS_FUNC_NAME_UNREGISTER, pid, server_fd);
+ if ((ret = _send_data_to_server(client_fd, &data, &result)))
+ debug_error("failed to _send_data_to_server(), ret[0x%x]", ret);
+
+ close(client_fd);
+
+ debug_fleave();
+
+ return ret;
+}
+
+EXPORT_API
+int mm_sound_focus_socket_add_watch_cb(int pid, mm_sound_focus_type_e focus_type, int *client_fd, int *server_fd)
+{
+ int ret = MM_ERROR_NONE;
+ _mm_sound_focus_socket_param_t data;
+ _mm_sound_focus_socket_result_t result;
+
+ debug_fenter();
+
+ if (!client_fd || !server_fd)
+ return MM_ERROR_INVALID_ARGUMENT;
+
+ if ((ret = _get_client_socket_fd(client_fd))) {
debug_error("failed to _get_client_socket_fd()");
return MM_ERROR_SOUND_INTERNAL;
}
- if ((ret = _connect_socket_fd(fd))) {
+ if ((ret = _connect_socket_fd(*client_fd))) {
debug_error("failed to _connect_socket_fd()");
- close(fd);
+ close(*client_fd);
return MM_ERROR_SOUND_INTERNAL;
}
- memset(&data, 0x00, sizeof(_mm_sound_mgr_focus_socket_param_t));
- FILL_SOCKET_PARAM(data, FOCUS_FUNC_NAME_ACQUIRE, instance, id, focus_type,
- option, ext_info, is_in_thread, is_for_session);
-
- if ((ret = _send_data_to_server(fd, &data))) {
+ /* get accepted fd from server */
+ memset(&data, 0x00, sizeof(_mm_sound_focus_socket_param_t));
+ memset(&result, 0x00, sizeof(_mm_sound_focus_socket_result_t));
+ FILL_SOCKET_PARAM_ADD_WATCH(data, FOCUS_FUNC_NAME_ADD_WATCH, pid, focus_type);
+ if ((ret = _send_data_to_server(*client_fd, &data, &result))) {
debug_error("failed to _send_data_to_server(), ret[0x%x]", ret);
- close(fd);
+ close(*client_fd);
return ret;
}
- close(fd);
+ debug_msg("ADDED WATCH CB : client fd[%d], server fd[%d]", *client_fd, result.handle_id);
+ *server_fd = result.handle_id;
debug_fleave();
- return MM_ERROR_NONE;
+ return ret;
+}
+
+EXPORT_API
+int mm_sound_focus_socket_remove_watch_cb(int pid, int client_fd, int server_fd)
+{
+ int ret = MM_ERROR_NONE;
+ _mm_sound_focus_socket_param_t data;
+ _mm_sound_focus_socket_result_t result;
+
+ debug_fenter();
+
+ debug_msg("REMOVING WATCH CB : client fd[%d], server fd[%d]", client_fd, server_fd);
+
+ memset(&data, 0x00, sizeof(_mm_sound_focus_socket_param_t));
+ memset(&result, 0x00, sizeof(_mm_sound_focus_socket_result_t));
+ FILL_SOCKET_PARAM_REMOVE_WATCH(data, FOCUS_FUNC_NAME_REMOVE_WATCH, pid, server_fd);
+ if ((ret = _send_data_to_server(client_fd, &data, &result)))
+ debug_error("failed to _send_data_to_server(), ret[0x%x]", ret);
+
+ close(client_fd);
+
+ debug_fleave();
+
+ return ret;
}
EXPORT_API
-int mm_sound_focus_socket_release(int instance, int id, mm_sound_focus_type_e focus_type, int option, const char *ext_info, bool is_in_thread, bool is_for_session)
+int mm_sound_focus_socket_acquire(int pid, int client_fd, int server_fd, mm_sound_focus_type_e focus_type, int option, const char *ext_info, bool is_in_thread)
{
int ret = MM_ERROR_NONE;
- int fd = -1;
- _mm_sound_mgr_focus_socket_param_t data;
+ _mm_sound_focus_socket_param_t data;
+ _mm_sound_focus_socket_result_t result;
debug_fenter();
- if (instance <= 0 || id < 0 || option < 0) {
- debug_error("invalid parameter, instance[%d], id[%d], option[%d]", instance, id, option);
+ if (pid <= 0 || client_fd < 0 || server_fd < 0 || option < 0) {
+ debug_error("invalid parameter, pid[%d], fd[%d/%d], option[%d]",
+ pid, client_fd, server_fd, option);
+ return MM_ERROR_INVALID_ARGUMENT;
+ }
+ if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
+ debug_error("focus type[%d] is not valid", focus_type);
+ return MM_ERROR_INVALID_ARGUMENT;
+ }
+
+ memset(&data, 0x00, sizeof(_mm_sound_focus_socket_param_t));
+ memset(&result, 0x00, sizeof(_mm_sound_focus_socket_result_t));
+ FILL_SOCKET_PARAM(data, FOCUS_FUNC_NAME_ACQUIRE, pid, server_fd, focus_type,
+ option, ext_info, is_in_thread);
+
+ if ((ret = _send_data_to_server(client_fd, &data, &result)))
+ debug_error("failed to _send_data_to_server(), ret[0x%x]", ret);
+
+ debug_fleave();
+
+ return ret;
+}
+
+EXPORT_API
+int mm_sound_focus_socket_release(int pid, int client_fd, int server_fd, mm_sound_focus_type_e focus_type, int option, const char *ext_info, bool is_in_thread)
+{
+ int ret = MM_ERROR_NONE;
+ _mm_sound_focus_socket_param_t data;
+ _mm_sound_focus_socket_result_t result;
+
+ debug_fenter();
+
+ if (pid <= 0 || client_fd < 0 || server_fd < 0 || option < 0) {
+ debug_error("invalid parameter, pid[%d], fd[%d/%d], option[%d]",
+ pid, client_fd, server_fd, option);
return MM_ERROR_INVALID_ARGUMENT;
}
if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
return MM_ERROR_INVALID_ARGUMENT;
}
+ memset(&data, 0x00, sizeof(_mm_sound_focus_socket_param_t));
+ memset(&result, 0x00, sizeof(_mm_sound_focus_socket_result_t));
+ FILL_SOCKET_PARAM(data, FOCUS_FUNC_NAME_RELEASE, pid, server_fd, focus_type,
+ option, ext_info, is_in_thread);
+
+ if ((ret = _send_data_to_server(client_fd, &data, &result)))
+ debug_error("failed to _send_data_to_server(), ret[0x%x]", ret);
+
+ debug_fleave();
+
+ return ret;
+}
+
+
+EXPORT_API
+int mm_sound_focus_socket_set_reacquisition(int pid, int client_fd, int server_fd, bool reacquisition)
+{
+ int ret = MM_ERROR_NONE;
+ _mm_sound_focus_socket_param_t data;
+ _mm_sound_focus_socket_result_t result;
+
+ debug_fenter();
+
+ if (pid <= 0 || client_fd < 0 || server_fd < 0) {
+ debug_error("invalid parameter, pid[%d], fd[%d/%d]", pid, client_fd, server_fd);
+ return MM_ERROR_INVALID_ARGUMENT;
+ }
+
+ memset(&data, 0x00, sizeof(_mm_sound_focus_socket_param_t));
+ memset(&result, 0x00, sizeof(_mm_sound_focus_socket_result_t));
+ FILL_SOCKET_PARAM_SET_REACQUISITION(data, FOCUS_FUNC_NAME_SET_REACQUISITION, pid, server_fd, reacquisition);
+
+ if ((ret = _send_data_to_server(client_fd, &data, &result)))
+ debug_error("failed to _send_data_to_server(), ret[0x%x]", ret);
+
+ debug_fleave();
+
+ return ret;
+}
+
+EXPORT_API
+int mm_sound_focus_socket_deliver(int pid, int src_client_fd, int src_server_fd, int dst_client_fd, int dst_server_fd, mm_sound_focus_type_e focus_type)
+{
+ int ret = MM_ERROR_NONE;
+ _mm_sound_focus_socket_param_t data;
+ _mm_sound_focus_socket_result_t result;
+
+ debug_fenter();
+
+ if (pid <= 0 || src_client_fd < 0 || src_server_fd < 0 || dst_client_fd < 0 || dst_server_fd < 0) {
+ debug_error("invalid parameter, pid[%d], src_fd[%d/%d], dst_fd[%d/%d]",
+ pid, src_client_fd, src_server_fd, dst_client_fd, dst_server_fd);
+ return MM_ERROR_INVALID_ARGUMENT;
+ }
+
+ memset(&data, 0x00, sizeof(_mm_sound_focus_socket_param_t));
+ memset(&result, 0x00, sizeof(_mm_sound_focus_socket_result_t));
+ FILL_SOCKET_PARAM_DELIVER(data, FOCUS_FUNC_NAME_DELIVER, pid, src_server_fd, dst_server_fd, focus_type);
+
+ if ((ret = _send_data_to_server(dst_client_fd, &data, &result)))
+ debug_error("failed to _send_data_to_server(), ret[0x%x]", ret);
+
+ debug_fleave();
+
+ return ret;
+}
+
+EXPORT_API
+int mm_sound_focus_socket_get_acquired_focus_stream_type(mm_sound_focus_type_e focus_type, char **stream_type, int *option, char **ext_info)
+{
+ int ret = MM_ERROR_NONE;
+ int fd = 0;
+ _mm_sound_focus_socket_param_t data;
+ _mm_sound_focus_socket_result_t result;
+
+ debug_fenter();
+
+ if (!stream_type) {
+ debug_error("invalid parameter, stream_type[%p]", stream_type);
+ return MM_ERROR_INVALID_ARGUMENT;
+ }
if ((ret = _get_client_socket_fd(&fd))) {
debug_error("failed to _get_client_socket_fd()");
return MM_ERROR_SOUND_INTERNAL;
return MM_ERROR_SOUND_INTERNAL;
}
- memset(&data, 0x00, sizeof(_mm_sound_mgr_focus_socket_param_t));
- FILL_SOCKET_PARAM(data, FOCUS_FUNC_NAME_RELEASE, instance, id, focus_type,
- option, ext_info, is_in_thread, is_for_session);
+ memset(&data, 0x00, sizeof(_mm_sound_focus_socket_param_t));
+ memset(&result, 0x00, sizeof(_mm_sound_focus_socket_result_t));
+ FILL_SOCKET_PARAM_GET_ACQUIRED(data, FOCUS_FUNC_NAME_GET_ACQUIRED_INFO, focus_type);
- if ((ret = _send_data_to_server(fd, &data))) {
- debug_error("failed to _send_data_to_server()");
+ if ((ret = _send_data_to_server(fd, &data, &result))) {
+ debug_error("failed to _send_data_to_server(), ret[0x%x]", ret);
close(fd);
- return MM_ERROR_SOUND_INTERNAL;
+ return ret;
}
+ debug_msg("stream_type[%s], option[%d], ext_info[%s]", result.stream_type, result.option, result.ext_info);
+
+ *stream_type = strdup(result.stream_type);
+ *ext_info = strdup(result.ext_info);
+ *option = result.option;
+
close(fd);
debug_fleave();