protocols: refactor protocol logging to a macro (#7324)

this avoids the usage of the unique_ptr PROTO::protocol before it has
been constructed incase one wants to log something inside the
constructor itself, move the logging to macros and print file:linenumber
on ERR,CRIT,WARN and classname on the rest of the levels.
This commit is contained in:
Tom Englund 2024-08-15 18:16:18 +02:00 committed by GitHub
parent 15f942000e
commit 12d9901472
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
45 changed files with 42 additions and 104 deletions

View file

@ -4,8 +4,6 @@
#include "../render/Renderer.hpp"
#include "core/Compositor.hpp"
#define LOGM PROTO::alphaModifier->protoLog
CAlphaModifier::CAlphaModifier(SP<CWpAlphaModifierSurfaceV1> resource_, SP<CWLSurfaceResource> surface_) : resource(resource_), pSurface(surface_) {
if (!resource->resource())
return;

View file

@ -2,8 +2,6 @@
#include <algorithm>
#include "../helpers/CursorShapes.hpp"
#define LOGM PROTO::cursorShape->protoLog
CCursorShapeProtocol::CCursorShapeProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
;
}

View file

@ -4,8 +4,6 @@
#include <aquamarine/backend/DRM.hpp>
#include <fcntl.h>
#define LOGM PROTO::lease->protoLog
CDRMLeaseResource::CDRMLeaseResource(SP<CWpDrmLeaseV1> resource_, SP<CDRMLeaseRequestResource> request) : resource(resource_) {
if (!good())
return;
@ -226,7 +224,7 @@ CDRMLeaseDevice::CDRMLeaseDevice(SP<Aquamarine::CDRMBackend> drmBackend) : backe
auto fd = drm->getNonMasterFD();
if (fd < 0) {
Debug::log(ERR, "[DRMLease] Failed to dup fd for drm node {}", drm->gpuName);
LOGM(ERR, "Failed to dup fd for drm node {}", drm->gpuName);
return;
}

View file

@ -7,8 +7,6 @@
#include <fcntl.h>
#define LOGM PROTO::sync->protoLog
CDRMSyncobjSurfaceResource::CDRMSyncobjSurfaceResource(SP<CWpLinuxDrmSyncobjSurfaceV1> resource_, SP<CWLSurfaceResource> surface_) : surface(surface_), resource(resource_) {
if (!good())
return;

View file

@ -3,8 +3,6 @@
#include "../managers/SeatManager.hpp"
#include "core/Seat.hpp"
#define LOGM PROTO::dataWlr->protoLog
CWLRDataOffer::CWLRDataOffer(SP<CZwlrDataControlOfferV1> resource_, SP<IDataSource> source_) : source(source_), resource(resource_) {
if (!good())
return;

View file

@ -8,8 +8,6 @@
#include <memory>
#include <wayland-server.h>
#define LOGM PROTO::focusGrab->protoLog
CFocusGrabSurfaceState::CFocusGrabSurfaceState(CFocusGrab* grab, SP<CWLSurfaceResource> surface) {
listeners.destroy = surface->events.destroy.registerListener([=](std::any d) { grab->eraseSurface(surface); });
}

View file

@ -1,8 +1,6 @@
#include "ForeignToplevel.hpp"
#include "../Compositor.hpp"
#define LOGM PROTO::foreignToplevel->protoLog
CForeignToplevelHandle::CForeignToplevelHandle(SP<CExtForeignToplevelHandleV1> resource_, PHLWINDOW pWindow_) : resource(resource_), pWindow(pWindow_) {
if (!resource_->resource())
return;

View file

@ -4,8 +4,6 @@
#include "protocols/core/Output.hpp"
#include "render/Renderer.hpp"
#define LOGM PROTO::foreignToplevelWlr->protoLog
CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHandleV1> resource_, PHLWINDOW pWindow_) : resource(resource_), pWindow(pWindow_) {
if (!resource_->resource())
return;

View file

@ -2,8 +2,6 @@
#include <algorithm>
#include "core/Compositor.hpp"
#define LOGM PROTO::fractional->protoLog
CFractionalScaleProtocol::CFractionalScaleProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
;
}

View file

@ -5,8 +5,6 @@
#include "../Compositor.hpp"
#include "../protocols/core/Output.hpp"
#define LOGM PROTO::gamma->protoLog
CGammaControl::CGammaControl(SP<CZwlrGammaControlV1> resource_, wl_resource* output) : resource(resource_) {
if (!resource_->resource())
return;

View file

@ -1,8 +1,6 @@
#include "GlobalShortcuts.hpp"
#include "../Compositor.hpp"
#define LOGM PROTO::globalShortcuts->protoLog
CShortcutClient::CShortcutClient(SP<CHyprlandGlobalShortcutsManagerV1> resource_) : resource(resource_) {
if (!good())
return;

View file

@ -1,8 +1,6 @@
#include "IdleNotify.hpp"
#include "../managers/eventLoop/EventLoopManager.hpp"
#define LOGM PROTO::idle->protoLog
static int onTimer(SP<CEventLoopTimer> self, void* data) {
const auto NOTIF = (CExtIdleNotification*)data;

View file

@ -6,8 +6,6 @@
#include "core/Compositor.hpp"
#include <cstring>
#define LOGM PROTO::ime->protoLog
CInputMethodKeyboardGrabV2::CInputMethodKeyboardGrabV2(SP<CZwpInputMethodKeyboardGrabV2> resource_, SP<CInputMethodV2> owner_) : resource(resource_), owner(owner_) {
if (!resource->resource())
return;

View file

@ -4,8 +4,6 @@
#include "core/Compositor.hpp"
#include "core/Output.hpp"
#define LOGM PROTO::layerShell->protoLog
void CLayerShellResource::SState::reset() {
anchor = 0;
exclusive = 0;

View file

@ -14,8 +14,6 @@
#include "../render/OpenGL.hpp"
#include "../Compositor.hpp"
#define LOGM PROTO::linuxDma->protoLog
static std::optional<dev_t> devIDFromFD(int fd) {
struct stat stat;
if (fstat(fd, &stat) != 0)
@ -425,7 +423,7 @@ CLinuxDMABufV1Protocol::CLinuxDMABufV1Protocol(const wl_interface* iface, const
auto dev = devIDFromFD(rendererFD);
if (!dev.has_value()) {
protoLog(ERR, "failed to get drm dev, disabling linux dmabuf");
LOGM(ERR, "failed to get drm dev, disabling linux dmabuf");
removeGlobal();
return;
}
@ -477,7 +475,7 @@ CLinuxDMABufV1Protocol::CLinuxDMABufV1Protocol(const wl_interface* iface, const
drmDevice* device = nullptr;
if (drmGetDeviceFromDevId(mainDevice, 0, &device) != 0) {
protoLog(ERR, "failed to get drm dev, disabling linux dmabuf");
LOGM(ERR, "failed to get drm dev, disabling linux dmabuf");
removeGlobal();
return;
}
@ -487,12 +485,12 @@ CLinuxDMABufV1Protocol::CLinuxDMABufV1Protocol(const wl_interface* iface, const
mainDeviceFD = open(name, O_RDWR | O_CLOEXEC);
drmFreeDevice(&device);
if (mainDeviceFD < 0) {
protoLog(ERR, "failed to open drm dev, disabling linux dmabuf");
LOGM(ERR, "failed to open drm dev, disabling linux dmabuf");
removeGlobal();
return;
}
} else {
protoLog(ERR, "DRM device {} has no render node, disabling linux dmabuf", device->nodes[DRM_NODE_PRIMARY] ? device->nodes[DRM_NODE_PRIMARY] : "null");
LOGM(ERR, "DRM device {} has no render node, disabling linux dmabuf", device->nodes[DRM_NODE_PRIMARY] ? device->nodes[DRM_NODE_PRIMARY] : "null");
drmFreeDevice(&device);
removeGlobal();
}

View file

@ -4,8 +4,6 @@
#include "../Compositor.hpp"
#include "types/WLBuffer.hpp"
#define LOGM PROTO::mesaDRM->protoLog
CMesaDRMBufferResource::CMesaDRMBufferResource(uint32_t id, wl_client* client, Aquamarine::SDMABUFAttrs attrs_) {
LOGM(LOG, "Creating a Mesa dmabuf, with id {}: size {}, fmt {}, planes {}", id, attrs_.size, attrs_.format, attrs_.planes);
for (int i = 0; i < attrs_.planes; ++i) {
@ -115,7 +113,7 @@ CMesaDRMProtocol::CMesaDRMProtocol(const wl_interface* iface, const int& ver, co
drmDevice* dev = nullptr;
int drmFD = g_pCompositor->m_iDRMFD;
if (drmGetDevice2(drmFD, 0, &dev) != 0) {
protoLog(ERR, "Failed to get device, disabling MesaDRM");
LOGM(ERR, "Failed to get device, disabling MesaDRM");
removeGlobal();
return;
}
@ -126,13 +124,13 @@ CMesaDRMProtocol::CMesaDRMProtocol(const wl_interface* iface, const int& ver, co
ASSERT(dev->available_nodes & (1 << DRM_NODE_PRIMARY));
if (!dev->nodes[DRM_NODE_PRIMARY]) {
protoLog(ERR, "No DRM render node available, both render and primary are null, disabling MesaDRM");
LOGM(ERR, "No DRM render node available, both render and primary are null, disabling MesaDRM");
drmFreeDevice(&dev);
removeGlobal();
return;
}
protoLog(WARN, "No DRM render node, falling back to primary {}", dev->nodes[DRM_NODE_PRIMARY]);
LOGM(WARN, "No DRM render node, falling back to primary {}", dev->nodes[DRM_NODE_PRIMARY]);
nodeName = dev->nodes[DRM_NODE_PRIMARY];
}
drmFreeDevice(&dev);

View file

@ -4,8 +4,6 @@
using namespace Aquamarine;
#define LOGM PROTO::outputManagement->protoLog
COutputManager::COutputManager(SP<CZwlrOutputManagerV1> resource_) : resource(resource_) {
if (!good())
return;

View file

@ -2,8 +2,6 @@
#include "../Compositor.hpp"
#include "core/Output.hpp"
#define LOGM PROTO::outputPower->protoLog
COutputPower::COutputPower(SP<CZwlrOutputPowerV1> resource_, CMonitor* pMonitor_) : resource(resource_), pMonitor(pMonitor_) {
if (!resource->resource())
return;

View file

@ -5,8 +5,6 @@
#include "../managers/SeatManager.hpp"
#include "core/Compositor.hpp"
#define LOGM PROTO::constraints->protoLog
CPointerConstraint::CPointerConstraint(SP<CZwpLockedPointerV1> resource_, SP<CWLSurfaceResource> surf, wl_resource* region_, zwpPointerConstraintsV1Lifetime lifetime_) :
resourceL(resource_), locked(true), lifetime(lifetime_) {
if (!resource_->resource())

View file

@ -4,8 +4,6 @@
#include "core/Seat.hpp"
#include "core/Compositor.hpp"
#define LOGM PROTO::pointerGestures->protoLog
CPointerGestureSwipe::CPointerGestureSwipe(SP<CZwpPointerGestureSwipeV1> resource_) : resource(resource_) {
if (!resource->resource())
return;

View file

@ -6,8 +6,6 @@
#include "core/Output.hpp"
#include <aquamarine/output/Output.hpp>
#define LOGM PROTO::presentation->protoLog
CQueuedPresentationData::CQueuedPresentationData(SP<CWLSurfaceResource> surf) : surface(surf) {
;
}

View file

@ -4,8 +4,6 @@
#include "core/Seat.hpp"
#include "../config/ConfigValue.hpp"
#define LOGM PROTO::primarySelection->protoLog
CPrimarySelectionOffer::CPrimarySelectionOffer(SP<CZwpPrimarySelectionOfferV1> resource_, SP<IDataSource> source_) : source(source_), resource(resource_) {
if (!good())
return;

View file

@ -9,8 +9,6 @@
#include <algorithm>
#define LOGM PROTO::screencopy->protoLog
CScreencopyFrame::~CScreencopyFrame() {
if (buffer && buffer->locked())
buffer->unlock();

View file

@ -1,8 +1,6 @@
#include "ServerDecorationKDE.hpp"
#include "core/Compositor.hpp"
#define LOGM PROTO::serverDecorationKDE->protoLog
CServerDecorationKDE::CServerDecorationKDE(SP<COrgKdeKwinServerDecoration> resource_, SP<CWLSurfaceResource> surf) : resource(resource_) {
if (!good())
return;

View file

@ -5,8 +5,6 @@
#include "core/Compositor.hpp"
#include "core/Output.hpp"
#define LOGM PROTO::sessionLock->protoLog
CSessionLockSurface::CSessionLockSurface(SP<CExtSessionLockSurfaceV1> resource_, SP<CWLSurfaceResource> surface_, CMonitor* pMonitor_, WP<CSessionLock> owner_) :
resource(resource_), sessionLock(owner_), pSurface(surface_), pMonitor(pMonitor_) {
if (!resource->resource())

View file

@ -3,8 +3,6 @@
#include "../Compositor.hpp"
#include "core/Compositor.hpp"
#define LOGM PROTO::shortcutsInhibit->protoLog
CKeyboardShortcutsInhibitor::CKeyboardShortcutsInhibitor(SP<CZwpKeyboardShortcutsInhibitorV1> resource_, SP<CWLSurfaceResource> surf) : resource(resource_), pSurface(surf) {
if (!resource->resource())
return;

View file

@ -7,8 +7,6 @@
#include <algorithm>
#include <cstring>
#define LOGM PROTO::tablet->protoLog
CTabletPadStripV2Resource::CTabletPadStripV2Resource(SP<CZwpTabletPadStripV2> resource_, uint32_t id_) : id(id_), resource(resource_) {
if (!good())
return;

View file

@ -3,8 +3,6 @@
#include "../Compositor.hpp"
#include "core/Compositor.hpp"
#define LOGM PROTO::textInputV1->protoLog
CTextInputV1::~CTextInputV1() {
events.destroy.emit();
}

View file

@ -2,8 +2,6 @@
#include <algorithm>
#include "core/Compositor.hpp"
#define LOGM PROTO::textInputV3->protoLog
void CTextInputV3::SState::reset() {
cause = ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_INPUT_METHOD;
surrounding.updated = false;

View file

@ -8,8 +8,6 @@
#include <algorithm>
#define LOGM PROTO::toplevelExport->protoLog
CToplevelExportClient::CToplevelExportClient(SP<CHyprlandToplevelExportManagerV1> resource_) : resource(resource_) {
if (!good())
return;

View file

@ -2,8 +2,6 @@
#include "core/Compositor.hpp"
#include <algorithm>
#define LOGM PROTO::viewport->protoLog
CViewportResource::CViewportResource(SP<CWpViewport> resource_, SP<CWLSurfaceResource> surface_) : surface(surface_), resource(resource_) {
if (!good())
return;

View file

@ -2,8 +2,6 @@
#include <sys/mman.h>
#include "../devices/IKeyboard.hpp"
#define LOGM PROTO::virtualKeyboard->protoLog
CVirtualKeyboardV1Resource::CVirtualKeyboardV1Resource(SP<CZwpVirtualKeyboardV1> resource_) : resource(resource_) {
if (!good())
return;

View file

@ -1,8 +1,6 @@
#include "VirtualPointer.hpp"
#include "core/Output.hpp"
#define LOGM PROTO::virtualPointer->protoLog
CVirtualPointerV1Resource::CVirtualPointerV1Resource(SP<CZwlrVirtualPointerV1> resource_, WP<CMonitor> boundOutput_) : boundOutput(boundOutput_), resource(resource_) {
if (!good())
return;

View file

@ -21,7 +21,7 @@ IWaylandProtocol::IWaylandProtocol(const wl_interface* iface, const int& ver, co
m_pGlobal = wl_global_create(g_pCompositor->m_sWLDisplay, iface, ver, this, &bindManagerInternal);
if (!m_pGlobal) {
protoLog(ERR, "could not create a global");
LOGM(ERR, "could not create a global [{}]", m_szName);
return;
}
@ -30,7 +30,7 @@ IWaylandProtocol::IWaylandProtocol(const wl_interface* iface, const int& ver, co
m_liDisplayDestroy.parent = this;
wl_display_add_destroy_listener(g_pCompositor->m_sWLDisplay, &m_liDisplayDestroy.listener);
protoLog(LOG, "Registered global");
LOGM(LOG, "Registered global [{}]", m_szName);
}
IWaylandProtocol::~IWaylandProtocol() {

View file

@ -11,6 +11,35 @@
#define PROTO NProtocols
#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() << "] "; \
} \
if constexpr (std::is_same_v<decltype(__VA_ARGS__), std::string>) { \
oss << __VA_ARGS__; \
Debug::log(level, oss.str()); \
} else { \
Debug::log(level, std::format("{}{}", oss.str(), std::format(__VA_ARGS__))); \
} \
} while (0)
class IWaylandProtocol;
struct IWaylandProtocolDestroyWrapper {
wl_listener listener;
@ -27,11 +56,6 @@ class IWaylandProtocol {
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) = 0;
template <typename... Args>
void protoLog(LogLevel level, std::format_string<Args...> fmt, Args&&... args) {
Debug::log(level, std::format("[{}] ", m_szName) + std::vformat(fmt.get(), std::make_format_args(args...)));
};
IWaylandProtocolDestroyWrapper m_liDisplayDestroy;
private:

View file

@ -4,8 +4,6 @@
#include "core/Compositor.hpp"
#include <algorithm>
#define LOGM PROTO::activation->protoLog
CXDGActivationToken::CXDGActivationToken(SP<CXdgActivationTokenV1> resource_) : resource(resource_) {
if (!resource_->resource())
return;

View file

@ -1,8 +1,6 @@
#include "XDGDecoration.hpp"
#include <algorithm>
#define LOGM PROTO::xdgDecoration->protoLog
CXDGDecoration::CXDGDecoration(SP<CZxdgToplevelDecorationV1> resource_, wl_resource* toplevel) : resource(resource_), pToplevelResource(toplevel) {
if (!resource->resource())
return;

View file

@ -12,8 +12,6 @@
//
#define LOGM PROTO::xdgOutput->protoLog
void CXDGOutputProtocol::onManagerResourceDestroy(wl_resource* res) {
std::erase_if(m_vManagerResources, [&](const auto& other) { return other->resource() == res; });
}

View file

@ -6,8 +6,6 @@
#include "core/Compositor.hpp"
#include <cstring>
#define LOGM PROTO::xdgShell->protoLog
void SXDGPositionerState::setAnchor(xdgPositionerAnchor edges) {
anchor.setTop(edges == XDG_POSITIONER_ANCHOR_TOP || edges == XDG_POSITIONER_ANCHOR_TOP_LEFT || edges == XDG_POSITIONER_ANCHOR_TOP_RIGHT);
anchor.setLeft(edges == XDG_POSITIONER_ANCHOR_LEFT || edges == XDG_POSITIONER_ANCHOR_TOP_LEFT || edges == XDG_POSITIONER_ANCHOR_BOTTOM_LEFT);

View file

@ -2,8 +2,6 @@
#include "core/Compositor.hpp"
#include <algorithm>
#define LOGM PROTO::xwaylandShell->protoLog
CXWaylandSurfaceResource::CXWaylandSurfaceResource(SP<CXwaylandSurfaceV1> resource_, SP<CWLSurfaceResource> surface_) : surface(surface_), resource(resource_) {
if (!good())
return;

View file

@ -13,8 +13,6 @@
#include "../../render/Renderer.hpp"
#include <cstring>
#define LOGM PROTO::compositor->protoLog
class CDefaultSurfaceRole : public ISurfaceRole {
public:
virtual eSurfaceRole role() {

View file

@ -6,8 +6,6 @@
#include "Seat.hpp"
#include "Compositor.hpp"
#define LOGM PROTO::data->protoLog
CWLDataOfferResource::CWLDataOfferResource(SP<CWlDataOffer> resource_, SP<IDataSource> source_) : source(source_), resource(resource_) {
if (!good())
return;

View file

@ -9,8 +9,6 @@
#include <fcntl.h>
#define LOGM PROTO::seat->protoLog
CWLTouchResource::CWLTouchResource(SP<CWlTouch> resource_, SP<CWLSeatResource> owner_) : owner(owner_), resource(resource_) {
if (!good())
return;

View file

@ -7,8 +7,6 @@
#include "../../Compositor.hpp"
#include "../../helpers/Format.hpp"
#define LOGM PROTO::shm->protoLog
CWLSHMBuffer::CWLSHMBuffer(SP<CWLSHMPoolResource> pool_, uint32_t id, int32_t offset_, const Vector2D& size_, int32_t stride_, uint32_t fmt_) {
if (!pool_->pool->data)
return;

View file

@ -2,8 +2,6 @@
#include "Compositor.hpp"
#include <algorithm>
#define LOGM PROTO::subcompositor->protoLog
CWLSubsurfaceResource::CWLSubsurfaceResource(SP<CWlSubsurface> resource_, SP<CWLSurfaceResource> surface_, SP<CWLSurfaceResource> parent_) :
surface(surface_), parent(parent_), resource(resource_) {
if (!good())