-
Notifications
You must be signed in to change notification settings - Fork 6
/
ti-apps-launcher.cpp
100 lines (88 loc) · 3.21 KB
/
ti-apps-launcher.cpp
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
89
90
91
92
93
94
95
96
97
98
99
100
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QCameraInfo>
#include <QStringListModel>
#include <QNetworkInterface>
#include <csignal>
#include <thread>
#include <unistd.h>
#include <sys/stat.h>
#include "backend/includes/common.h"
#include "backend/includes/appsmenu.h"
#include "backend/includes/topbar.h"
#include "backend/includes/deviceinfo.h"
#include "backend/includes/stats.h"
QStringListModel modelNamesList;
//objects
stats statsbackend;
apps_menu appsmenu;
power_menu powermenu;
Device_info deviceinfo;
/*
__attribute__((weak)) void platform_setup(QQmlApplicationEngine *engine) {
std::cout << "No platform setup needed!" << endl;
}
*/
void sigHandler(int s)
{
std::signal(s, SIG_DFL);
qApp->quit();
}
void GetIpAddr()
{
// Fetch IP Addr of the target to display at the bottom of the application
for(int i = 0; i < 10; i++) {
foreach (const QNetworkInterface &netInterface, QNetworkInterface::allInterfaces()) {
QNetworkInterface::InterfaceFlags flags = netInterface.flags();
if( (bool)(flags & QNetworkInterface::IsRunning) && !(bool)(flags & QNetworkInterface::IsLoopBack)){
foreach (const QNetworkAddressEntry &address, netInterface.addressEntries()) {
if(address.ip().protocol() == QAbstractSocket::IPv4Protocol) {
deviceinfo.set_ip_addr("IP Addr: " + address.ip().toString());
emit deviceinfo.ip_addr_changed();
return;
}
}
}
}
sleep(10);
}
return;
}
int main(int argc, char *argv[]) {
// cout << PLATFORM << endl;
QApplication app(argc, argv);
QStringList modelslist = modelNamesList.stringList();
fstream modelsfile;
struct stat sb;
thread getIpAddrThread(GetIpAddr);
getIpAddrThread.detach();
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
std::signal(SIGINT, sigHandler);
std::signal(SIGTERM, sigHandler);
QQmlApplicationEngine engine;
// Get and Populate contents of /opt/oob-demo-assets/allowedModels.txt to modelNamesList
// Add the model to list only if it's available in the filesystem
modelsfile.open("/opt/oob-demo-assets/allowedModels.txt",ios::in);
if (modelsfile.is_open()) {
string model;
while(getline(modelsfile, model)) {
string dir = "/opt/model_zoo/";
if (stat((dir + model).c_str(), &sb) == 0)
modelslist.append(QString::fromStdString(model));
}
modelsfile.close();
}
modelNamesList.setStringList(modelslist);
// set context properties to access in QML
engine.rootContext()->setContextProperty("modelNamesList", &modelNamesList);
engine.rootContext()->setContextProperty("appsmenu", &appsmenu);
engine.rootContext()->setContextProperty("powermenu", &powermenu);
engine.rootContext()->setContextProperty("deviceinfo", &deviceinfo);
engine.rootContext()->setContextProperty("statsbackend", &statsbackend);
platform_setup(&engine);
engine.load(QUrl(QStringLiteral("qrc:/ti-apps-launcher.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}