1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by a apache 2.0 license that can be
3 // found in the LICENSE file.
5 #include "common/pkgmgr_signal.h"
9 #include "utils/logging.h"
11 // Redefine this value as it is not exported by pkgmgr
12 // this should probably be in public interface because of
13 // otherwise there is no way to return errorcode
14 #define PKGMGR_INSTALLER_ERROR_KEY_STR "error"
16 namespace common_installer {
18 PkgmgrSignal::PkgmgrSignal(pkgmgr_installer* pi)
20 state_(State::NOT_SENT) {
23 bool PkgmgrSignal::SendStarted(
24 const std::string& type, const std::string& pkgid) {
25 if (state_ != State::NOT_SENT) {
29 if (!SendSignal(PKGMGR_INSTALLER_START_KEY_STR,
30 (pkgmgr_installer_get_request_type(pi_) != PKGMGR_REQ_UNINSTALL)
31 ? PKGMGR_INSTALLER_INSTALL_EVENT_STR
32 : PKGMGR_INSTALLER_UNINSTALL_EVENT_STR,
36 state_ = State::STARTED;
40 bool PkgmgrSignal::SendProgress(int progress,
41 const std::string& type, const std::string& pkgid) {
42 if (state_ != State::STARTED) {
46 return SendSignal(PKGMGR_INSTALLER_INSTALL_PERCENT_KEY_STR,
47 std::to_string(progress).c_str(), type, pkgid);
50 bool PkgmgrSignal::SendFinished(
51 Step::Status result, const std::string& type, const std::string& pkgid) {
52 if (state_ != State::STARTED) {
55 if (result != Step::Status::OK) {
57 PKGMGR_INSTALLER_ERROR_KEY_STR,
58 std::to_string(static_cast<int>(result)).c_str(), type, pkgid)) {
63 PKGMGR_INSTALLER_END_KEY_STR, GetResultKey(result), type, pkgid)) {
66 state_ = State::FINISHED;
70 bool PkgmgrSignal::IsFinished() const {
71 return state_ == State::FINISHED;
74 bool PkgmgrSignal::SendSignal(
77 const std::string& type,
78 const std::string& pkgid) const {
80 if (pkgmgr_installer_send_signal(
82 !type.empty() ? type.c_str(): "",
83 !pkgid.empty() ? pkgid.c_str() : "",
86 LOG(ERROR) << "Fail to send pkgmgr signal";
90 LOG(DEBUG) << "Success to send pkgmgr signal"
93 << " VALUE=" << value;
97 const char* PkgmgrSignal::GetResultKey(Step::Status result) const {
99 case Step::Status::OK:
100 return PKGMGR_INSTALLER_OK_EVENT_STR;
102 return PKGMGR_INSTALLER_FAIL_EVENT_STR;
106 } // namespace common_installer