From aa36f70eb842db8f1b68df6391296b39223ec0df Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 31 Oct 2022 18:12:17 +0000 Subject: [PATCH] request: Implement a new interface how to walk through problems/solutions Signed-off-by: Michael Tremer --- src/libpakfire/include/pakfire/problem.h | 4 +++- src/libpakfire/include/pakfire/request.h | 3 +++ src/libpakfire/problem.c | 30 ++++++++++++++++++++++++ src/libpakfire/request.c | 28 ++++++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/libpakfire/include/pakfire/problem.h b/src/libpakfire/include/pakfire/problem.h index aec5151f7..046d0b1e4 100644 --- a/src/libpakfire/include/pakfire/problem.h +++ b/src/libpakfire/include/pakfire/problem.h @@ -36,7 +36,6 @@ int pakfire_problem_get_solutions(struct pakfire_problem* problem, #ifdef PAKFIRE_PRIVATE - #include int pakfire_problem_create(struct pakfire_problem** problem, struct pakfire* pakfire, @@ -45,6 +44,9 @@ int pakfire_problem_create(struct pakfire_problem** problem, struct pakfire* pak struct pakfire* pakfire_problem_get_pakfire(struct pakfire_problem* problem); Id pakfire_problem_get_id(struct pakfire_problem* problem); +int pakfire_problem_next_solution( + struct pakfire_problem* problem, struct pakfire_solution** solution); + #endif #endif /* PAKFIRE_PROBLEM_H */ diff --git a/src/libpakfire/include/pakfire/request.h b/src/libpakfire/include/pakfire/request.h index 61ffafa9a..629ab1f91 100644 --- a/src/libpakfire/include/pakfire/request.h +++ b/src/libpakfire/include/pakfire/request.h @@ -74,6 +74,9 @@ int pakfire_request_take_solution(struct pakfire_request* request, Solver* pakfire_request_get_solver(struct pakfire_request* request); +int pakfire_request_next_problem( + struct pakfire_request* request, struct pakfire_problem** problem); + #endif #endif /* PAKFIRE_REQUEST_H */ diff --git a/src/libpakfire/problem.c b/src/libpakfire/problem.c index 1bcddc4fa..4bc7ebffb 100644 --- a/src/libpakfire/problem.c +++ b/src/libpakfire/problem.c @@ -18,6 +18,7 @@ # # #############################################################################*/ +#include #include #include @@ -290,3 +291,32 @@ ERROR: return r; } + +int pakfire_problem_next_solution( + struct pakfire_problem* problem, struct pakfire_solution** solution) { + Solver* solver = pakfire_request_get_solver(problem->request); + Id id = 0; + + // Check input + if (!solution) { + errno = EINVAL; + return 1; + } + + // Fetch the ID of the previous solution + if (*solution) { + id = pakfire_solution_get_id(*solution); + + // Free the previous solution + pakfire_solution_unref(*solution); + *solution = NULL; + } + + // Fetch the ID of the next problem + id = solver_next_solution(solver, problem->id, id); + if (!id) + return 0; + + // Create solution + return pakfire_solution_create(solution, problem, id); +} diff --git a/src/libpakfire/request.c b/src/libpakfire/request.c index 85855851d..848608133 100644 --- a/src/libpakfire/request.c +++ b/src/libpakfire/request.c @@ -590,6 +590,34 @@ PAKFIRE_EXPORT int pakfire_request_verify(struct pakfire_request* request, int f return 0; } +int pakfire_request_next_problem( + struct pakfire_request* request, struct pakfire_problem** problem) { + Id id = 0; + + // Check input + if (!problem) { + errno = EINVAL; + return 1; + } + + // Fetch the ID of the previous problem + if (*problem) { + id = pakfire_problem_get_id(*problem); + + // Free the previous problem + pakfire_problem_unref(*problem); + *problem = NULL; + } + + // Fetch the ID of the next problem + id = solver_next_problem(request->solver, id); + if (!id) + return 0; + + // Create problem + return pakfire_problem_create(problem, request->pakfire, request, id); +} + PAKFIRE_EXPORT int pakfire_request_take_solution(struct pakfire_request* request, struct pakfire_solution* solution) { struct pakfire_problem* problem = pakfire_solution_get_problem(solution); -- 2.39.5