kuzulis
16th January 2009, 06:50
Hi!
1. I need to create GPL the application similar on SCADA.
2. In it it is necessary to provide possibility of a choice and connection of external units of data gathering.
3. Data gathering units represent (preliminary) - classes The successor from QThread.
4. These units should have such interfaces as: (For example)
- Module. Start ()
- Module. Stop ()
- Module. Configure ()
....
Others API
....
5. They should be connected to the application by a choice in the menu of appropriate library with (*.dll/*.so unit.
6. After the unit is connected to the application done Module. Start (for example) -
and the unit reads out the configuration and is autonomously started in operation!
Prompt, how by means of mechanisms QT4 to me correctly to make it?
I while have thought up to do so: (but I do not know, it is correct so or not)
interfaces.h
#ifndef INTERFACES_H
#define INTERFACES_H
class MyModuleInterface
{
public:
virtual ~MyModuleInterface() {}
virtual void MyModuleStart() = 0;
virtual void MyModuleStop() = 0;
};
Q_DECLARE_INTERFACE(MyModuleInterface, "mywww.My.MyModuleInterface/1.0")
#endif
myPlug.h
#ifndef MYPLUG_H
#define MYPLUG_H
#include <QObject>
#include <QThread>
#include "../app/interfaces.h"
//this my connected module class
class TMyModule : public QThread
{
Q_OBJECT
protected:
void run();
/*
*/
public:
bool mabort;
/*
Here I will add then in public, private various methods of type necessary for me in future:
start, stop, configure, etc
*/
};
class MyModulePlugin : public QObject,
public MyModuleInterface
{
Q_OBJECT
Q_INTERFACES(MyModuleInterface)
public:
void MyModuleStart();
void MyModuleStop();
/*
Here I will add then in public, private various methods of type necessary for me in future:
start, stop, configure, etc
*/
private:
TMyModule Module;
};
#endif
myPlug.cpp
#include <QtGui>
#include "myPlug.h"
void TMyModule::run()
{
printf("Module is Running \n");
while (!mabort) {
sleep(1);
printf("Run \n");
/*
Here the algorithm of operation of the unit will be purely realised for example
*/
}
printf("Module is Stopped \n");
}
void MyModulePlugin::MyModuleStart()
{
Module.mabort = false;
if (!Module.isRunning())
Module.start();
}
void MyModulePlugin::MyModuleStop()
{
Module.mabort = true;
}
Q_EXPORT_PLUGIN2(mymoduleplugin, MyModulePlugin)
1. I need to create GPL the application similar on SCADA.
2. In it it is necessary to provide possibility of a choice and connection of external units of data gathering.
3. Data gathering units represent (preliminary) - classes The successor from QThread.
4. These units should have such interfaces as: (For example)
- Module. Start ()
- Module. Stop ()
- Module. Configure ()
....
Others API
....
5. They should be connected to the application by a choice in the menu of appropriate library with (*.dll/*.so unit.
6. After the unit is connected to the application done Module. Start (for example) -
and the unit reads out the configuration and is autonomously started in operation!
Prompt, how by means of mechanisms QT4 to me correctly to make it?
I while have thought up to do so: (but I do not know, it is correct so or not)
interfaces.h
#ifndef INTERFACES_H
#define INTERFACES_H
class MyModuleInterface
{
public:
virtual ~MyModuleInterface() {}
virtual void MyModuleStart() = 0;
virtual void MyModuleStop() = 0;
};
Q_DECLARE_INTERFACE(MyModuleInterface, "mywww.My.MyModuleInterface/1.0")
#endif
myPlug.h
#ifndef MYPLUG_H
#define MYPLUG_H
#include <QObject>
#include <QThread>
#include "../app/interfaces.h"
//this my connected module class
class TMyModule : public QThread
{
Q_OBJECT
protected:
void run();
/*
*/
public:
bool mabort;
/*
Here I will add then in public, private various methods of type necessary for me in future:
start, stop, configure, etc
*/
};
class MyModulePlugin : public QObject,
public MyModuleInterface
{
Q_OBJECT
Q_INTERFACES(MyModuleInterface)
public:
void MyModuleStart();
void MyModuleStop();
/*
Here I will add then in public, private various methods of type necessary for me in future:
start, stop, configure, etc
*/
private:
TMyModule Module;
};
#endif
myPlug.cpp
#include <QtGui>
#include "myPlug.h"
void TMyModule::run()
{
printf("Module is Running \n");
while (!mabort) {
sleep(1);
printf("Run \n");
/*
Here the algorithm of operation of the unit will be purely realised for example
*/
}
printf("Module is Stopped \n");
}
void MyModulePlugin::MyModuleStart()
{
Module.mabort = false;
if (!Module.isRunning())
Module.start();
}
void MyModulePlugin::MyModuleStop()
{
Module.mabort = true;
}
Q_EXPORT_PLUGIN2(mymoduleplugin, MyModulePlugin)