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()
49 MSG_DEBUG("Failed to fork");
54 MSG_DEBUG("Child Process - Run helper app for Sound");
56 execl("/usr/bin/msg-helper", MSG_SOUND_START, NULL);
58 MSG_DEBUG("Faild to run helper app for Sound");
62 else if (childpid != 0)
64 MSG_DEBUG("Parent Process - Mms Plugin Storage.");
67 if (g_bRepeat == false)
68 g_bRepeat = MsgSoundSetRepeatAlarm();
73 void MsgSoundPlayStop()
83 MSG_DEBUG("Failed to fork");
88 MSG_DEBUG("Child Process - Run helper app for Sound");
90 execl("/usr/bin/msg-helper", MSG_SOUND_STOP, NULL);
92 MSG_DEBUG("Faild to run helper app for Sound");
96 else if (childpid != 0)
98 MSG_DEBUG("Parent Process - Mms Plugin Storage.");
105 bool MsgSoundSetRepeatAlarm()
109 int nRepeatValue = 0;
110 long nRepeatTime = 0;
112 nRepeatValue = MsgSettingGetInt(MSG_ALERT_TONE);
114 switch (nRepeatValue)
116 case MSG_ALERT_TONE_ONCE:
120 case MSG_ALERT_TONE_2MINS:
124 case MSG_ALERT_TONE_5MINS:
128 case MSG_ALERT_TONE_10MINS:
133 MSG_DEBUG("Invalid Repetition time");
137 MSG_DEBUG("nRepeatTime = %d", nRepeatTime);
141 bRet = MsgSoundCreateRepeatAlarm(nRepeatTime);
148 bool MsgSoundCreateRepeatAlarm(int RepeatTime)
153 struct tm current_tm;
157 localtime_r(¤t_time, ¤t_tm);
161 retval = alarmmgr_init("msg-service-tools");
165 MSG_FATAL("alarmmgr_init() error [%d]", retval);
169 alarm_info_t* alarm_info;
170 alarm_date_t target_time;
172 alarm_info = alarmmgr_create_alarm();
174 target_time.year = 0;
175 target_time.month = 0;
178 if (current_tm.tm_min+RepeatTime < 60)
180 target_time.hour = current_tm.tm_hour;
181 target_time.min = current_tm.tm_min+RepeatTime;
185 if (current_tm.tm_hour < 12)
187 target_time.hour = current_tm.tm_hour+1;
191 target_time.hour = (current_tm.tm_hour+1)%12;
194 target_time.min = (current_tm.tm_min+RepeatTime)%60;
197 target_time.sec = current_tm.tm_sec;
199 alarmmgr_set_time(alarm_info, target_time);
200 alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_ONCE, 0);
201 alarmmgr_set_type(alarm_info, ALARM_TYPE_VOLATILE);
202 alarmmgr_add_alarm_with_localtime(alarm_info, NULL, &g_alarmId);
204 retval = alarmmgr_set_cb(MsgSoundRepeatAlarmCB, NULL);
208 MSG_DEBUG("alarmmgr_set_cb() error [%d]", retval);
212 MSG_DEBUG("Repeat Alarm Time : [%d-%d-%d %d:%d:%d]",
213 target_time.year,target_time.month,target_time.day,
214 target_time.hour, target_time.min, target_time.sec);
222 int MsgSoundRepeatAlarmCB(int TimerId, void *pUserParam)
228 if (MsgSoundGetUnreadMsgCnt() <= 0)
230 MSG_DEBUG("no unread msg");
243 int MsgSoundGetUnreadMsgCnt()
248 unreadCnt = MsgSettingGetInt(VCONFKEY_MESSAGE_RECV_SMS_STATE);
251 unreadCnt += MsgSettingGetInt(VCONFKEY_MESSAGE_RECV_MMS_STATE);
253 MSG_DEBUG("unread count : [%d]", unreadCnt);
258 void MsgSoundInitRepeatAlarm()
262 int nRepeatValue = 0;
263 long nRepeatTime = 0;
267 if (MsgSoundGetUnreadMsgCnt() <= 0) {
268 MSG_DEBUG("no unread msg");
272 nRepeatValue = MsgSettingGetInt(MSG_ALERT_TONE);
274 switch (nRepeatValue)
276 case MSG_ALERT_TONE_ONCE:
280 case MSG_ALERT_TONE_2MINS:
284 case MSG_ALERT_TONE_5MINS:
288 case MSG_ALERT_TONE_10MINS:
293 MSG_DEBUG("Invalid Repetition time");
297 MSG_DEBUG("nRepeatTime = %d", nRepeatTime);