4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungbae Shin <seungbae.shin@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
30 #include <semaphore.h>
35 #define KEYTONE_PATH "/tmp/keytone" /* Keytone pipe path */
36 #define FILE_FULL_PATH 1024 /* File path lenth */
38 #define RETRY_INTERVAL_USEC 50000
40 #define ROLE_NAME_LEN 64 /* Role name length */
41 #define VOLUME_GAIN_TYPE_LEN 64 /* Volume gain type length */
44 char filename[FILE_FULL_PATH];
45 char role[ROLE_NAME_LEN];
46 char volume_gain_type[VOLUME_GAIN_TYPE_LEN];
49 #define MMSOUND_STRNCPY(dst, src, size) \
51 if (src != NULL && dst != NULL && size > 0) { \
52 strncpy(dst, src, size - 1); \
53 dst[size - 1] = '\0'; \
54 } else if (dst == NULL) { \
55 debug_error("STRNCPY ERROR: Destination String is NULL"); \
57 else if (size <= 0) { \
58 debug_error("STRNCPY ERROR: Destination String is NULL"); \
61 debug_error("STRNCPY ERROR: Destination String is NULL"); \
65 static void unlink_if_symbolic_link(const char *path)
68 char *resolved_path = NULL;
73 /* return if it does not exist */
74 if ((ret = access(path, F_OK)))
77 if ((resolved_path = realpath(path, NULL))) {
78 /* assume that the path paramether is an absolute path */
79 if (strcmp(path, resolved_path)) {
80 debug_warning("unexpected symbolic link!, unlink the symbolic link(%s) to the resolved path(%s)", path, resolved_path);
86 strerror_r(errno, str_error, sizeof(str_error));
87 debug_warning("failed to realpath() for path:%s, err:%s", path, str_error);
92 int mm_sound_boot_ready(int timeout_sec)
97 debug_msg("[BOOT] check for sync....");
98 if ((sem = sem_open("booting-sound", O_CREAT, 0660, 0)) == SEM_FAILED) {
99 debug_error("error creating sem : %d", errno);
103 debug_msg("[BOOT] start to wait ready....timeout is set to %d sec", timeout_sec);
104 clock_gettime(CLOCK_REALTIME, &ts);
105 ts.tv_sec += timeout_sec;
107 if (sem_timedwait(sem, &ts) == -1) {
108 if (errno == ETIMEDOUT)
109 debug_warning("[BOOT] timeout!");
111 debug_msg("[BOOT] ready wait success!!!!");
119 int mm_sound_boot_play_sound(char* path)
124 ipc_t data = { { 0, }, { 0, }, { 0, } };
126 debug_msg("[BOOT] play boot sound [%s]!!!!", path);
128 return MM_ERROR_SOUND_INVALID_FILE;
130 /* Check whether file exists */
131 fd = open(path, O_RDONLY);
135 strerror_r(errsv, str_error, sizeof(str_error));
136 debug_error("file open failed with [%s][%d]", str_error, errsv);
139 return MM_ERROR_SOUND_FILE_NOT_FOUND;
141 return MM_ERROR_SOUND_INTERNAL;
147 unlink_if_symbolic_link(KEYTONE_PATH);
149 fd = open(KEYTONE_PATH, O_WRONLY | O_NONBLOCK);
151 debug_error("Fail to open pipe");
152 return MM_ERROR_SOUND_FILE_NOT_FOUND;
155 MMSOUND_STRNCPY(data.filename, path, FILE_FULL_PATH);
156 MMSOUND_STRNCPY(data.role, "system", ROLE_NAME_LEN);
157 MMSOUND_STRNCPY(data.volume_gain_type, "booting", VOLUME_GAIN_TYPE_LEN);
159 debug_msg("filepath=[%s], role=[%s], volume_gain_type=[%s]", data.filename, data.role, data.volume_gain_type);
160 size = sizeof(ipc_t);
163 err = write(fd, &data, size);
166 strerror_r(errno, str_error, sizeof(str_error));
167 debug_error("Fail to write data: [%s][%d]", str_error, errno);
169 return MM_ERROR_SOUND_INTERNAL;
174 return MM_ERROR_NONE;