2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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 * @author Yunchan Cho (yunchan.cho@samsung.com)
22 #include <dpl/singleton_safe_impl.h>
23 #include <dpl/log/log.h>
24 #include <pkgmgr_installer.h>
25 #include <pkg-manager/pkgmgr_signal.h>
27 IMPLEMENT_SAFE_SINGLETON(PackageManager::PkgmgrSignal)
29 namespace PackageManager {
31 PkgmgrSignal::PkgmgrSignal() :
35 m_reqType(PKGMGR_REQ_INVALID)
39 PkgmgrSignal::~PkgmgrSignal()
43 bool PkgmgrSignal::initialize(int argc, char* argv[])
47 LogInfo("Release already allocated pkgmgr handle");
48 pkgmgr_installer_free(m_handle);
52 m_handle = pkgmgr_installer_new();
54 LogError("Fail to get pkgmgr installer handle");
58 // set information from pkgmgr
59 if (!pkgmgr_installer_receive_request(
60 m_handle, argc, argv))
62 m_noPopup = pkgmgr_installer_is_quiet(m_handle);
63 m_reqType = pkgmgr_installer_get_request_type(m_handle);
64 if (m_reqType != PKGMGR_REQ_INSTALL &&
65 m_reqType != PKGMGR_REQ_UNINSTALL)
67 LogError("Fail to get request type of pkgmgr");
68 pkgmgr_installer_free(m_handle);
73 LogError("Fail to get information of pkgmgr's request");
74 pkgmgr_installer_free(m_handle);
79 m_type = PKGMGR_WEBAPP_TYPE;
84 bool PkgmgrSignal::deinitialize()
88 LogError("PkgmgrSingal not yet intialized");
92 pkgmgr_installer_free(m_handle);
94 m_initialized = false;
98 bool PkgmgrSignal::setPkgname(std::string name)
102 LogError("PkgmgrSingal not yet intialized");
108 LogError("name is empty");
113 LogInfo("Success to set tizen package name: " << m_pkgname);
118 bool PkgmgrSignal::sendSignal(std::string key, std::string value) const
122 LogError("PkgmgrSingal not yet intialized");
126 if (key.empty() || value.empty())
128 LogDebug("key or value is empty");
132 if (m_handle == NULL || m_type.empty() || m_pkgname.empty())
134 LogError("Some data of PkgmgrSignal is empty");
138 // send pkgmgr signal
139 if (pkgmgr_installer_send_signal(
140 m_handle, m_type.c_str(), m_pkgname.c_str(),
141 key.c_str(), value.c_str()))
143 LogError("Fail to send pkgmgr signal");
147 LogInfo("Success to send pkgmgr signal: " << key <<
152 std::string PkgmgrSignal::getPkgname() const
156 LogError("PkgmgrSingal not yet intialized");
162 int PkgmgrSignal::getRequestedType() const
166 LogError("PkgmgrSingal not yet intialized");
172 bool PkgmgrSignal::isNoPopupRequired() const
176 LogError("PkgmgrSingal not yet intialized");