1.1 --- a/librazor/importer.c Mon Jun 23 17:19:20 2008 -0400
1.2 +++ b/librazor/importer.c Wed Jul 02 18:46:47 2008 +0100
1.3 @@ -23,6 +23,59 @@
1.4 #include "razor-internal.h"
1.5 #include "razor.h"
1.6
1.7 +/**
1.8 + * razor_importer_create:
1.9 + *
1.10 + * Create a new %razor_importer.
1.11 + *
1.12 + * Returns: the new %razor_importer.
1.13 + **/
1.14 +RAZOR_EXPORT struct razor_importer *
1.15 +razor_importer_create(void)
1.16 +{
1.17 + struct razor_importer *importer;
1.18 +
1.19 + importer = zalloc(sizeof *importer);
1.20 + importer->set = razor_set_create();
1.21 + hashtable_init(&importer->table, &importer->set->string_pool);
1.22 + hashtable_init(&importer->details_table,
1.23 + &importer->set->details_string_pool);
1.24 + hashtable_init(&importer->file_table,
1.25 + &importer->set->file_string_pool);
1.26 +
1.27 + return importer;
1.28 +}
1.29 +
1.30 +/**
1.31 + * razor_importer_destroy:
1.32 + * @importer: the %razor_importer
1.33 + *
1.34 + * Destroy an importer without creating a %razor_set. Normally,
1.35 + * %razor_importer_finish will create a new %razor_set and destroy the
1.36 + * importer. If the import must be aborted without creating the set,
1.37 + * just destroy the import using this function.
1.38 + **/
1.39 +RAZOR_EXPORT void
1.40 +razor_importer_destroy(struct razor_importer *importer)
1.41 +{
1.42 + /* FIXME: write this */
1.43 +}
1.44 +
1.45 +
1.46 +/**
1.47 + * razor_importer_begin_package:
1.48 + * @importer: the %razor_importer
1.49 + * @name: the name of the new package
1.50 + * @version: the version of the new package
1.51 + * @arch: the architechture of the new package.
1.52 + *
1.53 + * Begin describing a new package to the importer. This creates a new
1.54 + * package and sets the %name, %version and %arch. Subsequent calls
1.55 + * to %razor_importer_add_details, %razor_importer_add_property and
1.56 + * %razor_importer_add_file further describe this package and
1.57 + * %razor_importer_finish_package marks the end of meta data for this
1.58 + * package.
1.59 + **/
1.60 RAZOR_EXPORT void
1.61 razor_importer_begin_package(struct razor_importer *importer,
1.62 const char *name,
1.63 @@ -41,7 +94,12 @@
1.64 array_init(&importer->properties);
1.65 }
1.66
1.67 -
1.68 +/**
1.69 + * razor_importer_finish_package:
1.70 + * @importer: the %razor_importer
1.71 + *
1.72 + * Tells the importer that the current package is complete.
1.73 + **/
1.74 RAZOR_EXPORT void
1.75 razor_importer_finish_package(struct razor_importer *importer)
1.76 {
1.77 @@ -53,6 +111,16 @@
1.78 array_release(&importer->properties);
1.79 }
1.80
1.81 +/**
1.82 + * razor_importer_add_details:
1.83 + * @importer: the %razor_importer
1.84 + * @summary: the package summary
1.85 + * @description: the package description
1.86 + * @url: the package url
1.87 + * @license: the package license
1.88 + *
1.89 + * Provide additional information for the current package.
1.90 + **/
1.91 RAZOR_EXPORT void
1.92 razor_importer_add_details(struct razor_importer *importer,
1.93 const char *summary,
1.94 @@ -66,6 +134,19 @@
1.95 importer->package->license = hashtable_tokenize(&importer->details_table, license);
1.96 }
1.97
1.98 +/**
1.99 + * razor_importer_add_property:
1.100 + * @importer: the %razor_importer
1.101 + * @name: name of the property
1.102 + * @flags: property flags
1.103 + * @version: version of the property or %NULL
1.104 + *
1.105 + * Add a property for the current package. The %flags parameter
1.106 + * determines the type of the property and optionally the relation to
1.107 + * the specified version and the availability constraint. See
1.108 + * %razor_property_flags for further information about the flag
1.109 + * parameter.
1.110 + **/
1.111 RAZOR_EXPORT void
1.112 razor_importer_add_property(struct razor_importer *importer,
1.113 const char *name,
1.114 @@ -92,6 +173,13 @@
1.115 }
1.116 }
1.117
1.118 +/**
1.119 + * razor_importer_add_file:
1.120 + * @importer: the %razor_importer
1.121 + * @name: name of the file
1.122 + *
1.123 + * Add a file to the current package.
1.124 + **/
1.125 RAZOR_EXPORT void
1.126 razor_importer_add_file(struct razor_importer *importer, const char *name)
1.127 {
1.128 @@ -104,29 +192,6 @@
1.129 e->name = strdup(name);
1.130 }
1.131
1.132 -RAZOR_EXPORT struct razor_importer *
1.133 -razor_importer_create(void)
1.134 -{
1.135 - struct razor_importer *importer;
1.136 -
1.137 - importer = zalloc(sizeof *importer);
1.138 - importer->set = razor_set_create();
1.139 - hashtable_init(&importer->table, &importer->set->string_pool);
1.140 - hashtable_init(&importer->details_table,
1.141 - &importer->set->details_string_pool);
1.142 - hashtable_init(&importer->file_table,
1.143 - &importer->set->file_string_pool);
1.144 -
1.145 - return importer;
1.146 -}
1.147 -
1.148 -/* Destroy an importer without creating the set. */
1.149 -RAZOR_EXPORT void
1.150 -razor_importer_destroy(struct razor_importer *importer)
1.151 -{
1.152 - /* FIXME: write this */
1.153 -}
1.154 -
1.155 static int
1.156 compare_packages(const void *p1, const void *p2, void *data)
1.157 {
1.158 @@ -469,6 +534,17 @@
1.159 free(pkgs);
1.160 }
1.161
1.162 +/**
1.163 + * razor_importer_finish:
1.164 + * @importer: the %razor_importer
1.165 + *
1.166 + * Finish importing packages and create the package set. This sorts
1.167 + * and indexes all the packages, properties and files in the importer
1.168 + * and creates a new %razor_set. After creating the new package set,
1.169 + * the importer is destroyed.
1.170 + *
1.171 + * Returns: the new %razor_set
1.172 + **/
1.173 RAZOR_EXPORT struct razor_set *
1.174 razor_importer_finish(struct razor_importer *importer)
1.175 {