Home · All Classes · Main Classes · Deprecated

Service framework

Introduction

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:

  1. Provides an IPC mechanism that is simple to use.
  2. Ensures there is no run-time binary dependency between the service user and provider.
  3. Allows the user to use an interface without worrying about the logic of choosing or connecting to an interface.
  4. Allows the user to query a list of providers and choose one of them.
sfw_mechanism.png

Basic service framework mechanism

The above diagram shows what happens behind the scenes when a Service User (SU) uses an Interface (IF).

  1. The service user instantiates an interface which causes the interface to ask the service mapper (a dedicated dbus service) for the name of a service provider that implements that interface.
  2. The service mapper maintains a map of services and interfaces (by watching the dbus services directory, typically /usr/share/dbus-1/services) and has rules for choosing a service. It selects a service and returns the name to the interface in SU.
  3. The interface in SU makes a regular dbus connection to the given service name and calls the appropriate method.

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.

Typical use cases for the service framework

  1. Launch/Display a certain view of an application from another application or applet in experience canvas
  2. Get a list/thumbnails of available video content on the device
  3. Launch a web browser displaying a certain web page
  4. Choose/Display some image from available content
  5. Show recent contacts
  6. Show calendar appointments for Friday, 13 June 2042

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.

Using debugging functions

As a Service Provider (SP)

The following are required of an SP developer:

Binary
Launched (if it is not already running) when a Service User application tries to connect to the service.
Interface
Consists of the files needed by the developer of a Service User application. It consists of:
  • mservicefwbaseif.h/cpp files that are common to all interfaces.
    The mservicefwbaseif.h file is part of the libmeegotouch-dev package. The mservicefwbaseif.cpp is compiled into libmeegotouch itself and is, thus, part of the libmeegotouchcore0 package.
  • XML file, header files, a library and a .service file for the interface being supplied.
    The interface-specific header files must be included in the maemo-interfaces-dev package along with the interface's XML file. The corresponding cpp files must be compiled into interface-specific libs included in the maemo-interfaces package. The .service file should also be included in the maemo-interfaces package.

Binary

Interface

To define an interface:

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

As a Service User

  1. Install the libmeegotouch-dev and libmeegotouch-bin debian packages. This gives you the service mapper dbus daemon, headers, and lib.
  2. Install the maemo-meegotouch-interfaces-dev package (includes the proxy header and lib, and the wrapper header file).
  3. Add -lmeegotouch and -l<interfacename> to LIBS in your project file.
  4. In your source, include the interface header file and create an instance of the interface and call method serviceName() to get the provider for the interface.
  5. Check to see if the service was found OK using the 'isValid()' method.
  6. Call the interface method(s) as desired/appropriate.
  7. Implement and connect slots to handle the 'serviceAvailable()', 'serviceUnavailable()' and 'serviceChanged()' signals sent by the service mapper.

Demos and example code

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