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.
17 * @file FAppPkg_PackageManagerServer.cpp
18 * @brief This is the implementation for the _PackageManagerServer class.
21 #include <unique_ptr.h>
23 #include <package-manager.h>
24 #include <pkgmgr-info.h>
25 #include <package-manager-types.h>
27 #include <FAppPkgPackageAppInfo.h>
28 #include <FAppPkgPackageInfo.h>
29 #include <FBaseString.h>
30 #include <FBaseSysLog.h>
32 #include <FAppPkg_PackageManagerServer.h>
33 #include <FAppPkg_PackageAppInfoImpl.h>
34 #include <FAppPkg_PackageInfoImpl.h>
35 #include <FAppPkg_PackageParser.h>
36 #include <FBase_StringConverter.h>
38 using namespace Tizen::Base;
39 using namespace Tizen::Io;
41 namespace Tizen { namespace App { namespace Package
44 _PackageManagerServer::_PackageManagerServer(void)
48 _PackageManagerServer::~_PackageManagerServer(void)
52 _PackageManagerServer*
53 _PackageManagerServer::GetInstance(void)
55 static _PackageManagerServer* pPackageManagerServer = null;
57 if (pPackageManagerServer == null)
59 pPackageManagerServer = new (std::nothrow) _PackageManagerServer();
60 SysTryReturn(NID_APP, pPackageManagerServer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageManagerServer is null.");
63 return pPackageManagerServer;
67 _PackageManagerServer::GetType(const PackageId& packageId) const
69 int res = PMINFO_R_OK;
70 pkgmgrinfo_pkginfo_h handle = null;
71 PackageType packageType = PACKAGE_TYPE_TPK;
75 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
76 SysTryReturn(NID_APP, pPackageId, PACKAGE_TYPE_TPK, E_OUT_OF_MEMORY, "pPackageId is null.");
78 res = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &handle);
79 SysTryReturn(NID_APP, res == PMINFO_R_OK, PACKAGE_TYPE_TPK, E_PKG_NOT_INSTALLED, "pkgmgrinfo_pkginfo_get_pkginfo() is failed. result=[%d], package=[%s]", res, pPackageId.get());
80 SysTryReturn(NID_APP, handle, PACKAGE_TYPE_TPK, E_SYSTEM, "[E_SYSTEM] handle is null.");
82 res = pkgmgrinfo_pkginfo_get_type(handle, &pType);
83 if (res == PMINFO_R_OK)
85 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_type(): type = [%s]", pType);
88 if (strcmp(pType, "tpk") == 0)
90 packageType = PACKAGE_TYPE_TPK;
92 else if (strcmp(pType, "wgt") == 0)
94 packageType = PACKAGE_TYPE_WGT;
96 else if (strcmp(pType, "rpm") == 0)
98 packageType = PACKAGE_TYPE_RPM;
103 SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_type() is failed. result = [%d]", res);
106 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
111 } } } // Tizen::App::Package