BPicture: Fix archive constructor.
[haiku.git] / src / kits / package / solver / Solver.cpp
blob53bb31b62159bdea8ab9a5d6e3464f90b6583c77
1 /*
2 * Copyright 2013, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
7 */
10 #include <package/solver/Solver.h>
13 typedef BPackageKit::BSolver* CreateSolverFunction();
16 #include <dlfcn.h>
17 #include <pthread.h>
20 static CreateSolverFunction* sCreateSolver = NULL;
22 static pthread_once_t sLoadLibsolvSolverAddOnInitOnce = PTHREAD_ONCE_INIT;
25 static void
26 load_libsolv_solver_add_on()
28 int flags = 0;
29 #ifdef HAIKU_TARGET_PLATFORM_HAIKU
30 void* imageHandle = dlopen("libpackage-add-on-libsolv.so", flags);
31 #else
32 #ifdef HAIKU_HOST_PLATFORM_LINUX
33 flags = RTLD_LAZY | RTLD_LOCAL;
34 #endif
35 void* imageHandle = dlopen("libpackage-add-on-libsolv_build.so", flags);
36 #endif
37 if (imageHandle == NULL)
38 return;
40 sCreateSolver = (CreateSolverFunction*)dlsym(imageHandle, "create_solver");
41 if (sCreateSolver == NULL)
42 dlclose(imageHandle);
46 namespace BPackageKit {
49 BSolver::BSolver()
54 BSolver::~BSolver()
59 /*static*/ status_t
60 BSolver::Create(BSolver*& _solver)
62 pthread_once(&sLoadLibsolvSolverAddOnInitOnce, &load_libsolv_solver_add_on);
63 if (sCreateSolver == NULL)
64 return B_NOT_SUPPORTED;
66 BSolver* solver = sCreateSolver();
67 if (solver == NULL)
68 return B_NO_MEMORY;
70 status_t error = solver->Init();
71 if (error != B_OK) {
72 delete solver;
73 return error;
76 _solver = solver;
77 return B_OK;
81 } // namespace BPackageKit