2023-07-18 15:30:28 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../defines.hpp"
|
|
|
|
|
2024-04-19 23:16:35 +02:00
|
|
|
#include <functional>
|
|
|
|
|
2023-08-21 19:36:09 +02:00
|
|
|
#define RESOURCE_OR_BAIL(resname) \
|
|
|
|
const auto resname = (CWaylandResource*)wl_resource_get_user_data(resource); \
|
|
|
|
if (!resname) \
|
|
|
|
return;
|
|
|
|
|
2024-04-19 23:16:35 +02:00
|
|
|
#define PROTO NProtocols
|
|
|
|
|
2024-08-15 18:16:18 +02:00
|
|
|
#define EXTRACT_CLASS_NAME() \
|
|
|
|
[]() constexpr -> std::string_view { \
|
|
|
|
constexpr std::string_view prettyFunction = __PRETTY_FUNCTION__; \
|
|
|
|
constexpr size_t colons = prettyFunction.find("::"); \
|
|
|
|
if (colons != std::string_view::npos) { \
|
|
|
|
constexpr size_t begin = prettyFunction.substr(0, colons).rfind(' ') + 1; \
|
|
|
|
constexpr size_t end = colons - begin; \
|
|
|
|
return prettyFunction.substr(begin, end); \
|
|
|
|
} else { \
|
|
|
|
return "Global"; \
|
|
|
|
} \
|
|
|
|
}()
|
|
|
|
|
|
|
|
#define LOGM(level, ...) \
|
|
|
|
do { \
|
|
|
|
std::ostringstream oss; \
|
|
|
|
if (level == WARN || level == ERR || level == CRIT) { \
|
|
|
|
oss << "[" << __FILE__ << ":" << __LINE__ << "] "; \
|
|
|
|
} else if (level == LOG || level == INFO || level == TRACE) { \
|
|
|
|
oss << "[" << EXTRACT_CLASS_NAME() << "] "; \
|
|
|
|
} \
|
2024-08-18 22:54:47 +02:00
|
|
|
if constexpr (std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value == 1 && std::is_same_v<decltype(__VA_ARGS__), std::string>) { \
|
2024-08-15 18:16:18 +02:00
|
|
|
oss << __VA_ARGS__; \
|
|
|
|
Debug::log(level, oss.str()); \
|
|
|
|
} else { \
|
|
|
|
Debug::log(level, std::format("{}{}", oss.str(), std::format(__VA_ARGS__))); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2024-07-29 19:19:47 +02:00
|
|
|
class IWaylandProtocol;
|
|
|
|
struct IWaylandProtocolDestroyWrapper {
|
|
|
|
wl_listener listener;
|
|
|
|
IWaylandProtocol* parent = nullptr;
|
|
|
|
};
|
|
|
|
|
2023-08-07 13:35:19 +02:00
|
|
|
class IWaylandProtocol {
|
2023-07-18 15:30:28 +02:00
|
|
|
public:
|
|
|
|
IWaylandProtocol(const wl_interface* iface, const int& ver, const std::string& name);
|
2024-06-08 10:07:59 +02:00
|
|
|
virtual ~IWaylandProtocol();
|
2023-07-18 15:30:28 +02:00
|
|
|
|
2024-08-15 18:16:18 +02:00
|
|
|
virtual void onDisplayDestroy();
|
|
|
|
virtual void removeGlobal();
|
2023-07-18 15:30:28 +02:00
|
|
|
|
2024-08-15 18:16:18 +02:00
|
|
|
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) = 0;
|
2024-04-22 19:44:25 +02:00
|
|
|
|
2024-07-29 19:19:47 +02:00
|
|
|
IWaylandProtocolDestroyWrapper m_liDisplayDestroy;
|
2024-07-24 19:07:36 +02:00
|
|
|
|
2023-07-18 15:30:28 +02:00
|
|
|
private:
|
2024-04-22 19:44:25 +02:00
|
|
|
std::string m_szName;
|
2023-07-18 15:30:28 +02:00
|
|
|
wl_global* m_pGlobal = nullptr;
|
2024-07-24 19:07:36 +02:00
|
|
|
};
|