6257e573366cf4db0de531f6cb4938fa07185898
[platform/core/security/drm-service-core-tizen.git] / tappsd / src / intf / drm_intf_tapps.cpp
1 /*
2  * Copyright (c) 2000-2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 /**
18  * @file        drm_intf_tapps.cpp
19  * @brief       This file includes definitions of the drm TAPPS intf APIs.
20  */
21
22 #include "drm_intf_tapps.h"
23
24 /* String Operations */
25 #ifdef _TAPPS_DEBUG_ENABLE_
26 unsigned int TAPPS_gstrlcat(char* s1,const char* s2,unsigned int destsize,const char* funName, unsigned int lineno)
27 {
28         unsigned int ret_g_strlcat = (unsigned int)g_strlcat(s1, s2, destsize);
29
30         if(ret_g_strlcat >= (unsigned int)destsize)
31         {
32                 DRM_TAPPS_EXCEPTION("Truncation occured during concatenation at [%s:%u] s1=%s s2=%s destsize=%u ret_g_strlcpy=%u \n",funName,lineno,s1,s2,destsize,ret_g_strlcat);
33         }
34         else
35         {
36                 DRM_TAPPS_FRQ_LOG("Concatenation Successful at [%s:%u] s1=%s s2=%s destsize=%u ret_g_strlcpy=%u \n",funName,lineno,s1,s2,destsize,ret_g_strlcat);
37         }
38
39         return ret_g_strlcat;
40 }
41
42 unsigned int TAPPS_gstrlcpy(char* s1,const char* s2,unsigned int destsize,const char* funName, unsigned int lineno)
43 {
44         unsigned int ret_g_strlcpy = (unsigned int)g_strlcpy(s1, s2, destsize);
45
46         if(ret_g_strlcpy >= (unsigned int)destsize)
47         {
48                 DRM_TAPPS_EXCEPTION("Truncation occured during copying at [%s:%u] s1=%s s2=%s destsize=%u ret_g_strlcpy=%u \n",funName,lineno,s1,s2,destsize,ret_g_strlcpy);
49         }
50         else
51         {
52                 DRM_TAPPS_FRQ_LOG("Copy Successful at [%s:%u] s1=%s s2=%s destsize=%u ret_g_strlcpy=%u \n",funName,lineno,s1,s2,destsize,ret_g_strlcpy);
53         }
54
55         return ret_g_strlcpy;
56 }
57
58 unsigned int TAPPS_strlen(const char* s,const char* funName, unsigned int lineno)
59 {
60         DRM_TAPPS_FRQ_LOG("Function = %s, Line number = %u",funName,lineno);
61
62         return strlen(s);
63 }
64 #endif
65
66 int TAPPS_strnicmp(const char * s1, const char * s2, unsigned int sz)
67 {
68         int tmp1=0, tmp2=0;
69
70         unsigned int idx =0;
71
72         do
73         {
74                 if ( ((tmp1 = (unsigned char)(*(s1++))) >= 'A') && (tmp1 <= 'Z') )
75                         tmp1 -= ('A' - 'a');
76
77                 if ( ((tmp2 = (unsigned char)(*(s2++))) >= 'A') && (tmp2 <= 'Z') )
78                         tmp2 -= ('A' - 'a');
79
80                 idx++;
81         } while ( tmp1 && (tmp1== tmp2)  && idx < sz);
82
83         return (tmp1 - tmp2);
84 }
85
86
87 /* Mutex Handling */
88
89 int dtapps_mutex_lock (dtappslockarg dtapps_mutex)
90 {
91         int retval=-1;
92
93         DRM_TAPPS_FRQ_LOG( "%s MUT-LK-ULK Thread [%d] trying to lock the Mutex=0x%x \n",__func__,drmgettid(),dtapps_mutex);
94
95         retval = pthread_mutex_lock(dtapps_mutex);
96
97         if(retval != 0)
98         {
99                 if(retval == EDEADLK)
100                 {
101                         DRM_TAPPS_FRQ_LOG("Mutex is already locked by the same thread  \n");
102                 }
103                 else
104                 {
105                         DRM_TAPPS_EXCEPTION( "Error locking mutex %d  \n", retval);
106                         perror("\n drm_mutex_lock:Error:");
107                 }
108                 retval=-1;
109         }
110         else
111         {
112                 DRM_TAPPS_FRQ_LOG( "Mutex lock is successful  \n");
113         }
114         DRM_TAPPS_FRQ_LOG( "%s retval=%d \n",__func__,retval);
115
116         return retval;
117 }
118
119
120 int dtapps_mutex_unlock (dtappslockarg dtapps_mutex)
121 {
122         int status=-1;
123
124         DRM_TAPPS_FRQ_LOG( "%s MUT-LK-ULK Thread [%d] trying to unlock the Mutex=0x%x \n",__func__,drmgettid(),dtapps_mutex);
125
126         status = pthread_mutex_unlock(dtapps_mutex);
127
128         if(status != 0)
129         {
130                 DRM_TAPPS_EXCEPTION( "Error unlocking mutex:return value=[%d] \n", status);
131                 perror("\n drm_mutex_unlock:Error:");
132                 status = -1;
133         }
134         else
135         {
136                 DRM_TAPPS_FRQ_LOG( "Mutex unlocked is successful :return value=[%d] \n",status);
137         }
138
139         DRM_TAPPS_FRQ_LOG( "%s status=%d \n",__func__,status);
140
141         return status;
142 }
143
144 void dtapps_sleep(unsigned int TimeInSec,unsigned int TimeInMicroSec)
145 {
146         struct timeval tv;
147         int retval= -1;
148         tv.tv_sec = TimeInSec;
149         tv.tv_usec = TimeInMicroSec;
150
151         DRM_TAPPS_FRQ_LOG("%s TimeInSec =%u TimeInMicroSec=%u \n",__func__,tv.tv_sec,tv.tv_usec);
152
153         retval = select(0, NULL, NULL, NULL, &tv);
154
155         DRM_TAPPS_FRQ_LOG("%s select retval=%d \n",__func__,retval);
156 }