external library.
TODO:
* PkgMgrSignal should be refactor. Possibly, it could inherit from
PkgMgrInterface
Change-Id: I3f934674aec54c69073a122fcb4b71e16a94565f
SET(SRCS
app_installer.cc
context_installer.cc
+ pkgmgr_interface.cc
pkgmgr_signal.cc
security_registration.cc
step/step_unzip.cc
#include "common/app_installer.h"
#include "common/context_installer.h"
+#include "common/pkgmgr_interface.h"
#include "common/pkgmgr_signal.h"
#include "utils/logging.h"
namespace common_installer {
-AppInstaller::AppInstaller(pkgmgr_installer *pi, const char* package_type)
- : context_(new ContextInstaller()) {
- int request_type = pkgmgr_installer_get_request_type(pi);
- pi_.reset(new PkgmgrSignal(pi));
- context_->request_type.set(request_type);
+AppInstaller::AppInstaller(const char* package_type)
+ : context_(new ContextInstaller()) {
+ PkgMgrPtr pkgmgr = PkgMgrInterface::Instance();
+ pi_.reset(new PkgmgrSignal(pkgmgr.get()->GetRawPi()));
context_->pkg_type.set(package_type);
- switch (request_type) {
- case PKGMGR_REQ_INSTALL:
- context_->file_path.set(pkgmgr_installer_get_request_info(pi));
- context_->pkgid.set(STR_EMPTY);
- break;
- case PKGMGR_REQ_UNINSTALL:
- context_->pkgid.set(pkgmgr_installer_get_request_info(pi));
- context_->file_path.set(STR_EMPTY);
- break;
+ context_->request_type.set(pkgmgr->GetRequestType());
+ switch (context_->request_type.get()) {
+ case PkgMgrInterface::Type::Install:
+ context_->file_path.set(pkgmgr->GetRequestInfo());
+ context_->pkgid.set(STR_EMPTY);
+ break;
+ case PkgMgrInterface::Type::Uninstall:
+ context_->pkgid.set(pkgmgr->GetRequestInfo());
+ context_->file_path.set(STR_EMPTY);
+ break;
+ default:
+ // currently, only installation and uninstallation handled
+ // TODO(p.sikorski): should return unsupported, and display error
+ break;
}
}
#ifndef COMMON_APP_INSTALLER_H_
#define COMMON_APP_INSTALLER_H_
-#include <pkgmgr_installer.h>
#include <list>
#include <memory>
class AppInstaller {
public:
- explicit AppInstaller(pkgmgr_installer *pi, const char* package_type);
+ explicit AppInstaller(const char* package_type);
virtual ~AppInstaller();
// Adds new step to installer by specified type
/* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
#include "common/context_installer.h"
-
#include <boost/filesystem.hpp>
-
-#include <pkgmgr_installer.h>
#include <tzplatform_config.h>
#include <unistd.h>
-
#include <cstdlib>
namespace common_installer {
namespace fs = boost::filesystem;
ContextInstaller::ContextInstaller()
- : request_type(PKGMGR_REQ_INVALID),
+ : request_type(PkgMgrInterface::Type::Unknown),
manifest_data(static_cast<manifest_x*>(calloc(1, sizeof(manifest_x)))),
uid(getuid()) {
#include <memory>
#include <string>
+#include "common/pkgmgr_interface.h"
+
namespace common_installer {
/** Template class for defining smart attributes.
ContextInstaller();
~ContextInstaller();
+ // TODO(p.sikorski) it looks, as it is not used anywhere.
// request type: Install, Reinstall, Uninstall, Update.
- Property<int> request_type;
+ Property<PkgMgrInterface::Type> request_type;
// package_type
Property<std::string> pkg_type;
--- /dev/null
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/pkgmgr_interface.h"
+
+#include <memory>
+
+namespace common_installer {
+
+PkgMgrPtr PkgMgrInterface::instance_;
+
+PkgMgrPtr PkgMgrInterface::Instance() {
+ return instance_;
+}
+
+int PkgMgrInterface::Init(int argc, char** argv) {
+ if (instance_)
+ return 0;
+
+ PkgMgrPtr tmp(new PkgMgrInterface());
+ int result = tmp->InitInternal(argc, argv);
+
+ instance_ = tmp;
+
+ return result;
+}
+
+int PkgMgrInterface::InitInternal(int argc, char** argv) {
+ pi_ = pkgmgr_installer_new();
+
+ if (!pi_) {
+ LOG(ERROR) << "Cannot create pkgmgr_installer object";
+ return ENOMEM;
+ }
+
+ int result = pkgmgr_installer_receive_request(pi_, argc, argv);
+ if (result) {
+ LOG(ERROR) << "Cannot receive request. Invalid arguments?";
+ // no need to free pkgmgr_installer here. it will be freed in DTOR.
+ }
+ return result;
+}
+
+PkgMgrInterface::~PkgMgrInterface() {
+ if (pi_)
+ pkgmgr_installer_free(pi_);
+}
+
+PkgMgrInterface::Type PkgMgrInterface::GetRequestType() const {
+ switch (pkgmgr_installer_get_request_type(pi_)) {
+ case PKGMGR_REQ_INSTALL:
+ return PkgMgrInterface::Type::Install;
+ case PKGMGR_REQ_UNINSTALL:
+ return PkgMgrInterface::Type::Uninstall;
+ case PKGMGR_REQ_REINSTALL:
+ return PkgMgrInterface::Type::Reinstall;
+ default:
+ return PkgMgrInterface::Type::Unknown;
+ }
+}
+
+const char* PkgMgrInterface::GetRequestInfo() const {
+ return pkgmgr_installer_get_request_info(pi_);
+}
+
+} // namespace common_installer
--- /dev/null
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_PKGMGR_INTERFACE_H_
+#define COMMON_PKGMGR_INTERFACE_H_
+
+#include <pkgmgr_installer.h>
+
+#include <memory>
+
+#include "utils/macros.h"
+#include "utils/logging.h"
+
+namespace common_installer {
+
+class PkgMgrInterface;
+typedef std::shared_ptr<PkgMgrInterface> PkgMgrPtr;
+
+/** Class that covers pkgmgr_installer basic platform calls.
+ *
+ * PkgMgr covers all pkgmgr_installer platform calls (and manages its
+ * creation/destruction.
+ */
+class PkgMgrInterface {
+ public:
+ /** Request type received from pkgmgr_installer
+ */
+ enum class Type {
+ Unknown,
+ Install,
+ Uninstall,
+ Reinstall
+ };
+
+ /** Returns Request type passed from pkgmgr_installer
+ */
+ PkgMgrInterface::Type GetRequestType() const;
+
+ /** Returns Request info passed from pkgmgr_installer
+ */
+ const char *GetRequestInfo() const;
+
+ /** Returns instance of PkgrMgr (Singleton pattern).
+ *
+ * However, Init method has to be called first (otherwise, this Instance
+ * returns nullptr).
+ *
+ * @see PkgMgr::Init(int argc, char** argv)
+ */
+ static PkgMgrPtr Instance();
+
+ /** Initialize PkgMgrInterface.
+ */
+ static int Init(int argc, char** argv);
+
+ /** Get Raw pointer to pkgmgr_installer object
+ *
+ * It should not be used (PkgMgrInterface can destroy it
+ */
+ DEPRECATED pkgmgr_installer *GetRawPi() const { return pi_; }
+
+ /** PkgMgrInstance destructor.
+ *
+ */
+ ~PkgMgrInterface();
+
+ private:
+ PkgMgrInterface() :pi_(nullptr) {}
+ int InitInternal(int argc, char** argv);
+
+ pkgmgr_installer* pi_;
+ static PkgMgrPtr instance_;
+
+ SCOPE_LOG_TAG(PkgMgrInterface)
+ DISALLOW_COPY_AND_ASSIGN(PkgMgrInterface);
+};
+
+} // namespace common_installer
+
+#endif // COMMON_PKGMGR_INTERFACE_H_
#ifdef HOSTTEST
#include "test/mock_pkgmgr_installer.h"
#else
-#include <pkgmgr_installer.h>
+#include "common/pkgmgr_interface.h"
#include "common/app_installer.h"
#include "common/step/step_copy.h"
#include "common/step/step_generate_xml.h"
/* Constructor
*/
-Task::Task() :
- pi_(nullptr),
- request_(PKGMGR_REQ_INVALID) {
+Task::Task() {
}
/* Destructor
*/
::tpk::Task::~Task() {
- if (pi_) {
- pkgmgr_installer_free(pi_);
- pi_ = nullptr;
- }
}
bool Task::Init(int argc, char** argv) {
- pi_ = pkgmgr_installer_new();
- if (!pi_) {
- LOG(ERROR) << "Failed to run pkgmgr_installer_new()";
- return false;
- }
- if (!!pkgmgr_installer_receive_request(pi_, argc, argv)) {
- LOG(ERROR) << "Invalid argument";
- pkgmgr_installer_free(pi_);
- pi_ = nullptr;
+ int result = ci::PkgMgrInterface::Init(argc, argv);
+ if (!result) {
+ LOG(ERROR) << "Cannot connect to PkgMgrInstaller";
return false;
}
- request_ = pkgmgr_installer_get_request_type(pi_);
-
return true;
}
bool Task::Run() {
int ret = 0;
- switch (request_) {
- case PKGMGR_REQ_INSTALL:
+ switch (ci::PkgMgrInterface::Instance()->GetRequestType()) {
+ case ci::PkgMgrInterface::Type::Install:
ret = Install();
break;
- case PKGMGR_REQ_UNINSTALL:
+ case ci::PkgMgrInterface::Type::Uninstall:
ret = Uninstall();
break;
- case PKGMGR_REQ_REINSTALL:
+ case ci::PkgMgrInterface::Type::Reinstall:
ret = Reinstall();
break;
+ default:
+ break;
}
if (ret != 0) {
LOG(ERROR) << "Got error from AppInstaler: error code " << ret;
}
int Task::Install() {
- ci::AppInstaller ai(pi_, kPkgType);
+ ci::AppInstaller ai(kPkgType);
ai.AddStep<ci::unzip::StepUnzip>();
ai.AddStep<ci::signature::StepCheckSignature>();
}
int Task::Uninstall() {
- ci::AppInstaller ai(pi_, kPkgType);
+ ci::AppInstaller ai(kPkgType);
ai.AddStep<ci::parse::StepParse>();
ai.AddStep<ci::unregister_app::StepUnregisterApplication>();
#ifdef HOSTTEST
#include "test/mock_pkgmgr_installer.h"
-#else
-#include <pkgmgr_installer.h>
#endif
namespace tpk {
int Install();
int Uninstall();
int Reinstall();
-
- pkgmgr_installer* pi_;
- int request_;
}; // class Task
} // namespace tpk
CLASS(const CLASS&) = delete; \
CLASS& operator=(const CLASS&) = delete \
+#define DEPRECATED __attribute__ ((__deprecated__))
+
#endif // UTILS_MACROS_H_
/* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <pkgmgr_installer.h>
-
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
#include <cerrno>
-#include <memory>
#include "common/app_installer.h"
+#include "common/pkgmgr_interface.h"
#include "common/step/step_copy.h"
#include "common/step/step_generate_xml.h"
#include "common/step/step_parse.h"
namespace ci = common_installer;
int main(int argc, char** argv) {
- // get request data
- pkgmgr_installer* pi = pkgmgr_installer_new();
- if (!pi)
- return ENOMEM;
-
- int result = pkgmgr_installer_receive_request(pi, argc, argv);
+ int result = ci::PkgMgrInterface::Init(argc, argv);
if (result) {
- pkgmgr_installer_free(pi);
+ LOG(ERROR) << "Cannot connect to PkgMgrInstaller";
return -result;
}
- common_installer::AppInstaller installer(pi, "wgt");
+
+ ci::PkgMgrPtr pkgmgr = ci::PkgMgrInterface::Instance();
+
+ ci::AppInstaller installer("wgt");
/* treat the request */
- switch (pkgmgr_installer_get_request_type(pi)) {
- case PKGMGR_REQ_INSTALL: {
+ switch (pkgmgr->GetRequestType()) {
+ case ci::PkgMgrInterface::Type::Install : {
installer.AddStep<ci::unzip::StepUnzip>();
installer.AddStep<ci::signature::StepCheckSignature>();
installer.AddStep<wgt::parse::StepParse>();
installer.AddStep<ci::register_app::StepRegisterApplication>();
break;
}
- case PKGMGR_REQ_UNINSTALL: {
+ case ci::PkgMgrInterface::Type::Uninstall: {
installer.AddStep<ci::parse::StepParse>();
installer.AddStep<ci::unregister_app::StepUnregisterApplication>();
installer.AddStep<ci::remove::StepRemoveFiles>();
}
default: {
// unsupported operation
- pkgmgr_installer_free(pi);
return EINVAL;
}
}
// run request
result = installer.Run();
- pkgmgr_installer_free(pi);
return result;
}