Vater-Klasse Pure Virtual (hart im Code)
Code: Alles auswählen
#ifndef FUNCTIONHANDLER_H
#define FUNCTIONHANDLER_H
class FunctionHandler: public QObject
{
Q_OBJECT
public:
virtual RonsPacket* execute ( p ) = 0;
virtual ~FunctionHandler() {}
signals:
void appointmentChanged ( ConnectionHandler*, QByteArray );
};
typedef FunctionHandler* create_t();
typedef void destroy_t(FunctionHandler*);
#endif // FUNCTIONHANDLER_H
Code: Alles auswählen
class login : public FunctionHandler
{
public:
RonsPacket* execute(ConnectionHandler*,RonsPacket* );
virtual ~login();
};
RonsPacket* login::execute(p)
{
//viel code
return p;
}
extern "C"
{
login* create() {
return new login;
}
void destroy ( login* p ) {
delete p;
}
}
Code: Alles auswählen
QDir directory;
qDebug() << directory.currentPath();
directory.setCurrent("Functions");
QStringList filters;
filters << "lib*.so";
directory.setNameFilters(filters);
qDebug() << directory.entryList();
foreach(QString str, directory.entryList())
{
QString pluginPath = str;
QString pluginName = str.replace("lib", "").replace(".so", "");
qDebug() << "Load Plugin: "<< pluginName;
void* handle = dlopen ( directory.absoluteFilePath(pluginPath).toAscii() , RTLD_NOW );
if ( !handle ) {
qDebug() << "Cannot load library: " << dlerror() << '\n';
} else {
dlerror();
void * sym = dlsym ( handle, "create" );
create_t *plugin = (create_t *) sym;
FunctionHandler* poly = plugin();
functions.insert(pluginName,poly);
}
}