]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: Make Problem obscure
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 15 Jan 2018 14:17:18 +0000 (15:17 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 15 Jan 2018 14:17:18 +0000 (15:17 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/problem.h
src/libpakfire/problem.c
src/libpakfire/solution.c

index 20c357ee61eae1b3ba5b5c07149922c8a3aa43b6..cecb056bb6c8785e7a54185fe4c570e38060a635 100644 (file)
@@ -21,9 +21,6 @@
 #ifndef PAKFIRE_PROBLEM_H
 #define PAKFIRE_PROBLEM_H
 
-#include <solv/pool.h>
-#include <solv/queue.h>
-
 #include <pakfire/request.h>
 
 PakfireProblem pakfire_problem_create(PakfireRequest request, Id id);
@@ -35,18 +32,14 @@ void pakfire_problem_append(PakfireProblem problem, PakfireProblem new_problem);
 
 const char* pakfire_problem_to_string(PakfireProblem problem);
 
+PakfireRequest pakfire_problem_get_request(PakfireProblem problem);
 PakfireSolution pakfire_problem_get_solutions(PakfireProblem problem);
 
 #ifdef PAKFIRE_PRIVATE
 
-struct _PakfireProblem {
-       PakfireRequest request;
-       Id id;
-       char* string;
+#include <solv/pooltypes.h>
 
-       PakfireProblem next;
-       int nrefs;
-};
+Id pakfire_problem_get_id(PakfireProblem problem);
 
 #endif
 
index a9f18f6cd87c91bea6c5a094f561924cf5c6b4a5..e38385913ea71c79044544883035fc32c3290632 100644 (file)
 #include <pakfire/solution.h>
 #include <pakfire/util.h>
 
+struct _PakfireProblem {
+       PakfireRequest request;
+       Id id;
+       char* string;
+
+       PakfireProblem next;
+       int nrefs;
+};
+
 static char* to_string(PakfireProblem problem) {
        Solver* solver = pakfire_request_get_solver(problem->request);
        Pool* pool = solver->pool;
@@ -253,6 +262,14 @@ PAKFIRE_EXPORT const char* pakfire_problem_to_string(PakfireProblem problem) {
        return problem->string;
 }
 
+Id pakfire_problem_get_id(PakfireProblem problem) {
+       return problem->id;
+}
+
+PAKFIRE_EXPORT PakfireRequest pakfire_problem_get_request(PakfireProblem problem) {
+       return pakfire_request_ref(problem->request);
+}
+
 PAKFIRE_EXPORT PakfireSolution pakfire_problem_get_solutions(PakfireProblem problem) {
        PakfireSolution ret = NULL;
        Solver* solver = pakfire_request_get_solver(problem->request);
index dc12ea79d5829015eb2392fcd7cdc2b23a90b0d3..403fc60ddcc3eda515caa3eaee4b06ba6bb8b574 100644 (file)
@@ -41,17 +41,19 @@ struct _PakfireSolution {
 };
 
 static void import_elements(PakfireSolution solution) {
-       Solver* solver = pakfire_request_get_solver(solution->problem->request);
+       PakfireRequest request = pakfire_problem_get_request(solution->problem);
+
+       Solver* solver = pakfire_request_get_solver(request);
        Pool* pool = solver->pool;
 
        // Reserve memory
-       unsigned int num = solver_solutionelement_count(solver, solution->problem->id, solution->id);
+       unsigned int num = solver_solutionelement_count(solver, pakfire_problem_get_id(solution->problem), solution->id);
        char** elements = solution->elements = pakfire_calloc(num + 1, sizeof(*elements));
 
        Id p;
        Id rp;
        Id element = 0;
-       while ((element = solver_next_solutionelement(solver, solution->problem->id, solution->id, element, &p, &rp)) != 0) {
+       while ((element = solver_next_solutionelement(solver, pakfire_problem_get_id(solution->problem), solution->id, element, &p, &rp)) != 0) {
                char line[STRING_SIZE];
 
                if (p == SOLVER_SOLUTION_JOB || p == SOLVER_SOLUTION_POOLJOB) {
@@ -112,6 +114,8 @@ static void import_elements(PakfireSolution solution) {
 
        // Terminate array
        *elements = NULL;
+
+       pakfire_request_unref(request);
 }
 
 PAKFIRE_EXPORT PakfireSolution pakfire_solution_create(PakfireProblem problem, Id id) {