2 * audio-session-manager
4 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungbae Shin <seungbae.shin at samsung.com>, Sangchul Lee <sc11.lee at 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.
22 #define CONFIG_ENABLE_MULTI_INSTANCE
23 #define CONFIG_ENABLE_ASM_SERVER_USING_GLIB
24 #define CONFIG_ENABLE_SIGNAL_HANDLER
25 #define CONFIG_ENABLE_RETCB
26 #define MAKE_HANDLE_FROM_SERVER
32 #include <sys/syscall.h>
34 #include <sys/types.h>
46 #include <security-server.h>
49 #if defined(USE_VCONF)
53 #include <gconf/gconf.h>
54 #include <gconf/gconf-client.h>
55 #include <phonestatus.h>
58 #include "../include/audio-session-manager.h"
60 #define asmgettid() (long int)getpid()
61 #define ASM_HANDLE_MAX 256
63 #define NO_EINTR(stmt) while ((stmt) == -1 && errno == EINTR); /* sample code by THE LINUX PROGRAMMING INTERFACE */
65 int asm_register_instance_id;
71 ASM_msg_lib_to_asm_t asm_snd_msg;
72 ASM_msg_asm_to_lib_t asm_rcv_msg;
73 ASM_msg_asm_to_cb_t asm_cb_msg;
75 ASM_sound_cb_t asm_callback;
77 unsigned char str_pass[] = "< OK >";
78 unsigned char str_fail[] = "<FAIL>";
80 typedef gboolean (*gLoopPollHandler_t)(gpointer d);
84 ASM_sound_events_t sound_event;
85 GSourceFuncs* g_src_funcs;
88 ASM_sound_cb_t asm_callback;
97 ASM_sound_ino_t ASM_sound_handle[ASM_HANDLE_MAX];
99 static const char* ASM_sound_events_str[] =
106 "EXCLUSIVE_MMPLAYER",
107 "EXCLUSIVE_MMCAMCORDER",
110 "EXCLUSIVE_AVSYSTEM",
124 static const char* ASM_sound_cases_str[] =
128 "CASE_1PLAY_2ALTER_PLAY",
130 "CASE_1ALTER_PLAY_2PLAY",
133 "CASE_1VIRTUAL_2PLAY",
134 "CASE_1PLAY_2PLAY_MIX",
135 "CASE_RESOURCE_CHECK"
138 static const char* ASM_sound_state_str[] =
145 "STATE_PAUSE_BY_APP",
146 "STATE_ALTER_PLAYING"
150 * function prototypes
154 unsigned int ASM_all_sound_status;
156 void __asm_init_module(void);
157 void __asm_fini_module(void);
158 int __ASM_find_index(int handle);
160 bool __ASM_get_sound_state(unsigned int *all_sound_status, int *error_code)
164 if(vconf_get_int(SOUND_STATUS_KEY, &value)) {
165 debug_error("failed to vconf_get_int(SOUND_STATUS_KEY)");
166 *error_code = ERR_ASM_VCONF_ERROR;
169 debug_msg("All status(%#X)", value);
170 *all_sound_status = value;
171 ASM_all_sound_status = value;
176 bool __ASM_set_sound_state(ASM_sound_events_t sound_event, ASM_sound_states_t sound_state, int *error_code)
178 /* this function will deprecated */
179 debug_msg("Event(%s), State(%s)", ASM_sound_events_str[sound_event], ASM_sound_state_str[sound_state]);
184 gboolean __asm_fd_check(GSource * source)
188 debug_error("GSource is null");
191 fd_list = source->poll_fds;
195 temp = (GPollFD*)fd_list->data;
196 if (temp->revents & (POLLIN | POLLPRI))
198 fd_list = fd_list->next;
201 return FALSE; /* there is no change in any fd state */
205 gboolean __asm_fd_prepare(GSource *source, gint *timeout)
210 gboolean __asm_fd_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
216 gboolean asm_callback_handler( gpointer d)
218 GPollFD *data = (GPollFD*)d;
226 debug_error("GPollFd is null");
229 if (data->revents & (POLLIN | POLLPRI)) {
233 unsigned int sound_status_value;
234 ASM_sound_commands_t rcv_command;
235 ASM_cb_result_t cb_res = ASM_CB_RES_NONE;
238 count = read(data->fd, &buf, sizeof(int));
240 handle = (int)( buf & 0x0000ffff);
241 rcv_command = (ASM_sound_commands_t)((buf >> 16) & 0x0f);
242 event_src = (ASM_event_sources_t)((buf >> 24) & 0x0f);
244 asm_index = __ASM_find_index(handle);
245 if (asm_index == -1) {
246 debug_error("Can not find index");
250 tid = ASM_sound_handle[asm_index].asm_tid;
253 debug_msg("got and start CB : TID(%d), handle(%d) cmd(%d) event_src(%d)", tid, handle, rcv_command, event_src );
254 if (!__ASM_get_sound_state(&sound_status_value, &error_code)) {
255 debug_error("failed to __ASM_get_sound_state(), error(%d)", error_code);
257 switch (rcv_command) {
258 case ASM_COMMAND_PLAY:
259 case ASM_COMMAND_RESUME:
260 case ASM_COMMAND_PAUSE:
261 case ASM_COMMAND_STOP:
262 if (ASM_sound_handle[asm_index].asm_callback == NULL) {
263 debug_msg("callback is null..");
266 debug_msg("[CALLBACK(%p) START]",ASM_sound_handle[asm_index].asm_callback);
267 cb_res = (ASM_sound_handle[asm_index].asm_callback)(handle, event_src, rcv_command, sound_status_value, ASM_sound_handle[asm_index].cb_data);
268 debug_msg("[CALLBACK END]");
273 #ifdef CONFIG_ENABLE_RETCB
275 /* If command is other than RESUME, send return */
276 if (rcv_command != ASM_COMMAND_RESUME) {
280 char *filename2 = g_strdup_printf("/tmp/ASM.%d.%dr", ASM_sound_handle[asm_index].asm_tid, handle);
281 tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
284 strerror_r(errno, str_error, sizeof(str_error));
285 debug_error("[RETCB][Failed(May Server Close First)]tid(%d) fd(%d) %s errno=%d(%s)\n", tid, tmpfd, filename2, errno, str_error);
289 rett = write(tmpfd, &buf, sizeof(buf));
292 debug_msg("[RETCB] tid(%d) finishing CB (write=%d)\n", tid, rett);
294 debug_msg("[RETCB] No need to send return for RESUME command\n");
303 bool __ASM_add_sound_callback(int index, int fd, gushort events, gLoopPollHandler_t p_gloop_poll_handler )
305 GSource* g_src = NULL;
306 GSourceFuncs *g_src_funcs = NULL; /* handler function */
307 guint gsource_handle;
308 GPollFD *g_poll_fd = NULL; /* file descriptor */
310 /* 1. make GSource Object */
311 g_src_funcs = (GSourceFuncs *)g_malloc(sizeof(GSourceFuncs));
313 debug_error("g_malloc failed on g_src_funcs");
316 g_src_funcs->prepare = __asm_fd_prepare;
317 g_src_funcs->check = __asm_fd_check;
318 g_src_funcs->dispatch = __asm_fd_dispatch;
319 g_src_funcs->finalize = NULL;
320 g_src = g_source_new(g_src_funcs, sizeof(GSource));
322 debug_error("g_malloc failed on m_readfd");
325 ASM_sound_handle[index].asm_src = g_src;
326 ASM_sound_handle[index].g_src_funcs = g_src_funcs;
327 debug_msg(" g_malloc : g_src_funcs(%#X)", g_src_funcs);
329 /* 2. add file description which used in g_loop() */
330 g_poll_fd = (GPollFD *)g_malloc(sizeof(GPollFD));
332 debug_error("g_malloc failed on g_poll_fd");
336 g_poll_fd->events = events;
337 ASM_sound_handle[index].g_poll_fd = g_poll_fd;
338 debug_msg(" g_malloc : g_poll_fd(%#X)", g_poll_fd);
340 /* 3. combine g_source object and file descriptor */
341 g_source_add_poll(g_src, g_poll_fd);
342 gsource_handle = g_source_attach(g_src, NULL);
343 if (!gsource_handle) {
344 debug_error(" Failed to attach the source to context");
348 debug_msg(" g_source_add_poll : g_src_id(%d)", gsource_handle);
349 ASM_sound_handle[index].ASM_g_id = gsource_handle;
351 /* 4. set callback */
352 g_source_set_callback(g_src, p_gloop_poll_handler,(gpointer)g_poll_fd, NULL);
354 debug_msg(" g_source_set_callback : %d", errno);
359 bool __ASM_remove_sound_callback(int index, gushort events)
362 gboolean gret = TRUE;
364 GSourceFunc *g_src_funcs = ASM_sound_handle[index].g_src_funcs;
365 GPollFD *g_poll_fd = ASM_sound_handle[index].g_poll_fd; /* store file descriptor */
367 debug_error("g_poll_fd is null..");
371 g_poll_fd->fd = ASM_sound_handle[index].asm_fd;
372 g_poll_fd->events = events;
374 debug_msg(" g_source_remove_poll : fd(%d), event(%x)", g_poll_fd->fd, g_poll_fd->events);
375 g_source_remove_poll(ASM_sound_handle[index].asm_src, g_poll_fd);
376 debug_msg(" g_source_remove_poll : %d", errno);
378 gret = g_source_remove(ASM_sound_handle[index].ASM_g_id);
379 debug_msg(" g_source_remove : gret(%d)", gret);
381 debug_error("failed to g_source_remove(). ASM_g_id(%d)", ASM_sound_handle[index].ASM_g_id);
389 debug_msg(" g_free : g_src_funcs(%#X)", g_src_funcs);
394 debug_msg(" g_free : g_poll_fd(%#X)", g_poll_fd);
398 ASM_sound_handle[index].g_src_funcs = NULL;
399 ASM_sound_handle[index].g_poll_fd = NULL;
400 ASM_sound_handle[index].ASM_g_id = 0;
401 ASM_sound_handle[index].asm_src = NULL;
402 ASM_sound_handle[index].asm_callback = NULL;
407 int __ASM_find_index(int handle)
410 for(i = 0; i< ASM_HANDLE_MAX; i++) {
411 if (handle == ASM_sound_handle[i].handle) {
412 debug_msg("found index(%d) for handle(%d)", i, handle);
419 void __ASM_add_callback(int index)
421 if (!__ASM_add_sound_callback(index, ASM_sound_handle[index].asm_fd, (gushort)POLLIN | POLLPRI, asm_callback_handler)) {
422 debug_error("failed to __ASM_add_sound_callback()");
428 void __ASM_remove_callback(int index)
430 if (!__ASM_remove_sound_callback(index, (gushort)POLLIN | POLLPRI)) {
431 debug_error("failed to __ASM_remove_sound_callback()");
437 void __ASM_open_callback(int index)
441 debug_msg("index (%d)", index);
442 char *filename = g_strdup_printf("/tmp/ASM.%d.%d", ASM_sound_handle[index].asm_tid, ASM_sound_handle[index].handle);
444 if (mknod(filename, S_IFIFO|0666, 0)) {
445 debug_error("mknod() failure, errno(%d)", errno);
448 ASM_sound_handle[index].asm_fd = open( filename, O_RDWR|O_NONBLOCK);
449 if (ASM_sound_handle[index].asm_fd == -1) {
450 debug_error("%s : file open error(%d)", str_fail, errno);
452 debug_msg("%s : filename(%s), fd(%d)", str_pass, filename, ASM_sound_handle[index].asm_fd);
456 #ifdef CONFIG_ENABLE_RETCB
457 char *filename2 = g_strdup_printf("/tmp/ASM.%d.%dr", ASM_sound_handle[index].asm_tid, ASM_sound_handle[index].handle);
459 if (mknod(filename2, S_IFIFO | 0666, 0)) {
460 debug_error("mknod() failure, errno(%d)", errno);
469 void __ASM_close_callback(int index)
471 debug_msg("index (%d)", index);
472 if (ASM_sound_handle[index].asm_fd < 0) {
473 debug_error("%s : fd error.", str_fail);
475 char *filename = g_strdup_printf("/tmp/ASM.%d.%d", ASM_sound_handle[index].asm_tid, ASM_sound_handle[index].handle);
476 close(ASM_sound_handle[index].asm_fd);
477 if (remove(filename)) {
478 debug_error("remove() failure, filename(%s), errno(%d)", filename, errno);
480 debug_msg("%s : filename(%s), fd(%d)", str_pass, filename, ASM_sound_handle[index].asm_fd);
484 #ifdef CONFIG_ENABLE_RETCB
485 char *filename2 = g_strdup_printf("/tmp/ASM.%d.%dr", ASM_sound_handle[index].asm_tid, ASM_sound_handle[index].handle);
487 /* Defensive code - wait until callback timeout although callback is removed */
488 int buf = ASM_CB_RES_STOP;
491 tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
494 strerror_r(errno, str_error, sizeof(str_error));
495 debug_error("failed to open file(%s) (may server close first), tid(%d) fd(%d) %s errno=%d(%s)",
496 filename2, ASM_sound_handle[index].asm_tid, tmpfd, filename2, errno, str_error);
498 debug_msg("write ASM_CB_RES_STOP(tid:%d) for waiting server", ASM_sound_handle[index].asm_tid);
499 write(tmpfd, &buf, sizeof(buf));
503 if (remove(filename2)) {
504 debug_error("remove() failure, filename(%s), errno(%d)", filename2, errno);
511 bool __asm_construct_snd_msg(int asm_pid, int handle, ASM_sound_events_t sound_event,
512 ASM_requests_t request_id, ASM_sound_states_t sound_state, ASM_resource_t resource, int *error_code)
514 asm_snd_msg.instance_id = asm_pid;
516 asm_snd_msg.data.handle = handle;
517 asm_snd_msg.data.request_id = request_id;
518 asm_snd_msg.data.sound_event = sound_event;
519 asm_snd_msg.data.sound_state = sound_state;
520 asm_snd_msg.data.system_resource = resource;
522 debug_msg("tid=%ld,handle=%d,req=%d,evt=%d,state=%d,resource=%d", asm_snd_msg.instance_id, asm_snd_msg.data.handle,
523 asm_snd_msg.data.request_id, asm_snd_msg.data.sound_event, asm_snd_msg.data.sound_state, asm_snd_msg.data.system_resource);
524 debug_msg(" instance_id : %ld\n", asm_snd_msg.instance_id);
525 debug_msg(" handle : %d\n", asm_snd_msg.data.handle);
531 bool __ASM_init_msg(int *error_code)
533 asm_snd_msgid = msgget((key_t)2014, 0666);
534 asm_rcv_msgid = msgget((key_t)4102, 0666);
535 asm_cb_msgid = msgget((key_t)4103, 0666);
537 debug_msg("snd_msqid(%#X), rcv_msqid(%#X), cb_msqid(%#X)\n", asm_snd_msgid, asm_rcv_msgid, asm_cb_msgid);
539 if (asm_snd_msgid == -1 || asm_rcv_msgid == -1 || asm_cb_msgid == -1 ) {
540 *error_code = ERR_ASM_MSG_QUEUE_MSGID_GET_FAILED;
541 debug_error("failed to msgget with error(%d)",error_code);
548 void __ASM_init_callback(int index)
551 __ASM_open_callback(index);
552 __ASM_add_callback(index);
557 void __ASM_destroy_callback(int index)
560 __ASM_remove_callback(index);
561 __ASM_close_callback(index);
566 bool __ASM_set_cookie (unsigned char* cookie)
571 cookie_size = security_server_get_cookie_size();
572 if (cookie_size != COOKIE_SIZE) {
573 debug_error ("[Security] security_server_get_cookie_size(%d) != COOKIE_SIZE(%d)\n", cookie_size, COOKIE_SIZE);
577 retval = security_server_request_cookie (cookie, COOKIE_SIZE);
578 if (retval == SECURITY_SERVER_API_SUCCESS) {
579 debug_msg ("[Security] security_server_request_cookie() returns [%d]\n", retval);
582 debug_error ("[Security] security_server_request_cookie() returns [%d]\n", retval);
589 bool ASM_register_sound_ex (const int application_pid, int *asm_handle, ASM_sound_events_t sound_event, ASM_sound_states_t sound_state,
590 ASM_sound_cb_t callback, void *cb_data, ASM_resource_t mm_resource, int *error_code, int (*func)(void*,void*))
593 unsigned int sound_status_value;
598 unsigned int rcv_sound_status_value;
602 if (error_code==NULL) {
603 debug_error ("invalid parameter. error code is null");
607 if (sound_event< ASM_EVENT_SHARE_MMPLAYER || sound_event >= ASM_EVENT_MAX) {
608 *error_code = ERR_ASM_EVENT_IS_INVALID;
609 debug_error ("invalid sound event(%d)",sound_event);
613 for (index = 0; index < ASM_HANDLE_MAX; index++) {
614 if (ASM_sound_handle[index].is_used == false) {
619 if (index == ASM_HANDLE_MAX) {
620 *error_code = ERR_ASM_EVENT_IS_FULL;
621 debug_error ("local sound event is full(MAX)");
625 if (application_pid == -1) {
626 asm_pid = asmgettid();
627 } else if (application_pid > 2) {
628 asm_pid = application_pid;
630 *error_code = ERR_ASM_INVALID_PARAMETER;
631 debug_error ("invalid pid %d", application_pid);
635 ASM_sound_handle[index].sound_event = sound_event;
636 ASM_sound_handle[index].asm_tid = asm_pid;
638 debug_msg(" <<<< Event(%s), Tid(%d), Index(%d)", ASM_sound_events_str[sound_event], ASM_sound_handle[index].asm_tid, index);
640 if (!__ASM_init_msg(&error)) {
641 debug_error("failed to __ASM_init_msg(), error(%d)", error);
644 if (!__ASM_get_sound_state(&sound_status_value, error_code)) {
645 debug_error("failed to __ASM_get_sound_state(), error(%d)", *error_code);
648 /* If state is PLAYING, do set state immediately */
649 if (sound_state == ASM_STATE_PLAYING) {
650 debug_msg(" <<<< Event(%s), Tid(%d), State(PLAYING)", ASM_sound_events_str[sound_event], ASM_sound_handle[index].asm_tid);
651 if (!__ASM_set_sound_state(sound_event, ASM_STATE_PLAYING, error_code)) {
652 debug_error("failed to __ASM_set_sound_state(PLAYING), error(%d)", *error_code);
656 debug_msg(" <<<< Event(%s), Tid(%ld), State(WAITING)", ASM_sound_events_str[sound_event], asmgettid());
660 handle = -1; /* for register & get handle from server */
663 /* get cookie from security server */
664 if (__ASM_set_cookie (asm_snd_msg.data.cookie) == false) {
665 debug_error("failed to ASM_set_cookie()");
670 /* Construct msg to send -> send msg -> recv msg */
671 if (!__asm_construct_snd_msg(asm_pid, handle, sound_event, ASM_REQUEST_REGISTER, sound_state, mm_resource, error_code)) {
672 debug_error("failed to __asm_construct_snd_msg(), error(%d)", *error_code);
677 func ((void*)&asm_snd_msg, (void*)&asm_rcv_msg);
679 NO_EINTR(ret = msgsnd(asm_snd_msgid, (void *)&asm_snd_msg, sizeof(asm_snd_msg.data), 0));
681 *error_code = ERR_ASM_MSG_QUEUE_SND_ERROR;
682 debug_error("failed to msgsnd(%d,%s)", errno, strerror(errno));
685 NO_EINTR(ret = msgrcv(asm_rcv_msgid, (void *)&asm_rcv_msg, sizeof(asm_rcv_msg.data), asm_pid, 0));
687 *error_code = ERR_ASM_MSG_QUEUE_RCV_ERROR;
688 debug_error("failed to msgrcv(%d,%s)", errno, strerror(errno));
692 /* Construct msg to send -> send msg -> recv msg : end */
695 /* Check privilege first */
696 if (asm_rcv_msg.data.check_privilege == 0) {
697 debug_error("[Security] Check privilege from server Failed!!!");
698 *error_code = ERR_ASM_CHECK_PRIVILEGE_FAILED;
701 debug_msg ("[Security] Check privilege from server Success");
705 handle = asm_rcv_msg.data.alloc_handle; /* get handle from server */
707 debug_error("failed to create handle from server");
708 *error_code = ERR_ASM_HANDLE_IS_FULL;
712 ASM_sound_handle[index].handle = handle;
714 __ASM_init_callback(index);
716 /********************************************************************************************************/
717 switch (asm_rcv_msg.data.result_sound_command) {
718 case ASM_COMMAND_PAUSE:
719 case ASM_COMMAND_STOP:
720 if (handle == asm_rcv_msg.data.cmd_handle) {
722 __ASM_destroy_callback(index);
724 ASM_sound_handle[index].asm_fd = 0;
725 ASM_sound_handle[index].asm_tid = 0;
726 ASM_sound_handle[index].sound_event = ASM_EVENT_NONE;
727 ASM_sound_handle[index].is_used = false;
729 *error_code = ERR_ASM_POLICY_CANNOT_PLAY;
732 int action_index = 0;
734 if (!__ASM_get_sound_state(&rcv_sound_status_value, error_code)) {
735 debug_error("failed to __ASM_get_sound_state(), error(%d)", *error_code);
738 debug_msg("Callback : TID(%ld), handle(%d), command(%d)", asm_rcv_msg.instance_id, asm_rcv_msg.data.cmd_handle, asm_rcv_msg.data.result_sound_command);
739 action_index = __ASM_find_index(asm_rcv_msg.data.cmd_handle);
740 if (action_index == -1) {
741 debug_error("Can not find index of instance %ld, handle %d", asm_rcv_msg.instance_id, asm_rcv_msg.data.cmd_handle);
743 if (ASM_sound_handle[action_index].asm_callback!=NULL) {
744 ASM_sound_handle[action_index].asm_callback(asm_rcv_msg.data.cmd_handle, ASM_sound_handle[action_index].sound_event, asm_rcv_msg.data.result_sound_command, rcv_sound_status_value, ASM_sound_handle[action_index].cb_data);
746 debug_msg("null callback");
752 case ASM_COMMAND_PLAY:
753 case ASM_COMMAND_NONE:
754 case ASM_COMMAND_RESUME:
758 /********************************************************************************************************/
761 ASM_sound_handle[index].asm_callback = callback;
762 ASM_sound_handle[index].cb_data = cb_data;
763 ASM_sound_handle[index].is_used = true;
765 debug_msg(" >>>> Event(%s), Handle(%d), CBFuncPtr(%p)", ASM_sound_events_str[sound_event], handle, callback);
766 /* Add [out] param, asm_handle */
767 *asm_handle = handle;
776 bool ASM_register_sound (const int application_pid, int *asm_handle, ASM_sound_events_t sound_event, ASM_sound_states_t sound_state,
777 ASM_sound_cb_t callback, void *cb_data, ASM_resource_t mm_resource, int *error_code)
779 return ASM_register_sound_ex (application_pid, asm_handle, sound_event, sound_state, callback, cb_data, mm_resource, error_code, NULL);
784 bool ASM_change_callback(const int asm_handle, ASM_sound_events_t sound_event, ASM_sound_cb_t callback, void *cb_data, int *error_code)
788 if (error_code==NULL) {
789 debug_error ("invalid parameter. error code is null");
793 if (sound_event < ASM_EVENT_SHARE_MMPLAYER || sound_event >= ASM_EVENT_MAX) {
794 *error_code = ERR_ASM_EVENT_IS_INVALID;
795 debug_error ("invalid sound event(%d)",sound_event);
801 if (asm_handle < 0 || asm_handle >= ASM_SERVER_HANDLE_MAX) {
802 *error_code = ERR_ASM_POLICY_INVALID_HANDLE;
803 debug_error("invalid handle(%d). callback is not registered", asm_handle);
809 asm_index = __ASM_find_index(handle);
810 if (asm_index == -1) {
811 *error_code = ERR_ASM_POLICY_INVALID_HANDLE;
812 debug_error("Can not find index for handle %d", handle);
816 debug_msg("callback function has changed to %p", callback);
817 ASM_sound_handle[asm_index].asm_callback = callback;
818 ASM_sound_handle[asm_index].cb_data = cb_data;
824 bool ASM_unregister_sound_ex(const int asm_handle, ASM_sound_events_t sound_event, int *error_code, int (*func)(void*,void*))
832 if (error_code==NULL) {
833 debug_error ("invalid parameter. error code is null");
837 if (sound_event<ASM_EVENT_SHARE_MMPLAYER || sound_event >= ASM_EVENT_MAX) {
838 *error_code = ERR_ASM_EVENT_IS_INVALID;
839 debug_error ("invalid sound event(%d)",sound_event);
843 if (asm_handle < 0 || asm_handle >= ASM_SERVER_HANDLE_MAX) {
844 *error_code = ERR_ASM_POLICY_INVALID_HANDLE;
845 debug_error("invalid handle(%d). callback is not registered", asm_handle);
850 asm_index = __ASM_find_index(handle);
851 if (asm_index == -1) {
852 *error_code = ERR_ASM_POLICY_INVALID_HANDLE;
853 debug_error("Can not find index for handle(%d)", handle);
856 debug_msg("<<<< Event(%s), Tid(%d), Handle(%d) Index(%d)",
857 ASM_sound_events_str[sound_event], ASM_sound_handle[asm_index].asm_tid, ASM_sound_handle[asm_index].handle, asm_index);
859 if (!__asm_construct_snd_msg(ASM_sound_handle[asm_index].asm_tid, handle, sound_event, ASM_REQUEST_UNREGISTER, ASM_STATE_NONE, ASM_RESOURCE_NONE, error_code)) {
860 debug_error("failed to __asm_construct_snd_msg(), error(%d)", *error_code);
865 func(&asm_snd_msg, &asm_rcv_msg);
867 NO_EINTR(ret = msgsnd(asm_snd_msgid, (void *)&asm_snd_msg, sizeof(asm_snd_msg.data), 0));
869 *error_code = ERR_ASM_MSG_QUEUE_SND_ERROR;
870 debug_error("failed to msgsnd(%d,%s)", errno, strerror(errno));
875 __ASM_destroy_callback(asm_index);
877 ASM_sound_handle[asm_index].asm_fd = 0;
878 ASM_sound_handle[asm_index].asm_tid = 0;
879 ASM_sound_handle[asm_index].sound_event = ASM_EVENT_NONE;
880 ASM_sound_handle[asm_index].is_used = false;
882 debug_msg(">>>> Event(%s)", ASM_sound_events_str[sound_event]);
890 bool ASM_unregister_sound(const int asm_handle, ASM_sound_events_t sound_event, int *error_code)
892 return ASM_unregister_sound_ex (asm_handle, sound_event, error_code, NULL);
896 bool ASM_get_sound_status(unsigned int *all_sound_status, int *error_code)
898 if (all_sound_status == NULL || error_code == NULL) {
900 *error_code = ERR_ASM_UNKNOWN_ERROR;
901 debug_error("invalid parameter");
905 debug_msg("Tid(%ld)", asmgettid());
907 if (!__ASM_get_sound_state(all_sound_status, error_code)) {
908 debug_error("failed to __ASM_get_sound_state(), error(%d)", *error_code);
916 bool ASM_get_process_session_state(const int asm_handle, ASM_sound_states_t *sound_state, int *error_code)
922 if (sound_state == NULL || error_code == NULL) {
924 *error_code = ERR_ASM_UNKNOWN_ERROR;
925 debug_error("invalid parameter");
930 asm_index = __ASM_find_index(handle);
931 if (asm_index == -1) {
932 debug_error("Can not find index of %d", handle);
937 debug_msg("Pid(%d)", ASM_sound_handle[asm_index].asm_tid);
939 if (!__asm_construct_snd_msg(ASM_sound_handle[asm_index].asm_tid, handle, ASM_EVENT_MONITOR, ASM_REQUEST_GETMYSTATE, ASM_STATE_NONE, ASM_RESOURCE_NONE, error_code)) {
940 debug_error("failed to __asm_construct_snd_msg(), error(%d)", *error_code);
945 NO_EINTR(ret = msgsnd(asm_snd_msgid, (void *)&asm_snd_msg, sizeof(asm_snd_msg.data), 0));
947 *error_code = ERR_ASM_MSG_QUEUE_SND_ERROR;
948 debug_error("failed to msgsnd(%d,%s)", errno, strerror(errno));
952 NO_EINTR(ret = msgrcv(asm_rcv_msgid, (void *)&asm_rcv_msg, sizeof(asm_rcv_msg.data), asm_snd_msg.instance_id, 0));
954 *error_code = ERR_ASM_MSG_QUEUE_RCV_ERROR;
955 debug_error("failed to msgrcv(%d,%s)", errno, strerror(errno));
959 *sound_state = asm_rcv_msg.data.result_sound_state;
961 debug_msg(">>>> Pid(%d), State(%s)", ASM_sound_handle[asm_index].asm_tid, ASM_sound_state_str[*sound_state]);
968 bool ASM_get_sound_state(const int asm_handle, ASM_sound_events_t sound_event, ASM_sound_states_t *sound_state, int *error_code)
974 if (sound_state == NULL || error_code == NULL) {
976 *error_code = ERR_ASM_UNKNOWN_ERROR;
977 debug_error("invalid parameter");
980 if (sound_event < ASM_EVENT_SHARE_MMPLAYER || sound_event >= ASM_EVENT_MAX) {
981 *error_code = ERR_ASM_EVENT_IS_INVALID;
982 debug_error("invalid sound event(%d)",sound_event);
987 asm_index = __ASM_find_index(handle);
988 if (asm_index == -1) {
989 debug_error("Can not find index of %d", handle);
992 debug_msg("<<<< Event(%s), Tid(%d), handle(%d)",
993 ASM_sound_events_str[sound_event], ASM_sound_handle[asm_index].asm_tid, ASM_sound_handle[asm_index].handle);
995 if (!__asm_construct_snd_msg(ASM_sound_handle[asm_index].asm_tid, handle, sound_event, ASM_REQUEST_GETSTATE, ASM_STATE_NONE, ASM_RESOURCE_NONE, error_code)) {
996 debug_error("failed to __asm_construct_snd_msg(), error(%d)", *error_code);
1001 NO_EINTR(ret = msgsnd(asm_snd_msgid, (void *)&asm_snd_msg, sizeof(asm_snd_msg.data), 0));
1003 *error_code = ERR_ASM_MSG_QUEUE_SND_ERROR;
1004 debug_error("failed to msgsnd(%d,%s)", errno, strerror(errno));
1008 NO_EINTR(ret = msgrcv(asm_rcv_msgid, (void *)&asm_rcv_msg, sizeof(asm_rcv_msg.data), asm_snd_msg.instance_id, 0));
1010 *error_code = ERR_ASM_MSG_QUEUE_RCV_ERROR;
1011 debug_error("failed to msgrcv(%d,%s)", errno, strerror(errno));
1015 *sound_state = asm_rcv_msg.data.result_sound_state;
1017 debug_msg(">>>> Event(%s), State(%s)", ASM_sound_events_str[sound_event], ASM_sound_state_str[*sound_state]);
1024 bool ASM_set_sound_state_ex (const int asm_handle, ASM_sound_events_t sound_event, ASM_sound_states_t sound_state, ASM_resource_t mm_resource, int *error_code, int (*func)(void*,void*))
1029 unsigned int rcv_sound_status_value;
1033 if (error_code == NULL) {
1034 debug_error("error_code is null");
1038 if (sound_event < 0 || sound_event > ASM_PRIORITY_MATRIX_MIN) {
1039 debug_error("invalid sound event(%d)",sound_event);
1040 *error_code = ERR_ASM_EVENT_IS_INVALID;
1044 if (asm_handle < 0 || asm_handle >= ASM_SERVER_HANDLE_MAX) {
1045 *error_code = ERR_ASM_POLICY_INVALID_HANDLE;
1046 debug_error("Invalid handle %d", asm_handle);
1050 handle = asm_handle;
1052 asm_index = __ASM_find_index(handle);
1053 if (asm_index == -1) {
1054 debug_error("Can not find index of %d", handle);
1058 debug_msg("<<<< Event(%s), State(%s), Tid(%d), handle(%d)",
1059 ASM_sound_events_str[sound_event], ASM_sound_state_str[sound_state], ASM_sound_handle[asm_index].asm_tid, ASM_sound_handle[asm_index].handle);
1061 if (!__asm_construct_snd_msg(ASM_sound_handle[asm_index].asm_tid, ASM_sound_handle[asm_index].handle, sound_event, ASM_REQUEST_SETSTATE, sound_state, mm_resource, error_code)) {
1062 debug_error("failed to __asm_construct_snd_msg(), error(%d)", *error_code);
1067 debug_msg( "[func(%p) START]", func);
1068 func (&asm_snd_msg, &asm_rcv_msg);
1069 debug_msg( "[func END]");
1071 NO_EINTR(ret = msgsnd(asm_snd_msgid, (void *)&asm_snd_msg, sizeof(asm_snd_msg.data), 0));
1073 *error_code = ERR_ASM_MSG_QUEUE_SND_ERROR;
1074 debug_error("failed to msgsnd(%d,%s)", errno, strerror(errno));
1079 if (sound_state == ASM_STATE_PLAYING ) {
1080 debug_msg( "sound_state is PLAYING");
1082 NO_EINTR(ret = msgrcv(asm_rcv_msgid, (void *)&asm_rcv_msg, sizeof(asm_rcv_msg.data), ASM_sound_handle[handle].asm_tid, 0));
1084 *error_code = ERR_ASM_MSG_QUEUE_RCV_ERROR;
1085 debug_error("failed to msgrcv(%d,%s)", errno, strerror(errno));
1092 debug_msg( " <<<<<<<<<<<<<<<< [BEFORE] Callback : Main Context >>>>>>>>>>>>>>>>>>>> \n");
1093 /********************************************************************************************************/
1094 switch (asm_rcv_msg.data.result_sound_command) {
1095 case ASM_COMMAND_PAUSE:
1096 case ASM_COMMAND_STOP:
1097 if (handle == asm_rcv_msg.data.cmd_handle) {
1099 debug_msg("handle(%d) is same as asm_rcv_msg.data.cmd_handle", handle);
1101 asm_index = __ASM_find_index(asm_rcv_msg.data.cmd_handle);
1102 if (asm_index == -1) {
1103 *error_code = ERR_ASM_POLICY_INVALID_HANDLE;
1104 debug_error( "Can not find index from instance_id %ld, handle %d", asm_rcv_msg.instance_id, asm_rcv_msg.data.cmd_handle);
1108 /* check former sound event */
1109 switch (asm_rcv_msg.data.former_sound_event) {
1110 case ASM_EVENT_ALARM:
1111 debug_msg("blocked by ALARM");
1112 *error_code = ERR_ASM_POLICY_CANNOT_PLAY_BY_ALARM;
1114 case ASM_EVENT_CALL:
1115 case ASM_EVENT_VIDEOCALL:
1116 case ASM_EVENT_RICH_CALL:
1117 debug_msg("blocked by CALL/VIDEOCALL/RICH_CALL");
1118 *error_code = ERR_ASM_POLICY_CANNOT_PLAY_BY_CALL;
1121 debug_msg("blocked by Other(sound_event num:%d)", asm_rcv_msg.data.former_sound_event);
1122 *error_code = ERR_ASM_POLICY_CANNOT_PLAY;
1128 if (!__ASM_get_sound_state(&rcv_sound_status_value, error_code)) {
1129 debug_error("failed to __ASM_get_sound_state(), error(%d)", *error_code);
1132 debug_msg("[ASM_CB] Callback : TID(%ld), handle(%d)", asm_rcv_msg.instance_id, asm_rcv_msg.data.cmd_handle);
1134 asm_index = __ASM_find_index(asm_rcv_msg.data.cmd_handle);
1135 if (asm_index == -1) {
1136 *error_code = ERR_ASM_POLICY_INVALID_HANDLE;
1137 debug_error("Can not find index from instance_id %ld, handle %d", asm_rcv_msg.instance_id, asm_rcv_msg.data.cmd_handle);
1141 if (ASM_sound_handle[asm_index].asm_callback!=NULL) {
1142 debug_msg( "[ASM_CB(%p) START]", ASM_sound_handle[asm_index].asm_callback);
1143 ASM_sound_handle[asm_index].asm_callback(asm_rcv_msg.data.cmd_handle, ASM_sound_handle[asm_index].sound_event, asm_rcv_msg.data.result_sound_command, rcv_sound_status_value, ASM_sound_handle[asm_index].cb_data);
1144 debug_msg( "[ASM_CB END]");
1146 debug_msg("asm callback is null");
1151 case ASM_COMMAND_PLAY:
1152 case ASM_COMMAND_NONE:
1153 case ASM_COMMAND_RESUME:
1157 /********************************************************************************************************/
1158 debug_msg(" <<<<<<<<<<<<<<<< [AFTER] Callback : Main Context >>>>>>>>>>>>>>>>>>>> \n");
1163 debug_msg(">>>> Event(%s), State(%s)", ASM_sound_events_str[sound_event],ASM_sound_state_str[sound_state]);
1171 bool ASM_set_sound_state (const int asm_handle, ASM_sound_events_t sound_event, ASM_sound_states_t sound_state, ASM_resource_t mm_resource, int *error_code)
1173 return ASM_set_sound_state_ex (asm_handle, sound_event, sound_state, mm_resource, error_code, NULL);
1177 bool ASM_set_subsession (const int asm_handle, int subsession, int *error_code, int (*func)(void*,void*))
1182 unsigned int rcv_sound_status_value;
1186 if (error_code == NULL) {
1187 debug_error("error_code is null");
1191 if (asm_handle < 0 || asm_handle >= ASM_SERVER_HANDLE_MAX) {
1192 *error_code = ERR_ASM_POLICY_INVALID_HANDLE;
1193 debug_error("Invalid handle(%d)", asm_handle);
1197 handle = asm_handle;
1199 asm_index = __ASM_find_index(handle);
1200 if (asm_index == -1) {
1201 debug_error("Can not find index of %d", handle);
1205 if (!__asm_construct_snd_msg(ASM_sound_handle[asm_index].asm_tid, ASM_sound_handle[asm_index].handle, subsession, ASM_REQUEST_SET_SUBSESSION, 0, 0, error_code)) {
1206 debug_error("failed to __asm_construct_snd_msg(), error(%d)", *error_code);
1212 func (&asm_snd_msg, &asm_rcv_msg);
1214 NO_EINTR(ret = msgsnd(asm_snd_msgid, (void *)&asm_snd_msg, sizeof(asm_snd_msg.data), 0));
1216 *error_code = ERR_ASM_MSG_QUEUE_SND_ERROR;
1217 debug_error("failed to msgsnd(%d,%s)", errno, strerror(errno));
1221 NO_EINTR(ret = msgrcv(asm_rcv_msgid, (void *)&asm_rcv_msg, sizeof(asm_rcv_msg.data), ASM_sound_handle[handle].asm_tid, 0));
1223 *error_code = ERR_ASM_MSG_QUEUE_RCV_ERROR;
1224 debug_error("failed to msgrcv(%d,%s)", errno, strerror(errno));
1229 /* TODO: Should check msg returned.....*/
1232 debug_msg( " <<<<<<<<<<<<<<<< [BEFORE] Callback : Main Context >>>>>>>>>>>>>>>>>>>> \n");
1233 /********************************************************************************************************/
1234 switch (asm_rcv_msg.data.result_sound_command) {
1235 case ASM_COMMAND_PAUSE:
1236 case ASM_COMMAND_STOP:
1237 case ASM_COMMAND_PLAY:
1238 case ASM_COMMAND_NONE:
1239 case ASM_COMMAND_RESUME:
1243 /********************************************************************************************************/
1244 debug_msg(" <<<<<<<<<<<<<<<< [AFTER] Callback : Main Context >>>>>>>>>>>>>>>>>>>> \n");
1255 bool ASM_get_subsession (const int asm_handle, int *subsession_value, int *error_code, int (*func)(void*,void*))
1260 unsigned int rcv_sound_status_value;
1264 if (error_code == NULL) {
1265 debug_error("error_code is null");
1269 /* TODO : Error Handling */
1271 if (sound_event < 0 || sound_event > ASM_PRIORITY_MATRIX_MIN) {
1272 debug_error("invalid sound event(%d)",sound_event);
1273 *error_code = ERR_ASM_EVENT_IS_INVALID;
1278 if (asm_handle < 0 || asm_handle >= ASM_SERVER_HANDLE_MAX) {
1279 *error_code = ERR_ASM_POLICY_INVALID_HANDLE;
1280 debug_error("Invalid handle %d \n", asm_handle);
1284 handle = asm_handle;
1286 asm_index = __ASM_find_index(handle);
1287 if (asm_index == -1) {
1288 debug_error("Can not find index of %d", handle);
1292 if (!__asm_construct_snd_msg(ASM_sound_handle[asm_index].asm_tid, ASM_sound_handle[asm_index].handle, 0, ASM_REQUEST_GET_SUBSESSION, 0, 0, error_code)) {
1293 debug_error("failed to __asm_construct_snd_msg(), error(%d)", *error_code);
1299 func (&asm_snd_msg, &asm_rcv_msg);
1301 NO_EINTR(ret = msgsnd(asm_snd_msgid, (void *)&asm_snd_msg, sizeof(asm_snd_msg.data), 0));
1303 *error_code = ERR_ASM_MSG_QUEUE_SND_ERROR;
1304 debug_error("failed to msgsnd(%d,%s)", errno, strerror(errno));
1308 NO_EINTR(ret = msgrcv(asm_rcv_msgid, (void *)&asm_rcv_msg, sizeof(asm_rcv_msg.data), ASM_sound_handle[handle].asm_tid, 0));
1310 *error_code = ERR_ASM_MSG_QUEUE_RCV_ERROR;
1311 debug_error("failed to msgrcv(%d,%s)", errno, strerror(errno));
1316 *subsession_value = asm_rcv_msg.data.result_sound_command;
1318 debug_msg(">>>> ASM_get_subsession with subsession value [%d]\n", *subsession_value);
1325 void ASM_dump_sound_state()
1330 if (!__ASM_init_msg(&error) ) {
1331 debug_error("failed to __ASM_init_msg(), error(%d)", error);
1333 if (!__asm_construct_snd_msg(getpid(), 0, 0, ASM_REQUEST_DUMP, ASM_STATE_NONE, ASM_RESOURCE_NONE, &error)) {
1334 debug_error("failed to __asm_construct_snd_msg(), error(%d)", error);
1337 NO_EINTR(ret = msgsnd(asm_snd_msgid, (void *)&asm_snd_msg, sizeof(asm_snd_msg.data), 0));
1339 debug_error("failed to msgsnd(%d,%s)", errno, strerror(errno));
1345 void ASM_ask_sound_policy(ASM_sound_events_t playing_sound, ASM_sound_events_t request_sound,
1346 ASM_sound_cases_t *sound_policy)
1351 #if defined(CONFIG_ENABLE_SIGNAL_HANDLER)
1352 struct sigaction ASM_int_old_action;
1353 struct sigaction ASM_abrt_old_action;
1354 struct sigaction ASM_segv_old_action;
1355 struct sigaction ASM_term_old_action;
1356 struct sigaction ASM_sys_old_action;
1357 struct sigaction ASM_xcpu_old_action;
1359 void __ASM_unregister_sound(int index)
1363 unsigned int sound_status_value;
1367 debug_msg(" <<<< Event(%s), Index(%d)", ASM_sound_events_str[ASM_sound_handle[index].sound_event], index);
1369 if (!__ASM_get_sound_state(&sound_status_value, &error_code)) {
1370 debug_error("failed to __ASM_get_sound_state()", error_code);
1372 if (!__ASM_set_sound_state(ASM_sound_handle[index].sound_event, ASM_STATE_NONE, &error_code)) {
1373 debug_error("failed to __ASM_set_sound_state(NONE)", error_code);
1376 if (!__asm_construct_snd_msg(ASM_sound_handle[index].asm_tid, ASM_sound_handle[index].handle, ASM_sound_handle[index].sound_event, ASM_REQUEST_UNREGISTER, ASM_STATE_NONE, ASM_RESOURCE_NONE, &error_code)) {
1377 debug_error("failed to __asm_construct_snd_msg(), error(%d)", error_code);
1380 NO_EINTR(ret = msgsnd(asm_snd_msgid, (void *)&asm_snd_msg, sizeof(asm_snd_msg.data), 0));
1382 debug_error("failed to msgsnd(%d,%s)", errno, strerror(errno));
1385 __ASM_destroy_callback(index);
1387 debug_msg(" >>>> Event(%s)", ASM_sound_events_str[ASM_sound_handle[index].sound_event]);
1389 ASM_sound_handle[index].asm_fd = 0;
1390 ASM_sound_handle[index].asm_tid = 0;
1391 ASM_sound_handle[index].sound_event = ASM_EVENT_NONE;
1392 ASM_sound_handle[index].is_used = false;
1398 void __ASM_signal_handler(int signo)
1402 int run_emergency_exit = 0;
1404 for (asm_index=0 ;asm_index < ASM_HANDLE_MAX; asm_index++) {
1405 if (ASM_sound_handle[asm_index].is_used == true) {
1406 exit_pid = ASM_sound_handle[asm_index].asm_tid;
1407 if (exit_pid == asmgettid()) {
1408 run_emergency_exit = 1;
1414 if (run_emergency_exit) {
1415 asm_snd_msg.instance_id = exit_pid;
1416 asm_snd_msg.data.handle = 0;
1417 asm_snd_msg.data.request_id = ASM_REQUEST_EMERGENT_EXIT;
1418 asm_snd_msg.data.sound_event = 0;
1419 asm_snd_msg.data.sound_state = 0;
1420 /* signal block -------------- */
1421 sigset_t old_mask, all_mask;
1422 sigfillset(&all_mask);
1423 sigprocmask(SIG_BLOCK, &all_mask, &old_mask);
1425 if (msgsnd(asm_snd_msgid, (void *)&asm_snd_msg, sizeof(asm_snd_msg.data), 0) < 0) {
1426 debug_error("msgsnd() failed, tid=%ld, reqid=%d, handle=0x%x, state=0x%x event=%d size=%d",asm_snd_msg.instance_id,
1427 asm_snd_msg.data.request_id, asm_snd_msg.data.handle, asm_snd_msg.data.sound_state, asm_snd_msg.data.sound_event, sizeof(asm_snd_msg.data) );
1428 int tmpid = msgget((key_t)2014, 0666);
1429 if (msgsnd(tmpid, (void *)&asm_snd_msg, sizeof(asm_snd_msg.data), 0) > 0) {
1430 debug_msg("msgsnd() succeed");
1432 debug_error("msgsnd() retry also failed");
1436 sigprocmask(SIG_SETMASK, &old_mask, NULL);
1437 /* signal unblock ------------ */
1442 sigaction(SIGINT, &ASM_int_old_action, NULL);
1446 sigaction(SIGABRT, &ASM_abrt_old_action, NULL);
1450 sigaction(SIGSEGV, &ASM_segv_old_action, NULL);
1454 sigaction(SIGTERM, &ASM_term_old_action, NULL);
1458 sigaction(SIGSYS, &ASM_sys_old_action, NULL);
1462 sigaction(SIGXCPU, &ASM_xcpu_old_action, NULL);
1471 void __attribute__((constructor)) __ASM_init_module(void)
1473 #if defined(CONFIG_ENABLE_SIGNAL_HANDLER)
1474 struct sigaction ASM_action;
1475 ASM_action.sa_handler = __ASM_signal_handler;
1476 ASM_action.sa_flags = SA_NOCLDSTOP;
1480 sigemptyset(&ASM_action.sa_mask);
1482 sigaction(SIGINT, &ASM_action, &ASM_int_old_action);
1483 sigaction(SIGABRT, &ASM_action, &ASM_abrt_old_action);
1484 sigaction(SIGSEGV, &ASM_action, &ASM_segv_old_action);
1485 sigaction(SIGTERM, &ASM_action, &ASM_term_old_action);
1486 sigaction(SIGSYS, &ASM_action, &ASM_sys_old_action);
1487 sigaction(SIGXCPU, &ASM_action, &ASM_xcpu_old_action);
1494 void __attribute__((destructor)) __ASM_fini_module(void)
1498 #if defined(CONFIG_ENABLE_SIGNAL_HANDLER)
1502 int run_emergency_exit = 0;
1504 for (asm_index = 0; asm_index < ASM_HANDLE_MAX; asm_index++) {
1505 if (ASM_sound_handle[asm_index].is_used == true) {
1506 exit_pid = ASM_sound_handle[asm_index].asm_tid;
1507 if (exit_pid == asmgettid()) {
1508 run_emergency_exit = 1;
1514 if (run_emergency_exit) {
1515 asm_snd_msg.instance_id = exit_pid;
1516 asm_snd_msg.data.handle = 0; /* dummy */
1517 asm_snd_msg.data.request_id = ASM_REQUEST_EMERGENT_EXIT;
1518 asm_snd_msg.data.sound_event = 0;
1519 asm_snd_msg.data.sound_state = 0;
1521 if (msgsnd(asm_snd_msgid, (void *)&asm_snd_msg, sizeof(asm_snd_msg.data), 0) < 0 ) {
1522 debug_msg( "msgsnd() failed, tid=%ld, reqid=%d, handle=0x%x, state=0x%x event=%d size=%d",asm_snd_msg.instance_id,
1523 asm_snd_msg.data.request_id, asm_snd_msg.data.handle, asm_snd_msg.data.sound_state, asm_snd_msg.data.sound_event, sizeof(asm_snd_msg.data) );
1524 int tmpid = msgget((key_t)2014, 0666);
1525 if (msgsnd(tmpid, (void *)&asm_snd_msg, sizeof(asm_snd_msg.data), 0) > 0) {
1526 debug_msg("msgsnd() succeed");
1528 debug_error("msgsnd() retry also failed");
1533 sigaction(SIGINT, &ASM_int_old_action, NULL);
1534 sigaction(SIGABRT, &ASM_abrt_old_action, NULL);
1535 sigaction(SIGSEGV, &ASM_segv_old_action, NULL);
1536 sigaction(SIGTERM, &ASM_term_old_action, NULL);
1537 sigaction(SIGSYS, &ASM_sys_old_action, NULL);
1538 sigaction(SIGXCPU, &ASM_xcpu_old_action, NULL);