Commit eee8eb0d authored by chouquette's avatar chouquette Committed by Ludovic Fauvet

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

basic errors are detectes, symbols are exported as expected... yeah o//
parent 4878d910
#include "../../src/API/vlmc_module.h"
#include <stdio.h>
vlmc_module_begin()
printf("Initializing sample_module\n");
vlmc_module_end()
static vlmc_return_type_t Open( void* pv_module )
......
......@@ -24,7 +24,31 @@
#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 @@
#define MODULE_H
#include <QLibrary>
#include <QFileInfo>
#include "vlmc_module.h"
#include "vlmc_module_internal.h"
class Module
{
public:
Module( const QString& moduleFileName );
Module( const QFileInfo& moduleFile );
~Module();
bool initialize();
static bool isLibrary( const QString& fileName );
private:
QString m_name;
QString m_name;
QLibrary* m_moduleInstance;
vlmc_module_entrypoint_t m_entryPoint;
};
#endif // MODULE_H
......@@ -67,8 +67,22 @@ bool ModuleManager::loadSubDir( const QFileInfo& dir )
loadSubDir( *it );
}
else
qDebug() << it->fileName();
checkAndAddModule( *it );
++it;
}
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 @@
#define MODULEMANAGER_H
#include <QFileInfo>
#include <QHash>
#include "Module.h"
#include "Singleton.hpp"
......@@ -31,10 +32,14 @@
class ModuleManager : public Singleton<ModuleManager>
{
public:
bool loadModules();
bool loadModules();
private:
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>;
};
......
......@@ -23,8 +23,10 @@
#ifndef VLMC_MODULE_H
#define VLMC_MODULE_H
#define VLMC_EXTERN extern "C"
#ifdef __cplusplus
extern "C"
VLMC_EXTERN
{
#endif
......@@ -75,7 +77,7 @@ typedef struct
#endif
#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() \
......
/*****************************************************************************
* 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 \
src/tools/Toggleable.hpp \
src/API/vlmc_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 \
src/gui/ui/PreviewWidget.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