Hello. I'm trying to use glib::module for a gtkmm project but have a
problem when access to module's functions.
I 've make a simple example to understand.

I've an error when executing "std::cout << "test D."<<
ptr_plugin->getModuleName()<< std::endl; " in plugs.cc

I've trying lot of things and still trying...

Thanks for any help or idea

Remy

ps: this is the sources

############## module.cc #####################
################"my module ###################
 
#include <iostream>
#include <gtkmm.h>
#include "module.hh"
 
#include <glibmm/ustring.h>
 
Module::Module(){
 
        //std::cout << "constructeur Module" << activeModule_ptr << std::endl;
        //std::cout << "module" << std::endl;
 
}
 
Module::~Module(){
 
        }
 
Glib::ustring getModuleName() { return "module(get module name)";};
 
IPlugin * get_module (){
        return new Module;
}
 
############## module.hh #####################
################"my module header###################
 
#ifndef EASYGEST_Module
#define EASYGEST_Module
 
#include "IPlugin.hh"
 
class Module : public IPlugin
{
 
public:
        Module::Module ();
        Module::~Module ();
 
        // Glib::ustring getModuleName();
};
 
PLUGIN_EXPORT IPlugin * get_module ();
 
 
#endif //EASYGEST_Module
 
 
############## Iplugin.hh #####################
################"my module header###################
 
#ifndef EASYGEST_IPLUGIN
#define EASYGEST_IPLUGIN
 
#include <glib.h>
#include <gtkmm.h>
 
 
 
 
class IPlugin : public sigc::trackable
{
public:
 
        IPlugin()                       {       }
        virtual ~IPlugin()      {       }
 
#ifdef WIN32
        #define PLUGIN_EXPORT   extern "C" __declspec(dllexport)
#else
        #define PLUGIN_EXPORT   extern "C" 
#endif  
 
//-------------misc---------------------//
        static IPlugin* activeModule_ptr;
 
/**
        * gets the name of the module (actually unuseful)
        * @return a Glib::ustring containing the module's name
        */
        virtual Glib::ustring getModuleName(){};
 
 
 
};
 
#endif
 
############## plugs.cc #####################
################ module loader###################
 
#include "plugs.hh"
#include "loadplugs.hh"
 
#include <iostream>
 
using namespace Glib;
IPlugin* IPlugin::activeModule_ptr;
 
 
 
typedef IPlugin* (*GetModule)();
 
void Plugs::loadModules()
{
    //std::cout << "looking for plugins ..."<< std::endl;       
    int nbplugs = InitPlugin();
    //std::cout << nbplugs << " plug-in(s) found(s)." << std::endl;
    std::list<IPlugin*>::iterator ip;
 
    IPlugin::activeModule_ptr = NULL;
 
 
}
 
int Plugs::InitPlugin()
{
    std::list<std::string>      list_file;
    //void * func =0;
    int NbPlugs = 0;
 
    if(LoadDir(".", &list_file))
    {
        std::list<std::string>::iterator f;
        for(f=list_file.begin(); f!=list_file.end(); ++f)
        {
            std::string filename = (*f).data();
            // testing if the file is the module is  *.so
                if
((filename[filename.size()-1]=='o')&&(filename[filename.size()-2]=='s')
                                &&(filename[filename.size()-3]=='.')){
            std::cout << "creating module with filename : " <<  filename
<< " ..." << std::endl ;
 
 
 
 
 
        void * essai = 0;
                Module* loadmod = new 
Module("/distant/remy/Projects/mini/src/libcontact",Glib::MODULE_BIND_LAZY);
 
 
 
                bool test = loadmod->get_symbol ("getModuleName", essai);
 
                if (test) 
        {
                        std::cout << "ok"  << std::endl;
                }
                        else {
                        std::cout << "rate"  << std::endl;
                        }
            if (loadmod->gobj() != NULL )
            {
                std::cout <<  "New module found." << std::endl;
                std::cout << "getting symbol ... " ;
                                void* func = 0;
                bool found = loadmod->get_symbol ("get_module", func);
                                std::cout << "last error" << 
loadmod->get_last_error () << std::endl;
                if (found)
                {
                    std::cout << "ok." << std::endl;
 
                                        GetModule get_module_test;
                    // la fonction existe, on recup la tool
                                        get_module_test = (GetModule) func;
                                        std::cout << "ok." << std::endl;
                    IPlugin* ptr_plugin = get_module_test();
                                        IPlugin *plugin = get_module_test(); 
                                        std::cout << "yeaaha" << 
plugin->activeModule_ptr << std::endl;
                                        std::cout << "test D."<< 
ptr_plugin->getModuleName()<< std::endl;
                    std::cout << "adding module into the list ... " <<
std::endl;
 
 
                }
                else std::cout << "symbol not found !!!! " << std::endl;
            }
            else
            {
                std::cout <<  "Error while loading module !!!" <<
std::endl;
                std::cout << Glib::Module::get_last_error() << std::endl;
            } // end if
                } // end for
        } // end if
}
        return NbPlugs;
}
 
 
############## plugs.hh #####################
################ module header###################
 
#ifndef EASYGEST_PLUGS
#define EASYGEST_PLUGS
 
#include "IPlugin.hh"
 
//      Class Plugs 
/*!
  Used by plugins to integrate the GUI interface
*/
class Plugs
{
 
public:
 
    Plugs() { }
    virtual     ~Plugs()        {       }
 
/**
    * loads the detected modules and adds their elements into the
interface 
    * @param interf = a ptr on EasyGest's whole interface (menuber,
toolbar, functree, quicksearch and mainwindow)
    * @return nothing
    */
    void loadModules();
 
 
protected:
/** liste des instances des plugins */
    std::list<IPlugin*> list_plugin;
 
/** initialisation de la liste des plugins
    * @return the number of detected modules
    */
    int InitPlugin();
};
 
 
#endif 
_______________________________________________
gtkmm-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Reply via email to