4 * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include "cal_internal.h"
23 #include "cal_typedef.h"
24 #include "cal_mutex.h"
25 #include "cal_server.h"
27 static pthread_mutex_t cal_mutex_timeout = PTHREAD_MUTEX_INITIALIZER;
28 static pthread_mutex_t cal_mutex_holding = PTHREAD_MUTEX_INITIALIZER;
29 static guint cal_timeout_id = 0;
30 static gboolean cal_holding = FALSE;
32 void cal_server_ondemand_stop(void)
34 int timeout = cal_server_get_timeout();
38 pthread_mutex_lock(&cal_mutex_timeout);
39 g_source_remove(cal_timeout_id);
41 pthread_mutex_unlock(&cal_mutex_timeout);
44 static gboolean _timeout_cb(gpointer user_data)
46 pthread_mutex_lock(&cal_mutex_holding);
47 if (FALSE == cal_holding) {
49 cal_server_quit_loop();
51 pthread_mutex_unlock(&cal_mutex_holding);
55 void cal_server_ondemand_start(void)
57 int timeout = cal_server_get_timeout();
61 DBG("timeout(%d)", timeout);
62 pthread_mutex_lock(&cal_mutex_timeout);
63 if (cal_timeout_id > 0)
64 g_source_remove(cal_timeout_id);
65 cal_timeout_id = g_timeout_add_seconds(timeout, _timeout_cb, NULL);
66 pthread_mutex_unlock(&cal_mutex_timeout);
69 void cal_server_ondemand_hold(void)
71 pthread_mutex_lock(&cal_mutex_holding);
73 pthread_mutex_unlock(&cal_mutex_holding);
76 void cal_server_ondemand_release(void)
78 pthread_mutex_lock(&cal_mutex_holding);
80 pthread_mutex_unlock(&cal_mutex_holding);