aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/managers/EventManager.hpp
blob: 383d324674d151636e2d8b96e8ddde07bf3da043 (plain)
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
#pragma once
#include <deque>
#include <vector>

#include "../defines.hpp"
#include "../helpers/memory/Memory.hpp"

struct SHyprIPCEvent {
    std::string event;
    std::string data;
};

class CEventManager {
  public:
    CEventManager();
    ~CEventManager();

    void postEvent(const SHyprIPCEvent& event);

  private:
    std::string formatEvent(const SHyprIPCEvent& event) const;

    static int  onServerEvent(int fd, uint32_t mask, void* data);
    static int  onClientEvent(int fd, uint32_t mask, void* data);

    int         onServerEvent(int fd, uint32_t mask);
    int         onClientEvent(int fd, uint32_t mask);

    struct SClient {
        int                         fd = -1;
        std::deque<SP<std::string>> events;
        wl_event_source*            eventSource = nullptr;
    };

    std::vector<SClient>::iterator findClientByFD(int fd);
    std::vector<SClient>::iterator removeClientByFD(int fd);

  private:
    int                  m_iSocketFD    = -1;
    wl_event_source*     m_pEventSource = nullptr;

    std::vector<SClient> m_vClients;
};

inline std::unique_ptr<CEventManager> g_pEventManager;