Home · All Classes · Main Classes · Deprecated
Public Slots | Public Member Functions | Protected Attributes

MApplicationService Class Reference

Adaptor class for interface com.nokia.MApplicationIf. More...

Inherits QObject.

List of all members.

Public Slots

virtual void launch ()
virtual void launch (const QStringList &parameters)
virtual void close ()
virtual void exit ()
virtual void launchAnotherWithQProcess ()
virtual void handleServiceRegistrationFailure ()
virtual void incrementAndRegister ()
virtual QString registeredName ()
virtual bool isRegistered ()
virtual bool registerService ()
void setServiceName (const QString &serviceName)

Public Member Functions

 MApplicationService (const QString &serviceName, QObject *parent=0)
virtual ~MApplicationService ()

Protected Attributes

MApplicationServicePrivate *const d_ptr

Detailed Description

Adaptor class for interface com.nokia.MApplicationIf.

This is the implementation for the MApplication QDBus service. Derive from this class to implement alternative behaviour.

If multiple processes are required, override the launch() method and from there call launchAnotherWithQProcess().

If it is desired for the subsequent processes to also have a MApplicationIf, then override handleServiceRegistrationFailure() and from there call incrementAndRegister().

If it is desired that there be no MApplicationIf interface, override registeredName() so that it returns QString(), isRegistered() to return false, and registerService() to return true.

Here is a code sample that allows multiple instances, each with its own DBus service :

class MyApplicationService: public MApplicationService
{
public:
    MyApplicationService(QObject *parent = 0) :
        MApplicationService("com.nokia.multipleinstances", parent) {
    }

    void launch() {
        launchAnotherWithQProcess();
    }

    void handleServiceRegistrationFailure() {
        qDebug() << "MyApplicationService::handleServiceRegistrationFailure()";

        incrementAndRegister();
    }
};

int main(int argc, char **argv)
{
    /* The base class of all DirectUI applications */
    MApplication app(argc, argv, "multipleinstances", new MyApplicationService());

Tip: You can use qdbusviewer from the qt4-dev-tools package to see the services appearing and disappearing when you run/kill multiple instances.


Constructor & Destructor Documentation

MApplicationService::MApplicationService ( const QString serviceName,
QObject parent = 0 
)
MApplicationService::~MApplicationService (  )  [virtual]

Member Function Documentation

void MApplicationService::close (  )  [virtual, slot]

Close the GUI.

Returns:
void
void MApplicationService::exit (  )  [virtual, slot]

Exit the application.

Returns:
void
void MApplicationService::handleServiceRegistrationFailure (  )  [virtual, slot]

Handles the situation when a service is already registered with this application's name.

Returns:
void

This method implements the default behaviour when there is already a service registrated with our service name, which is to call 'launch()' on that service and then exit. This method can be overridden and alternative behaviour implemented. One alternative behaviour is to register with another name and this is implemented in incrementAndRegister() which can be called from an overridden handleServiceRegistrationFailure().

void MApplicationService::incrementAndRegister (  )  [virtual, slot]

increment service name and register

Returns:
void

It is intended that this method be called from within an overridden handleServiceRegistrationFailure() method. The behaviour is to add an integer to the name of the service being registered until registration succeeds, or the maximum number of attempts (10) is exceeded.

bool MApplicationService::isRegistered (  )  [virtual, slot]

return if the service is registered

Returns:
true if the service is registered

If you want no MApplicationIf, override this to always return false.

void MApplicationService::launch ( const QStringList parameters  )  [virtual, slot]

Launch the application with parameters.

Returns:
void By default, this method will ignore the parameters and call launch()

If you want to process the parameters, derive a class from MApplicationService and override launch(const QStringList&).

This function is called when there is already an instance of this program running and registered to the DBus, and a second instance of this application gets executed. It will then try to register the same DBus interface, and fail at it. In this case when the second application was invoked with command line arguments, it will call this launch function with arguments on the first application instance via DBus. In this case no command line parameters are removed by libmeegotouch. The parameter list does not contain the executable name (argv[0]), but only the command line parameters.

void MApplicationService::launch (  )  [virtual, slot]

Launch the application.

Returns:
void By default, this method will raise the application's window

If it is required that it launch another instance of this application, derive a class from MApplicationService and override launch() to call launchAnotherWithQProcess().

void MApplicationService::launchAnotherWithQProcess (  )  [virtual, slot]

launch another process using QProcess

Returns:
void
QString MApplicationService::registeredName (  )  [virtual, slot]

return the registered service name

Returns:
registered service name

If you want no MApplicationIf, override this to return QString().

bool MApplicationService::registerService (  )  [virtual, slot]

registers the service

Returns:
true is registration was successful

If you want no MApplicationIf, override this to always return true.

void MApplicationService::setServiceName ( const QString serviceName  )  [slot]

sets the service name

Returns:
void

Member Data Documentation

MApplicationServicePrivate* const MApplicationService::d_ptr [protected]

Copyright © 2010 Nokia Corporation
MeeGo Touch