sync with master
[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 <unique_ptr.h>
24
25 #include <FBaseErrors.h>
26 #include <FBaseSysLog.h>
27 #include <FIo_IpcClient.h>
28
29 #include "FIo_IMmcStorageServiceEventListener.h"
30 #include "FIo_MmcStorageManagerProxy.h"
31 #include "FIo_MmcStorageManagerIpcMessages.h"
32
33 using namespace std;
34
35 using namespace Tizen::Base;
36
37 namespace Tizen { namespace Io
38 {
39
40 _MmcStorageManagerProxy::_MmcStorageManagerProxy(void)
41         : __pIpcClient(null)
42 {
43 }
44
45 _MmcStorageManagerProxy::~_MmcStorageManagerProxy(void)
46 {
47         delete __pIpcClient;
48 }
49
50 result
51 _MmcStorageManagerProxy::Construct(_IMmcStorageServiceEventListener* pListener)
52 {
53         unique_ptr<_IpcClient> pIpcClient(new (std::nothrow) _IpcClient);
54         SysTryReturnResult(NID_IO, pIpcClient != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
55
56         result r = pIpcClient->Construct("osp.io.ipcserver.mmcstoragemanager", this);
57         SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "Failed to connect to IPC server.");
58
59         __pIpcClient = pIpcClient.release();
60         __pListener = pListener;
61
62         return E_SUCCESS;
63 }
64
65 result
66 _MmcStorageManagerProxy::Mount(void)
67 {
68         SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
69
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.");
73
74         result r = __pIpcClient->SendRequest(pMsg.get());
75         SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "SendRequest is failed.");
76
77         SysLog(NID_IO, "Received sync mount response msg from server is: [%s]", GetErrorMessage(response));
78
79         return response;
80 }
81
82 result
83 _MmcStorageManagerProxy::Unmount(void)
84 {
85         SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
86
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.");
90
91         result r = __pIpcClient->SendRequest(pMsg.get());
92         SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "SendRequest is failed.");
93
94         SysLog(NID_IO, "Received sync unmount response msg from server is: [%s]", GetErrorMessage(response));
95
96         return response;
97 }
98
99 result
100 _MmcStorageManagerProxy::Format(void)
101 {
102         SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
103
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.");
107
108         result r = __pIpcClient->SendRequest(pMsg.get());
109         SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "SendRequest is failed.");
110
111         SysLog(NID_IO, "Received sync format response msg from server is: [%s]", GetErrorMessage(response));
112
113         return response;
114 }
115
116 void
117 _MmcStorageManagerProxy::OnIpcResponseReceived(Tizen::Io::_IpcClient& client, const IPC::Message& message)
118 {
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()
124 }
125
126 void
127 _MmcStorageManagerProxy::MountResponseReceived(result r)
128 {
129         SysLog(NID_IO, "Received Async mount response msg from server is : [%s]", GetErrorMessage(r));
130
131         __pListener->OnMmcMountResponseReceived(r);
132 }
133
134 void
135 _MmcStorageManagerProxy::UnmountResponseReceived(result r)
136 {
137         SysLog(NID_IO, "Received Async unmount response msg from server is : [%s]", GetErrorMessage(r));
138
139         __pListener->OnMmcUnmountResponseReceived(r);
140 }
141
142 void
143 _MmcStorageManagerProxy::FormatResponseReceived(result r)
144 {
145         SysLog(NID_IO, "Received Async format response msg from server is : [%s]", GetErrorMessage(r));
146
147         __pListener->OnMmcFormatResponseReceived(r);
148 }
149
150 } } // Tizen::Io