sync with tizen_2.0
[platform/framework/native/appfw.git] / src / io / FIo_MmcStorageManagerProxy.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file        FIo_MmcStorageManagerProxy.cpp
20  * @brief       This is the implementation for the _MmcStorageManagerProxy class.
21  */
22
23 #include <new>
24 #include <memory>
25
26 #include <FBaseErrors.h>
27 #include <FBaseSysLog.h>
28 #include <FIo_IpcClient.h>
29
30 #include "FIo_IMmcStorageServiceEventListener.h"
31 #include "FIo_MmcStorageManagerProxy.h"
32 #include "FIo_MmcStorageManagerIpcMessages.h"
33
34 using namespace Tizen::Base;
35
36 namespace Tizen { namespace Io
37 {
38
39 _IMmcStorageServiceEventListener* _MmcStorageManagerProxy::__pImpl = null;
40
41 _MmcStorageManagerProxy::_MmcStorageManagerProxy(void)
42         : __pIpcClient(null)
43 {
44 }
45
46 _MmcStorageManagerProxy::~_MmcStorageManagerProxy(void)
47 {
48         delete __pIpcClient;
49 }
50
51 result
52 _MmcStorageManagerProxy::Construct(_IMmcStorageServiceEventListener* pImpl)
53 {
54         __pIpcClient = new (std::nothrow) _IpcClient();
55         SysTryReturnResult(NID_IO, __pIpcClient != null, E_OUT_OF_MEMORY, "_IpcClient creation failed.");
56
57         result r = __pIpcClient->Construct("osp.io.ipcserver.mmcstoragemanager", this);
58         SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] _IpcClient::Construct failed.", GetErrorMessage(r));
59
60         __pImpl = pImpl;
61
62         return E_SUCCESS;
63 }
64
65 result
66 _MmcStorageManagerProxy::Mount(void)
67 {
68         SysTryReturnResult(NID_IO, __pIpcClient != null, E_INVALID_STATE, "__pIpcClient instance must not be null.");
69
70         result response = E_SUCCESS;
71         std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) MmcStorageManager_Mount(&response));
72         result r = __pIpcClient->SendRequest(pMsg.get());
73
74         SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] SendRequest is failed.", GetErrorMessage(r));
75
76         SysLog(NID_IO, "Received sync mount response msg from server is: [%s]\n", GetErrorMessage(response));
77         return response;
78 }
79
80 result
81 _MmcStorageManagerProxy::Unmount(void)
82 {
83         SysTryReturnResult(NID_IO, __pIpcClient != null, E_INVALID_STATE, "__pIpcClient instance must not be null.");
84
85         result response = E_SUCCESS;
86         std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) MmcStorageManager_Unmount(&response));
87         result r = __pIpcClient->SendRequest(pMsg.get());
88
89         SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] SendRequest is failed.", GetErrorMessage(r));
90
91         SysLog(NID_IO, "Received sync unmount response msg from server is: [%s]\n", GetErrorMessage(response));
92         return response;
93 }
94
95 result
96 _MmcStorageManagerProxy::Format(void)
97 {
98         SysTryReturnResult(NID_IO, __pIpcClient != null, E_INVALID_STATE, "__pIpcClient instance must not be null.");
99
100         result response = E_SUCCESS;
101         std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) MmcStorageManager_Format(&response));
102         result r = __pIpcClient->SendRequest(pMsg.get());
103
104         SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] SendRequest is failed.", GetErrorMessage(r));
105
106         SysLog(NID_IO, "Received sync format response msg from server is: [%s]\n", GetErrorMessage(response));
107         return response;
108 }
109
110 void
111 _MmcStorageManagerProxy::OnIpcResponseReceived(Tizen::Io::_IpcClient& client, const IPC::Message& message)
112 {
113         IPC_BEGIN_MESSAGE_MAP(_MmcStorageManagerProxy, message)
114                 IPC_MESSAGE_HANDLER_EX(MmcStorageManager_MountReceived, &client, MountResponseReceived)
115                 IPC_MESSAGE_HANDLER_EX(MmcStorageManager_UnmountReceived, &client, UnmountResponseReceived)
116                 IPC_MESSAGE_HANDLER_EX(MmcStorageManager_FormatReceived, &client, FormatResponseReceived)
117         IPC_END_MESSAGE_MAP()
118 }
119
120 void
121 _MmcStorageManagerProxy::MountResponseReceived(result r)
122 {
123         SysLog(NID_IO, "Received Async mount response msg from server is : [%s]\n", GetErrorMessage(r));
124         __pImpl->OnMmcMountResponseReceived(r);
125 }
126
127 void
128 _MmcStorageManagerProxy::UnmountResponseReceived(result r)
129 {
130         SysLog(NID_IO, "Received Async unmount response msg from server is : [%s]\n", GetErrorMessage(r));
131         __pImpl->OnMmcUnmountResponseReceived(r);
132 }
133
134 void
135 _MmcStorageManagerProxy::FormatResponseReceived(result r)
136 {
137         SysLog(NID_IO, "Received Async format response msg from server is : [%s]\n", GetErrorMessage(r));
138         __pImpl->OnMmcFormatResponseReceived(r);
139 }
140
141 } } // Tizen::Io