13.3. Underlying Technologies

Before describing the programming interface and the usage details for the current implementation of DCOP, it might be of interest to get acquainted with the underlying technologies and ideas. This section is optional for a developer interested in rapidly gaining the necessary skills for KDE programming. However, even a brief look at issues related to the employed technologies will sometimes help with a better understanding of the DCOP technology itself. This section will be of great interest to the developers proceeding at creating bindings between KDE and other technologies or entities through the use of DCOP.

13.3.1. ICE—The Inter-Client Exchange Mechanism

The KDE developers consider the principle of technology reuse as being of central importance. Whenever possible, existing specifications, standards, and algorithms are adopted and used. As a direct consequence of this way of thinking, the waste of effort in duplication work is diminished. Another consequence is the improved possibility for cooperation with other programming projects.

The authors of DCOP have chosen the ICE mechanism for the communication needs. The main reasons for this choice, as indicated by the main authors, are as follows:

  • The ICE library comes as a standard part of X11R6, thus it is available on all platforms on which X11R6 (and KDE for that matter) exists.

  • ICE is a well-established technology, used in the session management mechanism defined by X11R6.

  • The ICE library doesn't need a running X server to function, but benefits from other useful tools and technologies that the X Window System offers, such as providing authentication or reporting errors.

Detailed documentation concerning the ICE technology and the ICE library are available from public Internet resources. The X Window System Programmer's Guide, part of the large X Consortium Standard, contains a chapter (the eleventh) dedicated to ICE. This document is available at http://www.rzg.mpg.de/rzg/batch/NEC/sx4a_doc/g1ae04e/contents.html or, in a hardcopy format, at ftp://ftp.x.org/pub/R6.4/xc/doc/hardcopy/ICE/.

Learning more about ICE and its API is useful for developers who can't or don't want to use KDE's DCOP infrastructure, yet want to add to their application capabilities of communication with KDE applications that use DCOP. As an example, during the development of the notification system that KDE uses for application launchers, KDE developers used code based on pure ICE in order to connect to the DCOP server for broadcasting application startup notification.

A practical example of using ICE directly (other than in the DCOP engine itself) is Rik Hemsley's C wrapper API, contained in the KDE 2 libraries (kdelibs/dcop/dcopc.h and kdelibs/dcop/dcopc.c).

13.3.2. Data Streaming

Applications use DCOP to pass data between them. The nature and the structure of data are characterized by diversity. The DCOP transport mechanism has to ignore these characteristics of manipulated data. Thus, data has to be serialized. Serialization is the operation through which a collection of typed data items is transformed into an atypic, program-independent (and eventually even platform-independent) stream of information. Serialization has to respect a set of conversion rules that are then used accordingly in the de-serialization process.

For serialization/de-serialization, KDE uses QDataStream objects as defined by the Qt library. Reference documentation for QDataStream is available at http://doc.trolltech.com/qdatastream.html. The serialization format is described in http://doc.trolltech.com/datastreamformat.html. QDataStream assures binary data encoding independent of operating system, hardware platform, and byte order. Writing to and reading from a generic device through QDataStream serialization is simple (see Listings 13.1 and 13.2).


Example 13.1. Writing Through a QDataStream

   1 
   2 1: #include <qbitarray.h>
   3 2: #include <qdatastream.h>
   4 3:
   5 4: QByteArray message;
   6 5: QDataStream stream(message, IO_WriteOnly);
   7 6: int data = 10;
   8 7: stream << data; // put the data in the stream in usual way
   9 


Example 13.2. Reading from a Raw "Device" Using a QDataStream

   1 
   2 1: #include <qbitarray.h>
   3 2: #include <qdatastream.h>
   4 3:
   5 4: QByteArray message;
   6 5: QDataStream rstream(message, IO_ReadOnly);
   7 6: int rdata;
   8 7: rstream >> rdata; // get the data
   9 

You must imagine the QByteArray object as a piece of paper on which a message is written. The QDataStream object could then be the bottle in which the message can travel safely.

The data stream class implemented and used by the Qt library has many supplementary features, such as a means for setting the byte order manually, a tool for putting data in a printable form, and capabilities to operate on raw bytes collections. This technology is fast and convenient.

KDE's core libraries contain a few enhancements to QDataStream in the form of many new streaming operators that deal with supplementary data types that KDE classes need in DCOP (bool, unsigned long, and long). If you need to use these, you have to replace line 2 in the preceding listings with


   1 
   2 #include <kdatastream.h>
   3