source: SMSSender/src/business/BCLibraryLoader.cpp @ 71:415b45c71663

3.0
Last change on this file since 71:415b45c71663 was 71:415b45c71663, checked in by Sämy Zehnder <saemy.zehnder@…>, 12 years ago
  • Reorganized all the libraries. libinterfaces and libgateways are removed now and libdatatypes contains now all these files.
File size: 2.5 KB
Line 
1/*
2 * BCLibraryLoader.cpp
3 *
4 *  Created on: Jul 10, 2009
5 *      Author: saemy
6 */
7
8#include "BCLibraryLoader.h"
9
10#include <QApplication>
11#include <QDebug>
12#include <QDir>
13#include <QFileInfo>
14#include <QLibrary>
15
16#include <ilibrary.h>
17#include <libraryexceptions.h>
18
19BCLibraryLoader* BCLibraryLoader::instance_=0;
20BCLibraryLoader* BCLibraryLoader::instance() {
21    return instance_ ? instance_ : (instance_ = new BCLibraryLoader);
22}
23
24
25bool BCLibraryLoader::isLibrary(const QString& filename) {
26    return QLibrary::isLibrary(filename);
27}
28
29void BCLibraryLoader::loadLibraries(const QDir& libraryPath) {
30    foreach (QString filename, libraryPath.entryList(QDir::Files)) {
31        loadLibrary(libraryPath.absoluteFilePath(filename));
32    }
33}
34
35ILibrary* BCLibraryLoader::loadLibrary(const QString& filename) {
36    if (libraries_.contains(filename)) {
37        return libraries_[filename];
38    }
39
40    QLibrary library;
41    library.setLoadHints(QLibrary::ResolveAllSymbolsHint | QLibrary::ExportExternalSymbolsHint);
42    library.setFileName(filename);
43
44    typedef ILibrary* (*GetLibraryFunc)();
45    GetLibraryFunc getLibrary = (GetLibraryFunc)library.resolve("getLibrary");
46    if (getLibrary) {
47        ILibrary* lib = getLibrary();
48        if (lib != NULL) {
49            libraries_.insert(filename, lib);
50            IGateway* gateway = lib->getGateway();
51            if (gateway != NULL) {
52                gateways_.insert(lib, gateway);
53            }
54
55            return lib;
56        } else {
57            qWarning() << "The library could not have been loaded: The returned library object was NULL";
58        }
59    } else {
60        qWarning() << "The library could not have been loaded: " + library.errorString();
61    }
62    return NULL;
63
64/*    pluginLoader()->setLoadHints(QLibrary::ResolveAllSymbolsHint | QLibrary::ExportExternalSymbolsHint);
65    pluginLoader()->setFileName(filename);
66    QObject* plugin = pluginLoader()->instance();
67    if (plugin != NULL) {
68        ILibrary* library = qobject_cast<ILibrary*>(plugin);
69        if (library != NULL) {
70            libraries_.insert(filename, library);
71            IGateway* gateway = library->getGateway();
72            if (gateway != NULL) {
73                gateways_.insert(library, gateway);
74            }
75
76            return library;
77        }
78    } else {
79        qWarning() << pluginLoader()->errorString();
80    }
81    return NULL;*/
82}
83
84QList<IGateway*> BCLibraryLoader::gateways() const {
85    return gateways_.values();
86}
87
88QList<ILibrary*> BCLibraryLoader::libraries() const {
89    return libraries_.values();
90}
Note: See TracBrowser for help on using the repository browser.