Home · All Classes · Main Classes · Deprecated

Service Framework

Introduction

The service framework is an IPC mechanism that allows applications to simply either use or serve an interface. For the purposes of this documentation, the interface user process is referred to as 'user' and the interface provider process is referred to as the 'provider'.

The objectives of the service framework are :

  1. to provide an IPC mechanism that is simple to use,
  2. to ensure there is no run time binary dependancy between the service user and provider,
  3. to allow the user to just use an interface and not worry about the logic of choosing or connecting to an interface,
  4. to allow the user to query a list of providers and choose one of them.
sfw_mechanism.png

The 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 servicemapper (a dedicated dbus service) for the name of a service provider that implements that interface.
  2. The service mapper has been maintaining a map of services<->interfaces (by watching the dbus services directory, typically /usr/share/dbus-1/services) and has rules to determine which one to pick. It picks a service and returns the name to the interface in SU.
  3. The interface in SU then makes a regular dbus connection to the given service name and calls the appropriate method.

The service mapper will send 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, a gallery application may wish to allow a user to send a photo via email and it might listen to the 'no more SP for IF' signal in order to tell when to disable the option.

Typical usecases 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 13. friday 2042

Service Framework should not be used for generic IPC communication purposes or, for example, communication between applets. This should be done using other means like using a data backend that provides notifications of changes to values like MValueSpace.

Usage

As a Service Provider (SP)

Two things are required of the developer of an SP :

Binary
This is the binary that will be launched (if it is not already running) when a Service User application tries to connect to the service.
Interface
This 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 and the mservicefwbaseif.cpp is compiled into libmeegotouch itself and so is 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 should be made part of the maemo-interfaces-dev package along with the interface's XML file, and the corresponding cpp files compiled into interface specific libs that are made part of the maemo-interfaces package. The .service file should also be made part of the maemo-interfaces package.

Binary

Interface

There are three steps to defining an interface.

The above files should be made part of 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, as follows :

    <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 (incudes 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 so that we are able to remove services and see that the service user is switched from one service to another/etc. There is one script tools/m-servicefwgen, which is used to generate the source files that are 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 'does the right thing'.


Copyright © 2010 Nokia Corporation Generated on Thu Nov 4 2010 18:14:23 (PDT)
Doxygen 1.7.1
MeeGo Touch