Coverity issue fixes for email service
[platform/core/messaging/email-service.git] / email-core / email-core-timer.c
1 /*
2 *  email-service
3 *
4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5 *
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
7 *
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
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
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.
19 *
20 */
21
22
23 #include <stdlib.h>
24 #include <string.h>
25 #include <sys/time.h>
26 #include <signal.h>
27 #include <unistd.h>
28 #include <stdio.h>
29 #include <time.h>
30 #include <errno.h>
31 #include <sys/signal.h>
32 #include <sys/timeb.h>
33 #include "email-core-timer.h"
34 #include "email-debug-log.h"
35
36
37 typedef struct {
38         EMAIL_TIMER_CALLBACK user_callback_function;
39         void *callback_user_data;
40         int time_id;
41 } em_timer_callback_data;
42
43
44 INTERNAL_FUNC int emcore_timer_ex_callback(void *a_pData)
45 {
46         EM_DEBUG_LOG("[emcore_timer_ex_callback] enter\n");
47         void *pUserData = NULL;
48
49 #if !GLIB_CHECK_VERSION(2, 31, 0)
50         g_thread_init(NULL);
51 #endif
52
53         em_timer_callback_data *pTimerData = (em_timer_callback_data *)a_pData;
54         if (pTimerData != NULL) {
55                 EMAIL_TIMER_CALLBACK pfn_UserCB = pTimerData->user_callback_function;
56                 pUserData = pTimerData->callback_user_data;
57                 if (pUserData)
58                         EM_DEBUG_LOG("emcore_timer_ex_callback >>> data  :  %s", (char *)pTimerData->callback_user_data);
59
60                 EM_SAFE_FREE(pTimerData);
61                 pfn_UserCB(pUserData);
62         }
63
64  #if !GLIB_CHECK_VERSION(2, 31, 0)
65         g_thread_init(NULL);
66 #endif
67
68         EM_DEBUG_LOG("[emcore_timer_ex_callback] leave\n");
69
70         if (pUserData)
71                 return 0;
72         else
73         return 1;
74 }
75
76 INTERNAL_FUNC int emcore_set_timer_ex(long a_nSetTimeValue, EMAIL_TIMER_CALLBACK a_pCallBack, void *a_pData)
77 {
78         EM_DEBUG_LOG("emcore_set_timer_ex %ld", a_nSetTimeValue);
79         em_timer_callback_data *pTimerData = NULL;
80         pTimerData = malloc(sizeof(em_timer_callback_data));
81         if (!pTimerData)
82                 return -1;
83
84     memset(pTimerData, 0x00, sizeof(em_timer_callback_data));
85
86         pTimerData->user_callback_function = a_pCallBack;
87         if (a_pData) {
88                 pTimerData->callback_user_data = a_pData;
89         }
90         pTimerData->time_id = g_timeout_add(a_nSetTimeValue, emcore_timer_ex_callback, pTimerData);
91         return pTimerData->time_id;
92 }
93
94 INTERNAL_FUNC void emcore_kill_timer_ex(int a_nTimerID)
95 {
96         EM_DEBUG_LOG("[emcore_kill_timer_ex] a_nTimerID %d", a_nTimerID);
97         g_source_remove(a_nTimerID);
98 }
99