X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=homescreen%2Fsrc%2Fmain.cpp;h=a98a15bb0113f3b28c1766e79c5d3f2d0b20fac4;hb=HEAD;hp=d0bd2c3db59df68e1e4c0381755f7e1144b806ef;hpb=c9ae3bc5a102caad6d8040cd268a64295654e162;p=apps%2Fhomescreen.git diff --git a/homescreen/src/main.cpp b/homescreen/src/main.cpp index d0bd2c3..a98a15b 100644 --- a/homescreen/src/main.cpp +++ b/homescreen/src/main.cpp @@ -3,6 +3,7 @@ * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH * Copyright (c) 2017, 2018 TOYOTA MOTOR CORPORATION * Copyright (c) 2022 Konsulko Group + * Copyright (c) 2023 Collabora, Ltd. */ #include @@ -15,6 +16,7 @@ #include #include #include +#include #include #include @@ -30,7 +32,9 @@ #include #include "agl-shell-client-protocol.h" -#include "shell.h" + +#include +#include "AglShellGrpcClient.h" #ifndef MIN #define MIN(a, b) (((a) < (b)) ? (a) : (b)) @@ -83,32 +87,7 @@ static void agl_shell_app_state(void *data, struct agl_shell *agl_shell, const char *app_id, uint32_t state) { - struct shell_data *shell_data = static_cast(data); - HomescreenHandler *homescreenHandler = shell_data->homescreenHandler; - - if (!homescreenHandler) - return; - - switch (state) { - case AGL_SHELL_APP_STATE_STARTED: - qDebug() << "Got AGL_SHELL_APP_STATE_STARTED for app_id " << app_id; - homescreenHandler->processAppStatusEvent(app_id, "started"); - break; - case AGL_SHELL_APP_STATE_TERMINATED: - qDebug() << "Got AGL_SHELL_APP_STATE_TERMINATED for app_id " << app_id; - // handled by HomescreenHandler::processAppStatusEvent - break; - case AGL_SHELL_APP_STATE_ACTIVATED: - qDebug() << "Got AGL_SHELL_APP_STATE_ACTIVATED for app_id " << app_id; - homescreenHandler->addAppToStack(app_id); - break; - case AGL_SHELL_APP_STATE_DEACTIVATED: - qDebug() << "Got AGL_SHELL_APP_STATE_DEACTIVATED for app_id " << app_id; - homescreenHandler->processAppStatusEvent(app_id, "deactivated"); - break; - default: - break; - } + /* unused */ } static void @@ -139,8 +118,9 @@ agl_shell_app_on_output(void *data, struct agl_shell *agl_shell, homescreenHandler->pending_app_list.push_back(new_pending_app); if (homescreenHandler->apps_stack.contains(QString(app_id))) { - qDebug() << "Gove event to move " << app_id << + qDebug() << "Got event to move " << app_id << " to another output " << output_name; + homescreenHandler->processAppStatusEvent(app_id, "started"); } } @@ -331,11 +311,21 @@ load_agl_shell_for_ci(QPlatformNativeInterface *native, qDebug() << "CI mode - with multiple surfaces"; } +static void +app_status_callback(::agl_shell_ipc::AppStateResponse app_response, void *data); + +static void +run_in_thread(GrpcClient *client) +{ + grpc::Status status = client->Wait(); +} + static void load_agl_shell_app(QPlatformNativeInterface *native, QQmlApplicationEngine *engine, - struct agl_shell *agl_shell, const char *screen_name, bool is_demo) + struct shell_data shell_data, const char *screen_name, bool is_demo) { QScreen *screen = nullptr; + HomescreenHandler *homescreenHandler = shell_data.homescreenHandler; if (!screen_name) screen = qApp->primaryScreen(); @@ -348,19 +338,55 @@ load_agl_shell_app(QPlatformNativeInterface *native, QQmlApplicationEngine *engi } if (is_demo) { - load_agl_shell_for_ci(native, engine, agl_shell, screen); + load_agl_shell_for_ci(native, engine, shell_data.shell, screen); } else { - load_agl_shell(native, engine, agl_shell, screen); + load_agl_shell(native, engine, shell_data.shell, screen); } /* Delay the ready signal until after Qt has done all of its own setup * in a.exec() */ - QTimer::singleShot(500, [agl_shell](){ + QTimer::singleShot(500, [shell_data](){ qDebug() << "sending ready to compositor"; - agl_shell_ready(agl_shell); + agl_shell_ready(shell_data.shell); }); } +static void +app_status_callback(::agl_shell_ipc::AppStateResponse app_response, void *data) +{ + HomescreenHandler *homescreenHandler = static_cast(data); + + if (!homescreenHandler) { + return; + } + + auto app_id = QString(app_response.app_id().c_str()); + auto state = app_response.state(); + + qDebug() << "appstateresponse: app_id " << app_id << "state " << state; + + switch (state) { + case AGL_SHELL_APP_STATE_STARTED: + qDebug() << "Got AGL_SHELL_APP_STATE_STARTED for app_id " << app_id; + homescreenHandler->processAppStatusEvent(app_id, "started"); + break; + case AGL_SHELL_APP_STATE_TERMINATED: + qDebug() << "Got AGL_SHELL_APP_STATE_TERMINATED for app_id " << app_id; + homescreenHandler->processAppStatusEvent(app_id, "terminated"); + break; + case AGL_SHELL_APP_STATE_ACTIVATED: + qDebug() << "Got AGL_SHELL_APP_STATE_ACTIVATED for app_id " << app_id; + homescreenHandler->addAppToStack(app_id); + break; + case AGL_SHELL_APP_STATE_DEACTIVATED: + qDebug() << "Got AGL_SHELL_APP_STATE_DEACTIVATED for app_id " << app_id; + homescreenHandler->processAppStatusEvent(app_id, "deactivated"); + break; + default: + break; + } +} + int main(int argc, char *argv[]) { setenv("QT_QPA_PLATFORM", "wayland", 1); @@ -392,6 +418,10 @@ int main(int argc, char *argv[]) // we need to have an app_id app.setDesktopFileName("homescreen"); + GrpcClient *client = new GrpcClient(); + // create a new thread to listner for gRPC events + std::thread th = std::thread(run_in_thread, client); + register_agl_shell(native, &shell_data); if (!shell_data.shell) { fprintf(stderr, "agl_shell extension is not advertised. " @@ -416,7 +446,6 @@ int main(int argc, char *argv[]) std::shared_ptr agl_shell{shell_data.shell, agl_shell_destroy}; - Shell *aglShell = new Shell(agl_shell, &app); // Import C++ class to QML qmlRegisterType("HomeScreen", 1, 0, "StatusBarModel"); @@ -425,8 +454,14 @@ int main(int argc, char *argv[]) ApplicationLauncher *launcher = new ApplicationLauncher(); launcher->setCurrent(QStringLiteral("launcher")); - HomescreenHandler* homescreenHandler = new HomescreenHandler(aglShell, launcher); + HomescreenHandler* homescreenHandler = new HomescreenHandler(launcher); shell_data.homescreenHandler = homescreenHandler; + shell_data.homescreenHandler->setGrpcClient(client); + + // blocks until we're sure connected with the server + HMI_DEBUG("HomescreenHandler", "Checking if connected to the gRPC server..."); + client->WaitForConnected(500, 10); + client->AppStatusState(app_status_callback, homescreenHandler); QQmlApplicationEngine engine; QQmlContext *context = engine.rootContext(); @@ -436,10 +471,7 @@ int main(int argc, char *argv[]) context->setContextProperty("weather", new Weather()); context->setContextProperty("bluetooth", new Bluetooth(false, context)); - // We add it here even if we don't use it - context->setContextProperty("shell", aglShell); - - load_agl_shell_app(native, &engine, shell_data.shell, + load_agl_shell_app(native, &engine, shell_data, screen_name, is_demo_val); return app.exec();