r4387 - in trunk/src/target/opkg: libopkg tests

thomas at sita.openmoko.org thomas at sita.openmoko.org
Tue Apr 22 12:53:40 CEST 2008


Author: thomas
Date: 2008-04-22 12:53:38 +0200 (Tue, 22 Apr 2008)
New Revision: 4387

Modified:
   trunk/src/target/opkg/libopkg/opkg.c
   trunk/src/target/opkg/libopkg/opkg.h
   trunk/src/target/opkg/tests/libopkg_test.c
Log:
opkg: add progress callbacks to libopkg api
libopkg: fix opkg_install_package()


Modified: trunk/src/target/opkg/libopkg/opkg.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg.c	2008-04-22 02:50:50 UTC (rev 4386)
+++ trunk/src/target/opkg/libopkg/opkg.c	2008-04-22 10:53:38 UTC (rev 4387)
@@ -243,59 +243,72 @@
 }
 
 int
-opkg_install_package (opkg_t *opkg, char *package_name)
+opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
 {
   int err;
+  char *package_id;
 
+  progress_callback (opkg, 0, user_data);
+
+  /* download the package */
+  opkg_prepare_url_for_install (opkg->conf, package_name, &package_id);
+  progress_callback (opkg, 50, user_data);
+
+  /* ... */
   pkg_info_preinstall_check (opkg->conf);
 
+  /* unpack the package */
   if (opkg->conf->multiple_providers)
   {
-    err = opkg_install_multi_by_name (opkg->conf, package_name);
+    err = opkg_install_multi_by_name (opkg->conf, package_id);
   }
   else
   {
-    err = opkg_install_by_name (opkg->conf, package_name);
+    err = opkg_install_by_name (opkg->conf, package_id);
   }
 
+  progress_callback (opkg, 75, user_data);
+
+  /* run configure scripts, etc. */
   err = opkg_configure_packages (opkg->conf, NULL);
 
-  if (opkg->conf->noaction)
-    return err;
-
+  /* write out status files and file lists */
   opkg_conf_write_status_files (opkg->conf);
   pkg_write_changed_filelists (opkg->conf);
 
+  progress_callback (opkg, 100, user_data);
   return err;
 }
 
 int
-opkg_remove_package (opkg_t *opkg, char *package_name)
+opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
 {
   return 1;
 }
 
 int
-opkg_upgrade_package (opkg_t *opkg, char *package_name)
+opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
 {
   return 1;
 }
 
 int
-opkg_upgrade_all (opkg_t *opkg)
+opkg_upgrade_all (opkg_t *opkg, opkg_progress_callback_t progress_callback, void *user_data)
 {
   return 1;
 }
 
 int
-opkg_update_package_lists (opkg_t *opkg)
+opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callback, void *user_data)
 {
   char *tmp;
   int err;
   char *lists_dir;
   pkg_src_list_elt_t *iter;
   pkg_src_t *src;
+  int sources_list_count, sources_done;
 
+  progress_callback (opkg, 0, user_data);
 
   sprintf_alloc (&lists_dir, "%s",
                  (opkg->conf->restrict_to_default_dest)
@@ -330,6 +343,15 @@
     return 1;
   }
 
+  /* cout the number of sources so we can give some progress updates */
+  sources_list_count = 0;
+  sources_done = 0;
+  iter = opkg->conf->pkg_src_list.head;
+  while (iter)
+  {
+    sources_list_count++;
+    iter = iter->next;
+  }
 
   for (iter = opkg->conf->pkg_src_list.head; iter; iter = iter->next)
   {
@@ -420,6 +442,9 @@
      */
 #endif
     free (list_file_name);
+
+    sources_done++;
+    progress_callback (opkg, 100 * sources_done / sources_list_count, user_data);
   }
   rmdir (tmp);
   free (tmp);

Modified: trunk/src/target/opkg/libopkg/opkg.h
===================================================================
--- trunk/src/target/opkg/libopkg/opkg.h	2008-04-22 02:50:50 UTC (rev 4386)
+++ trunk/src/target/opkg/libopkg/opkg.h	2008-04-22 10:53:38 UTC (rev 4387)
@@ -16,6 +16,7 @@
 */
 
 typedef struct _opkg_t opkg_t;
+typedef void (*opkg_progress_callback_t) (opkg_t *opkg, int percentage, void *user_data);
 
 opkg_t* opkg_new ();
 void opkg_free (opkg_t *opkg);
@@ -23,8 +24,8 @@
 void opkg_set_option (opkg_t *opkg, char *option, void *value);
 int opkg_read_config_files (opkg_t *opkg);
 
-int opkg_install_package (opkg_t *opkg, char *package_name);
-int opkg_remove_package (opkg_t *opkg, char *package_name);
-int opkg_upgrade_package (opkg_t *opkg, char *package_name);
-int opkg_upgrade_all (opkg_t *opkg);
-int opkg_update_package_lists (opkg_t *opkg);
+int opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t callback, void *user_data);
+int opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t callback, void *user_data);
+int opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t callback, void *user_data);
+int opkg_upgrade_all (opkg_t *opkg, opkg_progress_callback_t callback, void *user_data);
+int opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t callback, void *user_data);

Modified: trunk/src/target/opkg/tests/libopkg_test.c
===================================================================
--- trunk/src/target/opkg/tests/libopkg_test.c	2008-04-22 02:50:50 UTC (rev 4386)
+++ trunk/src/target/opkg/tests/libopkg_test.c	2008-04-22 10:53:38 UTC (rev 4387)
@@ -1,6 +1,14 @@
 #include <opkg.h>
 #include <stdlib.h>
+#include <stdio.h>
 
+void
+progress_callback (opkg_t *opkg, int percent, void *data)
+{
+  printf ("%s %d\n", (char*) data, percent);
+}
+
+
 int
 main (int argc, char **argv)
 {
@@ -13,9 +21,13 @@
 
   opkg_read_config_files (opkg);
 
-  err = opkg_update_package_lists (opkg);
+  err = opkg_update_package_lists (opkg, progress_callback, "Updating...");
 
   printf ("opkg_update_package_lists returned %d\n", err);
 
+  err = opkg_install_package (opkg, "aspell", progress_callback, "Installing...");
+
+  printf ("opkg_install_package returned %d\n", err);
+
   opkg_free (opkg);
 }





More information about the commitlog mailing list