-#ifndef __APPINSTALLER_H__
-#define __APPINSTALLER_H__
-#include <context_installer.h>
-#include <step.h>
+/* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
+
+#ifndef COMMON_INCLUDE_APP_INSTALLER_H_
+#define COMMON_INCLUDE_APP_INSTALLER_H_
+
#include <list>
+#include "include/step.h"
+
class AppInstaller {
+ private:
+ std::list<Step*> ListStep;
+ ContextInstaller* ctx_;
-protected:
- std::list<Step*> ListStep;
- ContextInstaller* ctx_;
-public:
- AppInstaller(int request, const char * file, const char* pkgid);
- ~AppInstaller();
- int AddStep(Step *step);
- int Run();
+ public:
+ AppInstaller(int request, const char* file, const char* pkgid);
+ ~AppInstaller();
+
+ int AddStep(Step* step);
+ int Run();
};
-#endif
+
+#endif // COMMON_INCLUDE_APP_INSTALLER_H_
+/* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
+
/*
A step is made of 3 functions (that can be defined or NULL)
and one data pointer.
Otherwise, the returned code should be set to -1 with errno set
to some meaningful value.
*/
-#ifndef __STEP_H__
-#define __STEP_H__
-#include <context_installer.h>
+#ifndef COMMON_INCLUDE_STEP_H_
+#define COMMON_INCLUDE_STEP_H_
-class Step {
-public:
- virtual int process(ContextInstaller*)=0;
- virtual int undo(ContextInstaller*)=0;
- virtual int clean(ContextInstaller*)=0;
+#include "include/context_installer.h"
+class Step {
+ public:
+ virtual int process(ContextInstaller* context)=0;
+ virtual int undo(ContextInstaller* context)=0;
+ virtual int clean(ContextInstaller* context)=0;
};
-#endif
+
+#endif // COMMON_INCLUDE_STEP_H_
-#include <app_installer.h>
+/* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
+
#include <iostream>
#include <cstdio>
-AppInstaller::AppInstaller(int request, const char * file, const char* pkgid) {
+#include "include/app_installer.h"
+#include "include/context_installer.h"
+
+AppInstaller::AppInstaller(int request, const char* file, const char* pkgid) {
ctx_ = new ContextInstaller();
ctx_->set_request_type(request);
ctx_->set_pkgid(pkgid);
ctx_->set_file_path(file);
}
-AppInstaller::~AppInstaller() { delete ctx_; }
+AppInstaller::~AppInstaller() { delete ctx_; }
int AppInstaller::AddStep(Step *step) {
- try {
- ListStep.push_back(step);
- } catch (int e) {
- return -1;
- }
- return 0;
+ try {
+ ListStep.push_back(step);
+ } catch (int e) {
+ return -1;
+ }
+ return 0;
}
int AppInstaller::Run() {
- std::list<Step *>::iterator it (ListStep.begin());
- std::list<Step *>::iterator itStart(ListStep.begin());
- std::list<Step *>::iterator itEnd(ListStep.end());
-
- int ret = 0;
- for(;it!=itEnd;++it) {
- if((*it)->process(ctx_) != APPINST_R_OK) {
- std::cout << "Error during processing" << std::endl;
- ret = -1;
- break;
- }
- }
- if (it!=itEnd) {
- std::cout << "Faillure occurs" << std::endl;
- do {
- if((*it)->undo(ctx_) != APPINST_R_OK) {
- std::cout << "Error during undo operation" << std::endl;
- ret = -2;
- break;
- }
- } while (it--!=itStart);
- } else {
- while (it--!=itStart) {
- if((*it)->clean(ctx_) != APPINST_R_OK) {
- std::cout << "Error during clean operation" << std::endl;
- ret = -3;
- break;
- }
- }
- }
- return ret;
+ std::list<Step *>::iterator it(ListStep.begin());
+ std::list<Step *>::iterator itStart(ListStep.begin());
+ std::list<Step *>::iterator itEnd(ListStep.end());
+
+ int ret = 0;
+ for (; it != itEnd; ++it) {
+ if ((*it)->process(ctx_) != APPINST_R_OK) {
+ std::cout << "Error during processing" << std::endl;
+ ret = -1;
+ break;
+ }
+ }
+ if (it != itEnd) {
+ std::cout << "Faillure occurs" << std::endl;
+ do {
+ if ((*it)->undo(ctx_) != APPINST_R_OK) {
+ std::cout << "Error during undo operation" << std::endl;
+ ret = -2;
+ break;
+ }
+ } while (it-- != itStart);
+ } else {
+ while (it-- != itStart) {
+ if ((*it)->clean(ctx_) != APPINST_R_OK) {
+ std::cout << "Error during clean operation" << std::endl;
+ ret = -3;
+ break;
+ }
+ }
+ }
+ return ret;
}
/* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
-#include <pkgmgr_installer.h>
-#include <cstdio>
-#include <cstdlib>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
+
+#include <pkgmgr_installer.h>
+
+#include <cstdio>
+#include <cstdlib>
#include <cstring>
#include <cerrno>
-#include <cassert>
#include <memory>
-#include <app_installer.h>
-#include <step_unzip.h>
-#include "step/signature_step.h"
-int
-main (int argc, char **argv)
-{
- int result;
- AppInstaller *Installer = NULL;
- step_unzip *step_unpack = NULL;
+#include "include/app_installer.h"
+#include "include/step_unzip.h"
+#include "step/signature_step.h"
+int main(int argc, char **argv) {
/* get request data */
- pkgmgr_installer *pi = pkgmgr_installer_new ();
+ pkgmgr_installer *pi = pkgmgr_installer_new();
if (!pi)
return ENOMEM;
- result = pkgmgr_installer_receive_request (pi, argc, argv);
- if (result)
- {
- pkgmgr_installer_free (pi);
- return -result;
- }
+
+ int result = pkgmgr_installer_receive_request(pi, argc, argv);
+ if (result) {
+ pkgmgr_installer_free(pi);
+ return -result;
+ }
/* treat the request */
- switch (pkgmgr_installer_get_request_type (pi)) {
+ switch (pkgmgr_installer_get_request_type(pi)) {
case PKGMGR_REQ_INSTALL: {
- Installer = new AppInstaller(PKGMGR_REQ_INSTALL, pkgmgr_installer_get_request_info(pi), "");
- step_unpack = new step_unzip();
-
- Installer->AddStep(step_unpack);
+ AppInstaller* Installer = new AppInstaller(PKGMGR_REQ_INSTALL,
+ pkgmgr_installer_get_request_info(pi), "");
+
+ step_unzip* step_unpack = new step_unzip();
+ Installer->AddStep(step_unpack);
- // FIXME: unique_ptr because steps are not freed in installer.
- std::unique_ptr<common::SignatureStep> signature_step(
- new common::SignatureStep);
- Installer->AddStep(signature_step.get());
+ // FIXME: unique_ptr because steps are not freed in installer.
+ std::unique_ptr<common::SignatureStep> signature_step(
+ new common::SignatureStep);
+ Installer->AddStep(signature_step.get());
- Installer->Run();
+ Installer->Run();
break;
}
case PKGMGR_REQ_UNINSTALL: {
break;
}
}
- pkgmgr_installer_free (pi);
+ pkgmgr_installer_free(pi);
return result;
}