#define AUDIO_VOLUME_CONFIG_TYPE(vol) (vol & 0x00FF)
#define AUDIO_VOLUME_CONFIG_GAIN(vol) (vol & 0xFF00)
+#define MAX_WRITE_RETRY 50
+#define WRITE_RETRY_INTERVAL_MS 20
+
typedef struct ipc_data {
char filename[FILE_FULL_PATH];
char role[ROLE_NAME_LEN];
int ret = MM_ERROR_NONE;
const char *role = NULL;
const char *vol_gain_type = NULL;
+ int retry_remaining = MAX_WRITE_RETRY;
#ifdef USE_LWIPC
if (!_mm_sound_check_pa_ready()) {
if (!filename)
return MM_ERROR_SOUND_INVALID_FILE;
+ /* Check whether file exists */
+ if (access(filename, F_OK) == -1) {
+ char str_error[256];
+
+ strerror_r(errno, str_error, sizeof(str_error));
+ debug_error("file [%s] doesn't exists : [%s][%d]", filename, str_error, errno);
+
+ return MM_ERROR_SOUND_FILE_NOT_FOUND;
+ }
+
/* convert volume type to role/volume gain */
role = convert_volume_type_to_role(AUDIO_VOLUME_CONFIG_TYPE(volume_config));
if (role)
vol_gain_type = convert_volume_gain_type_to_string(AUDIO_VOLUME_CONFIG_GAIN(volume_config));
if (ipc_type == IPC_TYPE_PIPE) {
- int res = 0;
+ size_t size_to_write = sizeof(ipc_t);
+ ssize_t written = 0;
int fd = -1;
- int size = 0;
ipc_t data = { { 0, }, { 0, }, { 0, } };
- /* Check whether file exists */
- fd = open(filename, O_RDONLY);
- if (fd == -1) {
- char str_error[256];
- int errsv = errno;
- strerror_r(errsv, str_error, sizeof(str_error));
- debug_error("file open failed with [%s][%d]", str_error, errsv);
- switch (errsv) {
- case ENOENT:
- return MM_ERROR_SOUND_FILE_NOT_FOUND;
- default:
- return MM_ERROR_SOUND_INTERNAL;
- }
- }
- close(fd);
- fd = -1;
-
/* Open PIPE */
fd = open(KEYTONE_PATH, O_WRONLY | O_NONBLOCK);
if (fd == -1) {
- debug_error("Fail to open pipe");
- return MM_ERROR_SOUND_FILE_NOT_FOUND;
+ char str_error[256];
+
+ strerror_r(errno, str_error, sizeof(str_error));
+ debug_error("Fail to open pipe: [%s][%d]", str_error, errno);
+
+ return MM_ERROR_SOUND_INTERNAL;
}
/* convert volume type to role/volume gain */
if (role)
MMSOUND_STRNCPY(data.role, role, ROLE_NAME_LEN);
-
if (vol_gain_type)
MMSOUND_STRNCPY(data.volume_gain_type, vol_gain_type, VOLUME_GAIN_TYPE_LEN);
-
MMSOUND_STRNCPY(data.filename, filename, FILE_FULL_PATH);
debug_msg("filepath=[%s], role=[%s], volume_gain_type=[%s]", data.filename, data.role, data.volume_gain_type);
- size = sizeof(ipc_t);
/* Write to PIPE */
- res = write(fd, &data, size);
- if (res < 0) {
- char str_error[256];
- strerror_r(errno, str_error, sizeof(str_error));
- debug_error("Fail to write data: [%s][%d]", str_error, errno);
- ret = MM_ERROR_SOUND_INTERNAL;
- }
+ do {
+ written = write(fd, &data, size_to_write);
+ if (written == -1) {
+ char str_error[256];
+ int errsv = errno;
+
+ strerror_r(errsv, str_error, sizeof(str_error));
+ debug_error("[%d] Fail to write, written = %zd, [%s][%d]",
+ MAX_WRITE_RETRY - retry_remaining, written, str_error, errsv);
+
+ if (errsv != EAGAIN || --retry_remaining == 0) {
+ ret = MM_ERROR_SOUND_INTERNAL;
+ break;
+ }
+
+ usleep(WRITE_RETRY_INTERVAL_MS * 1000);
+ } else if (retry_remaining != MAX_WRITE_RETRY) {
+ debug_msg("retry success!!");
+ }
+ } while (written != size_to_write);
+
/* Close PIPE */
close(fd);