
\begin{DoxyItemize}
\item infos = Information about the dbus plugin is in keys below
\item infos/author = Markus Raab \href{mailto:elektra@libelektra.org}{\tt elektra@libelektra.\+org}
\item infos/licence = B\+S\+D
\item infos/needs =
\item infos/provides = notification
\item infos/placements = postgetstorage postcommit
\item infos/description = Sends D\+Bus signals when a method is called
\end{DoxyItemize}

This plugin is a notification plugin which sends a signal to dbus when a method is called. This plugin allows external programs to take action when dbus notifies the program that a certain method has taken place with Elektra.

\subsection*{Dependencies}


\begin{DoxyItemize}
\item {\ttfamily libdbus-\/1-\/dev}
\end{DoxyItemize}

\subsection*{Dbus}

A preferred way to interconnect desktop applications and even embedded system applications on mobile devices running Linux is D-\/\+Bus. The idea of D-\/\+Bus accords to that of Elektra\+: to provide standards to let software work together more tightly. D-\/\+Bus provides a simple and lightweight I\+P\+C (Inter-\/\+Process Communication= system to be used within desktop systems. Next to R\+P\+C (Remote Procedure Call), which is not used in this plugin, it supports signals which can notify an arbitrary number of other applications about changes. Given software like a D-\/\+Bus library, notification itself is a rather easy task, but it involves additional library dependences. So it is the perfect task to be implemented as a plugin. The information about the channels to be used can be stored in the global key database.

D-\/\+Bus supports a {\bfseries system-\/wide bus} and a {\bfseries session bus}. The system configuration can be accessed by each user and the user configuration is limited to a single user. Both buses can immediately be used for the system and user configuration notification updates to get pleasing results. But, there is a problem with the session bus\+: It is possible within D-\/\+Bus that a user starts several sessions. The user configuration should be global to the user and is not aware of these sessions. So if several sessions are started, some of the user's processes will miss notification updates.

The namespaces are mapped to the buses the following way\+:


\begin{DoxyItemize}
\item system\+: system-\/wide bus
\item user\+: session bus
\end{DoxyItemize}

Following signal names are used to notify about changes in the elektra Key\+Set\+:
\begin{DoxyItemize}
\item Key\+Added\+: a key has been added
\item Key\+Changed\+: a key has been changed
\item Key\+Deleted\+: a key has been deleted
\end{DoxyItemize}

\subsection*{Usage}

Mount the plugin additionally to a storage plugin, e.\+g. \begin{DoxyVerb}    kdb mount file.dump / dump dbus
\end{DoxyVerb}


then we can receive the notification events using\+: \begin{DoxyVerb}    dbus-monitor type='signal',interface='org.libelektra',path='/org/libelektra/configuration'
\end{DoxyVerb}


\subsubsection*{Python}

In Python the D\+Bus notifications can be used as follows

```python import dbus import gobject gobject.\+threads\+\_\+init() \# important\+: initialize threads if gobject main loop is used from dbus.\+mainloop.\+glib import D\+Bus\+G\+Main\+Loop

class D\+Bus\+Test()\+: def {\bfseries init}(self)\+: D\+Bus\+G\+Main\+Loop(set\+\_\+as\+\_\+default=True) bus = dbus.\+System\+Bus() \# may use session bus for user db bus.\+add\+\_\+signal\+\_\+receiver(self.\+elektra\+\_\+dbus\+\_\+key\+\_\+changed\+\_\+cb, signal\+\_\+name=\char`\"{}\+Key\+Changed\char`\"{}, dbus\+\_\+interface=\char`\"{}org.\+libelektra\char`\"{}, path=\char`\"{}/org/libelektra/configuration\char`\"{})

def elektra\+\_\+dbus\+\_\+key\+\_\+changed\+\_\+cb(self, key)\+: print('key changed s' \% key)

test = D\+Bus\+Test() loop = gobject.\+Main\+Loop() try\+: loop.\+run() except Keyboard\+Interrupt\+: loop.\+quit() ```

\subsection*{Background}

Today, programs are often interconnected in a dense way. Such applications should always be informed when something in their environment changes. For user interactive software, notification about configuration changes is expected. The only alternative is polling, which wastes resources. It additionally is no option, because for interactive software the latency needs to be low. Instead, the software which changes the configuration has to notify all other interested applications that can reread their configuration without significant delay. In Elektra, a notification plugin ensures that a notification is actually sent on each change.

Applications can wait for such a notification with hand-\/written code. Bindings, however, allow for better integration. It is a common approach for toolkits to provide a main loop. Applications using such toolkits can integrate notification services into this main loop.

The actions that occur in such events are application or toolkit specific because of the non-\/invasive nature of Elektra. Software reacts in many different ways to update events. Hence, the frequency of update events should be kept at a minimum. Changes are kept atomic with a single attempt to write out configuration. Notification callbacks shall not change configuration because this can lead to a longer chain of unwanted modifications. That might not be true, however, if a programmer of the whole system knows that a chain of reactions will terminate. When doing such event-\/driven programming, care is needed to avoid infinite loops. Elektra guarantees consistency of the key database even in such cases. 