step/step_remove_files.cc
step/step_revoke_security.cc
step/step_register_security.cc
- step/step_signal.cc
step/step_unregister_app.cc
)
# Target - definition
AppInstaller::AppInstaller(pkgmgr_installer *pi, const char* package_type)
: context_(new ContextInstaller()) {
int request_type = pkgmgr_installer_get_request_type(pi);
- context_->set_pi(std::unique_ptr<PkgmgrSignal>(new PkgmgrSignal(pi)));
+ pi_.reset(new PkgmgrSignal(pi));
context_->request_type.set(request_type);
context_->pkg_type.set(package_type);
switch (request_type) {
AppInstaller::~AppInstaller() {
}
-void AppInstaller::EnsureSignalSend() {
- if (!context_->pi()->IsFinished()) {
- // if signal was not sent during normal step execution
- // then this will sent any signal about failure
- (void) context_->pi()->sendStarted();
- (void) context_->pi()->sendFinished(PkgmgrSignal::Result::FAILED);
- }
-}
-
int AppInstaller::Run() {
std::list<std::unique_ptr<Step>>::iterator it(steps_.begin());
std::list<std::unique_ptr<Step>>::iterator itStart(steps_.begin());
std::list<std::unique_ptr<Step>>::iterator itEnd(steps_.end());
+ Step::Status process_status = Step::Status::OK;
int ret = 0;
for (; it != itEnd; ++it) {
- if ((*it)->process() != Step::Status::OK) {
+ process_status = (*it)->process();
+
+ // send START signal as soon as possible
+ if (pi_->state() == PkgmgrSignal::State::NOT_SENT) {
+ if (!context_->pkgid.get().empty()) {
+ pi_->SendStarted(context_->pkg_type.get(), context_->pkgid.get());
+ }
+ }
+
+ if (process_status != Step::Status::OK) {
LOG(ERROR) << "Error during processing";
ret = -1;
break;
}
}
- EnsureSignalSend();
-
+ // send START if pkgid was not parsed
+ if (pi_->state() == PkgmgrSignal::State::NOT_SENT) {
+ pi_->SendStarted(context_->pkg_type.get(), context_->pkgid.get());
+ }
+ pi_->SendFinished(process_status,
+ context_->pkg_type.get(),
+ context_->pkgid.get());
return ret;
}
#include <list>
#include <memory>
+#include "common/pkgmgr_signal.h"
#include "common/step/step.h"
#include "utils/logging.h"
#include "utils/macros.h"
int Run();
private:
- void EnsureSignalSend();
-
std::list<std::unique_ptr<Step>> steps_;
std::unique_ptr<ContextInstaller> context_;
+ // data used to send signal
+ std::unique_ptr<PkgmgrSignal> pi_;
+
SCOPE_LOG_TAG(AppInstaller)
DISALLOW_COPY_AND_ASSIGN(AppInstaller);
#include <memory>
#include <string>
-#include "common/pkgmgr_signal.h"
-
namespace common_installer {
/** Template class for defining smart attributes.
// uid of the user that request the operation
Property<uid_t> uid;
-
// data from config.xml
Property<ConfigData> config_data;
- // TODO(p.sikorski@samsung.com) change "pi" to Property
- PkgmgrSignal* pi() const { return pi_.get(); }
- void set_pi(std::unique_ptr<PkgmgrSignal> pi) {
- pi_ = std::move(pi);
- }
-
// path for the applications directory
Property<std::string> application_path;
// path for the applications root directory
Property<std::string> root_application_path;
-
- private :
- // data used to send signal
- std::unique_ptr<PkgmgrSignal> pi_;
};
} // namespace common_installer
#include "utils/logging.h"
+// Redefine this value as it is not exported by pkgmgr
+// this should probably be in public interface because of
+// otherwise there is no way to return errorcode
+#define PKGMGR_INSTALLER_ERROR_KEY_STR "error"
+
namespace common_installer {
PkgmgrSignal::PkgmgrSignal(pkgmgr_installer* pi)
state_(State::NOT_SENT) {
}
-bool PkgmgrSignal::sendStarted(
+bool PkgmgrSignal::SendStarted(
const std::string& type, const std::string& pkgid) {
if (state_ != State::NOT_SENT) {
return false;
return true;
}
-bool PkgmgrSignal::sendFinished(
- Result result, const std::string& type, const std::string& pkgid) {
+bool PkgmgrSignal::SendFinished(
+ Step::Status result, const std::string& type, const std::string& pkgid) {
if (state_ != State::STARTED) {
return false;
}
+ if (result != Step::Status::OK) {
+ if (!SendSignal(
+ PKGMGR_INSTALLER_ERROR_KEY_STR,
+ std::to_string(static_cast<int>(result)).c_str(), type, pkgid)) {
+ return false;
+ }
+ }
if (!SendSignal(
- PKGMGR_INSTALLER_END_KEY_STR, GetResultKey(result), type, pkgid)) {
+ PKGMGR_INSTALLER_END_KEY_STR, GetResultKey(result), type, pkgid)) {
return false;
}
state_ = State::FINISHED;
return true;
}
-const char* PkgmgrSignal::GetResultKey(Result result) const {
+const char* PkgmgrSignal::GetResultKey(Step::Status result) const {
switch (result) {
- case Result::SUCCESS:
+ case Step::Status::OK:
return PKGMGR_INSTALLER_OK_EVENT_STR;
- case Result::FAILED:
- return PKGMGR_INSTALLER_FAIL_EVENT_STR;
default:
- assert(false && "Not Reached");
+ return PKGMGR_INSTALLER_FAIL_EVENT_STR;
}
}
#include <memory>
#include <string>
+#include "common/step/step.h"
+
namespace common_installer {
//
//
class PkgmgrSignal {
public:
- enum class Result {
- SUCCESS,
- FAILED
+ enum class State {
+ NOT_SENT,
+ STARTED,
+ FINISHED
};
explicit PkgmgrSignal(pkgmgr_installer* pi);
- bool sendStarted(
+ bool SendStarted(
const std::string& type = std::string(),
const std::string& pkgid = std::string());
- bool sendFinished(
- Result result,
+ bool SendFinished(
+ Step::Status result,
const std::string& type = std::string(),
const std::string& pkgid = std::string());
bool IsFinished() const;
- private:
- enum class State {
- NOT_SENT,
- STARTED,
- FINISHED
- };
+ State state() const { return state_; }
+ private:
bool SendSignal(
const char* key,
const char* value,
const std::string& type = std::string(),
const std::string& pkgid = std::string()) const;
- const char* GetResultKey(Result result) const;
+ const char* GetResultKey(Step::Status result) const;
pkgmgr_installer* pi_;
State state_;
The returned code of Step::Status::OK indicates a succeful execution.
Otherwise, the returned code should be set to value different than
Step::Status::OK.
+
+ Errornous result of processing is casted to interger value and sent to
+ client which sent request.
*/
#ifndef COMMON_STEP_STEP_H_
#define COMMON_STEP_STEP_H_
explicit Step(ContextInstaller* context) : context_(context) { }
virtual ~Step() { }
- virtual Step::Status process() = 0;
- virtual Step::Status undo() = 0;
- virtual Step::Status clean() = 0;
+ virtual Status process() = 0;
+ virtual Status undo() = 0;
+ virtual Status clean() = 0;
protected:
ContextInstaller* context_;
+++ /dev/null
-/* 2014, Copyright © Eurogiciel Coporation, APACHE-2.0, see LICENSE file */
-
-#include "common/step/step_signal.h"
-
-#include <pkgmgr-info.h>
-#include <unistd.h>
-
-#include "utils/file_util.h"
-
-namespace common_installer {
-namespace signal {
-
-Step::Status StepSignal::process() {
- if (!context_->pi()->sendStarted(
- context_->manifest_data.get()->type, context_->pkgid.get())) {
- return Status::ERROR;
- }
- LOG(DEBUG) << "Send Start";
- return Status::OK;
-}
-
-Step::Status StepSignal::clean() {
- if (!context_->pi()->sendFinished(
- PkgmgrSignal::Result::SUCCESS,
- context_->manifest_data.get()->type, context_->pkgid.get())) {
- return Status::ERROR;
- }
- LOG(DEBUG) << "Send Success";
- return Status::OK;
-}
-
-Step::Status StepSignal::undo() {
- if (!context_->pi()->sendFinished(
- PkgmgrSignal::Result::FAILED,
- context_->manifest_data.get()->type, context_->pkgid.get())) {
- return Status::ERROR;
- }
- LOG(ERROR) << "Send Error";
- return Status::OK;
-}
-
-} // namespace signal
-} // namespace common_installer
+++ /dev/null
-/* 2014, Copyright © Eurogiciel Coporation, APACHE-2.0, see LICENSE file */
-
-#ifndef COMMON_STEP_STEP_SIGNAL_H_
-#define COMMON_STEP_STEP_SIGNAL_H_
-
-#include <string>
-
-#include "common/context_installer.h"
-
-#include "common/step/step.h"
-#include "utils/logging.h"
-
-namespace common_installer {
-namespace signal {
-
-class StepSignal : public Step {
- public:
- using Step::Step;
-
- Status process() override;
- Status clean() override;
- Status undo() override;
- private:
- SCOPE_LOG_TAG(Signal)
-};
-
-} // namespace signal
-} // namespace common_installer
-
-#endif // COMMON_STEP_STEP_SIGNAL_H_
#include "common/step/step_remove_files.h"
#include "common/step/step_revoke_security.h"
#include "common/step/step_register_security.h"
-#include "common/step/step_signal.h"
#include "common/step/step_check_signature.h"
#include "common/step/step_unregister_app.h"
#include "common/step/step_unzip.h"
ai.AddStep<ci::unzip::StepUnzip>();
ai.AddStep<ci::signature::StepCheckSignature>();
ai.AddStep<tpk::step::StepParse>();
- ai.AddStep<ci::signal::StepSignal>();
ai.AddStep<ci::copy::StepCopy>();
ai.AddStep<tpk::step::StepCreateSymbolicLink>();
ai.AddStep<ci::security::StepRegisterSecurity>();
ci::AppInstaller ai(pi_, kPkgType);
ai.AddStep<ci::parse::StepParse>();
- ai.AddStep<ci::signal::StepSignal>();
ai.AddStep<ci::unregister_app::StepUnregisterApplication>();
ai.AddStep<ci::remove::StepRemoveFiles>();
ai.AddStep<ci::revoke_security::StepRevokeSecurity>();
#include "common/step/step_remove_files.h"
#include "common/step/step_revoke_security.h"
#include "common/step/step_register_security.h"
-#include "common/step/step_signal.h"
#include "common/step/step_check_signature.h"
#include "common/step/step_unregister_app.h"
#include "common/step/step_unzip.h"
installer.AddStep<ci::unzip::StepUnzip>();
installer.AddStep<ci::signature::StepCheckSignature>();
installer.AddStep<wgt::parse::StepParse>();
- installer.AddStep<ci::signal::StepSignal>();
installer.AddStep<ci::copy::StepCopy>();
installer.AddStep<wgt::symbolic_link::StepCreateSymbolicLink>();
installer.AddStep<ci::security::StepRegisterSecurity>();
}
case PKGMGR_REQ_UNINSTALL: {
installer.AddStep<ci::parse::StepParse>();
- installer.AddStep<ci::signal::StepSignal>();
installer.AddStep<ci::unregister_app::StepUnregisterApplication>();
installer.AddStep<ci::remove::StepRemoveFiles>();
installer.AddStep<ci::revoke_security::StepRevokeSecurity>();