free(p);
}
-static void __cli_progressbar_free(struct pakfire* pakfire,
+static void __cli_progressbar_free(struct pakfire_ctx* ctx,
struct pakfire_progress* progress, void* data) {
struct cli_progressbar* progressbar = data;
return (void *)(intptr_t)r;
}
-static int cli_progressbar_start(struct pakfire* pakfire, struct pakfire_progress* progress,
+static int cli_progressbar_start(struct pakfire_ctx* ctx, struct pakfire_progress* progress,
void* data, unsigned long int max_value) {
struct cli_progressbar* progressbar = data;
return pthread_create(&progressbar->renderer, NULL, cli_progressbar_renderer, progressbar);
}
-static int cli_progressbar_finish(struct pakfire* pakfire, struct pakfire_progress* progress,
+static int cli_progressbar_finish(struct pakfire_ctx* ctx, struct pakfire_progress* progress,
void* data) {
struct cli_progressbar* progressbar = data;
void* retval = NULL;
return cli_progressbar_add_widget(p, cli_progressbar_transfer_speed, NULL, 0, NULL);
}
-int cli_setup_progressbar(struct pakfire_ctx* ctx, struct pakfire* pakfire,
- struct pakfire_progress* p, void* data) {
+int cli_setup_progressbar(struct pakfire_ctx* ctx, struct pakfire_progress* p, void* data) {
struct cli_progressbar* progressbar = NULL;
int r;
#ifndef PAKFIRE_CLI_PROGRESSBAR_H
#define PAKFIRE_CLI_PROGRESSBAR_H
-#include <pakfire/pakfire.h>
+#include <pakfire/ctx.h>
#include <pakfire/progress.h>
-int cli_setup_progressbar(struct pakfire_ctx* ctx, struct pakfire* pakfire,
- struct pakfire_progress* p, void* data);
+int cli_setup_progressbar(struct pakfire_ctx* ctx, struct pakfire_progress* p, void* data);
#endif /* PAKFIRE_CLI_PROGRESSBAR_H */
#include <lzma.h>
#include <zstd.h>
+#include <pakfire/ctx.h>
#include <pakfire/compress.h>
#include <pakfire/file.h>
#include <pakfire/filelist.h>
int progress_flags = PAKFIRE_PROGRESS_SHOW_PERCENTAGE;
int r = 1;
+ struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
+
// Use / if no prefix is set
if (!prefix)
prefix = "/";
progress_flags |= PAKFIRE_PROGRESS_SHOW_TRANSFER_SPEED;
// Create the progress indicator
- r = pakfire_progress_create(&data.progress, pakfire, progress_flags, NULL);
+ r = pakfire_progress_create(&data.progress, ctx, progress_flags, NULL);
if (r)
goto ERROR;
pakfire_progress_unref(data.progress);
if (data.writer)
archive_write_free(data.writer);
+ if (ctx)
+ pakfire_ctx_unref(ctx);
return r;
}
PAKFIRE_PROGRESS_SHOW_BYTES_TRANSFERRED;
int r = 1;
+ struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
+
struct pakfire_compress data = {
.pakfire = pakfire,
.archive = archive,
const size_t size = pakfire_filelist_total_size(filelist);
// Create the progress indicator
- r = pakfire_progress_create(&data.progress, pakfire, progress_flags, NULL);
+ r = pakfire_progress_create(&data.progress, ctx, progress_flags, NULL);
if (r)
goto ERROR;
pakfire_progress_unref(data.progress);
if (data.linkresolver)
archive_entry_linkresolver_free(data.linkresolver);
+ if (ctx)
+ pakfire_ctx_unref(ctx);
return r;
}
ctx->progress.data = data;
}
-int pakfire_ctx_setup_progress(struct pakfire_ctx* ctx, struct pakfire* pakfire,
- struct pakfire_progress* progress) {
+int pakfire_ctx_setup_progress(struct pakfire_ctx* ctx, struct pakfire_progress* progress) {
if (!ctx->progress.callback)
return 0;
- return ctx->progress.callback(ctx, pakfire, ctx->progress.data, progress);
+ return ctx->progress.callback(ctx, ctx->progress.data, progress);
}
// Pick Solution
if (!sources)
return 0;
+ struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
+
// Create a downloader
- r = pakfire_downloader_create(&downloader, pakfire);
+ r = pakfire_downloader_create(&downloader, ctx);
if (r)
goto ERROR;
pakfire_downloader_unref(downloader);
if (mirrorlist)
pakfire_mirrorlist_unref(mirrorlist);
+ if (ctx)
+ pakfire_ctx_unref(ctx);
if (sources)
free(sources);
// Progress
-typedef int (*pakfire_progress_callback)(struct pakfire_ctx*ctx, struct pakfire* pakfire,
+typedef int (*pakfire_progress_callback)(struct pakfire_ctx* ctx,
struct pakfire_progress* progress, void* data);
void pakfire_ctx_set_progress_callback(struct pakfire_ctx* ctx,
// Progress
-int pakfire_ctx_setup_progress(struct pakfire_ctx* ctx, struct pakfire* pakfire,
- struct pakfire_progress* progress);
+int pakfire_ctx_setup_progress(struct pakfire_ctx* ctx, struct pakfire_progress* progress);
// Pick Solution
struct pakfire_progress;
+#include <pakfire/ctx.h>
+
enum pakfire_progress_flags {
PAKFIRE_PROGRESS_NO_PROGRESS = (1 << 0),
PAKFIRE_PROGRESS_SHOW_PERCENTAGE = (1 << 1),
Callbacks
*/
typedef int (*pakfire_progress_start_callback)
- (struct pakfire* pakfire, struct pakfire_progress* progress, void* data, unsigned long int value);
+ (struct pakfire_ctx* ctx, struct pakfire_progress* progress, void* data, unsigned long int value);
typedef int (*pakfire_progress_finish_callback)
- (struct pakfire* pakfire, struct pakfire_progress* progress, void* data);
+ (struct pakfire_ctx* ctx, struct pakfire_progress* progress, void* data);
typedef int (*pakfire_progress_update_callback)
- (struct pakfire* pakfire, struct pakfire_progress* progress, void* data, unsigned long int value);
+ (struct pakfire_ctx* ctx, struct pakfire_progress* progress, void* data, unsigned long int value);
typedef void (*pakfire_progress_free_callback)
- (struct pakfire* pakfire, struct pakfire_progress* progress, void* data);
+ (struct pakfire_ctx* ctx, struct pakfire_progress* progress, void* data);
void pakfire_progress_set_callback_data(struct pakfire_progress* p, void* data);
#include <pakfire/pakfire.h>
int pakfire_progress_create(struct pakfire_progress** progress,
- struct pakfire* pakfire, int flags, struct pakfire_progress* parent);
+ struct pakfire_ctx* ctx, int flags, struct pakfire_progress* parent);
struct pakfire_progress* pakfire_progress_ref(struct pakfire_progress* p);
struct pakfire_progress* pakfire_progress_unref(struct pakfire_progress* p);
#include <pakfire/ctx.h>
#include <pakfire/logging.h>
-#include <pakfire/pakfire.h>
#include <pakfire/private.h>
#include <pakfire/progress.h>
struct pakfire_progress {
struct pakfire_ctx* ctx;
- struct pakfire* pakfire;
int nrefs;
// Title
// Call the free callback
if (p->callbacks.free)
- p->callbacks.free(p->pakfire, p, p->callbacks.data);
+ p->callbacks.free(p->ctx, p, p->callbacks.data);
if (p->parent)
pakfire_progress_unref(p->parent);
if (p->title)
free(p->title);
- if (p->pakfire)
- pakfire_unref(p->pakfire);
if (p->ctx)
pakfire_ctx_unref(p->ctx);
free(p);
}
-static int pakfire_progress_default_start_callback(struct pakfire* pakfire,
+static int pakfire_progress_default_start_callback(struct pakfire_ctx* ctx,
struct pakfire_progress* p, void* data, unsigned long int value) {
// Fetch the title
const char* title = pakfire_progress_get_title(p);
// Log the title
if (title)
- INFO(pakfire, "%s\n", title);
+ CTX_INFO(ctx, "%s\n", title);
return 0;
}
int pakfire_progress_create(struct pakfire_progress** progress,
- struct pakfire* pakfire, int flags, struct pakfire_progress* parent) {
+ struct pakfire_ctx* ctx, int flags, struct pakfire_progress* parent) {
struct pakfire_progress* p = NULL;
int r;
return -errno;
// Store a reference to the context
- p->ctx = pakfire_ctx(pakfire);
-
- // Store a reference to Pakfire
- p->pakfire = pakfire_ref(pakfire);
+ p->ctx = pakfire_ctx_ref(ctx);
// Initialize the reference counter
p->nrefs = 1;
// Call setup
if (!pakfire_progress_has_flag(p, PAKFIRE_PROGRESS_NO_PROGRESS)) {
- r = pakfire_ctx_setup_progress(p->ctx, p->pakfire, p);
+ r = pakfire_ctx_setup_progress(p->ctx, p);
if (r)
goto ERROR;
}
// Call the start callback
if (p->callbacks.start) {
- r = p->callbacks.start(p->pakfire, p, p->callbacks.data, value);
+ r = p->callbacks.start(p->ctx, p, p->callbacks.data, value);
if (r)
return r;
}
// Call the finish callback
if (p->callbacks.finish) {
- r = p->callbacks.finish(p->pakfire, p, p->callbacks.data);
+ r = p->callbacks.finish(p->ctx, p, p->callbacks.data);
if (r)
return r;
}
// Call the update callback
if (p->callbacks.update) {
- r = p->callbacks.update(p->pakfire, p, p->callbacks.data, value);
+ r = p->callbacks.update(p->ctx, p, p->callbacks.data, value);
if (r)
return r;
}