PDA

View Full Version : The application with connected units.



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)

seim
16th January 2009, 23:54
Prompt, how by means of mechanisms QT4 to me correctly to make it?
I'm not sure if I correctly understand.. If you ask about possible ways how to design your plugin architecture..

It seems functional on the first look.. It is questionable if the plugin's main class MyModulePlugin should implement MyModuleInterface or should provide a general factory for on object (or thread) implementing your interface, but it depends.. if you want to have only one interface per plugin, your solution is good.

If your threads in the plugins need to communicate with each other, you should also consider some communication mechanism. And if they communicate and you provide dynamic attaching and detaching of your plugins, you should also add some locking mechanism to be sure, that plugin is not being detached in the moment somebody is communicating with him..

everything is question of your needs :p