Home · All Classes · Main Classes · Deprecated |
The service framework is an IPC mechanism that simply allows applications to either use or serve an interface. In this section, the interface user process is referred to as 'user' and the interface provider process is referred to as the 'provider'.
The service framework:
Basic service framework mechanism
The above diagram shows what happens behind the scenes when a Service User (SU) uses an Interface (IF).
The service mapper sends signals to the corresponding SU interfaces to inform them when there is a new SP for the IF, or if there are no more SPs for the IF. The application should connect to the signals in the IF in order to tell when these events occur and to take appropriate action. For example, if a gallery application allows a user to send a photo by e-mail, it listens to the 'no more SP for IF' signal to know when to disable the option.
Do not use the service framework for generic IPC communication purposes or, for example, for communication between applets. For this purpose, use other means, such as a data backend that provides notifications of changes to values such as MValueSpace.
The following are required of an SP developer:
Create an XML file that defines the interface.
To chain a method to the current application, add a 'chainTask="true"' attribute to the method tag. To create an asynchronous method, add an 'asyncTask="true"' attribute to the method tag. Note: The asynchronous methods must not have any 'out' parameters.
For example:
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> <node> <interface name="com.nokia.TextProcessorInterface"> <method name="reverse" chainTask="true"> <arg name="message" type="s" direction="in"/> <arg name="" type="s" direction="out"/> </method> <method name="blinkScreen" asyncTask="true"> <arg name="message" type="s" direction="in"/> </method> </interface> </node>
Run the m-servicefwgen tool to generate the adaptor h and cpp files. For example:
m-servicefwgen -a com.nokia.TextProcessorInterface
Change your code.
The following code snippet illustrates three steps:
// 1. Make an instance of the class that has methods which implement the interface functionality MyService myService; // 2. Make an adaptor to link the dbus methods with the methods in myService // According to QDBusAbstractAdaptor(), this must be on the heap, // and memory is owned by QDBusAbstractAdaptor, so no need to keep pointer new MyServiceIfAdaptor( &myService ); // 3. Connect to session bus and register this service QDBusConnection connection = QDBusConnection::sessionBus(); bool ret = connection.registerService("com.nokia.TextProcessor"); // continue with rest of app return app.exec();
To define an interface:
Run the m-servicefwgen tool to generate the proxy header, cpp files, and the wrapper header file. For example :
m-servicefwgen -p com.nokia.TextProcessorInterface
The above files should be included in the maemo-interfaces package. The library should be in maemo-interfaces, and the header and XML files should be in maemo-interfaces-dev.
Documentation for an interface and its methods can be added between '<doc>' and '</doc>' tags. For example:
<interface name="com.nokia.someserviceinterface"> <doc> <arg tag="brief">brief documentation for the interface</arg> <arg tag="details">detailed documentation for the interface</arg> </doc> <method name="showPage"> <doc> <arg tag="brief">brief documentation for showPage() method</arg> <arg tag="details">detailed documentation for showPage() method</arg> </doc> <arg name="targetPage" type="s" direction="in" /> <arg name="previousPage" type="s" direction="in" /> <arg name="" type="b" direction="out"/> </method> ....etc
In libmeegotouch/demos/servicefw/ there is example code showing three service providers and a service user. The com.nokia.textprocessor and org.maemo.textprocessor services both implement the same interface - com.nokia.TextProcessorInterface. There are two services that enable you to remove services and see that the service user is switched from one service to another, and so on. There is one script tools/m-servicefwgen, which is used to generate the source files used to define the interface to the service user. To run this demo:
In this demo, you can remove the various service files from /usr/share/dbus-1/services to simulate the service being removed (and added again) and see that the service user application functions correctly.
Copyright © 2010 Nokia Corporation | MeeGo Touch |