summaryrefslogtreecommitdiffstats
path: root/main.cpp
blob: a43e37b55f22ff3e752061931c39ce00e38aae10 (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
81
82
83
84
85
86
87
88
#include <QApplication>
#include <iostream>
#include "MainApp.h"
#include <getopt.h>

#include <libhomescreen.hpp>
#include <qlibwindowmanager.h>


#define DEFAULT_CREDENTIALS_FILE "/etc/poikey"

using namespace std;

QLibWindowmanager* qwm;
LibHomeScreen* hs;
QString graphic_role;
MainApp *mainapp;

void SyncDrawHandler(json_object *object)
{
	qwm->endDraw(graphic_role);
}

void TapShortcutHandler(json_object *object)
{
    qwm->activateWindow(graphic_role);
}

int main(int argc, char *argv[], char *env[])
{
    int opt;
    QApplication a(argc, argv);
    QString credentialsFile(DEFAULT_CREDENTIALS_FILE);
    qwm = new QLibWindowmanager();
    hs = new LibHomeScreen();
	graphic_role = QString("poi");

	QString pt = QString(argv[1]);
	int port = pt.toInt();
	QString secret = QString(argv[2]);
	std::string token = secret.toStdString();

    if (qwm->init(port, secret) != 0) {
        exit(EXIT_FAILURE);
    }

    if (qwm->requestSurface(graphic_role) != 0) {
        cerr << "Error: wm check failed" << endl;
        exit(EXIT_FAILURE);
    }

	qwm->set_event_handler(QLibWindowmanager::Event_SyncDraw, SyncDrawHandler);

    mainapp = new MainApp();

	hs->init(port, token.c_str());

	hs->set_event_handler(LibHomeScreen::Event_TapShortcut, TapShortcutHandler);

    //force setting
    mainapp->setInfoScreen(true);
    mainapp->setKeyboard(true);

    /* check naviapi */
    if (mainapp->CheckNaviApi(argc, argv) == false)
    {
        cerr << "Error: naviapi check failed" << endl;
        return -1;
    }

    /* then, authenticate connexion to POI service: */
    if (mainapp->AuthenticatePOI(credentialsFile) < 0)
    {
        cerr << "Error: POI server authentication failed" << endl;
        return -1;
    }

    cerr << "authentication succes !" << endl;

    /* now, let's start monitor user inut (register callbacks): */
    if (mainapp->StartMonitoringUserInput() < 0)
        return -1;

	qwm->activateWindow(graphic_role);

    /* main loop: */
    return a.exec();
}