Add pws to be able to start apps
[apps/onscreenapp.git] / pws / launcher.h
1 /*
2  * Copyright (c) 2020 Collabora Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef LAUNCHER_H
18 #define LAUNCHER_H
19
20 #include <QObject>
21 #include <QString>
22 #include <QScreen>
23 #include <QWindow>
24 #include <QHash>
25
26 #include <memory>
27
28 #include "pws.h"
29
30 class Launcher : public QObject
31 {
32         Q_OBJECT
33
34 public:
35         Launcher(const QString &sock_name, QObject *parent = nullptr) :
36                 QObject(parent), afm_sock_name(sock_name)
37         {
38                 pws = nullptr;
39                 connection_set = false;
40         }
41
42         ~Launcher()
43         {
44                 destroy();
45         }
46
47         // call this before to any start-up
48         int setup_pws_connection(void);
49         bool connection_is_set(void);
50
51 public slots:
52         int start(const QString &app);
53         bool terminate(const QString &app);
54         bool is_running(const QString &app);
55         size_t get_list_runnables(QString *data);
56
57 private:
58         struct pws_data_source *pws;
59         bool connection_set;
60         QString afm_sock_name;
61
62         QHash<QString, int> applications; // stores the apps started
63
64         void destroy(void)
65         {
66                 pws_data_source_destroy(pws);
67         }
68 };
69
70 #endif // LAUNCHER_H