summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2021-11-30 10:06:38 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2021-12-20 15:01:56 +1000
commitb47fa8a0aa0b987e675222fd18195a759d40ecaa (patch)
treeb2f0eb0f44b59bdd9e73fe48a12ade9db7cdf7aa
parent3271defd328ad2c33e88de0bcf0600f1b2c8f1ec (diff)
downloadxf86-input-wacom-b47fa8a0aa0b987e675222fd18195a759d40ecaa.tar.gz
Split the various logging functions into several calls
We have driver and device logging, and each as a normal log function, a sigsafe log path and a debug message log path. So 6 functions overall. This doesn't matter for the X driver which routes sigsafe to LogMessageVerbSigSafe but for other frontends it's useful to keep these apart. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--src/WacomInterface.h40
-rw-r--r--src/wcmCommon.c7
-rw-r--r--src/wcmFilter.c2
-rw-r--r--src/wcmISDV4.c16
-rw-r--r--src/wcmTouchFilter.c2
-rw-r--r--src/wcmUSB.c10
-rw-r--r--src/xf86Wacom.c67
-rw-r--r--src/xf86Wacom.h8
-rw-r--r--src/xf86WacomDefs.h6
-rw-r--r--test/fake-symbols.c6
10 files changed, 133 insertions, 31 deletions
diff --git a/src/WacomInterface.h b/src/WacomInterface.h
index 1c1db0b..dc4bf89 100644
--- a/src/WacomInterface.h
+++ b/src/WacomInterface.h
@@ -32,6 +32,7 @@
#include <stdint.h>
typedef struct _WacomDeviceRec *WacomDevicePtr;
+typedef struct _WacomCommonRec *WacomCommonPtr;
/* Identical to MessageType */
typedef enum {
@@ -80,13 +81,46 @@ typedef struct {
/**
- * General logging function. If priv is NULL, use a generic logging method,
- * otherwise priv is the device to log the message for.
+ * General logging function for a device.
*/
-__attribute__((__format__(__printf__ ,3, 4)))
+__attribute__((__format__(__printf__ , 3, 4)))
void wcmLog(WacomDevicePtr priv, WacomLogType type, const char *format, ...);
/**
+ * Same as the above but uses the sigsafe logging function if needed.
+ */
+__attribute__((__format__(__printf__ , 3, 4)))
+void wcmLogSafe(WacomDevicePtr priv, WacomLogType type, const char *format, ...);
+
+/**
+ * General logging function for the driver.
+ */
+__attribute__((__format__(__printf__ , 3, 4)))
+void wcmLogCommon(WacomCommonPtr priv, WacomLogType type, const char *format, ...);
+
+/**
+ * Same as the above but uses the sigsafe logging function if needed.
+ */
+__attribute__((__format__(__printf__ , 3, 4)))
+void wcmLogCommonSafe(WacomCommonPtr priv, WacomLogType type, const char *format, ...);
+
+/**
+ * Identical to wcmLog but used for debug messages inside the driver for a
+ * specific device. This must use a sigsafe path.
+ */
+__attribute__((__format__(__printf__ , 4, 5)))
+void wcmLogDebugDevice(WacomDevicePtr priv, int debug_level, const char *func,
+ const char *format, ...);
+
+/**
+ * Identical to wcmLog but used for debug messages inside the driver from the
+ * common shared path. This must use a sigsafe path.
+ */
+__attribute__((__format__(__printf__ , 4, 5)))
+void wcmLogDebugCommon(WacomCommonPtr common, int debug_level, const char *func,
+ const char *format, ...);
+
+/**
* @retval 0 to abort the loop (counts as match)
* @retval -ENODEV if the device is not a match
* @retval 1 for success (counts as match).
diff --git a/src/wcmCommon.c b/src/wcmCommon.c
index 209e8c8..85c0b3b 100644
--- a/src/wcmCommon.c
+++ b/src/wcmCommon.c
@@ -1181,14 +1181,14 @@ void wcmEvent(WacomCommonPtr common, unsigned int channel,
return;
}
+ priv = tool->device;
/* Tool on the tablet when driver starts. This sometime causes
* access errors to the device */
if (!tool->enabled) {
- wcmLog(NULL, W_ERROR, "tool not initialized yet. Skipping event. \n");
+ wcmLogSafe(priv, W_ERROR, "tool not initialized yet. Skipping event. \n");
return;
}
- priv = tool->device;
DBG(11, common, "tool id=%d for %s\n", ds.device_type, priv->name);
if (TabletHasFeature(common, WCM_ROTATION) &&
@@ -1373,7 +1373,7 @@ static void detectPressureIssue(WacomDevicePtr priv,
and is too close to the maximum pressure */
if (priv->oldMinPressure > pressureThreshold &&
priv->eventCnt > MIN_EVENT_COUNT)
- wcmLog(NULL, W_WARNING,
+ wcmLogSafe(priv, W_WARNING,
"On %s(%d) a base pressure of %d persists while the pen is in proximity.\n"
"\tThis is > %d percent of the maximum value (%d).\n"
"\tThis indicates a worn out pen, it is time to change your tool. Also see:\n"
@@ -1690,6 +1690,7 @@ WacomCommonPtr wcmNewCommon(void)
if (!common)
return NULL;;
+ common->is_common_rec = true;
common->refcnt = 1;
common->wcmFlags = 0; /* various flags */
common->wcmProtocolLevel = WCM_PROTOCOL_4; /* protocol level */
diff --git a/src/wcmFilter.c b/src/wcmFilter.c
index f685611..3758ee3 100644
--- a/src/wcmFilter.c
+++ b/src/wcmFilter.c
@@ -65,7 +65,7 @@ void wcmSetPressureCurve(WacomDevicePtr pDev, int x0, int y0,
pDev->pPressCurve = calloc(FILTER_PRESSURE_RES+1, sizeof(*pDev->pPressCurve));
if (!pDev->pPressCurve) {
- wcmLog(NULL, W_WARNING,
+ wcmLogSafe(pDev, W_WARNING,
"Unable to allocate memory for pressure curve; using default.\n");
x0 = 0;
y0 = 0;
diff --git a/src/wcmISDV4.c b/src/wcmISDV4.c
index bf0baa7..8b6bf79 100644
--- a/src/wcmISDV4.c
+++ b/src/wcmISDV4.c
@@ -107,12 +107,12 @@ static void memdump(WacomDevicePtr priv, char *buffer, unsigned int len)
/* can't use DBG macro here, need to do it manually. */
for (i = 0 ; i < len && common->debugLevel >= 10; i++)
{
- wcmLog(NULL, W_NONE, "%#hhx ", buffer[i]);
+ wcmLogSafe(priv, W_NONE, "%#hhx ", buffer[i]);
if (i % 8 == 7)
- wcmLog(NULL, W_NONE, "\n");
+ wcmLogSafe(priv, W_NONE, "\n");
}
- wcmLog(NULL, W_NONE, "\n");
+ wcmLogSafe(priv, W_NONE, "\n");
#endif
}
@@ -123,7 +123,7 @@ static int wcmWait(WacomDevicePtr priv, int t)
if (err != -1)
return Success;
- wcmLog(NULL, W_ERROR, "Wacom select error : %s\n", strerror(errno));
+ wcmLogSafe(priv, W_ERROR, "Wacom select error : %s\n", strerror(errno));
return err;
}
@@ -161,7 +161,7 @@ static int wcmSerialValidate(WacomDevicePtr priv, const unsigned char* data)
if (!(data[0] & HEADER_BIT))
{
n = wcmSkipInvalidBytes(data, common->wcmPktLength);
- wcmLog(NULL, W_WARNING,
+ wcmLogSafe(priv, W_WARNING,
"missing header bit. skipping %d bytes.\n",
n);
return n;
@@ -174,7 +174,7 @@ static int wcmSerialValidate(WacomDevicePtr priv, const unsigned char* data)
n = wcmSkipInvalidBytes(&data[1], common->wcmPktLength - 1);
n += 1; /* the header byte we already checked */
if (n != common->wcmPktLength) {
- wcmLog(NULL, W_WARNING, "%s: bad data at %d v=%x l=%d\n", priv->name,
+ wcmLogSafe(priv, W_WARNING, "%s: bad data at %d v=%x l=%d\n", priv->name,
n, data[n], common->wcmPktLength);
return n;
}
@@ -589,7 +589,7 @@ static int isdv4ParseTouchPacket(WacomDevicePtr priv, const unsigned char *data,
rc = isdv4ParseTouchData(data, len, common->wcmPktLength, &touchdata);
if (rc <= 0)
{
- wcmLog(NULL, W_ERROR, "%s: failed to parse touch data (err %d).\n",
+ wcmLogSafe(priv, W_ERROR, "%s: failed to parse touch data (err %d).\n",
priv->name, rc);
return -1;
}
@@ -663,7 +663,7 @@ static int isdv4ParsePenPacket(WacomDevicePtr priv, const unsigned char *data,
if (rc == -1)
{
- wcmLog(NULL, W_ERROR, "%s: failed to parse coordinate data.\n", priv->name);
+ wcmLogSafe(priv, W_ERROR, "%s: failed to parse coordinate data.\n", priv->name);
return -1;
}
diff --git a/src/wcmTouchFilter.c b/src/wcmTouchFilter.c
index bf31259..642436f 100644
--- a/src/wcmTouchFilter.c
+++ b/src/wcmTouchFilter.c
@@ -405,7 +405,7 @@ void wcmGestureFilter(WacomDevicePtr priv, int touch_id)
if (!IsTouch(priv))
{
/* this should never happen */
- wcmLog(NULL, W_ERROR, "WACOM: No touch device found for %s \n",
+ wcmLogSafe(priv, W_ERROR, "WACOM: No touch device found for %s \n",
common->device_path);
return;
}
diff --git a/src/wcmUSB.c b/src/wcmUSB.c
index ac7be67..3d062aa 100644
--- a/src/wcmUSB.c
+++ b/src/wcmUSB.c
@@ -980,7 +980,7 @@ static void usbParseEvent(WacomDevicePtr priv,
/* space left? bail if not. */
if (private->wcmEventCnt >= ARRAY_SIZE(private->wcmEvents))
{
- wcmLog(NULL, W_ERROR, "%s: usbParse: Exceeded event queue (%d) \n",
+ wcmLogSafe(priv, W_ERROR, "%s: usbParse: Exceeded event queue (%d) \n",
priv->name, private->wcmEventCnt);
usbResetEventCounter(private);
return;
@@ -1022,7 +1022,7 @@ static void usbParseMscEvent(WacomDevicePtr priv,
/* we don't report serial numbers for some tools but we never report
* a serial number with a value of 0 - if that happens drop the
* whole frame */
- wcmLog(NULL, W_ERROR, "%s: usbParse: Ignoring event from invalid serial 0\n",
+ wcmLogSafe(priv, W_ERROR, "%s: usbParse: Ignoring event from invalid serial 0\n",
priv->name);
usbResetEventCounter(private);
}
@@ -1353,7 +1353,7 @@ mod_buttons(WacomCommonPtr common, int buttons, int btn, int state)
if (btn >= sizeof(int) * 8)
{
- wcmLog(NULL, W_ERROR,
+ wcmLogCommonSafe(common, W_ERROR,
"%s: Invalid button number %d. Insufficient storage\n",
__func__, btn);
return buttons;
@@ -1853,7 +1853,7 @@ static void usbDispatchEvents(WacomDevicePtr priv)
dslast = common->wcmChannel[channel].valid.state;
if (ds->device_type && ds->device_type != private->wcmDeviceType)
- wcmLog(NULL, W_ERROR,
+ wcmLogSafe(priv, W_ERROR,
"usbDispatchEvents: Device Type mismatch - %d -> %d. This is a BUG.\n",
ds->device_type, private->wcmDeviceType);
/* no device type? */
@@ -1909,7 +1909,7 @@ static void usbDispatchEvents(WacomDevicePtr priv)
common->wcmChannel[channel].dirty |= TRUE;
}
else
- wcmLog(NULL, W_ERROR,
+ wcmLogSafe(priv, W_ERROR,
"%s: rel event recv'd (%d)!\n",
priv->name,
event->code);
diff --git a/src/xf86Wacom.c b/src/xf86Wacom.c
index ee8e34d..5babf82 100644
--- a/src/xf86Wacom.c
+++ b/src/xf86Wacom.c
@@ -59,6 +59,14 @@
#define XI86_DRV_CAP_SERVER_FD 0x01
#endif
+__attribute__((__format__(__printf__ , 2, 0)))
+static void
+log_sigsafe(WacomLogType type, const char *format, va_list args)
+{
+ MessageType xtype = (MessageType)type;
+ LogVMessageVerbSigSafe(xtype, -1, format, args);
+}
+
void
wcmLog(WacomDevicePtr priv, WacomLogType type, const char *format, ...)
{
@@ -66,14 +74,61 @@ wcmLog(WacomDevicePtr priv, WacomLogType type, const char *format, ...)
va_list args;
va_start(args, format);
- if (!priv) {
- LogVMessageVerbSigSafe(xtype, -1, format, args);
- } else {
- xf86VIDrvMsgVerb(priv->frontend, xtype, 0, format, args);
- }
+ xf86VIDrvMsgVerb(priv->frontend, xtype, 0, format, args);
va_end(args);
}
+void wcmLogSafe(WacomDevicePtr priv, WacomLogType type, const char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+ log_sigsafe(type, format, args);
+ va_end(args);
+}
+
+void wcmLogCommon(WacomCommonPtr common, WacomLogType type, const char *format, ...)
+{
+ MessageType xtype = (MessageType)type;
+ va_list args;
+
+ va_start(args, format);
+ LogVMessageVerb(xtype, -1, format, args);
+ va_end(args);
+}
+
+void wcmLogCommonSafe(WacomCommonPtr common, WacomLogType type, const char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+ log_sigsafe(type, format, args);
+ va_end(args);
+}
+
+void
+wcmLogDebugDevice(WacomDevicePtr priv, int debug_level, const char *func, const char *format, ...)
+{
+ va_list args;
+
+ LogMessageVerbSigSafe(X_INFO, -1, "%s (%d:%s): ", priv->name, debug_level, func);
+ va_start(args, format);
+ log_sigsafe(W_NONE, format, args);
+ va_end(args);
+}
+
+void
+wcmLogDebugCommon(WacomCommonPtr common, int debug_level, const char *func, const char *format, ...)
+{
+ va_list args;
+
+ LogMessageVerbSigSafe(X_INFO, -1, "%s (%d:%s): ", common->device_path, debug_level, func);
+ va_start(args, format);
+ log_sigsafe(W_NONE, format, args);
+ va_end(args);
+}
+
+
char *wcmOptGetStr(WacomDevicePtr priv, const char *key, const char *default_value)
{
InputInfoPtr pInfo = priv->frontend;
@@ -675,7 +730,7 @@ static void wcmDevReadInput(InputInfoPtr pInfo)
/* dispatch */
if ((rc = wcmReadPacket(priv)) < 0) {
- wcmLog(NULL, W_ERROR,
+ wcmLogSafe(priv, W_ERROR,
"%s: Error reading wacom device : %s\n", priv->name, strerror(-rc));
if (rc == -ENODEV)
xf86RemoveEnabledDevice(pInfo);
diff --git a/src/xf86Wacom.h b/src/xf86Wacom.h
index fd40a2c..8cd121d 100644
--- a/src/xf86Wacom.h
+++ b/src/xf86Wacom.h
@@ -58,9 +58,11 @@
#define DBG(lvl, priv, ...) \
do { \
if ((lvl) <= priv->debugLevel) { \
- wcmLog(NULL, W_INFO, "%s (%d:%s): ", \
- ((WacomDeviceRec*)priv)->name, lvl, __func__); \
- wcmLog(NULL, W_NONE, __VA_ARGS__); \
+ if (((WacomDeviceRec*)(priv))->is_common_rec) { \
+ wcmLogDebugCommon((WacomCommonRec*)priv, lvl, __func__, __VA_ARGS__); \
+ } else { \
+ wcmLogDebugDevice((WacomDeviceRec*)priv, lvl, __func__, __VA_ARGS__); \
+ } \
} \
} while (0)
#else
diff --git a/src/xf86WacomDefs.h b/src/xf86WacomDefs.h
index 96a7c69..0fdf767 100644
--- a/src/xf86WacomDefs.h
+++ b/src/xf86WacomDefs.h
@@ -74,7 +74,7 @@ typedef struct _WacomModel WacomModel, *WacomModelPtr;
typedef struct _WacomDeviceRec WacomDeviceRec;
typedef struct _WacomDeviceState WacomDeviceState, *WacomDeviceStatePtr;
typedef struct _WacomChannel WacomChannel, *WacomChannelPtr;
-typedef struct _WacomCommonRec WacomCommonRec, *WacomCommonPtr;
+typedef struct _WacomCommonRec WacomCommonRec;
typedef struct _WacomFilterState WacomFilterState, *WacomFilterStatePtr;
typedef struct _WacomHWClass WacomHWClass, *WacomHWClassPtr;
typedef struct _WacomTool WacomTool, *WacomToolPtr;
@@ -230,6 +230,8 @@ typedef enum {
struct _WacomDeviceRec
{
char *name; /* Do not move, same offset as common->device_path. Used by DBG macro */
+ bool is_common_rec; /* Do not move, same offset as common->is_common_rec. Used by DBG macro */
+
WacomType type;
/* configuration fields */
struct _WacomDeviceRec *next;
@@ -379,6 +381,8 @@ struct _WacomCommonRec
{
/* Do not move device_path, same offset as priv->name. Used by DBG macro */
char* device_path; /* device file name */
+ /* Do not move is_common_rec, same offset as priv->is_common_rec. Used by DBG macro */
+ bool is_common_rec;
dev_t min_maj; /* minor/major number */
unsigned char wcmFlags; /* various flags (handle tilt) */
int debugLevel;
diff --git a/test/fake-symbols.c b/test/fake-symbols.c
index 8a779b0..cb7ba03 100644
--- a/test/fake-symbols.c
+++ b/test/fake-symbols.c
@@ -308,6 +308,12 @@ LogVMessageVerbSigSafe(MessageType type, int verb, const char *format, va_list a
}
_X_EXPORT void
+LogVMessageVerb(MessageType type, int verb, const char *format, va_list args)
+{
+ return;
+}
+
+_X_EXPORT void
xf86MsgVerb(MessageType type, int verb, const char *format, ...)
{
return;