2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FIo_MmcStorageManagerProxy.cpp
20 * @brief This is the implementation for the _MmcStorageManagerProxy class.
23 #include <unique_ptr.h>
25 #include <FBaseErrors.h>
26 #include <FBaseSysLog.h>
27 #include <FIo_IpcClient.h>
29 #include "FIo_IMmcStorageServiceEventListener.h"
30 #include "FIo_MmcStorageManagerProxy.h"
31 #include "FIo_MmcStorageManagerIpcMessages.h"
35 using namespace Tizen::Base;
37 namespace Tizen { namespace Io
40 _MmcStorageManagerProxy::_MmcStorageManagerProxy(void)
45 _MmcStorageManagerProxy::~_MmcStorageManagerProxy(void)
51 _MmcStorageManagerProxy::Construct(_IMmcStorageServiceEventListener* pListener)
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();
60 __pListener = pListener;
66 _MmcStorageManagerProxy::Mount(void)
68 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
70 result response = E_SUCCESS;
71 unique_ptr<IPC::Message> pMsg (new (std::nothrow) MmcStorageManager_Mount(&response));
72 SysTryReturnResult(NID_IO, pMsg != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
74 result r = __pIpcClient->SendRequest(pMsg.get());
75 SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "SendRequest is failed.");
77 SysLog(NID_IO, "Received sync mount response msg from server is: [%s]", GetErrorMessage(response));
83 _MmcStorageManagerProxy::Unmount(void)
85 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
87 result response = E_SUCCESS;
88 unique_ptr<IPC::Message> pMsg (new (std::nothrow) MmcStorageManager_Unmount(&response));
89 SysTryReturnResult(NID_IO, pMsg != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
91 result r = __pIpcClient->SendRequest(pMsg.get());
92 SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "SendRequest is failed.");
94 SysLog(NID_IO, "Received sync unmount response msg from server is: [%s]", GetErrorMessage(response));
100 _MmcStorageManagerProxy::Format(void)
102 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
104 result response = E_SUCCESS;
105 unique_ptr<IPC::Message> pMsg (new (std::nothrow) MmcStorageManager_Format(&response));
106 SysTryReturnResult(NID_IO, pMsg != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
108 result r = __pIpcClient->SendRequest(pMsg.get());
109 SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "SendRequest is failed.");
111 SysLog(NID_IO, "Received sync format response msg from server is: [%s]", GetErrorMessage(response));
117 _MmcStorageManagerProxy::OnIpcResponseReceived(Tizen::Io::_IpcClient& client, const IPC::Message& message)
119 IPC_BEGIN_MESSAGE_MAP(_MmcStorageManagerProxy, message)
120 IPC_MESSAGE_HANDLER_EX(MmcStorageManager_MountReceived, &client, MountResponseReceived)
121 IPC_MESSAGE_HANDLER_EX(MmcStorageManager_UnmountReceived, &client, UnmountResponseReceived)
122 IPC_MESSAGE_HANDLER_EX(MmcStorageManager_FormatReceived, &client, FormatResponseReceived)
123 IPC_END_MESSAGE_MAP()
127 _MmcStorageManagerProxy::MountResponseReceived(result r)
129 SysLog(NID_IO, "Received Async mount response msg from server is : [%s]", GetErrorMessage(r));
131 __pListener->OnMmcMountResponseReceived(r);
135 _MmcStorageManagerProxy::UnmountResponseReceived(result r)
137 SysLog(NID_IO, "Received Async unmount response msg from server is : [%s]", GetErrorMessage(r));
139 __pListener->OnMmcUnmountResponseReceived(r);
143 _MmcStorageManagerProxy::FormatResponseReceived(result r)
145 SysLog(NID_IO, "Received Async format response msg from server is : [%s]", GetErrorMessage(r));
147 __pListener->OnMmcFormatResponseReceived(r);