~aleteoryx/muditaos

ref: 5c57dff00e811f00a703309fe3ba66d96469247e muditaos/module-services/service-gui/WorkerGUI.cpp -rw-r--r-- 1.6 KiB
5c57dff0 — Piotr Tanski [EGD-4713] Add task control block into a heap allocated memory block for debug purposes. (#1143) 5 years ago
                                                                                
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
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "WorkerGUI.hpp"

#include <DrawCommand.hpp>
#include <log/log.hpp>
#include <MessageType.hpp>
#include <projdefs.h>
#include <queue.h>
#include <Renderer.hpp>
#include <semphr.h>
#include <Service/Bus.hpp>
#include <Service/Message.hpp>
#include <Service/Service.hpp>
#include <Service/Worker.hpp>
#include <service-gui/ServiceGUI.hpp>

#include <memory>
#include <utility>
#include <vector>
#include "messages/RenderingFinished.hpp"

namespace sgui
{

    WorkerGUI::WorkerGUI(ServiceGUI *service) : Worker(service)
    {}

    bool WorkerGUI::handleMessage(uint32_t queueID)
    {
        QueueHandle_t queue = queues[queueID];

        auto serviceGUI = static_cast<sgui::ServiceGUI *>(service);

        if (queueID == 0) {
            sys::WorkerCommand received;
            xQueueReceive(queue, &received, 0);

            std::list<std::unique_ptr<gui::DrawCommand>> uniqueCommands;
            if (xSemaphoreTake(serviceGUI->semCommands, pdMS_TO_TICKS(1000)) == pdTRUE) {
                uniqueCommands = std::move(serviceGUI->commands);
                xSemaphoreGive(serviceGUI->semCommands);
            }
            else {
                LOG_ERROR("Failed to acquire semaphore");
            }

            serviceGUI->renderer.render(serviceGUI->renderContext, uniqueCommands);

            sys::Bus::SendUnicast(std::make_shared<service::gui::RenderingFinished>(), service->GetName(), service);
        }
        return true;
    }

} /* namespace sgui */