Merge "Change the way to convert wchar_t* to char* in CopyToCharArrayN()" into tizen_2.1
[platform/framework/native/appfw.git] / src / app / FApp_PackageManagerProxy.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         FApp_PackageManagerProxy.cpp
20  * @brief       This is the implementation for the _PackageManagerProxy.cpp class.
21  */
22
23 #include <new>
24 #include <memory>
25
26 #include <FBaseErrors.h>
27 #include <FBaseSysLog.h>
28 #include <FAppPkgIPackageInstallationResponseListener.h>
29 #include <FAppPkgIPackageUninstallationResponseListener.h>
30 #include <FIo_IpcClient.h>
31
32 #include "FApp_PackageManagerIpcMessages.h"
33 #include "FApp_PackageManagerProxy.h"
34
35 using namespace Tizen::Base;
36 using namespace Tizen::App::Package;
37
38 namespace Tizen { namespace App
39 {
40
41 _PackageManagerProxy::_PackageManagerProxy(void)
42         : __pIpcClient(null)
43 {
44 }
45
46 _PackageManagerProxy::~_PackageManagerProxy(void)
47 {
48         delete __pIpcClient;
49 }
50
51 result
52 _PackageManagerProxy::Construct()
53 {
54         __pIpcClient = new (std::nothrow) Tizen::Io::_IpcClient();
55         SysTryReturnResult(NID_APP, __pIpcClient != null, E_OUT_OF_MEMORY, "_IpcClient creation failed.");
56
57         result r = __pIpcClient->Construct("osp.app.ipcserver.packagemanager");
58         SysTryReturn(NID_APP, !IsFailed(r), r, r, "_IpcClient constructing failed [%s].", GetErrorMessage(r));
59
60         return E_SUCCESS;
61 }
62
63 result
64 _PackageManagerProxy::InstallPackage(const PackageId& packageId, const String& packagePath, IPackageInstallationResponseListener* pListener)
65 {
66         SysTryReturnResult(NID_APP, __pIpcClient != null, E_INVALID_STATE, "__pIpcClient instance must not be null.");
67         SysLog(NID_APP, "_PackageManagerProxy::InstallPackage");
68
69         result response = E_SUCCESS;
70         std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) PackageManager_InstallPackage(packageId, packagePath, (int) pListener, &response));
71         result r = __pIpcClient->SendRequest(*pMsg.get());
72
73         SysTryReturn(NID_APP, !IsFailed(r), r, r, "__pIpcClient->SendRequest is failed. (%s)", GetErrorMessage(r));
74
75         return response;
76 }
77
78 result
79 _PackageManagerProxy::UninstallPackage(const PackageId& packageId, IPackageUninstallationResponseListener* pListener)
80 {
81         SysTryReturnResult(NID_APP, __pIpcClient != null, E_INVALID_STATE, "__pIpcClient instance must not be null.");
82         SysLog(NID_APP, "_PackageManagerProxy::UninstallPackage");
83
84         result response = E_SUCCESS;
85         std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) PackageManager_UninstallPackage(packageId, (int)pListener, &response));
86         result r = __pIpcClient->SendRequest(*pMsg.get());
87
88         SysTryReturn(NID_APP, !IsFailed(r), r, r, "__pIpcClient->SendRequest is failed. (%s)", GetErrorMessage(r));
89
90         return response;
91 }
92
93 } } // Tizen::App