Nokia claimsMeeGo is more open than Android: MeeGo is a Linux-based platform that can drive a variety of computing devices, including mobile phones, netbooks, tablets, connected TVs, and on-board information and entertainment systems. Is that true? Let's take a look at the MeeGo Touch service framework.
BKJIA recommended topic: MeeGo: ubiquitous mobile operating system
The user process interface is called this service framework as an IPC mechanism that allows application units to use or serve an interface easily. In this document, the provider process interface is called "provider ".
The purpose of this service framework is as follows:
◆ Provides a simple IPC Mechanism
◆ Ensure that there is no runtime binary dependency between service users and providers
◆ Allow users to use an interface without worrying about the specific logic when selecting or connecting to an interface
◆ Allows users to query the list of providers and select
Basic Service Mechanism
Demonstrate what will happen when a server user SU uses an interface IF.
MeeGo touch Architecture
◆ Server user example: an interface is used to request the service er to give the name of the service provider that implements the interface
◆ This server er maintains a ing table between services and interfaces (by viewing the catalog service directory, usually/usr/share/dbus-1/services) the server er also has a set of service selection rules. it selects a service and returns the service name to the SU interface.
◆ The SU interface then creates a proper token to connect to a service with a given name, and then calls an appropriate method
IF a new SP exists, the Service er sends a signal to the appropriate SU interface to notify them, or IF there are no more SP, the SU will also send a notification. When an event occurs, the application will receive a notification and take the corresponding action by connecting to a signal in IF. For example, an image app may want to allow a user to send a photo by EMAIL. It can listen to the signal "no more SP sends to IF, so as to know when to invalidate this operation.
The service framework should not be used for general IPC communication or communication between two small programs, such, the same way as DuiValueSpace can be used to provide the data backend method for numerical change notifications.
Usage
As a service provider (SP)
◆ SP developers need to prepare two items:
Binary files
When a server user application tries to connect to this service, the binary file will be loaded if it is not running ).
Interface
The files required by the developer of the server user application include:
◆ Duiservicefwbaseif. h/cpp files. These files are common duiservicefwbaseif for all interface layers. the hfile is part of the libdui-dev package, duiservicefwbaseif. cpp will be compiled to libdui, so they are all part of the libdui0 package.
◆ The interface must be provided with XML files, header files, libraries, and A. serveice File
Interface-specific header files and interface XML files will be part of the maemo-interfaces-dev package, and the corresponding cpp file needs to be compiled into the interface-specific library file, these libraries are part of the maemo-interfaces package .. The service file will also be part of the maemo-interfaces package.
Binary files
◆ Create an XML file for defining interfaces.
If you want a method to connect to the current application, you can add a chainTask = "true" attribute to this method label. If you want a method to be asynchronous, you can add an asyncTask = "true" attribute to the label of this method. Note that these methods must not contain any 'out' parameter.
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>
- <interfacenameinterfacename="com.nokia.TextProcessorInterface">
- <methodnamemethodname="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 dui-servicefwgen to generate related. h and. cpp files. The command is as follows:
-
- Dui-servicefwgen-acom. nokia. TextProcessorInterfac [font =, SimSun] e [/font]
Modify code
◆ The modification can be divided into three steps:
- // 1. Create a class instance that has implemented interface functions
- MyService myService;
-
- // 2. Create an adapter to connect to the methods in ingress and myService
- // According to QDBusAbstractAdaptor (), it must be created on the stack,
- // And the memory is managed by QDBusAbstractAdaptor, so you do not need to save the pointer
- New MyServiceIfAdaptor (& myService );
-
- // 3. Connect to the session and register the service
- QDBusConnection connection = QDBusConnection: sessionBus ();
- Boolret = connection. registerService ("com. nokia. TextProcessor ");
- // Compile the remaining part of the program
- Return app.exe c ();
Interface
There are three steps to define an interface:
◆ Create an XML file defining an interface-the same XML file as described above.
◆ Run dui-servicefwgen to generate the. h and. cpp files. The command is as follows:
-
- dui-servicefwgen -pcom.nokia.TextProcessorInterface
-
-
-
◆ Service-related libraries need to be generated.
The above files must be included in the maemo-interfaces package, and the library must be included in maemo-interfaces. header files and XML files must also be included in maemo-interfaces-dev.
Descriptions of interfaces and methods can be added between '<doc> ''</doc>'. For example:
-
- <interfacenameinterfacename="com.nokia.someserviceinterface">
- <doc>
- <argtagargtag="brief">brief documentation for the interface</arg>
- <argtagargtag="details">detailed documentation for theinterface</arg>
- </doc>
- <method name="showPage">
- <doc>
- <argtagargtag="brief">brief documentation for showPage()method</arg>
- <argtagargtag="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
As a service user
◆ Install the libdui-dev debian package. It will provide you with service ing to the ghost daemon, header files, and library files.
◆ Install the maemo-interfaces-dev package that contains the header file of the proxy header, library, and package)
◆ Add-ldui and-l <Interface Name> to the LIBS of your project file.
◆ Include this interface header file in your source file, create an interface instance, and call serviceName () to obtain the interface provider.
◆ Use the 'isvalid () 'method to check whether the service is available.
◆ Call the interface method you want to use.
Implement and connect slots to process signals sent by a service er 'serviceavailable () ', 'serviceunavailable ()', and 'servicechanged () '.
Demo and code example
In libdui/demos/servicefw/, an example demonstrates three service providers and one service user. Com. nokia. textprocessor and org. maemo. the textprocessor Service implements the same interface-com. nokia. textProcessorInterface. because there are two services, we can try to remove the service and then observe that the service users are switching from one service to another. There is a script tool/dui-servicefwgen, which is used to generate source files that are used to define interfaces for service users. Run the following demo:
◆ Cd libdui
◆ Qmake & make instal (or execute at least one make iinstall operation in the duiservicemapper directory)
◆ Cd demos/servicefw
◆ Pushd misc; sudo./INSTALL; popd (this operation will INSTALL the ghost service related files to the/usr/share/dbus-1/services Directory)
◆ LD_LIBRARY_PATH = lib bin/user
◆ This step opens a small window that allows you to enter characters. These characters will be sent to a service through the interface, and the service will return the characters after being reversed.
In this demo, you can remove several services from/usr/share/dbus-1/services to simulate the removal of the service and then add ), to verify whether the service user program can perform the correct operation.
Original English:Http://apidocs.meego.com/mtf/servicefw.html
Original article addressHttp://www.meegoq.com/thread-250-1-1.html