summaryrefslogtreecommitdiffstats
path: root/examples/applicationmanager/custom-appman/doc/src/custom-appman.qdoc
blob: fffb5c473963c3ea6709847e85bed0c2955b80c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (C) 2021 The Qt Company Ltd.
// Copyright (C) 2019 Luxoft Sweden AB
// Copyright (C) 2018 Pelagicore AG
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!

\example applicationmanager/custom-appman
\title Implement a Custom Application Manager Example
\image custom-appman.png Screenshot
\brief Provides the basic structure and starting point for a custom application manager executable.
\ingroup applicationmanager-examples

\note Please \l{wayland-dev-packages}{read this} if you want to build the example on a Linux machine.

\section1 Introduction

The application manager is compiled as a self-contained executable that can be configured in large
parts through the YAML-based config file system and startup plugins. However, if you need to have
more control over the application's startup behavior, it may be necessary to implement a custom
application manager executable.

\note Currently, all C++ classes in the application manager modules are considered private API, so
there are no compatibility guarantees at all.

If you still require this behavior, this example provides a starting point that you can build your
custom implementation upon. Keep in mind, that this custom application manager executable needs a
System UI to display something on the screen, just like the standard \c appman executable.

Linking against those application manager modules is prohibited by default to prevent
potential problems with duplicate symbols coming from QML plugins. However here building against
them is both intended and required, so we need to set the define \c AM_COMPILING_APPMAN:

\quotefromfile applicationmanager/custom-appman/CMakeLists.txt
\skipuntil /allows us to link against/
\printuntil /AM_COMPILING_APPMAN/

The following is a breakdown of the minimal code necessary:

\quotefromfile applicationmanager/custom-appman/custom-appman.cpp
\skipto #include <QtAppManMain/main.h>
\printuntil QT_USE_NAMESPACE_AM

The application manager is split into functional building blocks. These include statements
pull in the basic set of classes that you need. To avoid possible clashes with QML plugins, all of
the application manager's symbols are namespaced - \c QT_USE_NAMESPACE_AM expands to the equivalent
\c using statement.

\skipto QCoreApplication::setApplicationName
\printuntil QCoreApplication::setApplicationVersion

Generally, it's a good idea to set an application name and version.

\printuntil a = std::make_unique<Main>

This \c try block is the heart of the custom application manager. You need to create a \c Main
object, which is a class derived from QGuiApplication (or QApplication, if widgets support is
enabled). In this case, we are supplying two init flags to the Main constructor:

The first init flag, \c ForkSudoServer, is useful for the installer part of the application
manager: if the executable is setuid-root, this will implicitly fork off a child process, which
does keep the root privileges while the main process permanently drops them.

The second init flag, \c InitializeLogging, sets up the application manager's logging part
implicitly for us (this is especially useful when dealing with DLT logging).

Both parts could be initialized explicitly as well, but this is not needed in most cases.

\printuntil return 2
\printline }

The application manager needs a suitable configuration object. In this case, we use the
application manager's default YAML parsing, so we instantiate a \c Configuration object. The rest
of the function involves parsing the configuration and then calling the relevant setup routines on
the \c Main object.

Most functions in the application manager throw exceptions that are derived from \c std::exception,
so a \c catch handler is compulsory.

*/