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_IMmcStorageServiceEventListener.h"
29 #include "FIo_MmcStorageManagerProxy.h"
30 #include "FIo_MmcStorageManagerIpcMessages.h"
34 using namespace Tizen::Base;
36 namespace Tizen { namespace Io
39 _MmcStorageManagerProxy::_MmcStorageManagerProxy(void)
44 _MmcStorageManagerProxy::~_MmcStorageManagerProxy(void)
50 _MmcStorageManagerProxy::Construct(_IMmcStorageServiceEventListener* pListener)
52 unique_ptr<_IpcClient> pIpcClient(new (std::nothrow) _IpcClient);
53 SysTryReturnResult(NID_IO, pIpcClient != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
55 result r = pIpcClient->Construct("osp.io.ipcserver.mmcstoragemanager", this);
56 SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "Failed to connect to IPC server.");
58 __pIpcClient = pIpcClient.release();
59 __pListener = pListener;
65 _MmcStorageManagerProxy::Mount(void)
67 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
69 result response = E_SUCCESS;
70 unique_ptr<IPC::Message> pMsg (new (std::nothrow) MmcStorageManager_Mount(&response));
71 SysTryReturnResult(NID_IO, pMsg != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
73 result r = __pIpcClient->SendRequest(pMsg.get());
74 SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "SendRequest is failed.");
76 SysLog(NID_IO, "Received sync mount response msg from server is: [%s]", GetErrorMessage(response));
82 _MmcStorageManagerProxy::Unmount(void)
84 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
86 result response = E_SUCCESS;
87 unique_ptr<IPC::Message> pMsg (new (std::nothrow) MmcStorageManager_Unmount(&response));
88 SysTryReturnResult(NID_IO, pMsg != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
90 result r = __pIpcClient->SendRequest(pMsg.get());
91 SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "SendRequest is failed.");
93 SysLog(NID_IO, "Received sync unmount response msg from server is: [%s]", GetErrorMessage(response));
99 _MmcStorageManagerProxy::Format(void)
101 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
103 result response = E_SUCCESS;
104 unique_ptr<IPC::Message> pMsg (new (std::nothrow) MmcStorageManager_Format(&response));
105 SysTryReturnResult(NID_IO, pMsg != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
107 result r = __pIpcClient->SendRequest(pMsg.get());
108 SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "SendRequest is failed.");
110 SysLog(NID_IO, "Received sync format response msg from server is: [%s]", GetErrorMessage(response));
116 _MmcStorageManagerProxy::OnIpcResponseReceived(Tizen::Io::_IpcClient& client, const IPC::Message& message)
118 IPC_BEGIN_MESSAGE_MAP(_MmcStorageManagerProxy, message)
119 IPC_MESSAGE_HANDLER_EX(MmcStorageManager_MountReceived, &client, MountResponseReceived)
120 IPC_MESSAGE_HANDLER_EX(MmcStorageManager_UnmountReceived, &client, UnmountResponseReceived)
121 IPC_MESSAGE_HANDLER_EX(MmcStorageManager_FormatReceived, &client, FormatResponseReceived)
122 IPC_END_MESSAGE_MAP()
126 _MmcStorageManagerProxy::MountResponseReceived(result r)
128 SysLog(NID_IO, "Received Async mount response msg from server is : [%s]", GetErrorMessage(r));
130 __pListener->OnMmcMountResponseReceived(r);
134 _MmcStorageManagerProxy::UnmountResponseReceived(result r)
136 SysLog(NID_IO, "Received Async unmount response msg from server is : [%s]", GetErrorMessage(r));
138 __pListener->OnMmcUnmountResponseReceived(r);
142 _MmcStorageManagerProxy::FormatResponseReceived(result r)
144 SysLog(NID_IO, "Received Async format response msg from server is : [%s]", GetErrorMessage(r));
146 __pListener->OnMmcFormatResponseReceived(r);