2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (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://www.tizenopensource.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 alarmmgr_set_time(alarm_info, target_time);
203 alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_ONCE, 0);
204 alarmmgr_set_type(alarm_info, ALARM_TYPE_VOLATILE);
205 alarmmgr_add_alarm_with_localtime(alarm_info, NULL, &g_alarmId);
207 retval = alarmmgr_set_cb(MsgSoundRepeatAlarmCB, (void *)alarm_info);
211 MSG_DEBUG("alarmmgr_set_cb() error [%d]", retval);
215 MSG_DEBUG("Repeat Alarm Time : [%d-%d-%d %d:%d:%d]",
216 target_time.year,target_time.month,target_time.day,
217 target_time.hour, target_time.min, target_time.sec);
225 int MsgSoundRepeatAlarmCB(int TimerId, void *pUserParam)
229 alarm_info_t *alarm_info = (alarm_info_t *)pUserParam;
233 if (MsgSoundGetUnreadMsgCnt() <= 0) {
234 MSG_DEBUG("no unread msg");
236 MsgSoundPlayStart(false);
239 if (alarmmgr_free_alarm(alarm_info) != ALARMMGR_RESULT_SUCCESS)
240 MSG_DEBUG("alarmmgr_free_alarm is failed");
248 int MsgSoundGetUnreadMsgCnt()
253 unreadCnt = MsgSettingGetInt(VCONFKEY_MESSAGE_RECV_SMS_STATE);
256 unreadCnt += MsgSettingGetInt(VCONFKEY_MESSAGE_RECV_MMS_STATE);
258 MSG_DEBUG("unread count : [%d]", unreadCnt);
263 void MsgSoundInitRepeatAlarm()
267 int nRepeatValue = 0;
268 long nRepeatTime = 0;
272 if (MsgSoundGetUnreadMsgCnt() <= 0) {
273 MSG_DEBUG("no unread msg");
277 nRepeatValue = MsgSettingGetInt(MSG_ALERT_TONE);
279 switch (nRepeatValue)
281 case MSG_ALERT_TONE_ONCE:
285 case MSG_ALERT_TONE_2MINS:
289 case MSG_ALERT_TONE_5MINS:
293 case MSG_ALERT_TONE_10MINS:
298 MSG_DEBUG("Invalid Repetition time");
302 MSG_DEBUG("nRepeatTime = %d", nRepeatTime);
305 MsgSoundPlayStart(false);