]> git.ipfire.org Git - pakfire.git/commitdiff
request: Implement a new interface how to walk through problems/solutions
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 31 Oct 2022 18:12:17 +0000 (18:12 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 31 Oct 2022 18:12:17 +0000 (18:12 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/problem.h
src/libpakfire/include/pakfire/request.h
src/libpakfire/problem.c
src/libpakfire/request.c

index aec5151f74d073ca7c9b65ad45d9c2f95168ecf7..046d0b1e453b009bc8150f4e84558c1c8f52eef3 100644 (file)
@@ -36,7 +36,6 @@ int pakfire_problem_get_solutions(struct pakfire_problem* problem,
 
 #ifdef PAKFIRE_PRIVATE
 
-
 #include <pakfire/request.h>
 
 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 */
index 61ffafa9ae5ac689d83b56a1bc54b4c5bd8734e4..629ab1f9117472e917edc20f09b4c6ca2e8435fc 100644 (file)
@@ -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 */
index 1bcddc4fa5ee29af2aaa397c86c4ef9f93c52b86..4bc7ebffb5a4a7a51939ab34a4b9efa6fe1cd396 100644 (file)
@@ -18,6 +18,7 @@
 #                                                                             #
 #############################################################################*/
 
+#include <errno.h>
 #include <stdlib.h>
 
 #include <pakfire/constants.h>
@@ -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);
+}
index 85855851d5f09725f455f98cebcd2f34347f6656..848608133c8e9872a0ff3db080d33f7bf9084fe9 100644 (file)
@@ -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);