1 /* 2 * Copyright 2013, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Ingo Weinhold <ingo_weinhold@gmx.de> 7 */ 8 9 10 #include <package/solver/Solver.h> 11 12 13 typedef BPackageKit::BSolver* CreateSolverFunction(); 14 15 16 #include <dlfcn.h> 17 #include <pthread.h> 18 19 20 static CreateSolverFunction* sCreateSolver = NULL; 21 22 static pthread_once_t sLoadLibsolvSolverAddOnInitOnce = PTHREAD_ONCE_INIT; 23 24 25 static void 26 load_libsolv_solver_add_on() 27 { 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; 39 40 sCreateSolver = (CreateSolverFunction*)dlsym(imageHandle, "create_solver"); 41 if (sCreateSolver == NULL) 42 dlclose(imageHandle); 43 } 44 45 46 namespace BPackageKit { 47 48 49 BSolver::BSolver() 50 { 51 } 52 53 54 BSolver::~BSolver() 55 { 56 } 57 58 59 /*static*/ status_t 60 BSolver::Create(BSolver*& _solver) 61 { 62 pthread_once(&sLoadLibsolvSolverAddOnInitOnce, &load_libsolv_solver_add_on); 63 if (sCreateSolver == NULL) 64 return B_NOT_SUPPORTED; 65 66 BSolver* solver = sCreateSolver(); 67 if (solver == NULL) 68 return B_NO_MEMORY; 69 70 status_t error = solver->Init(); 71 if (error != B_OK) { 72 delete solver; 73 return error; 74 } 75 76 _solver = solver; 77 return B_OK; 78 } 79 80 81 } // namespace BPackageKit 82