Backout 128 limits in DataControl
[platform/framework/native/appfw.git] / src / io / FIoMmcStorageManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 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 /**
19  * @file        FIoMmcStorageManager.cpp
20  * @brief       This is the implementation file for MmcStorageManager class.
21  */
22
23 #include <cstdlib>
24 #include <pthread.h>
25 #include <limits.h>
26
27 #include <FBaseSysLog.h>
28 #include <FIoMmcStorageManager.h>
29
30 #include <FSec_AccessController.h>
31 #include <FBase_NativeError.h>
32 #include <FIo_MmcStorageManagerImpl.h>
33
34 using namespace Tizen::Base;
35 using namespace Tizen::Security;
36
37 namespace Tizen { namespace Io
38 {
39
40 MmcStorageManager* MmcStorageManager::__pMmcStorageManagerInstance = null;
41
42 MmcStorageManager::MmcStorageManager(void)
43         : __pMmcStorageManagerImpl(null)
44 {
45 }
46
47 MmcStorageManager::~MmcStorageManager(void)
48 {
49         delete __pMmcStorageManagerImpl;
50 }
51
52 void
53 MmcStorageManager::InitSingleton(void)
54 {
55         MmcStorageManager* pInst = new (std::nothrow) MmcStorageManager();
56         SysTryReturnVoidResult(NID_IO, pInst != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
57
58         pInst->__pMmcStorageManagerImpl = _MmcStorageManagerImpl::GetInstance();
59         SysTryCatch(NID_IO, pInst->__pMmcStorageManagerImpl != null, , GetLastResult(),
60                         "[%s] Propagated.", GetErrorMessage(GetLastResult()));
61
62         __pMmcStorageManagerInstance = pInst;
63                 
64         std::atexit(DestroySingleton);
65         return;
66
67 CATCH:
68         delete pInst;
69 }
70
71 void
72 MmcStorageManager::DestroySingleton(void)
73 {
74         delete __pMmcStorageManagerInstance;
75 }
76
77 MmcStorageManager*
78 MmcStorageManager::GetInstance(void)
79 {
80         static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
81
82         if (__pMmcStorageManagerInstance == null)
83         {
84                 ClearLastResult();
85                 pthread_once(&onceBlock, InitSingleton);
86                 result r = GetLastResult();
87                 if (IsFailed(r))
88                 {
89                         onceBlock = PTHREAD_ONCE_INIT;
90                         SysPropagate(NID_IO, r);
91                 }
92         }
93
94         return __pMmcStorageManagerInstance;
95 }
96
97 result
98 MmcStorageManager::Mount(void)
99 {
100         SysAssertf(__pMmcStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
101
102         return __pMmcStorageManagerImpl->Mount();
103 }
104
105 result
106 MmcStorageManager::Unmount(void)
107 {
108         SysAssertf(__pMmcStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
109
110         return __pMmcStorageManagerImpl->Unmount();
111 }
112
113 result
114 MmcStorageManager::Format(void)
115 {
116         SysAssertf(__pMmcStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
117
118         return __pMmcStorageManagerImpl->Format();
119 }
120
121 result
122 MmcStorageManager::AddMmcStorageMountListener(IMmcStorageMountListener& listener)
123 {
124         SysAssertf(__pMmcStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
125
126         // Compatibility issue
127         result r = __pMmcStorageManagerImpl->AddMmcStorageMountListener(listener);
128         switch(r)
129         {
130                 case E_OBJ_ALREADY_EXIST:
131                         return E_SUCCESS;
132                 case E_INVALID_OPERATION:
133                         return E_SYSTEM;
134                 default:
135                         break;
136         }
137
138         return r;
139 }
140
141 result
142 MmcStorageManager::RemoveMmcStorageMountListener(IMmcStorageMountListener& listener)
143 {
144         SysAssertf(__pMmcStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
145
146         // Compatibility issue
147         result r = __pMmcStorageManagerImpl->RemoveMmcStorageMountListener(listener);
148         switch(r)
149         {
150                 case E_OBJ_NOT_FOUND:
151                         return E_SUCCESS;
152                 default:
153                         break;
154         }
155
156         return r;
157 }
158
159 result
160 MmcStorageManager::AddMmcStorageFormatListener(IMmcStorageFormatListener& listener)
161 {
162         SysAssertf(__pMmcStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
163
164         // Compatibility issue
165         result r = __pMmcStorageManagerImpl->AddMmcStorageFormatListener(listener);
166         switch(r)
167         {
168                 case E_OBJ_ALREADY_EXIST:
169                         return E_SUCCESS;
170                 case E_INVALID_OPERATION:
171                         return E_SYSTEM;
172                 default:
173                         break;
174         }
175
176         return r;
177 }
178
179 result
180 MmcStorageManager::RemoveMmcStorageFormatListener(IMmcStorageFormatListener& listener)
181 {
182         SysAssertf(__pMmcStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
183
184         result r = __pMmcStorageManagerImpl->RemoveMmcStorageFormatListener(listener);
185         switch(r)
186         {
187                 case E_OBJ_NOT_FOUND:
188                         return E_SUCCESS;
189                 default:
190                         break;
191         }
192
193         return r;
194 }
195
196 }} // Tizen::Io
197