#pragma once

#include <memory>
#include <unordered_map>
#include <thread>
#include <vector>
#include <functional>

class RenderTarget;
namespace egl { class Context; }
namespace aidl::com::omixlab::mosis { class IMosisListener; }
namespace aidl::android::hardware { struct HardwareBuffer; }
namespace Rml { class Context; }

class Kernel
{
    std::unique_ptr<egl::Context> m_egl_context;
    std::unique_ptr<RenderTarget> m_render_target;
    std::unordered_map<pid_t, std::shared_ptr<aidl::com::omixlab::mosis::IMosisListener>> m_listeners;
    std::unique_ptr<aidl::android::hardware::HardwareBuffer> m_aidl_buffer;
    std::vector<std::function<void(Rml::Context*)>> m_tasks;
    std::mutex m_mutex;
    std::thread m_main_loop_thread;
    void main_loop();
public:
    explicit Kernel(const std::shared_ptr<aidl::com::omixlab::mosis::IMosisListener>& listener);
    virtual ~Kernel();
    void add_listener(const std::shared_ptr<aidl::com::omixlab::mosis::IMosisListener>& listener);
    void on_touch_down(float x, float y);
    void on_touch_move(float x, float y);
    void on_touch_up(float x, float y);
};
