2 * Copyright 2012-2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "MsgHelper.h"
21 #include "MsgGconfWrapper.h"
22 #include "MsgSettingTypes.h"
23 #include "MsgSoundPlayer.h"
27 /*==================================================================================================
29 ==================================================================================================*/
30 static bool g_bRepeat = false;
31 static alarm_id_t g_alarmId = 0;
34 /*==================================================================================================
35 FUNCTION IMPLEMENTATION
36 ==================================================================================================*/
39 void MsgSoundPlayStart(bool isEmergency)
49 MSG_DEBUG("Failed to fork");
54 MSG_DEBUG("Child Process - Run helper app for Sound");
57 execl("/usr/bin/msg-helper", MSG_EMERGENCY_SOUND_START, NULL);
59 execl("/usr/bin/msg-helper", MSG_NORMAL_SOUND_START, NULL);
61 MSG_DEBUG("Faild to run helper app for Sound");
65 else if (childpid != 0)
67 MSG_DEBUG("Parent Process - Mms Plugin Storage.");
70 if (g_bRepeat == false)
71 g_bRepeat = MsgSoundSetRepeatAlarm();
76 void MsgSoundPlayStop()
86 MSG_DEBUG("Failed to fork");
91 MSG_DEBUG("Child Process - Run helper app for Sound");
93 execl("/usr/bin/msg-helper", MSG_SOUND_STOP, NULL);
95 MSG_DEBUG("Faild to run helper app for Sound");
99 else if (childpid != 0)
101 MSG_DEBUG("Parent Process - Mms Plugin Storage.");
108 bool MsgSoundSetRepeatAlarm()
112 int nRepeatValue = 0;
113 long nRepeatTime = 0;
115 nRepeatValue = MsgSettingGetInt(MSG_ALERT_TONE);
117 switch (nRepeatValue)
119 case MSG_ALERT_TONE_ONCE:
123 case MSG_ALERT_TONE_2MINS:
127 case MSG_ALERT_TONE_5MINS:
131 case MSG_ALERT_TONE_10MINS:
136 MSG_DEBUG("Invalid Repetition time");
140 MSG_DEBUG("nRepeatTime = %d", nRepeatTime);
144 bRet = MsgSoundCreateRepeatAlarm(nRepeatTime);
151 bool MsgSoundCreateRepeatAlarm(int RepeatTime)
156 struct tm current_tm;
160 localtime_r(¤t_time, ¤t_tm);
164 retval = alarmmgr_init("msg-service-tools");
168 MSG_FATAL("alarmmgr_init() error [%d]", retval);
172 alarm_info_t* alarm_info;
173 alarm_date_t target_time;
175 alarm_info = alarmmgr_create_alarm();
177 target_time.year = 0;
178 target_time.month = 0;
181 if (current_tm.tm_min+RepeatTime < 60)
183 target_time.hour = current_tm.tm_hour;
184 target_time.min = current_tm.tm_min+RepeatTime;
188 if (current_tm.tm_hour < 12)
190 target_time.hour = current_tm.tm_hour+1;
194 target_time.hour = (current_tm.tm_hour+1)%12;
197 target_time.min = (current_tm.tm_min+RepeatTime)%60;
200 target_time.sec = current_tm.tm_sec;
202 retval = alarmmgr_set_time(alarm_info, target_time);
203 MSG_DEBUG("alarmmgr_set_time return = [%d]", retval);
204 retval = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_ONCE, 0);
205 MSG_DEBUG("alarmmgr_set_repeat_mode return = [%d]", retval);
206 retval = alarmmgr_set_type(alarm_info, ALARM_TYPE_VOLATILE);
207 MSG_DEBUG("alarmmgr_set_type return = [%d]", retval);
208 retval = alarmmgr_add_alarm_with_localtime(alarm_info, NULL, &g_alarmId);
209 MSG_DEBUG("alarmmgr_add_alarm_with_localtime return = [%d]", retval);
211 retval = alarmmgr_set_cb(MsgSoundRepeatAlarmCB, (void *)alarm_info);
215 MSG_DEBUG("alarmmgr_set_cb() error [%d]", retval);
219 MSG_DEBUG("Repeat Alarm Time : [%d-%d-%d %d:%d:%d]",
220 target_time.year,target_time.month,target_time.day,
221 target_time.hour, target_time.min, target_time.sec);
229 int MsgSoundRepeatAlarmCB(int TimerId, void *pUserParam)
233 alarm_info_t *alarm_info = (alarm_info_t *)pUserParam;
237 if (MsgSoundGetUnreadMsgCnt() <= 0) {
238 MSG_DEBUG("no unread msg");
240 MsgSoundPlayStart(false);
243 if (alarmmgr_free_alarm(alarm_info) != ALARMMGR_RESULT_SUCCESS)
244 MSG_DEBUG("alarmmgr_free_alarm is failed");
252 int MsgSoundGetUnreadMsgCnt()
257 unreadCnt = MsgSettingGetInt(VCONFKEY_MESSAGE_RECV_SMS_STATE);
260 unreadCnt += MsgSettingGetInt(VCONFKEY_MESSAGE_RECV_MMS_STATE);
262 MSG_DEBUG("unread count : [%d]", unreadCnt);
267 void MsgSoundInitRepeatAlarm()
271 int nRepeatValue = 0;
272 long nRepeatTime = 0;
276 if (MsgSoundGetUnreadMsgCnt() <= 0) {
277 MSG_DEBUG("no unread msg");
281 nRepeatValue = MsgSettingGetInt(MSG_ALERT_TONE);
283 switch (nRepeatValue)
285 case MSG_ALERT_TONE_ONCE:
289 case MSG_ALERT_TONE_2MINS:
293 case MSG_ALERT_TONE_5MINS:
297 case MSG_ALERT_TONE_10MINS:
302 MSG_DEBUG("Invalid Repetition time");
306 MSG_DEBUG("nRepeatTime = %d", nRepeatTime);
309 MsgSoundPlayStart(false);