opkg: correct the name of the state changed callback and run it when appropriate
[oweals/opkg-lede.git] / opkg_state.c
index ded9683c6b9ac48c6b0d1f02e79f7fbfabc594e1..2cc85949374ca01e03b11b0c814eb662d5125026 100644 (file)
 */
 
 #include "libopkg.h"
+#include "opkg_state.h"
 
-opkg_state_changed_callback opkg_cb_state;
+
+static char *state_strings[] =
+{
+  "None",
+  "Downloading Package",
+  "Installing Package",
+  "Configuring Package",
+  "Upgrading Package",
+  "Removing Package",
+  "Downloading Repository",
+  "Verifying Repository Signature"
+};
+
+
+
+opkg_state_changed_callback opkg_cb_state_changed = NULL;
 
 static opkg_state_t opkg_state = 0;
 static char *opkg_state_data = NULL;
@@ -27,10 +43,25 @@ opkg_set_current_state (opkg_state_t state, const char *data)
 {
   if (opkg_state_data)
     free (opkg_state_data);
-  opkg_state_data = malloc (strlen (data));
-  strcpy (opkg_state_data, data);
+  if (data)
+  {
+    opkg_state_data = malloc (strlen (data));
+    strcpy (opkg_state_data, data);
+  }
+  else
+  {
+    opkg_state_data = NULL;
+  }
 
   opkg_state = state;
+
+  if (opkg_cb_state_changed)
+  {
+    opkg_cb_state_changed (opkg_state, opkg_state_data);
+  }
+
+
+  printf ("opkg state set to %s: %s\n", state_strings[state], data);
 }
 
 void