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 FIo_MmcStorageManagerImpl.cpp
19 * @brief This is the implementation file for _MmcStorageManagerImpl class.
22 #include <unique_ptr.h>
24 #include <FBaseSysLog.h>
25 #include <FBaseRtIEventArg.h>
26 #include <FBase_NativeError.h>
27 #include "FIoIMmcStorageMountListener.h"
28 #include "FIoIMmcStorageFormatListener.h"
30 #include "FIo_MmcStorageManagerImpl.h"
31 #include "FIo_MmcStorageManagerProxy.h"
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Base::Runtime;
39 namespace Tizen { namespace Io
42 static const int MOUNT_TYPE = 0;
43 static const int UNMOUNT_TYPE = 1;
49 _MountEventArg(int type, result r)
62 _FormatEventArg(result r)
73 virtual void FireImpl(IEventListener& listener, const IEventArg& arg)
75 const _MountEventArg* pArg = dynamic_cast<const _MountEventArg*>(&arg);
78 IMmcStorageMountListener* pListener = dynamic_cast<IMmcStorageMountListener*> (&listener);
79 if (pListener != null)
81 if (pArg->__type == MOUNT_TYPE) // Mount
83 pListener->OnMmcStorageMounted(pArg->__r);
87 pListener->OnMmcStorageUnmounted(pArg->__r);
99 virtual void FireImpl(IEventListener& listener, const IEventArg& arg)
101 IMmcStorageFormatListener* pListener = dynamic_cast<IMmcStorageFormatListener*> (&listener);
102 if (pListener != null)
104 const _FormatEventArg* pArg = dynamic_cast<const _FormatEventArg*>(&arg);
107 pListener->OnMmcStorageFormatted(pArg->__r);
115 _MmcStorageManagerImpl::_MmcStorageManagerImpl(void)
116 : __pMmcStorageManagerProxy(null)
117 , __pMountEvent(null)
118 , __pFormatEvent(null)
122 _MmcStorageManagerImpl::~_MmcStorageManagerImpl(void)
124 delete __pMountEvent;
125 delete __pFormatEvent;
129 _MmcStorageManagerImpl::Construct(void)
131 unique_ptr<_MountEvent> pMountEvent(new (std::nothrow) _MountEvent);
132 SysTryReturnResult(NID_IO, pMountEvent != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
134 unique_ptr<_FormatEvent> pFormatEvent(new (std::nothrow) _FormatEvent);
135 SysTryReturnResult(NID_IO, pFormatEvent != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
137 __pMountEvent = pMountEvent.release();
138 __pFormatEvent = pFormatEvent.release();
143 _MmcStorageManagerImpl*
144 _MmcStorageManagerImpl::GetInstance(void)
146 static _MmcStorageManagerImpl* pImpl = null;
149 unique_ptr<_MmcStorageManagerImpl> pMmcStorageManagerImpl(new (std::nothrow) _MmcStorageManagerImpl);
150 SysTryReturn(NID_IO, pMmcStorageManagerImpl != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
152 result r = pMmcStorageManagerImpl->Construct();
153 SysTryReturn(NID_IO, !IsFailed(r), null, r, "[%s] Propagating to caller...", GetErrorMessage(r));
155 pImpl = pMmcStorageManagerImpl.release();
162 _MmcStorageManagerImpl::Mount(void)
164 if (__pMmcStorageManagerProxy == null)
166 __pMmcStorageManagerProxy = _MmcStorageManagerProxy::GetInstance();
167 SysTryReturnResult(NID_IO, __pMmcStorageManagerProxy != null, E_SERVICE_BUSY, "Failed to get IPC proxy instance.");
168 __pMmcStorageManagerProxy->SetMmcStorageManagerListener(this);
170 return __pMmcStorageManagerProxy->Mount();
174 _MmcStorageManagerImpl::Unmount(void)
176 if (__pMmcStorageManagerProxy == null)
178 __pMmcStorageManagerProxy = _MmcStorageManagerProxy::GetInstance();
179 SysTryReturnResult(NID_IO, __pMmcStorageManagerProxy != null, E_SERVICE_BUSY, "Failed to get IPC proxy instance.");
180 __pMmcStorageManagerProxy->SetMmcStorageManagerListener(this);
182 return __pMmcStorageManagerProxy->Unmount();
186 _MmcStorageManagerImpl::Format(void)
188 if (__pMmcStorageManagerProxy == null)
190 __pMmcStorageManagerProxy = _MmcStorageManagerProxy::GetInstance();
191 SysTryReturnResult(NID_IO, __pMmcStorageManagerProxy != null, E_SERVICE_BUSY, "Failed to get IPC proxy instance.");
192 __pMmcStorageManagerProxy->SetMmcStorageManagerListener(this);
194 return __pMmcStorageManagerProxy->Format();
198 _MmcStorageManagerImpl::AddMmcStorageMountListener(IMmcStorageMountListener& listener)
200 return __pMountEvent->AddListener(listener);
204 _MmcStorageManagerImpl::RemoveMmcStorageMountListener(IMmcStorageMountListener& listener)
206 return __pMountEvent->RemoveListener(listener);
210 _MmcStorageManagerImpl::AddMmcStorageFormatListener(IMmcStorageFormatListener& listener)
212 return __pFormatEvent->AddListener(listener);
216 _MmcStorageManagerImpl::RemoveMmcStorageFormatListener(IMmcStorageFormatListener& listener)
218 return __pFormatEvent->RemoveListener(listener);
222 _MmcStorageManagerImpl::OnMmcMountResponseReceived(result r)
224 _MountEventArg* pEventArg= new (std::nothrow) _MountEventArg(MOUNT_TYPE, r);
225 if(pEventArg != null)
227 __pMountEvent->Fire(*pEventArg);
232 _MmcStorageManagerImpl::OnMmcUnmountResponseReceived(result r)
234 _MountEventArg* pEventArg= new (std::nothrow) _MountEventArg(UNMOUNT_TYPE, r);
235 if(pEventArg != null)
237 __pMountEvent->Fire(*pEventArg);
242 _MmcStorageManagerImpl::OnMmcFormatResponseReceived(result r)
244 _FormatEventArg* pEventArg= new (std::nothrow) _FormatEventArg(r);
245 if(pEventArg != null)
247 __pFormatEvent->Fire(*pEventArg);