Add Send signal Step 29/34329/5
authorBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Fri, 23 Jan 2015 11:29:43 +0000 (12:29 +0100)
committerBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Fri, 23 Jan 2015 12:53:16 +0000 (13:53 +0100)
Change-Id: I3cf119442f2d231ebd4aab84790e2af12c792182
Signed-off-by: Baptiste DURAND <baptiste.durand@open.eurogiciel.org>
src/common/CMakeLists.txt
src/common/app_installer.cc
src/common/app_installer.h
src/common/context_installer.h
src/common/step/step_signal.cc [new file with mode: 0644]
src/common/step/step_signal.h [new file with mode: 0644]
src/wgt/wgt_backend.cc

index 894b27d..c80dfb0 100644 (file)
@@ -9,6 +9,7 @@ SET(SRCS
   step/step_record.cc
   step/step_parse.cc
   step/step_remove.cc
+  step/step_signal.cc
   step/step_unregister.cc
   utils.cc
 )
index 7851bc0..60ee508 100644 (file)
@@ -8,11 +8,21 @@
 
 namespace common_installer {
 
-AppInstaller::AppInstaller(int request, const char* file, const char* pkgid) {
+AppInstaller::AppInstaller(pkgmgr_installer *pi) {
   ctx_ = new ContextInstaller();
-  ctx_->set_request_type(request);
-  ctx_->set_pkgid(pkgid);
-  ctx_->set_file_path(file);
+  int request_type = pkgmgr_installer_get_request_type(pi);
+  ctx_->set_pi(pi);
+  ctx_->set_request_type(request_type);
+  switch (request_type) {
+    case PKGMGR_REQ_INSTALL:
+     ctx_->set_file_path(pkgmgr_installer_get_request_info(pi));
+     ctx_->set_pkgid("");
+    break;
+    case PKGMGR_REQ_UNINSTALL:
+     ctx_->set_pkgid(pkgmgr_installer_get_request_info(pi));
+     ctx_->set_file_path("");
+    break;
+  }
 }
 
 AppInstaller::~AppInstaller() { delete ctx_; }
@@ -27,6 +37,7 @@ int AppInstaller::AddStep(Step *step) {
   return 0;
 }
 
+
 int AppInstaller::Run() {
   std::list<Step *>::iterator it(ListStep.begin());
   std::list<Step *>::iterator itStart(ListStep.begin());
index cd142ac..ca877e1 100644 (file)
@@ -3,10 +3,12 @@
 #ifndef COMMON_APP_INSTALLER_H_
 #define COMMON_APP_INSTALLER_H_
 
+#include <pkgmgr_installer.h>
 #include <list>
 
 #include "common/step/step.h"
 
+
 namespace common_installer {
 
 class AppInstaller {
@@ -15,7 +17,7 @@ class AppInstaller {
   ContextInstaller* ctx_;
 
  public:
-  AppInstaller(int request, const char* file, const char* pkgid);
+  AppInstaller(pkgmgr_installer *pi);
   ~AppInstaller();
 
   int AddStep(Step* step);
index cab8560..9f2c461 100644 (file)
@@ -4,6 +4,7 @@
 #define COMMON_CONTEXT_INSTALLER_H_
 
 #include <pkgmgr_parser.h>
+#include <pkgmgr_installer.h>
 
 #include <unistd.h>
 #include <sys/types.h>
@@ -81,6 +82,10 @@ class ContextInstaller {
     file_path_ = file_path;
   }
 
+  void set_pi(pkgmgr_installer* pi) {
+    pi_ = pi;
+  }
+
   uid_t uid() const { return uid_; }
 
   std::string unpack_directory() const { return unpack_directory_; }
@@ -90,6 +95,8 @@ class ContextInstaller {
 
   ConfigData* config_data() { return config_data_.get(); }
 
+  pkgmgr_installer* pi() const { return pi_; }
+
   const char* GetApplicationPath();
   const char* GetRootApplicationPath();
 
@@ -120,6 +127,9 @@ class ContextInstaller {
 
   // data from config.xml
   ConfigDataPtr config_data_;
+
+  // data used to send signal
+  pkgmgr_installer *pi_;
 };
 
 }  // namespace common_installer
diff --git a/src/common/step/step_signal.cc b/src/common/step/step_signal.cc
new file mode 100644 (file)
index 0000000..f005275
--- /dev/null
@@ -0,0 +1,68 @@
+/* 2014, Copyright © Eurogiciel Coporation, APACHE-2.0, see LICENSE file */
+
+#include "common/step/step_signal.h"
+
+#include <pkgmgr-info.h>
+#include <unistd.h>
+
+#include <iostream>
+#include "common/utils.h"
+
+#define DBG(msg) std::cout << "[Signal] " << msg << std::endl;
+#define ERR(msg) std::cout << "[ERROR: Signal] " << msg << std::endl;
+
+namespace common_installer {
+namespace signal {
+
+bool StepSignal::sendSignal(ContextInstaller* data, const std::string& key,
+                              const std::string& value) {
+    if (!data->pi()) {
+        ERR("PkgmgrSingal not yet intialized");
+        return false;
+    }
+
+    if (key.empty() || value.empty()) {
+        DBG("key or value is empty");
+        return false;
+    }
+
+    // send pkgmgr signal
+    if (pkgmgr_installer_send_signal(
+            data->pi(), data->manifest_data()->type, data->pkgid().c_str(),
+            key.c_str(), value.c_str())) {
+        ERR("Fail to send pkgmgr signal");
+        return false;
+    }
+
+    DBG("Success to send pkgmgr signal");
+    return true;
+}
+
+
+int StepSignal::process(ContextInstaller* data) {
+  sendSignal(data, PKGMGR_INSTALLER_START_KEY_STR,
+    PKGMGR_INSTALLER_INSTALL_EVENT_STR);
+  DBG("Send Start");
+  return APPINST_R_OK;
+}
+
+int StepSignal::clean(ContextInstaller* data) {
+  sendSignal(data, PKGMGR_INSTALLER_END_KEY_STR,
+    PKGMGR_INSTALLER_OK_EVENT_STR);
+  DBG("Send Sucess");
+  return APPINST_R_OK;
+}
+
+int StepSignal::undo(ContextInstaller* data) {
+  sendSignal(data, PKGMGR_INSTALLER_END_KEY_STR,
+    PKGMGR_INSTALLER_FAIL_EVENT_STR);
+  DBG("Send Error");
+  return APPINST_R_OK;
+}
+
+
+
+
+
+}  // namespace signal
+}  // namespace common_installer
diff --git a/src/common/step/step_signal.h b/src/common/step/step_signal.h
new file mode 100644 (file)
index 0000000..c1c34d7
--- /dev/null
@@ -0,0 +1,28 @@
+/* 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"
+
+namespace common_installer {
+namespace signal {
+
+class StepSignal : public Step {
+ public:
+  int process(ContextInstaller* context) override;
+  int clean(ContextInstaller* context) override;
+  int undo(ContextInstaller* context) override;
+ private:
+  bool sendSignal(ContextInstaller* data, const std::string& key,
+    const std::string& value);
+};
+
+}  // namespace signal
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_STEP_SIGNAL_H_
index 439cb55..87a1a01 100644 (file)
@@ -19,6 +19,7 @@
 #include "wgt/step/step_parse.h"
 #include "common/step/step_generate_xml.h"
 #include "common/step/step_record.h"
+#include "common/step/step_signal.h"
 
 // uninstall includes:
 #include "common/step/step_parse.h"
@@ -36,14 +37,11 @@ int main(int argc, char **argv) {
     pkgmgr_installer_free(pi);
     return -result;
   }
-
+  common_installer::AppInstaller* installer =
+      new common_installer::AppInstaller(pi);
   /* treat the request */
   switch (pkgmgr_installer_get_request_type(pi)) {
     case PKGMGR_REQ_INSTALL: {
-      common_installer::AppInstaller* installer =
-          new common_installer::AppInstaller(PKGMGR_REQ_INSTALL,
-              pkgmgr_installer_get_request_info(pi), "");
-
       common_installer::unzip::StepUnzip* step_unpack =
           new common_installer::unzip::StepUnzip();
       common_installer::signature::StepSignature* step_signature =
@@ -52,6 +50,8 @@ int main(int argc, char **argv) {
               wgt::parse::StepParse();
       common_installer::copy::StepCopy* step_copy =
           new common_installer::copy::StepCopy();
+      common_installer::signal::StepSignal* step_sendsignal =
+          new common_installer::signal::StepSignal();
       common_installer::generate_xml::StepGenerateXml* step_xml =
           new common_installer::generate_xml::StepGenerateXml();
       common_installer::record::StepRecord* step_record =
@@ -60,6 +60,7 @@ int main(int argc, char **argv) {
       installer->AddStep(step_unpack);
       installer->AddStep(step_signature);
       installer->AddStep(step_parse);
+      installer->AddStep(step_sendsignal);
       installer->AddStep(step_copy);
       installer->AddStep(step_xml);
       installer->AddStep(step_record);
@@ -69,24 +70,22 @@ int main(int argc, char **argv) {
       delete step_signature;
       delete step_parse;
       delete step_copy;
-      delete installer;
+      delete step_sendsignal;
       delete step_xml;
       delete step_record;
       break;
     }
     case PKGMGR_REQ_UNINSTALL: {
-      common_installer::AppInstaller* installer =
-          new common_installer::AppInstaller(PKGMGR_REQ_UNINSTALL,
-              "", pkgmgr_installer_get_request_info(pi));
-
       common_installer::parse::StepParse* step_parse =
           new common_installer::parse::StepParse();
       common_installer::remove::StepRemove* step_remove =
           new common_installer::remove::StepRemove();
       common_installer::unregister::StepUnregister* step_unregister =
           new common_installer::unregister::StepUnregister();
-
+      common_installer::signal::StepSignal* step_sendsignal =
+          new common_installer::signal::StepSignal();
       installer->AddStep(step_parse);
+      installer->AddStep(step_sendsignal);
       installer->AddStep(step_unregister);
       installer->AddStep(step_remove);
 
@@ -95,6 +94,8 @@ int main(int argc, char **argv) {
       delete step_remove;
       delete step_unregister;
       delete step_parse;
+      delete step_sendsignal;
+
       break;
     }
     default: {
@@ -103,6 +104,7 @@ int main(int argc, char **argv) {
       break;
     }
   }
+  delete installer;
   pkgmgr_installer_free(pi);
   return result;
 }