tizen 2.3.1 release
[framework/web/wearable/wrt-plugins-tizen.git] / src / Package / PackageInformation.cpp
1 //
2 // Tizen Web Device API
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 #include <package-manager.h>
19 #include <pkgmgr-info.h>
20 #include <Logger.h>
21
22 #include "PackageInformation.h"
23 #include "PackageUtil.h"
24
25 namespace DeviceAPI {
26 namespace Package {
27
28 PackageInformation::PackageInformation() :
29     m_isInitialized(false)
30 {
31 }
32
33 PackageInformation::~PackageInformation()
34 {
35 }
36
37 void PackageInformation::initializePackageInfo()
38 {
39     LOGD("Enter : %s", m_id.c_str());
40
41     pkgmgr_client *pc = pkgmgr_client_new(PC_REQUEST);
42     if (pc == NULL) {
43         LOGE("Fail to create pkgmgr client");
44     } else {
45         int ret = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, PM_GET_TOTAL_SIZE, pc, NULL, m_id.c_str(), NULL, NULL, NULL);
46         if (ret < 0) {
47             LOGE("Fail to get total size");
48         } else {
49             m_totalSize = ret;
50         }
51
52         ret = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, PM_GET_DATA_SIZE, pc, NULL, m_id.c_str(), NULL, NULL, NULL);
53         if (ret < 0) {
54             LOGE("Fail to get data size");
55         } else {
56             m_dataSize = ret;
57         }
58
59         ret = pkgmgr_client_free(pc);
60         if(ret != PMINFO_R_OK){
61             LOGE("ret : %d , %s", ret, PackageUtil::getPkginfoErrorMessage(ret).c_str());
62         }
63         pc = NULL;
64     }
65
66     LOGD("enter");
67     m_isInitialized = true;
68 }
69
70 }
71 }