Debian Codegraph @

docs/api/spec/pk-backend-spawn.xml

raw
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
3
4 <chapter id="backend-spawn">
5 <title>Spawned Backends</title>
6 <sect1 id="backends-spawn-intro">
7 <title>Introduction</title>
8 <para>
9 If you do not have a C or C++ language binding, PackageKit executes
10 helper scripts written in pretty much any language.
11 It then watches the standard out and standard error and parses the
12 output into compiled backend commands.
13 This means a python library can be interfaced easily with a C backend.
14 </para>
15 <para>
16 Even when using helpers, a compiled backend stub is still used for
17 two reasons:
18 </para>
19 <itemizedlist>
20 <listitem>
21 <para>
22 It is still needed for the dlopen internally in PackageKit.
23 </para>
24 </listitem>
25 <listitem>
26 <para>
27 You can add cleverness in the C backend that you might not want to
28 do in the scripted backend, for example using a hash table in C
29 rather than checking all the names in awk.
30 </para>
31 </listitem>
32 </itemizedlist>
33 <para>
34 Backends are typically open-programmable, which means we can define a
35 standard for what goes on stdin and stdout to try and maximise
36 the common code between the backends.
37 </para>
38 <para>
39 If you are unable to write scripts that conform to these specifications
40 then just launch a PkSpawn object in the compiled helper with stdout
41 callbacks and then try to do screenscraping in the backend.
42 </para>
43 <para>
44 Backends scripts are run with arguments and data is sent to standard out
45 and standard error asynchronously so that PackageKit can proxy this to D-Bus.
46 A method has command line arguments separated with tabs, and data is also
47 separated with tabs.
48 </para>
49 <para>
50 It is important to flush the standard output after each output, else
51 Linux will helpfully buffer the output into more efficient size chunks.
52 If you do not flush, then there will be a long IPC delay.
53 Flushing can be achieved in C using <literal>fflush</literal> or in python
54 using <literal>sys.stdout.flush()</literal>.
55 </para>
56 <para>
57 The "dispatcher" mode is where a command is used to startup the
58 backend, for instance <literal>yumBackend.py search-name none power</literal>
59 and then the backend then sits and waits for more standard input.
60 Further operations can be done on the loaded backend sending commands
61 to stdin, e.g. <literal>search-name none power</literal>.
62 If there are no more operations after a preset time (default 5 seconds)
63 then the backend is sent <literal>exit</literal> over stdin, and the
64 backend terminates.
65 The daemon will ensure the operations are serialised, and that backends
66 not sending <literal>finished</literal> are cleaned up properly.
67 </para>
68 <para>
69 The dispatcher mode does not have to implemented in python; any
70 language that can read from stdin can block and be used in this way.
71 </para>
72 </sect1>
73
74 </chapter>