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

thomas at sita.openmoko.org thomas at sita.openmoko.org
Fri Apr 25 15:48:55 CEST 2008


Author: thomas
Date: 2008-04-25 15:48:53 +0200 (Fri, 25 Apr 2008)
New Revision: 4398

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: implement package listing in new libopkg


Modified: trunk/src/target/opkg/libopkg/opkg.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg.c	2008-04-24 11:05:21 UTC (rev 4397)
+++ trunk/src/target/opkg/libopkg/opkg.c	2008-04-25 13:48:53 UTC (rev 4398)
@@ -26,6 +26,7 @@
 #include "opkg_configure.h"
 #include "opkg_download.h"
 #include "opkg_remove.h"
+#include "opkg_upgrade.h"
 
 #include "sprintf_alloc.h"
 #include "file_util.h"
@@ -124,6 +125,49 @@
 
 /*** Public API ***/
 
+opkg_package_t *
+opkg_package_new ()
+{
+
+  opkg_package_t *p;
+
+  p = malloc (sizeof (opkg_package_t));
+  memset (p, 0, sizeof (opkg_package_t));
+
+  return p;
+}
+
+opkg_package_t *
+opkg_package_new_with_values (const char *name, const char *version,
+    const char *arch, const char *desc, const char *tags, int installed)
+{
+  opkg_package_t *package;
+  package = opkg_package_new ();
+
+#define sstrdup(x) (x) ? strdup (x) : NULL;
+
+  package->name = sstrdup (name);
+  package->version = sstrdup (version);
+  package->architecture = sstrdup (arch);
+  package->description = sstrdup (desc);
+  package->tags = sstrdup (tags);
+  package->installed = (installed != 0);
+
+  return package;
+}
+
+void
+opkg_package_free (opkg_package_t *p)
+{
+  free (p->name);
+  free (p->version);
+  free (p->architecture);
+  free (p->description);
+  free (p->tags);
+
+  free (p);
+}
+
 opkg_t *
 opkg_new ()
 {
@@ -647,3 +691,39 @@
 
   return 0;
 }
+
+
+int
+opkg_list_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data)
+{
+  pkg_vec_t *all;
+  int i;
+
+  opkg_assert (opkg);
+  opkg_assert (callback);
+
+  all = pkg_vec_alloc ();
+  pkg_hash_fetch_available (&opkg->conf->pkg_hash, all);
+  for (i = 0; i < all->len; i++)
+  {
+    pkg_t *pkg;
+    opkg_package_t *package;
+
+    pkg = all->pkgs[i];
+
+    package = opkg_package_new_with_values (
+        pkg->name,
+        pkg->version,
+        pkg->architecture,
+        pkg->description,
+        pkg->tags,
+        (pkg->state_status == SS_INSTALLED));
+
+    callback (opkg, package, user_data);
+  }
+
+  pkg_vec_free (all);
+
+  return 0;
+}
+

Modified: trunk/src/target/opkg/libopkg/opkg.h
===================================================================
--- trunk/src/target/opkg/libopkg/opkg.h	2008-04-24 11:05:21 UTC (rev 4397)
+++ trunk/src/target/opkg/libopkg/opkg.h	2008-04-25 13:48:53 UTC (rev 4398)
@@ -16,8 +16,27 @@
 */
 
 typedef struct _opkg_t opkg_t;
+typedef struct _opkg_package_t opkg_package_t;
+
 typedef void (*opkg_progress_callback_t) (opkg_t *opkg, int percentage, void *user_data);
+typedef void (*opkg_package_callback_t) (opkg_t *opkg, opkg_package_t *package, void *user_data);
 
+
+struct _opkg_package_t
+{
+  char *name;
+  char *version;
+  char *architecture;
+  char *repository;
+  char *description;
+  char *tags;
+  int installed;
+};
+
+opkg_package_t* opkg_package_new ();
+opkg_package_t* opkg_package_new_with_values (const char *name, const char *version, const char *arch, const char *desc, const char *tags, int installed);
+void opkg_package_free (opkg_package_t *package);
+
 opkg_t* opkg_new ();
 void opkg_free (opkg_t *opkg);
 void opkg_get_option (opkg_t *opkg, char *option, void **value);
@@ -29,3 +48,5 @@
 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);
+
+int opkg_list_packages (opkg_t *opkg, opkg_package_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-24 11:05:21 UTC (rev 4397)
+++ trunk/src/target/opkg/tests/libopkg_test.c	2008-04-25 13:48:53 UTC (rev 4398)
@@ -9,7 +9,23 @@
   fflush (stdout);
 }
 
+void
+package_list_callback (opkg_t *opkg, opkg_package_t *pkg, void *data)
+{
+  static install_count = 0;
+  static total_count = 0;
 
+  if (pkg->installed)
+    install_count++;
+
+  total_count++;
+
+  printf ("\rPackage count: %d Installed, %d Total Available", install_count, total_count);
+  fflush (stdout);
+
+  opkg_package_free (pkg);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -37,5 +53,8 @@
   err = opkg_remove_package (opkg, "aspell", progress_callback, "Removing...");
   printf ("\nopkg_remove_package returned %d\n", err);
 
+  opkg_list_packages (opkg, package_list_callback, NULL);
+  printf ("\n");
+
   opkg_free (opkg);
 }





More information about the commitlog mailing list