Add pws to be able to start apps
[apps/onscreenapp.git] / pws / pws.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 PWS_HEADER_H
18 #define PWS_HEADER_H
19
20 #include <systemd/sd-event.h>
21
22 /* linker will complain it can't find them and given they're only for C */
23 extern "C" {
24 #include "afb/afb-ws-client.h"
25 #include "afb/afb-proto-ws.h"
26 }
27
28 #define TIMEOUT_SD_LOOP 30000000
29
30 struct pws_data_source_json_reply;
31
32 struct pws_data_source {
33         struct sd_event *loop;
34         struct afb_proto_ws *pws;
35         int callcount;
36         int num_id;     /* key id */
37
38         struct json_object *reply;
39         bool reply_valid;
40 };
41
42 void
43 pws_data_source_reply_destroy(struct pws_data_source *pws);
44
45 /* inits a connection to connect_to
46  *
47  */
48 struct pws_data_source *
49 pws_data_source_init(const char *connect_to);
50
51 /* destroys connection init'ed by pws_data_source_init
52  */
53 void
54 pws_data_source_destroy(struct pws_data_source *pws);
55
56
57 /*
58  * starts the app by @afm_name
59  *
60  * returns 0 in case of success, negative in case of failure
61  *
62  */
63 int
64 pws_start_process(struct pws_data_source *pws, const char *afm_name);
65
66 /*
67  * terminates the app by @afm_name
68  *
69  * returns true case of success, false in case of failure
70  */
71 bool
72 pws_stop_process(struct pws_data_source *pws, const char *afm_name);
73
74 /* returns pid or -1 in case the @afm_name is not running
75  *
76  */
77 int
78 pws_check_process_is_running(struct pws_data_source *pws, const char *afm_name);
79
80 /* returns #no of (current) active, running applications
81  *
82  * (prints) as well
83  */
84 size_t
85 pws_list_runners(struct pws_data_source *pws);
86
87 /* returns #no of (all) applications
88  *
89  * (prints) as well
90  */
91 size_t
92 pws_list_runnables(struct pws_data_source *pws);
93
94 /*
95  */
96 size_t
97 pws_get_list_runnables(struct pws_data_source *pws, struct json_object **json_obj);
98
99 #endif