Home · All Namespaces · All Classes · Grouped Classes · Modules · Functions codeless banner

Tutorial: Writing server task plugin

Files:

The server task tutorial deomonstrates how to develop server task plugins. Server task plugins allow to dynamically extend the Qt Extended server even after the deployment process.

Plugin class definition

Each server task plugin must inherit from ServerTaskPlugin. It describes the various attributes of the task. During its startup phase the server loads all plugins which inherit from ServerTaskPlugin. Once it is time to actually start the server task provided by the plugin ServerTaskPlugin::initTask() is called which returns a reference to the new task object.

    #include <ServerTaskPlugin>

    class ExampleTaskPlugin : public ServerTaskPlugin
    {
        Q_OBJECT
    public:
        ExampleTaskPlugin( QObject* parent = 0 );
        virtual ~ExampleTaskPlugin();

        //name of task
        QByteArray name() const;

        //initialises task
        QObject* initTask( void* createArg = 0 ) const;

        //returns true if started in demand
        bool demand() const;
    };

Plugin class implementation

The implementation of the plugin class may look like this:

    ExampleTaskPlugin::ExampleTaskPlugin(QObject* parent)
        : ServerTaskPlugin( parent )
    {
    }

    ExampleTaskPlugin::~ExampleTaskPlugin()
    {
    }

    QByteArray ExampleTaskPlugin::name() const
    {
        return QByteArray("ExampleTask");
    }

    QObject* ExampleTaskPlugin::initTask(void* createArg ) const
    {
        Q_UNUSED( createArg );
        return new ExampleTask();
    }

    bool ExampleTaskPlugin::demand() const
    {
        return true;
    }

    QTOPIA_EXPORT_PLUGIN( ExampleTaskPlugin )

functiondescription
ServerTaskPlugin()The constructor is called immediately after startup of the server in order to identify all available server task plugins.
ServerTaskPlugin::initTask()Initialises/starts the task.
ServerTaskPlugin::name()This function returns the name of the task. This name may be used in conjunction with Task.cfg or QtopiaServerApplication::qtopiaTask().
ServerTaskPlugin::demand()If this function returns false this task will be started automatically unless otherwise specified byTask.cfg. If this function returns true this task is only started if another server task explicitly requests a reference to it.

The subsequent example task implementation does nothing and is only provided for the sake of completeness:

    #include "exampletask.h"
    #include <qtopiaglobal.h>

    #include <QDebug>

    class ExampleTask: public QObject
    {
    public:
        ExampleTask( QObject* parent = 0 ) : QObject(parent)
        {
            //server task code
        }

        ~ExampleTask()
        {
        }
    };

Limitations

Due to the fact that server task plugins don't have access to symbols in the server and vice versa some limitations apply:

  1. Plug-in task must inherit from QObject.
  2. Plug-in tasks do not have access to symbols in the Qt Extended server. Therefore it is not possible to obtain references to other server tasks via qtopiawidget<CLASS>() whereby CLASS is a class that is defined and declared in the server. Server tasks and plugin task can only refer to each other via QtopiaServerApplication::qtopiaTask() which returns a generic reference to a QObject. This means that server tasks provided via plugins must be self-contained.


Copyright © 2009 Trolltech Trademarks
Qt Extended 4.4.3