aboutsummaryrefslogtreecommitdiffstats
path: root/launcher/src/appfwhandler.h
blob: 25a401b753c9fbf93831ee9b31babea1579684b3 (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
/*
 * Copyright (c) 2018 TOYOTA MOTOR CORPORATION
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef APPFWHANDLER_H
#define APPFWHANDLER_H

#include <QObject>
#include <QString>
#include <QTimer>
#include <json-c/json.h>
#include <systemd/sd-event.h>
extern "C" {
#include <afb/afb-proto-ws.h>
#include <afb/afb-ws-client.h>
}

class AppFwHandler : public QObject
{
    Q_OBJECT
public:
    AppFwHandler(const char* appname, QObject *parent = nullptr);
    AppFwHandler(AppFwHandler&) = delete;
    AppFwHandler &operator=(AppFwHandler&) = delete;
    ~AppFwHandler() = default;

    int init(void);
    int runnables(void);
    int detail(QString id);
    void on_pws_hangup(void);
    void registerCallback(
        /* can't be NULL */
        void (*on_reply_cb)(void *closure, void *request, struct json_object *obj, const char *error, const char *info),

        /* can be NULL */
        void (*on_event_create_cb)(void *closure, const char *event_name, int event_id) = nullptr,
        void (*on_event_remove_cb)(void *closure, const char *event_name, int event_id) = nullptr,
        void (*on_event_subscribe_cb)(void *closure, void *request, const char *event_name, int event_id) = nullptr,
        void (*on_event_unsubscribe_cb)(void *closure, void *request, const char *event_name, int event_id) = nullptr,
        void (*on_event_push_cb)(void *closure, const char *event_name, int event_id, struct json_object *data) = nullptr,
        void (*on_event_broadcast_cb)(void *closure, const char *event_name, struct json_object *data) = nullptr);

    static AppFwHandler* myself;
signals:
    void applistupdate(QStringList info);

private slots:
    void connect_pws_timer_slot(void);

private:
    int try_connect_pws(void);
    void attempt_connect_pws(int count);
    int call(const char *verb, const char *object);

    QString m_api = "afm-main";
    QString m_uri;
    QString m_sessionid;
    sd_event *m_evloop = nullptr;
    afb_proto_ws *m_pws = nullptr;
    QTimer* m_time;
    int m_retry = 0;
};

#endif // APPFWHANDLER_H