SPTK concept for plugins (depricated)

The plugins are based on C++-classes, which are created by a C-function in the plugin. It returns a pointer of the instance of the object casted to the master class of SPTK, like sptkButtonGadget and so on. The so written plugin performs actions on the master class of the object, like sptkButtonGagget, but uses the functionality of the plugin class, like sptkDocHTMLButtonGadget. So you don't have to rewrite a program if you want to use another plugin, you don't even have to recompile as the pugin is specified with a standard c++-string. With this fact you can get the plugin-name from a configfile or as command line option.
 
If you want to use more than one plugin of one kind, e.g. mysql and ODBC as database plugins, at the same time. The enables database converters, GUI applications generating documents, applications using more than one network protocol, and so one.
 
An example how to load and use a plugin:
#include "sptkcore/sptkplugin.h"
#include "sptksql/sptksqldatabase.h"
 
int main(int argc, char *argv[])
{
    /*
      Load the SQL plugin for mySQL
    */

 
    sptkPlugin *sqlPlugin=new sptkPlugin("sql_mysql");
 
    /*
      If there was an error loading the plugin, exit the application
    */

 
    if(!sqlPlugin) {
        std::cerr << "Connot load SQL-Plugin.\n";
        exit(1);
    }
[...]
    /*
      Get a sptkDatabase object from the SQL plugin initializied before
    */

 
    sptkSQLDatabase *myDB=(sptkSQLDatabase *)sqlPlugin->createObject("Database");
 
    /*
      Check if object was returned and than try to connect to a database
    */

 
    if((!myDB)||(myDB->connect("localhost","user","passwd","",0)))
    {
        std::cerr <<"Can't open DB" << myDB->error();
        return 1;
    }
[...]
    delete sqlPlugin;
}

Powered by SPOM