| 1 | /* |
|---|
| 2 | * QuteCom, a voice over Internet phone |
|---|
| 3 | * Copyright (C) 2004-2010 Mbdsys |
|---|
| 4 | * |
|---|
| 5 | * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | * it under the terms of the GNU General Public License as published by |
|---|
| 7 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 | * (at your option) any later version. |
|---|
| 9 | * |
|---|
| 10 | * This program is distributed in the hope that it will be useful, |
|---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | * GNU General Public License for more details. |
|---|
| 14 | * |
|---|
| 15 | * You should have received a copy of the GNU General Public License |
|---|
| 16 | * along with this program; if not, write to the Free Software |
|---|
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 18 | */ |
|---|
| 19 | |
|---|
| 20 | #include <shlibloader/SharedLibLoader.h> |
|---|
| 21 | |
|---|
| 22 | #include <util/String.h> |
|---|
| 23 | #include <util/SafeDelete.h> |
|---|
| 24 | |
|---|
| 25 | #include <cutil/global.h> |
|---|
| 26 | |
|---|
| 27 | #if defined(OS_WINDOWS) |
|---|
| 28 | #include "win32/Win32SharedLibLoader.h" |
|---|
| 29 | #elif defined(OS_POSIX) |
|---|
| 30 | #include "posix/PosixSharedLibLoader.h" |
|---|
| 31 | #else |
|---|
| 32 | #include "null/NullSharedLibLoader.h" |
|---|
| 33 | #endif |
|---|
| 34 | |
|---|
| 35 | SharedLibLoader::SharedLibLoader(const std::string & fileName) { |
|---|
| 36 | _loaderPrivate = NULL; |
|---|
| 37 | String tmp(fileName); |
|---|
| 38 | |
|---|
| 39 | if (!tmp.contains(SharedLibLoader::getSharedLibExtension(), false)) { |
|---|
| 40 | tmp += SharedLibLoader::getSharedLibExtension(); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | #if defined(OS_WINDOWS) |
|---|
| 44 | _loaderPrivate = new Win32SharedLibLoader(tmp); |
|---|
| 45 | #elif defined(OS_POSIX) |
|---|
| 46 | _loaderPrivate = new PosixSharedLibLoader(tmp); |
|---|
| 47 | #else |
|---|
| 48 | _loaderPrivate = new NullSharedLibLoader(tmp); |
|---|
| 49 | #endif |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | SharedLibLoader::~SharedLibLoader() { |
|---|
| 53 | OWSAFE_DELETE(_loaderPrivate); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | bool SharedLibLoader::load() { |
|---|
| 57 | return _loaderPrivate->load(); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | bool SharedLibLoader::unload() { |
|---|
| 61 | return _loaderPrivate->unload(); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | void * SharedLibLoader::resolve(const std::string & symbol) { |
|---|
| 65 | return _loaderPrivate->resolve(symbol); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | void * SharedLibLoader::resolve(const std::string & fileName, const std::string & symbol) { |
|---|
| 69 | SharedLibLoader loader(fileName); |
|---|
| 70 | if (loader.load()) { |
|---|
| 71 | return loader.resolve(symbol); |
|---|
| 72 | } |
|---|
| 73 | return NULL; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | std::string SharedLibLoader::getSharedLibExtension() { |
|---|
| 77 | #if defined(OS_WINDOWS) |
|---|
| 78 | return ".dll"; |
|---|
| 79 | #else |
|---|
| 80 | return ".so"; |
|---|
| 81 | #endif |
|---|
| 82 | } |
|---|