Commit 8cb0e564 authored by chouquette's avatar chouquette

"Functionnal" API. IE modules can be loaded...

basic errors are detectes, symbols are exported as expected... yeah o//
parent d39a5c58
#include "../../src/API/vlmc_module.h" #include "../../src/API/vlmc_module.h"
#include <stdio.h>
vlmc_module_begin() vlmc_module_begin()
printf("Initializing sample_module\n");
vlmc_module_end() vlmc_module_end()
static vlmc_return_type_t Open( void* pv_module ) static vlmc_return_type_t Open( void* pv_module )
......
...@@ -24,7 +24,31 @@ ...@@ -24,7 +24,31 @@
#include "Module.h" #include "Module.h"
Module::Module( const QString& moduleFileName ) Module::Module( const QFileInfo& moduleFile )
{ {
qDebug() << "Trying to load module :" << moduleFileName; qDebug() << "Trying to load module :" << moduleFile.absolutePath() + '/' + moduleFile.baseName();
m_moduleInstance = new QLibrary( moduleFile.absolutePath() + '/' + moduleFile.baseName() );
}
Module::~Module()
{
m_moduleInstance->unload();
delete m_moduleInstance;
}
bool Module::initialize()
{
m_entryPoint = reinterpret_cast<vlmc_module_entrypoint_t>( m_moduleInstance->resolve( "vlmc_module_entrypoint" ) );
if ( m_entryPoint == NULL )
{
qDebug() << "Can't find module entry point";
return false;
}
m_entryPoint( NULL );
return true;
}
bool Module::isLibrary( const QString& fileName )
{
return QLibrary::isLibrary( fileName );
} }
...@@ -24,16 +24,24 @@ ...@@ -24,16 +24,24 @@
#define MODULE_H #define MODULE_H
#include <QLibrary> #include <QLibrary>
#include <QFileInfo>
#include "vlmc_module.h" #include "vlmc_module_internal.h"
class Module class Module
{ {
public: public:
Module( const QString& moduleFileName ); Module( const QFileInfo& moduleFile );
~Module();
bool initialize();
static bool isLibrary( const QString& fileName );
private: private:
QString m_name; QString m_name;
QLibrary* m_moduleInstance;
vlmc_module_entrypoint_t m_entryPoint;
}; };
#endif // MODULE_H #endif // MODULE_H
...@@ -67,8 +67,22 @@ bool ModuleManager::loadSubDir( const QFileInfo& dir ) ...@@ -67,8 +67,22 @@ bool ModuleManager::loadSubDir( const QFileInfo& dir )
loadSubDir( *it ); loadSubDir( *it );
} }
else else
qDebug() << it->fileName(); checkAndAddModule( *it );
++it; ++it;
} }
return true; return true;
} }
void ModuleManager::checkAndAddModule( const QFileInfo& moduleFile )
{
if ( Module::isLibrary( moduleFile.absoluteFilePath() ) )
{
Module* module = new Module( moduleFile );
if (module->initialize() == false)
{
qDebug() << "Invalid module. Unloading...";
}
}
else
qDebug() << moduleFile.absoluteFilePath() << "isn't a library file";
}
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#define MODULEMANAGER_H #define MODULEMANAGER_H
#include <QFileInfo> #include <QFileInfo>
#include <QHash>
#include "Module.h" #include "Module.h"
#include "Singleton.hpp" #include "Singleton.hpp"
...@@ -35,6 +36,10 @@ public: ...@@ -35,6 +36,10 @@ public:
private: private:
ModuleManager(); ModuleManager();
bool loadSubDir( const QFileInfo& dir ); bool loadSubDir( const QFileInfo& dir );
void checkAndAddModule( const QFileInfo& moduleFile );
private:
QHash<QString, Module*> m_modules;
friend class Singleton<ModuleManager>; friend class Singleton<ModuleManager>;
}; };
......
...@@ -23,8 +23,10 @@ ...@@ -23,8 +23,10 @@
#ifndef VLMC_MODULE_H #ifndef VLMC_MODULE_H
#define VLMC_MODULE_H #define VLMC_MODULE_H
#define VLMC_EXTERN extern "C"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" VLMC_EXTERN
{ {
#endif #endif
...@@ -75,7 +77,7 @@ typedef struct ...@@ -75,7 +77,7 @@ typedef struct
#endif #endif
#define vlmc_module_begin() \ #define vlmc_module_begin() \
VLMC_EXPORT vlmc_return_type_t vlmc_module_entrypoint( vlmc_module_t* p_module ) \ VLMC_EXTERN VLMC_EXPORT vlmc_return_type_t vlmc_module_entrypoint( vlmc_module_t* p_module ) \
{ {
#define vlmc_module_end() \ #define vlmc_module_end() \
......
/*****************************************************************************
* vlmc_module_internal.h: Represents the vlmc's internal representation of a module
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef VLMC_MODULE_INTERNAL_H
#define VLMC_MODULE_INTERNAL_H
#include "vlmc_module.h"
#ifdef __cplusplus
extern "C"
{
#endif
typedef vlmc_return_type_t (*vlmc_module_entrypoint_t)( vlmc_module_t* );
#ifdef __cplusplus
}
#endif
#endif // VLMC_MODULE_INTERNAL_H
...@@ -83,7 +83,8 @@ HEADERS += src/gui/MainWindow.h \ ...@@ -83,7 +83,8 @@ HEADERS += src/gui/MainWindow.h \
src/tools/Toggleable.hpp \ src/tools/Toggleable.hpp \
src/API/vlmc_module.h \ src/API/vlmc_module.h \
src/API/Module.h \ src/API/Module.h \
src/API/ModuleManager.h src/API/ModuleManager.h \
src/API/vlmc_module_internal.h
FORMS += src/gui/ui/MainWindow.ui \ FORMS += src/gui/ui/MainWindow.ui \
src/gui/ui/PreviewWidget.ui \ src/gui/ui/PreviewWidget.ui \
src/gui/ui/Preferences.ui \ src/gui/ui/Preferences.ui \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment