2.0_alpha release commit
[framework/messaging/email-service.git] / email-core / email-core-timer.c
1 /*
2 *  email-service
3 *
4 * Copyright (c) 2000 - 2011 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 #include <dbus/dbus-glib.h> 
36
37
38 typedef struct
39 {
40         EMAIL_TIMER_CALLBACK user_callback_function;
41         void *callback_user_data;
42         int time_id;
43 }em_timer_callback_data;
44
45
46 INTERNAL_FUNC int emcore_timer_ex_callback(void *a_pData)
47 {
48         EM_DEBUG_LOG("[emcore_timer_ex_callback] enter\n");
49         void *pUserData = NULL;
50
51
52         g_thread_init(NULL);
53         dbus_g_thread_init ();
54
55         em_timer_callback_data *pTimerData = (em_timer_callback_data *)a_pData;
56         if (pTimerData != NULL)
57                 {
58                 EMAIL_TIMER_CALLBACK pfn_UserCB = pTimerData->user_callback_function;
59                         pUserData = pTimerData->callback_user_data;
60                 if (pUserData)
61                         EM_DEBUG_LOG("emcore_timer_ex_callback >>> data  :  %s", (char *)pTimerData->callback_user_data);
62                         EM_SAFE_FREE(pTimerData);
63                         pfn_UserCB(pUserData);
64                 }
65  
66                 
67         g_thread_init(NULL);
68         dbus_g_thread_init ();
69
70         EM_DEBUG_LOG("[emcore_timer_ex_callback] leave\n");
71
72         if (pUserData)
73                 return 0;
74         else
75                         return 1;
76 }
77
78 INTERNAL_FUNC int emcore_set_timer_ex(long a_nSetTimeValue, EMAIL_TIMER_CALLBACK a_pCallBack, void *a_pData)
79 {
80         EM_DEBUG_LOG("emcore_set_timer_ex %d", a_nSetTimeValue);
81         em_timer_callback_data *pTimerData = NULL;
82         pTimerData = malloc(sizeof(em_timer_callback_data));
83         char *data = NULL;
84         if (!pTimerData)
85                 return -1;
86         memset(pTimerData, 0x00, sizeof(em_timer_callback_data));
87         if (a_pData)
88                 EM_DEBUG_LOG("emcore_set_timer_ex >>> data  :  %s", (char *)a_pData);
89
90         pTimerData->user_callback_function = a_pCallBack;
91         if (a_pData) {
92                 data = (char *) a_pData;
93                 pTimerData->callback_user_data = EM_SAFE_STRDUP(data);
94         }
95         pTimerData->time_id = g_timeout_add(a_nSetTimeValue, emcore_timer_ex_callback, pTimerData);
96         return pTimerData->time_id;
97 }
98
99 INTERNAL_FUNC void emcore_kill_timer_ex(int a_nTimerID)
100 {
101         EM_DEBUG_LOG("[emcore_kill_timer_ex] a_nTimerID %d", a_nTimerID);
102         g_source_remove(a_nTimerID);
103 }
104