Fix the defect of calculating time
[platform/framework/native/appfw.git] / src / io / FIo_MmcStorageManagerProxy.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file        FIo_MmcStorageManagerProxy.cpp
19  * @brief       This is the implementation for the _MmcStorageManagerProxy class.
20  */
21
22 #include <unique_ptr.h>
23
24 #include <FBaseErrors.h>
25 #include <FBaseSysLog.h>
26 #include <FIo_IpcClient.h>
27
28 #include "FIo_IMmcStorageServiceEventListener.h"
29 #include "FIo_MmcStorageManagerProxy.h"
30 #include "FIo_MmcStorageManagerIpcMessages.h"
31
32 using namespace std;
33
34 using namespace Tizen::Base;
35
36 namespace Tizen { namespace Io
37 {
38
39 _MmcStorageManagerProxy::_MmcStorageManagerProxy(void)
40         : __pIpcClient(null)
41 {
42 }
43
44 _MmcStorageManagerProxy::~_MmcStorageManagerProxy(void)
45 {
46         delete __pIpcClient;
47 }
48
49 result
50 _MmcStorageManagerProxy::Construct(_IMmcStorageServiceEventListener* pListener)
51 {
52         unique_ptr<_IpcClient> pIpcClient(new (std::nothrow) _IpcClient);
53         SysTryReturnResult(NID_IO, pIpcClient != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
54
55         result r = pIpcClient->Construct("osp.io.ipcserver.mmcstoragemanager", this);
56         SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "Failed to connect to IPC server.");
57
58         __pIpcClient = pIpcClient.release();
59         __pListener = pListener;
60
61         return E_SUCCESS;
62 }
63
64 result
65 _MmcStorageManagerProxy::Mount(void)
66 {
67         SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
68
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.");
72
73         result r = __pIpcClient->SendRequest(pMsg.get());
74         SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "SendRequest is failed.");
75
76         SysLog(NID_IO, "Received sync mount response msg from server is: [%s]", GetErrorMessage(response));
77
78         return response;
79 }
80
81 result
82 _MmcStorageManagerProxy::Unmount(void)
83 {
84         SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
85
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.");
89
90         result r = __pIpcClient->SendRequest(pMsg.get());
91         SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "SendRequest is failed.");
92
93         SysLog(NID_IO, "Received sync unmount response msg from server is: [%s]", GetErrorMessage(response));
94
95         return response;
96 }
97
98 result
99 _MmcStorageManagerProxy::Format(void)
100 {
101         SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
102
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.");
106
107         result r = __pIpcClient->SendRequest(pMsg.get());
108         SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "SendRequest is failed.");
109
110         SysLog(NID_IO, "Received sync format response msg from server is: [%s]", GetErrorMessage(response));
111
112         return response;
113 }
114
115 void
116 _MmcStorageManagerProxy::OnIpcResponseReceived(Tizen::Io::_IpcClient& client, const IPC::Message& message)
117 {
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()
123 }
124
125 void
126 _MmcStorageManagerProxy::MountResponseReceived(result r)
127 {
128         SysLog(NID_IO, "Received Async mount response msg from server is : [%s]", GetErrorMessage(r));
129
130         __pListener->OnMmcMountResponseReceived(r);
131 }
132
133 void
134 _MmcStorageManagerProxy::UnmountResponseReceived(result r)
135 {
136         SysLog(NID_IO, "Received Async unmount response msg from server is : [%s]", GetErrorMessage(r));
137
138         __pListener->OnMmcUnmountResponseReceived(r);
139 }
140
141 void
142 _MmcStorageManagerProxy::FormatResponseReceived(result r)
143 {
144         SysLog(NID_IO, "Received Async format response msg from server is : [%s]", GetErrorMessage(r));
145
146         __pListener->OnMmcFormatResponseReceived(r);
147 }
148
149 } } // Tizen::Io