input_server addons: use shared FunctionTracer

Change-Id: I1985dd8508388ff829b8bfb4af61a0b118da26a0
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10045
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
PulkoMandy
2025-12-03 07:48:12 +00:00
committed by Adrien Destugues
parent 9cb525a2e3
commit 1dfcf1b9c6
3 changed files with 67 additions and 165 deletions
@@ -32,54 +32,22 @@
//#define TRACE_KEYBOARD_DEVICE
#ifdef TRACE_KEYBOARD_DEVICE
#include <private/shared/FunctionTracer.h>
static int32 sFunctionDepth = -1;
class FunctionTracer {
public:
FunctionTracer(const void* pointer, const char* className,
const char* functionName)
:
fFunctionName(),
fPrepend(),
fPointer(pointer)
{
sFunctionDepth++;
fPrepend.Append(' ', sFunctionDepth * 2);
fFunctionName << className << "::" << functionName << "()";
debug_printf("%p -> %s%s {\n", fPointer, fPrepend.String(),
fFunctionName.String());
}
~FunctionTracer()
{
debug_printf("%p -> %s}\n", fPointer, fPrepend.String());
sFunctionDepth--;
}
static int32 Depth() { return sFunctionDepth; }
private:
BString fFunctionName;
BString fPrepend;
const void* fPointer;
};
# define KD_CALLED(x...) \
FunctionTracer _ft(this, "KeyboardDevice", __FUNCTION__)
# define KID_CALLED(x...) \
FunctionTracer _ft(this, "KeyboardInputDevice", __FUNCTION__)
# define CALLED(x...) \
FunctionTracer _ft(debug_printf, this, __PRETTY_FUNCTION__, sFunctionDepth)
# define TRACE(x...) \
do { BString _to; \
_to.Append(' ', (FunctionTracer::Depth() + 1) * 2); \
_to.Append(' ', (sFunctionDepth + 1) * 2); \
debug_printf("%p -> %s", this, _to.String()); \
debug_printf(x); } while (0)
# define LOG_EVENT(text...) debug_printf(text)
# define LOG_ERR(text...) TRACE(text)
#else
# define TRACE(x...) do {} while (0)
# define KD_CALLED(x...) TRACE(x)
# define KID_CALLED(x...) TRACE(x)
# define CALLED(x...) TRACE(x)
# define LOG_ERR(text...) debug_printf(text)
# define LOG_EVENT(text...) TRACE(x)
#endif
@@ -137,7 +105,7 @@ KeyboardDevice::KeyboardDevice(KeyboardInputDevice* owner, const char* path)
fSettingsCommand(0),
fKeymapLock("keymap lock")
{
KD_CALLED();
CALLED();
strlcpy(fPath, path, B_PATH_NAME_LENGTH);
fDeviceRef.name = get_short_name(path);
@@ -153,7 +121,7 @@ KeyboardDevice::KeyboardDevice(KeyboardInputDevice* owner, const char* path)
KeyboardDevice::~KeyboardDevice()
{
KD_CALLED();
CALLED();
TRACE("delete\n");
if (fActive)
@@ -171,7 +139,7 @@ KeyboardDevice::~KeyboardDevice()
void
KeyboardDevice::MessageReceived(BMessage* message)
{
KD_CALLED();
CALLED();
if (message->what != B_INPUT_METHOD_EVENT) {
BHandler::MessageReceived(message);
@@ -190,7 +158,7 @@ KeyboardDevice::MessageReceived(BMessage* message)
status_t
KeyboardDevice::Start()
{
KD_CALLED();
CALLED();
TRACE("name: %s\n", fDeviceRef.name);
fFD = open(fPath, O_RDWR);
@@ -217,7 +185,7 @@ KeyboardDevice::Start()
void
KeyboardDevice::Stop()
{
KD_CALLED();
CALLED();
TRACE("name: %s\n", fDeviceRef.name);
fActive = false;
@@ -237,7 +205,7 @@ KeyboardDevice::Stop()
status_t
KeyboardDevice::UpdateSettings(uint32 opcode)
{
KD_CALLED();
CALLED();
if (fThread < 0)
return B_ERROR;
@@ -264,7 +232,7 @@ KeyboardDevice::_ControlThreadEntry(void* arg)
int32
KeyboardDevice::_ControlThread()
{
KD_CALLED();
CALLED();
TRACE("fPath: %s\n", fPath);
if (fFD < B_OK) {
@@ -533,7 +501,7 @@ KeyboardDevice::_ControlThreadCleanup()
void
KeyboardDevice::_UpdateSettings(uint32 opcode)
{
KD_CALLED();
CALLED();
if (opcode == 0 || opcode == B_KEY_REPEAT_RATE_CHANGED) {
if (get_key_repeat_rate(&fSettings.key_repeat_rate) != B_OK) {
@@ -621,7 +589,7 @@ KeyboardInputDevice::KeyboardInputDevice()
fDeviceListLock("KeyboardInputDevice list"),
fTeamMonitorWindow(NULL)
{
KID_CALLED();
CALLED();
StartMonitoringDevice(kKeyboardDevicesDirectory);
_RecursiveScan(kKeyboardDevicesDirectory);
@@ -630,7 +598,7 @@ KeyboardInputDevice::KeyboardInputDevice()
KeyboardInputDevice::~KeyboardInputDevice()
{
KID_CALLED();
CALLED();
if (fTeamMonitorWindow) {
fTeamMonitorWindow->PostMessage(B_QUIT_REQUESTED);
@@ -645,7 +613,7 @@ KeyboardInputDevice::~KeyboardInputDevice()
status_t
KeyboardInputDevice::SystemShuttingDown()
{
KID_CALLED();
CALLED();
if (fTeamMonitorWindow)
fTeamMonitorWindow->PostMessage(SYSTEM_SHUTTING_DOWN);
@@ -656,7 +624,7 @@ KeyboardInputDevice::SystemShuttingDown()
status_t
KeyboardInputDevice::InitCheck()
{
KID_CALLED();
CALLED();
return BInputServerDevice::InitCheck();
}
@@ -664,7 +632,7 @@ KeyboardInputDevice::InitCheck()
status_t
KeyboardInputDevice::Start(const char* name, void* cookie)
{
KID_CALLED();
CALLED();
TRACE("name %s\n", name);
KeyboardDevice* device = (KeyboardDevice*)cookie;
@@ -676,7 +644,7 @@ KeyboardInputDevice::Start(const char* name, void* cookie)
status_t
KeyboardInputDevice::Stop(const char* name, void* cookie)
{
KID_CALLED();
CALLED();
TRACE("name %s\n", name);
KeyboardDevice* device = (KeyboardDevice*)cookie;
@@ -690,7 +658,7 @@ status_t
KeyboardInputDevice::Control(const char* name, void* cookie,
uint32 command, BMessage* message)
{
KID_CALLED();
CALLED();
TRACE("KeyboardInputDevice::Control(%s, code: %" B_PRIu32 ")\n", name,
command);
@@ -708,7 +676,7 @@ KeyboardInputDevice::Control(const char* name, void* cookie,
status_t
KeyboardInputDevice::_HandleMonitor(BMessage* message)
{
KID_CALLED();
CALLED();
const char* path;
int32 opcode;
@@ -745,7 +713,7 @@ KeyboardInputDevice::_FindDevice(const char* path) const
status_t
KeyboardInputDevice::_AddDevice(const char* path)
{
KID_CALLED();
CALLED();
TRACE("path: %s\n", path);
BAutolock _(fDeviceListLock);
@@ -775,7 +743,7 @@ KeyboardInputDevice::_RemoveDevice(const char* path)
if (device == NULL)
return B_ENTRY_NOT_FOUND;
KID_CALLED();
CALLED();
TRACE("path: %s\n", path);
input_device_ref* devices[2];
@@ -793,7 +761,7 @@ KeyboardInputDevice::_RemoveDevice(const char* path)
void
KeyboardInputDevice::_RecursiveScan(const char* directory)
{
KID_CALLED();
CALLED();
TRACE("directory: %s\n", directory);
BEntry entry;
@@ -42,43 +42,11 @@
//#define TRACE_MOUSE_DEVICE
#ifdef TRACE_MOUSE_DEVICE
class FunctionTracer {
public:
FunctionTracer(const void* pointer, const char* className,
const char* functionName,
int32& depth)
: fFunctionName(),
fPrepend(),
fFunctionDepth(depth),
fPointer(pointer)
{
fFunctionDepth++;
fPrepend.Append(' ', fFunctionDepth * 2);
fFunctionName << className << "::" << functionName << "()";
debug_printf("%p -> %s%s {\n", fPointer, fPrepend.String(),
fFunctionName.String());
}
~FunctionTracer()
{
debug_printf("%p -> %s}\n", fPointer, fPrepend.String());
fFunctionDepth--;
}
private:
BString fFunctionName;
BString fPrepend;
int32& fFunctionDepth;
const void* fPointer;
};
#include <private/shared/FunctionTracer.h>
static int32 sFunctionDepth = -1;
# define MD_CALLED(x...) FunctionTracer _ft(this, "MouseDevice", \
__FUNCTION__, sFunctionDepth)
# define MID_CALLED(x...) FunctionTracer _ft(this, "MouseInputDevice", \
__FUNCTION__, sFunctionDepth)
# define CALLED(x...) FunctionTracer _ft(debug_printf, this, \
__PRETTY_FUNCTION__, sFunctionDepth)
# define TRACE(x...) do { BString _to; \
_to.Append(' ', (sFunctionDepth + 1) * 2); \
debug_printf("%p -> %s", this, _to.String()); \
@@ -87,8 +55,7 @@
# define LOG_ERR(text...) TRACE(text)
#else
# define TRACE(x...) do {} while (0)
# define MD_CALLED(x...) TRACE(x)
# define MID_CALLED(x...) TRACE(x)
# define CALLED(x...) TRACE(x)
# define LOG_ERR(x...) debug_printf(x)
# define LOG_EVENT(x...) TRACE(x)
#endif
@@ -178,7 +145,7 @@ MouseDevice::MouseDevice(MouseInputDevice& target, const char* driverPath)
fTouchpadSettingsMessage(NULL),
fTouchpadSettingsLock("Touchpad settings lock")
{
MD_CALLED();
CALLED();
fDeviceRef.name = _BuildShortName();
fDeviceRef.type = B_POINTING_DEVICE;
@@ -193,7 +160,7 @@ MouseDevice::MouseDevice(MouseInputDevice& target, const char* driverPath)
MouseDevice::~MouseDevice()
{
MD_CALLED();
CALLED();
TRACE("delete\n");
if (fActive)
@@ -207,7 +174,7 @@ MouseDevice::~MouseDevice()
status_t
MouseDevice::Start()
{
MD_CALLED();
CALLED();
fDevice = open(fPath.String(), O_RDWR);
// let the control thread handle any error on opening the device
@@ -242,7 +209,7 @@ MouseDevice::Start()
void
MouseDevice::Stop()
{
MD_CALLED();
CALLED();
fActive = false;
// this will stop the thread as soon as it reads the next packet
@@ -264,7 +231,7 @@ MouseDevice::Stop()
status_t
MouseDevice::UpdateSettings()
{
MD_CALLED();
CALLED();
if (fThread < 0)
return B_ERROR;
@@ -360,7 +327,7 @@ MouseDevice::_ControlThreadEntry(void* arg)
void
MouseDevice::_ControlThread()
{
MD_CALLED();
CALLED();
if (fDevice < 0) {
_ControlThreadCleanup();
@@ -567,7 +534,7 @@ MouseDevice::_ControlThreadCleanup()
void
MouseDevice::_UpdateSettings()
{
MD_CALLED();
CALLED();
// retrieve current values
if (get_mouse_map(fDeviceRef.name, &fSettings.map) != B_OK)
@@ -737,7 +704,7 @@ MouseInputDevice::MouseInputDevice()
fDevices(2),
fDeviceListLock("MouseInputDevice list")
{
MID_CALLED();
CALLED();
StartMonitoringDevice(kMouseDevicesDirectory);
StartMonitoringDevice(kTouchpadDevicesDirectory);
@@ -748,7 +715,7 @@ MouseInputDevice::MouseInputDevice()
MouseInputDevice::~MouseInputDevice()
{
MID_CALLED();
CALLED();
StopMonitoringDevice(kTouchpadDevicesDirectory);
StopMonitoringDevice(kMouseDevicesDirectory);
@@ -759,7 +726,7 @@ MouseInputDevice::~MouseInputDevice()
status_t
MouseInputDevice::InitCheck()
{
MID_CALLED();
CALLED();
return BInputServerDevice::InitCheck();
}
@@ -768,7 +735,7 @@ MouseInputDevice::InitCheck()
status_t
MouseInputDevice::Start(const char* name, void* cookie)
{
MID_CALLED();
CALLED();
MouseDevice* device = (MouseDevice*)cookie;
@@ -792,7 +759,7 @@ status_t
MouseInputDevice::Control(const char* name, void* cookie,
uint32 command, BMessage* message)
{
TRACE("%s(%s, code: %lu)\n", __PRETTY_FUNCTION__, name, command);
TRACE("%s(%s, code: %" B_PRIu32 ")\n", __PRETTY_FUNCTION__, name, command);
MouseDevice* device = (MouseDevice*)cookie;
@@ -813,7 +780,7 @@ MouseInputDevice::Control(const char* name, void* cookie,
status_t
MouseInputDevice::_HandleMonitor(BMessage* message)
{
MID_CALLED();
CALLED();
const char* path;
int32 opcode;
@@ -837,7 +804,7 @@ MouseInputDevice::_HandleMonitor(BMessage* message)
void
MouseInputDevice::_RecursiveScan(const char* directory)
{
MID_CALLED();
CALLED();
BEntry entry;
BDirectory dir(directory);
@@ -861,7 +828,7 @@ MouseInputDevice::_RecursiveScan(const char* directory)
MouseDevice*
MouseInputDevice::_FindDevice(const char* path) const
{
MID_CALLED();
CALLED();
for (int32 i = fDevices.CountItems() - 1; i >= 0; i--) {
MouseDevice* device = fDevices.ItemAt(i);
@@ -876,7 +843,7 @@ MouseInputDevice::_FindDevice(const char* path) const
status_t
MouseInputDevice::_AddDevice(const char* path)
{
MID_CALLED();
CALLED();
BAutolock _(fDeviceListLock);
@@ -907,7 +874,7 @@ MouseInputDevice::_AddDevice(const char* path)
status_t
MouseInputDevice::_RemoveDevice(const char* path)
{
MID_CALLED();
CALLED();
BAutolock _(fDeviceListLock);
@@ -36,43 +36,11 @@
//#define TRACE_TABLET_DEVICE
#ifdef TRACE_TABLET_DEVICE
class FunctionTracer {
public:
FunctionTracer(const void* pointer, const char* className,
const char* functionName,
int32& depth)
: fFunctionName(),
fPrepend(),
fFunctionDepth(depth),
fPointer(pointer)
{
fFunctionDepth++;
fPrepend.Append(' ', fFunctionDepth * 2);
fFunctionName << className << "::" << functionName << "()";
debug_printf("%p -> %s%s {\n", fPointer, fPrepend.String(),
fFunctionName.String());
}
~FunctionTracer()
{
debug_printf("%p -> %s}\n", fPointer, fPrepend.String());
fFunctionDepth--;
}
private:
BString fFunctionName;
BString fPrepend;
int32& fFunctionDepth;
const void* fPointer;
};
#include <private/shared/FunctionTracer.h>
static int32 sFunctionDepth = -1;
# define TD_CALLED(x...) FunctionTracer _ft(this, "TabletDevice", \
__FUNCTION__, sFunctionDepth)
# define TID_CALLED(x...) FunctionTracer _ft(this, "TabletInputDevice", \
__FUNCTION__, sFunctionDepth)
# define CALLED(x...) FunctionTracer _ft(debug_printf, this, \
__PRETTY_FUNCTION__, sFunctionDepth)
# define TRACE(x...) do { BString _to; \
_to.Append(' ', (sFunctionDepth + 1) * 2); \
debug_printf("%p -> %s", this, _to.String()); \
@@ -81,8 +49,7 @@
# define LOG_ERR(text...) TRACE(text)
#else
# define TRACE(x...) do {} while (0)
# define TD_CALLED(x...) TRACE(x)
# define TID_CALLED(x...) TRACE(x)
# define CALLED(x...) TRACE(x)
# define LOG_ERR(x...) debug_printf(x)
# define LOG_EVENT(x...) TRACE(x)
#endif
@@ -151,7 +118,7 @@ TabletDevice::TabletDevice(TabletInputDevice& target, const char* driverPath)
fActive(false),
fUpdateSettings(false)
{
TD_CALLED();
CALLED();
fDeviceRef.name = _BuildShortName();
fDeviceRef.type = B_POINTING_DEVICE;
@@ -161,7 +128,7 @@ TabletDevice::TabletDevice(TabletInputDevice& target, const char* driverPath)
TabletDevice::~TabletDevice()
{
TD_CALLED();
CALLED();
TRACE("delete\n");
if (fActive)
@@ -174,7 +141,7 @@ TabletDevice::~TabletDevice()
status_t
TabletDevice::Start()
{
TD_CALLED();
CALLED();
fDevice = open(fPath.String(), O_RDWR);
// let the control thread handle any error on opening the device
@@ -209,7 +176,7 @@ TabletDevice::Start()
void
TabletDevice::Stop()
{
TD_CALLED();
CALLED();
fActive = false;
// this will stop the thread as soon as it reads the next packet
@@ -231,7 +198,7 @@ TabletDevice::Stop()
status_t
TabletDevice::UpdateSettings()
{
TD_CALLED();
CALLED();
if (fThread < 0)
return B_ERROR;
@@ -281,7 +248,7 @@ TabletDevice::_ControlThreadEntry(void* arg)
void
TabletDevice::_ControlThread()
{
TD_CALLED();
CALLED();
if (fDevice < 0) {
_ControlThreadCleanup();
@@ -415,7 +382,7 @@ TabletDevice::_ControlThreadCleanup()
void
TabletDevice::_UpdateSettings()
{
TD_CALLED();
CALLED();
if (get_click_speed(fDeviceRef.name, &fSettings.click_speed) != B_OK)
LOG_ERR("error when get_click_speed\n");
@@ -454,7 +421,7 @@ TabletInputDevice::TabletInputDevice()
fDevices(2),
fDeviceListLock("TabletInputDevice list")
{
TID_CALLED();
CALLED();
StartMonitoringDevice(kTabletDevicesDirectory);
_RecursiveScan(kTabletDevicesDirectory);
@@ -463,7 +430,7 @@ TabletInputDevice::TabletInputDevice()
TabletInputDevice::~TabletInputDevice()
{
TID_CALLED();
CALLED();
StopMonitoringDevice(kTabletDevicesDirectory);
fDevices.MakeEmpty();
@@ -473,7 +440,7 @@ TabletInputDevice::~TabletInputDevice()
status_t
TabletInputDevice::InitCheck()
{
TID_CALLED();
CALLED();
return BInputServerDevice::InitCheck();
}
@@ -482,7 +449,7 @@ TabletInputDevice::InitCheck()
status_t
TabletInputDevice::Start(const char* name, void* cookie)
{
TID_CALLED();
CALLED();
TabletDevice* device = (TabletDevice*)cookie;
@@ -506,7 +473,7 @@ status_t
TabletInputDevice::Control(const char* name, void* cookie,
uint32 command, BMessage* message)
{
TRACE("%s(%s, code: %lu)\n", __PRETTY_FUNCTION__, name, command);
TRACE("%s(%s, code: %" B_PRIu32 ")\n", __PRETTY_FUNCTION__, name, command);
TabletDevice* device = (TabletDevice*)cookie;
@@ -523,7 +490,7 @@ TabletInputDevice::Control(const char* name, void* cookie,
status_t
TabletInputDevice::_HandleMonitor(BMessage* message)
{
TID_CALLED();
CALLED();
const char* path;
int32 opcode;
@@ -543,7 +510,7 @@ TabletInputDevice::_HandleMonitor(BMessage* message)
void
TabletInputDevice::_RecursiveScan(const char* directory)
{
TID_CALLED();
CALLED();
BEntry entry;
BDirectory dir(directory);
@@ -562,7 +529,7 @@ TabletInputDevice::_RecursiveScan(const char* directory)
TabletDevice*
TabletInputDevice::_FindDevice(const char* path) const
{
TID_CALLED();
CALLED();
for (int32 i = fDevices.CountItems() - 1; i >= 0; i--) {
TabletDevice* device = fDevices.ItemAt(i);
@@ -577,7 +544,7 @@ TabletInputDevice::_FindDevice(const char* path) const
status_t
TabletInputDevice::_AddDevice(const char* path)
{
TID_CALLED();
CALLED();
BAutolock _(fDeviceListLock);
@@ -608,7 +575,7 @@ TabletInputDevice::_AddDevice(const char* path)
status_t
TabletInputDevice::_RemoveDevice(const char* path)
{
TID_CALLED();
CALLED();
BAutolock _(fDeviceListLock);