Merge "Add the exception handling when using manual cert mode" into tizen_2.1
[platform/framework/native/net.git] / src / FNet_NetUtility.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file                FNet_NetUtility.cpp
19  * @brief               This is the implementation file for %_NetUtility class.
20  *
21  * This file contains the implementation of %_NetUtility class.
22  */
23
24 #include <pthread.h>
25 #include <FBaseResult.h>
26 #include <FBaseObject.h>
27 #include <FBaseString.h>
28 #include <FBaseRtMutex.h>
29 #include <FBaseSysLog.h>
30 #include "FNet_NetUtility.h"
31
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Runtime;
34
35 namespace Tizen { namespace Net {
36
37 Mutex* _NetUtility::__pLock = null;
38
39 _NetUtility::_NetUtility(void)
40 {
41 }
42
43 _NetUtility::~_NetUtility(void)
44 {
45 }
46
47 Mutex*
48 _NetUtility::GetLock(void)
49 {
50         static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
51
52         if (__pLock == null)
53         {
54                 ClearLastResult();
55                 pthread_once(&onceBlock, InitLock);
56                 result r = GetLastResult();
57                 if (r != E_SUCCESS)
58                 {
59                         onceBlock = PTHREAD_ONCE_INIT;
60                 }
61         }
62
63         return __pLock;
64 }
65
66 void
67 _NetUtility::InitLock(void)
68 {
69     result r = E_SUCCESS;
70     static Mutex lock;
71
72     r = lock.Create(L"NetLock");
73         SysTryReturnVoidResult(NID_NET, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
74
75         __pLock = &lock;
76
77 }
78
79 }} // Tizen::Net