X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=homescreen%2Fsrc%2Fmain.cpp;h=a98a15bb0113f3b28c1766e79c5d3f2d0b20fac4;hb=HEAD;hp=b004fd59d130a379801f9829509f94a5438df6a4;hpb=36e2c9697e431414ae0263635f3ebf1f3c200723;p=apps%2Fhomescreen.git diff --git a/homescreen/src/main.cpp b/homescreen/src/main.cpp index b004fd5..a98a15b 100644 --- a/homescreen/src/main.cpp +++ b/homescreen/src/main.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -31,7 +32,6 @@ #include #include "agl-shell-client-protocol.h" -#include "shell.h" #include #include "AglShellGrpcClient.h" @@ -87,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 @@ -143,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"); } } @@ -335,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(); @@ -352,31 +338,53 @@ 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 -run_in_thread(GrpcClient *client) +app_status_callback(::agl_shell_ipc::AppStateResponse app_response, void *data) { - grpc::Status status = client->Wait(); -} + HomescreenHandler *homescreenHandler = static_cast(data); -static void -app_status_callback(::agl_shell_ipc::AppStateResponse app_response) -{ - std::cout << " >> AppStateResponse app_id " << - app_response.app_id() << ", with state " << - app_response.state() << std::endl; + 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[]) @@ -410,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. " @@ -442,14 +454,14 @@ int main(int argc, char *argv[]) ApplicationLauncher *launcher = new ApplicationLauncher(); launcher->setCurrent(QStringLiteral("launcher")); - GrpcClient *client = new GrpcClient(); - - // create a new thread to listner for gRPC events - std::thread th = std::thread(run_in_thread, client); - client->AppStatusState(app_status_callback); - - HomescreenHandler* homescreenHandler = new HomescreenHandler(launcher, client); + 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(); @@ -459,7 +471,7 @@ int main(int argc, char *argv[]) context->setContextProperty("weather", new Weather()); context->setContextProperty("bluetooth", new Bluetooth(false, context)); - 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();