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_MmcStorageManagerProxy.cpp
19 * @brief This is the implementation for the _MmcStorageManagerProxy class.
22 #include <unique_ptr.h>
24 #include <FBaseErrors.h>
25 #include <FBaseSysLog.h>
26 #include "FIo_IpcClient.h"
28 #include "FIo_MmcStorageManagerProxy.h"
29 #include "FIo_MmcStorageManagerIpcMessages.h"
32 using namespace Tizen::Base;
34 namespace Tizen { namespace Io
37 _MmcStorageManagerProxy* _MmcStorageManagerProxy::__pMmcStorageManagerProxyInstance = null;
39 _MmcStorageManagerProxy::_MmcStorageManagerProxy(void)
45 _MmcStorageManagerProxy::~_MmcStorageManagerProxy(void)
51 _MmcStorageManagerProxy::Construct(void)
53 unique_ptr<_IpcClient> pIpcClient(new (std::nothrow) _IpcClient);
54 SysTryReturnResult(NID_IO, pIpcClient != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
56 result r = pIpcClient->Construct("osp.io.ipcserver.mmcstoragemanager", this);
57 SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "Failed to connect to IPC server.");
59 __pIpcClient = pIpcClient.release();
65 _MmcStorageManagerProxy::InitSingleton(void)
67 _MmcStorageManagerProxy* pInst = new (std::nothrow) _MmcStorageManagerProxy();
68 SysTryReturnVoidResult(NID_IO, pInst != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
70 result r = pInst->Construct();
71 SysTryCatch(NID_IO, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
73 __pMmcStorageManagerProxyInstance = pInst;
75 std::atexit(DestroySingleton);
83 _MmcStorageManagerProxy::DestroySingleton(void)
85 delete __pMmcStorageManagerProxyInstance;
88 _MmcStorageManagerProxy*
89 _MmcStorageManagerProxy::GetInstance(void)
91 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
93 if (__pMmcStorageManagerProxyInstance == null)
96 pthread_once(&onceBlock, InitSingleton);
97 result r = GetLastResult();
100 onceBlock = PTHREAD_ONCE_INIT;
101 SysPropagate(NID_IO, r);
105 return __pMmcStorageManagerProxyInstance;
109 _MmcStorageManagerProxy::SetMmcStorageManagerListener(_IMmcStorageManagerListener* pListener)
111 __pListener = pListener;
115 _MmcStorageManagerProxy::Mount(void)
117 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
119 result response = E_SUCCESS;
120 unique_ptr<IPC::Message> pMsg (new (std::nothrow) MmcStorageManager_Mount(&response));
121 SysTryReturnResult(NID_IO, pMsg != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
123 result r = __pIpcClient->SendRequest(pMsg.get());
124 SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "SendRequest is failed.");
126 SysLog(NID_IO, "Received sync mount response msg from server is: [%s]", GetErrorMessage(response));
132 _MmcStorageManagerProxy::Unmount(void)
134 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
136 result response = E_SUCCESS;
137 unique_ptr<IPC::Message> pMsg (new (std::nothrow) MmcStorageManager_Unmount(&response));
138 SysTryReturnResult(NID_IO, pMsg != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
140 result r = __pIpcClient->SendRequest(pMsg.get());
141 SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "SendRequest is failed.");
143 SysLog(NID_IO, "Received sync unmount response msg from server is: [%s]", GetErrorMessage(response));
149 _MmcStorageManagerProxy::Format(void)
151 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
153 result response = E_SUCCESS;
154 unique_ptr<IPC::Message> pMsg (new (std::nothrow) MmcStorageManager_Format(&response));
155 SysTryReturnResult(NID_IO, pMsg != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
157 result r = __pIpcClient->SendRequest(pMsg.get());
158 SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "SendRequest is failed.");
160 SysLog(NID_IO, "Received sync format response msg from server is: [%s]", GetErrorMessage(response));
166 _MmcStorageManagerProxy::OnIpcResponseReceived(Tizen::Io::_IpcClient& client, const IPC::Message& message)
168 IPC_BEGIN_MESSAGE_MAP(_MmcStorageManagerProxy, message)
169 IPC_MESSAGE_HANDLER_EX(MmcStorageManager_MountReceived, &client, MountResponseReceived)
170 IPC_MESSAGE_HANDLER_EX(MmcStorageManager_UnmountReceived, &client, UnmountResponseReceived)
171 IPC_MESSAGE_HANDLER_EX(MmcStorageManager_FormatReceived, &client, FormatResponseReceived)
172 IPC_END_MESSAGE_MAP()
176 _MmcStorageManagerProxy::MountResponseReceived(result r)
178 SysLog(NID_IO, "Received Async mount response msg from server is : [%s]", GetErrorMessage(r));
179 if (__pListener != null)
181 __pListener->OnMmcMountResponseReceived(r);
186 _MmcStorageManagerProxy::UnmountResponseReceived(result r)
188 SysLog(NID_IO, "Received Async unmount response msg from server is : [%s]", GetErrorMessage(r));
189 if (__pListener != null)
191 __pListener->OnMmcUnmountResponseReceived(r);
196 _MmcStorageManagerProxy::FormatResponseReceived(result r)
198 SysLog(NID_IO, "Received Async format response msg from server is : [%s]", GetErrorMessage(r));
199 if (__pListener != null)
201 __pListener->OnMmcFormatResponseReceived(r);