Add rule for 'All devices apps' when access rule is empty.
[platform/core/connectivity/smartcard-service.git] / common / Synchronous.cpp
1 /*
2  * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /* standard library header */
18 #include <stdio.h>
19 #include <sys/time.h>
20
21 /* SLP library header */
22
23 /* local header */
24 #include "Synchronous.h"
25
26 namespace smartcard_service_api
27 {
28         Synchronous::Synchronous()
29         {
30                 pthread_mutex_init(&syncMutex, NULL);
31                 pthread_cond_init(&syncCondition, NULL);
32         }
33
34         void Synchronous::syncLock()
35         {
36                 pthread_mutex_lock(&syncMutex);
37         }
38
39         void Synchronous::syncUnlock()
40         {
41                 pthread_mutex_unlock(&syncMutex);
42         }
43
44         int Synchronous::waitTimedCondition(int second)
45         {
46                 struct timeval now;
47                 struct timespec ts;
48                 int result;
49
50                 if (second > 0)
51                 {
52                         gettimeofday(&now, NULL);
53                         ts.tv_sec = now.tv_sec + second;
54                         ts.tv_nsec = now.tv_usec * 1000;
55
56                         result = pthread_cond_timedwait(&syncCondition, &syncMutex, &ts);
57                 }
58                 else
59                 {
60                         result = pthread_cond_wait(&syncCondition, &syncMutex);
61                 }
62
63                 return result;
64         }
65
66         void Synchronous::signalCondition()
67         {
68                 pthread_cond_signal(&syncCondition);
69         }
70
71 } /* namespace smartcard_service_api */