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::SendFinished(
41 Step::Status result, const std::string& type, const std::string& pkgid) {
42 if (state_ != State::STARTED) {
45 if (result != Step::Status::OK) {
47 PKGMGR_INSTALLER_ERROR_KEY_STR,
48 std::to_string(static_cast<int>(result)).c_str(), type, pkgid)) {
53 PKGMGR_INSTALLER_END_KEY_STR, GetResultKey(result), type, pkgid)) {
56 state_ = State::FINISHED;
60 bool PkgmgrSignal::IsFinished() const {
61 return state_ == State::FINISHED;
64 bool PkgmgrSignal::SendSignal(
67 const std::string& type,
68 const std::string& pkgid) const {
70 if (pkgmgr_installer_send_signal(
72 !type.empty() ? type.c_str(): "",
73 !pkgid.empty() ? pkgid.c_str() : "",
76 LOG(ERROR) << "Fail to send pkgmgr signal";
80 LOG(DEBUG) << "Success to send pkgmgr signal"
83 << " VALUE=" << value;
87 const char* PkgmgrSignal::GetResultKey(Step::Status result) const {
89 case Step::Status::OK:
90 return PKGMGR_INSTALLER_OK_EVENT_STR;
92 return PKGMGR_INSTALLER_FAIL_EVENT_STR;
96 } // namespace common_installer