2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FIoMmcStorageManager.cpp
19 * @brief This is the implementation file for MmcStorageManager class.
26 #include <FBaseSysLog.h>
27 #include <FIoMmcStorageManager.h>
29 #include <FBase_NativeError.h>
30 #include <FIo_MmcStorageManagerImpl.h>
31 #include <FSec_AccessController.h>
33 using namespace Tizen::Base;
34 using namespace Tizen::Security;
36 namespace Tizen { namespace Io
39 MmcStorageManager* MmcStorageManager::__pMmcStorageManagerInstance = null;
41 MmcStorageManager::MmcStorageManager(void)
42 : __pMmcStorageManagerImpl(null)
46 MmcStorageManager::~MmcStorageManager(void)
48 delete __pMmcStorageManagerImpl;
52 MmcStorageManager::InitSingleton(void)
54 MmcStorageManager* pInst = new (std::nothrow) MmcStorageManager();
55 SysTryReturnVoidResult(NID_IO, pInst != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
57 pInst->__pMmcStorageManagerImpl = _MmcStorageManagerImpl::GetInstance();
58 SysTryCatch(NID_IO, pInst->__pMmcStorageManagerImpl != null, , GetLastResult(),
59 "[%s] Propagating to caller...", GetErrorMessage(GetLastResult()));
61 __pMmcStorageManagerInstance = pInst;
63 std::atexit(DestroySingleton);
71 MmcStorageManager::DestroySingleton(void)
73 delete __pMmcStorageManagerInstance;
77 MmcStorageManager::GetInstance(void)
79 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
81 if (__pMmcStorageManagerInstance == null)
84 pthread_once(&onceBlock, InitSingleton);
85 result r = GetLastResult();
88 onceBlock = PTHREAD_ONCE_INIT;
89 SysPropagate(NID_IO, r);
93 return __pMmcStorageManagerInstance;
97 MmcStorageManager::Mount(void)
99 SysAssertf(__pMmcStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
101 return __pMmcStorageManagerImpl->Mount();
105 MmcStorageManager::Unmount(void)
107 SysAssertf(__pMmcStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
109 return __pMmcStorageManagerImpl->Unmount();
113 MmcStorageManager::Format(void)
115 SysAssertf(__pMmcStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
117 return __pMmcStorageManagerImpl->Format();
121 MmcStorageManager::AddMmcStorageMountListener(IMmcStorageMountListener& listener)
123 SysAssertf(__pMmcStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
125 // Compatibility issue
126 result r = __pMmcStorageManagerImpl->AddMmcStorageMountListener(listener);
129 case E_OBJ_ALREADY_EXIST:
131 case E_INVALID_OPERATION:
141 MmcStorageManager::RemoveMmcStorageMountListener(IMmcStorageMountListener& listener)
143 SysAssertf(__pMmcStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
145 // Compatibility issue
146 result r = __pMmcStorageManagerImpl->RemoveMmcStorageMountListener(listener);
149 case E_OBJ_NOT_FOUND:
159 MmcStorageManager::AddMmcStorageFormatListener(IMmcStorageFormatListener& listener)
161 SysAssertf(__pMmcStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
163 // Compatibility issue
164 result r = __pMmcStorageManagerImpl->AddMmcStorageFormatListener(listener);
167 case E_OBJ_ALREADY_EXIST:
169 case E_INVALID_OPERATION:
179 MmcStorageManager::RemoveMmcStorageFormatListener(IMmcStorageFormatListener& listener)
181 SysAssertf(__pMmcStorageManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
183 result r = __pMmcStorageManagerImpl->RemoveMmcStorageFormatListener(listener);
186 case E_OBJ_NOT_FOUND: