diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2021-11-26 10:21:59 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2021-12-20 15:01:56 +1000 |
commit | 759f919d808971fa015fd3016e15538b4301aedd (patch) | |
tree | 0b429d9fda24258dbba33b52594d37afda39d648 | |
parent | 9c12ae753fbb06ef83e79d4438941a33b8c896da (diff) | |
download | xf86-input-wacom-759f919d808971fa015fd3016e15538b4301aedd.tar.gz |
Replace pInfo->fd direct access with a get/set abstraction layer
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | src/WacomInterface.h | 4 | ||||
-rw-r--r-- | src/wcmCommon.c | 5 | ||||
-rw-r--r-- | src/wcmConfig.c | 12 | ||||
-rw-r--r-- | src/wcmISDV4.c | 34 | ||||
-rw-r--r-- | src/wcmUSB.c | 54 | ||||
-rw-r--r-- | src/xf86Wacom.c | 10 |
6 files changed, 58 insertions, 61 deletions
diff --git a/src/WacomInterface.h b/src/WacomInterface.h index 3902c71..ef12e83 100644 --- a/src/WacomInterface.h +++ b/src/WacomInterface.h @@ -105,6 +105,10 @@ int wcmOpen(WacomDevicePtr priv); /* Close the device */ void wcmClose(WacomDevicePtr priv); +int wcmGetFd(WacomDevicePtr priv); +void wcmSetFd(WacomDevicePtr priv, int fd); + + static inline void wcmAxisSet(WacomAxisData *data, enum WacomAxisType which, int value) { diff --git a/src/wcmCommon.c b/src/wcmCommon.c index 3ab4ccd..95dc304 100644 --- a/src/wcmCommon.c +++ b/src/wcmCommon.c @@ -166,18 +166,17 @@ void wcmResetWheelAction(WacomDevicePtr priv, int index) /* Main event hanlding function */ int wcmReadPacket(WacomDevicePtr priv) { - InputInfoPtr pInfo = priv->pInfo; WacomCommonPtr common = priv->common; int len, pos, cnt, remaining; - DBG(10, common, "fd=%d\n", pInfo->fd); + DBG(10, common, "fd=%d\n", wcmGetFd(priv)); remaining = sizeof(common->buffer) - common->bufpos; DBG(1, common, "pos=%d remaining=%d\n", common->bufpos, remaining); /* fill buffer with as much data as we can handle */ - SYSCALL((len = read(pInfo->fd, common->buffer + common->bufpos, remaining))); + SYSCALL((len = read(wcmGetFd(priv), common->buffer + common->bufpos, remaining))); if (len <= 0) { diff --git a/src/wcmConfig.c b/src/wcmConfig.c index 901c41c..b8a4858 100644 --- a/src/wcmConfig.c +++ b/src/wcmConfig.c @@ -726,7 +726,7 @@ int wcmPreInit(WacomDevicePtr priv) if ((fd = wcmOpen(priv)) < 0) goto SetupProc_fail; - pInfo->fd = fd; + wcmSetFd(priv, fd); /* Try to guess whether it's USB or ISDV4 */ if (!wcmDetectDeviceClass(priv)) @@ -819,7 +819,6 @@ SetupProc_fail: int wcmDevOpen(WacomDevicePtr priv) { - InputInfoPtr pInfo = priv->pInfo; WacomCommonPtr common = priv->common; struct stat st; @@ -853,9 +852,9 @@ int wcmDevOpen(WacomDevicePtr priv) } /* Grab the common descriptor, if it's available */ - if (pInfo->fd < 0) + if (wcmGetFd(priv) < 0) { - pInfo->fd = common->fd; + wcmSetFd(priv, common->fd); common->fd_refs++; } @@ -1062,16 +1061,15 @@ void wcmDevStop(WacomDevicePtr priv) void wcmDevClose(WacomDevicePtr priv) { - InputInfoPtr pInfo = priv->pInfo; WacomCommonPtr common = priv->common; DBG(4, priv, "Wacom number of open devices = %d\n", common->fd_refs); - if (pInfo->fd >= 0) + if (wcmGetFd(priv) >= 0) { if (!--common->fd_refs) wcmClose(priv); - pInfo->fd = -1; + wcmSetFd(priv, -1); } } diff --git a/src/wcmISDV4.c b/src/wcmISDV4.c index 4427493..8a07493 100644 --- a/src/wcmISDV4.c +++ b/src/wcmISDV4.c @@ -187,11 +187,10 @@ static int wcmSerialValidate(WacomDevicePtr priv, const unsigned char* data) static Bool isdv4Detect(WacomDevicePtr priv) { - InputInfoPtr pInfo = priv->pInfo; struct serial_struct ser; int rc; - rc = ioctl(pInfo->fd, TIOCGSERIAL, &ser); + rc = ioctl(wcmGetFd(priv), TIOCGSERIAL, &ser); if (rc == -1) return FALSE; @@ -248,14 +247,13 @@ static Bool isdv4ParseOptions(WacomDevicePtr priv) static Bool isdv4Init(WacomDevicePtr priv) { - InputInfoPtr pInfo = priv->pInfo; WacomCommonPtr common = priv->common; wcmISDV4Data *isdv4data = common->private; DBG(1, priv, "initializing ISDV4 tablet\n"); /* Set baudrate */ - if (xf86SetSerialSpeed(pInfo->fd, isdv4data->baudrate) < 0) + if (xf86SetSerialSpeed(wcmGetFd(priv), isdv4data->baudrate) < 0) return !Success; /*set the model */ @@ -302,7 +300,6 @@ static int isdv4Query(WacomDevicePtr priv, const char* query, char* data) static int isdv4InitISDV4(WacomDevicePtr priv) { char data[BUFFER_SIZE]; - InputInfoPtr pInfo = priv->pInfo; WacomCommonPtr common = priv->common; wcmISDV4Data *isdv4data = common->private; int ret = Success; @@ -324,7 +321,7 @@ static int isdv4InitISDV4(WacomDevicePtr priv) common->wcmFlags &= ~TILT_ENABLED_FLAG; /* Set baudrate to configured value */ - if (xf86SetSerialSpeed(pInfo->fd, isdv4data->baudrate) < 0) + if (xf86SetSerialSpeed(wcmGetFd(priv), isdv4data->baudrate) < 0) { ret = !Success; goto out; @@ -343,7 +340,7 @@ static int isdv4InitISDV4(WacomDevicePtr priv) "Query failed with %d baud. Trying %d.\n", isdv4data->baudrate, baud); - if (xf86SetSerialSpeed(pInfo->fd, baud) < 0) + if (xf86SetSerialSpeed(wcmGetFd(priv), baud) < 0) { ret = !Success; goto out; @@ -542,7 +539,6 @@ static int isdv4StartTablet(WacomDevicePtr priv) static int isdv4StopTablet(WacomDevicePtr priv) { - InputInfoPtr pInfo = priv->pInfo; #ifdef DEBUG WacomCommonPtr common = priv->common; #endif @@ -557,13 +553,13 @@ static int isdv4StopTablet(WacomDevicePtr priv) return !Success; /* discard potential data on the line */ - fd_flags = fcntl(pInfo->fd, F_GETFL); - if (fcntl(pInfo->fd, F_SETFL, fd_flags | O_NONBLOCK) == 0) + fd_flags = fcntl(wcmGetFd(priv), F_GETFL); + if (fcntl(wcmGetFd(priv), F_SETFL, fd_flags | O_NONBLOCK) == 0) { char buffer[10]; - while (read(pInfo->fd, buffer, sizeof(buffer)) > 0) + while (read(wcmGetFd(priv), buffer, sizeof(buffer)) > 0) DBG(10, common, "discarding garbage data.\n"); - (void)fcntl(pInfo->fd, F_SETFL, fd_flags); + (void)fcntl(wcmGetFd(priv), F_SETFL, fd_flags); } return Success; @@ -807,13 +803,12 @@ static int isdv4Parse(WacomDevicePtr priv, const unsigned char* data, int len) static int wcmWriteWait(WacomDevicePtr priv, const char* request) { - InputInfoPtr pInfo = priv->pInfo; int len, maxtry = MAXTRY; /* send request string */ do { - SYSCALL((len = write(pInfo->fd, request, strlen(request)))); + SYSCALL((len = write(wcmGetFd(priv), request, strlen(request)))); if ((len == -1) && (errno != EAGAIN)) { wcmLog(priv, W_ERROR, @@ -840,15 +835,14 @@ static int wcmWriteWait(WacomDevicePtr priv, const char* request) static int wcmWaitForTablet(WacomDevicePtr priv, char* answer, int size) { - InputInfoPtr pInfo = priv->pInfo; int len, maxtry = MAXTRY; /* Read size bytes of the answer */ do { - if ((len = xf86WaitForInput(pInfo->fd, 1000000)) > 0) + if ((len = xf86WaitForInput(wcmGetFd(priv), 1000000)) > 0) { - SYSCALL((len = read(pInfo->fd, answer, size))); + SYSCALL((len = read(wcmGetFd(priv), answer, size))); if ((len == -1) && (errno != EAGAIN)) { wcmLog(priv, W_ERROR, @@ -950,7 +944,6 @@ static Bool get_keys_vendor_tablet_id(char *name, WacomCommonPtr common) */ static Bool get_sysfs_id(WacomDevicePtr priv, char *buf, int buf_size) { - InputInfoPtr pInfo = priv->pInfo; struct udev *udev = NULL; struct udev_device *device = NULL; struct stat st; @@ -959,7 +952,7 @@ static Bool get_sysfs_id(WacomDevicePtr priv, char *buf, int buf_size) Bool ret = FALSE; int bytes_read; - if (fstat(pInfo->fd, &st) == -1) + if (fstat(wcmGetFd(priv), &st) == -1) goto out; udev = udev_new(); @@ -1005,10 +998,9 @@ out: static int isdv4ProbeKeys(WacomDevicePtr priv) { struct serial_struct tmp; - InputInfoPtr pInfo = priv->pInfo; WacomCommonPtr common = priv->common; - if (ioctl(pInfo->fd, TIOCGSERIAL, &tmp) < 0) + if (ioctl(wcmGetFd(priv), TIOCGSERIAL, &tmp) < 0) return 0; common->tablet_id = 0x90; diff --git a/src/wcmUSB.c b/src/wcmUSB.c index 17ab3e1..63549ee 100644 --- a/src/wcmUSB.c +++ b/src/wcmUSB.c @@ -111,14 +111,13 @@ DEFINE_MODEL(usbTabletPC, "USB TabletPC", 4); static Bool usbDetect(WacomDevicePtr priv) { - InputInfoPtr pInfo = priv->pInfo; int version; int err; #ifdef DEBUG DBG(1, priv, "\n"); #endif - SYSCALL(err = ioctl(pInfo->fd, EVIOCGVERSION, &version)); + SYSCALL(err = ioctl(wcmGetFd(priv), EVIOCGVERSION, &version)); if (err < 0) { @@ -153,7 +152,6 @@ static Bool usbParseOptions(WacomDevicePtr priv) static int usbStart(WacomDevicePtr priv) { - InputInfoPtr pInfo = priv->pInfo; WacomCommonPtr common = priv->common; wcmUSBData *usbdata = common->private; int err; @@ -161,7 +159,7 @@ usbStart(WacomDevicePtr priv) if (usbdata->grabDevice) { /* Try to grab the event device so that data don't leak to /dev/input/mice */ - SYSCALL(err = ioctl(pInfo->fd, EVIOCGRAB, (pointer)1)); + SYSCALL(err = ioctl(wcmGetFd(priv), EVIOCGRAB, (pointer)1)); /* this is called for all tools, so all but the first one fails with * EBUSY */ @@ -432,14 +430,13 @@ static Bool usbWcmInit(WacomDevicePtr priv) { int i; struct input_id sID; - InputInfoPtr pInfo = priv->pInfo; WacomCommonPtr common = priv->common; wcmUSBData *usbdata; DBG(1, priv, "initializing USB tablet\n"); /* fetch vendor, product, and model name */ - if (ioctl(pInfo->fd, EVIOCGID, &sID) == -1) { + if (ioctl(wcmGetFd(priv), EVIOCGID, &sID) == -1) { wcmLog(priv, W_ERROR, "failed to ioctl ID .\n"); return !Success; } @@ -582,7 +579,6 @@ int usbInitialize(WacomDevicePtr priv) unsigned long ev[NBITS(EV_MAX)] = {0}; unsigned long abs[NBITS(ABS_MAX)] = {0}; unsigned long sw[NBITS(SW_MAX)] = {0}; - InputInfoPtr pInfo = priv->pInfo; WacomCommonPtr common = priv->common; wcmUSBData* private = common->private; int is_touch = IsTouch(priv); @@ -595,7 +591,7 @@ int usbInitialize(WacomDevicePtr priv) && ISBITSET(common->wcmKeys, BTN_FORWARD)) is_touch = 1; - if (ioctl(pInfo->fd, EVIOCGBIT(0 /*EV*/, sizeof(ev)), ev) < 0) + if (ioctl(wcmGetFd(priv), EVIOCGBIT(0 /*EV*/, sizeof(ev)), ev) < 0) { wcmLog(priv, W_ERROR, "unable to ioctl event bits.\n"); return !Success; @@ -613,14 +609,14 @@ int usbInitialize(WacomDevicePtr priv) } /* absolute values */ - if (ioctl(pInfo->fd, EVIOCGBIT(EV_ABS, sizeof(abs)), abs) < 0) + if (ioctl(wcmGetFd(priv), EVIOCGBIT(EV_ABS, sizeof(abs)), abs) < 0) { wcmLog(priv, W_ERROR, "unable to ioctl max values.\n"); return !Success; } /* max x */ - if (ioctl(pInfo->fd, EVIOCGABS(ABS_X), &absinfo) < 0) + if (ioctl(wcmGetFd(priv), EVIOCGABS(ABS_X), &absinfo) < 0) { /* may be a PAD only interface */ if (ISBITSET(common->wcmKeys, BTN_FORWARD) || @@ -651,7 +647,7 @@ int usbInitialize(WacomDevicePtr priv) } /* max y */ - if (ioctl(pInfo->fd, EVIOCGABS(ABS_Y), &absinfo) < 0) + if (ioctl(wcmGetFd(priv), EVIOCGABS(ABS_Y), &absinfo) < 0) { wcmLog(priv, W_ERROR, "unable to ioctl ymax value.\n"); return !Success; @@ -678,7 +674,7 @@ int usbInitialize(WacomDevicePtr priv) /* max finger strip X for tablets with Expresskeys * or physical X for touch devices in hundredths of a mm */ if (ISBITSET(abs, ABS_RX) && - !ioctl(pInfo->fd, EVIOCGABS(ABS_RX), &absinfo)) + !ioctl(wcmGetFd(priv), EVIOCGABS(ABS_RX), &absinfo)) { if (is_touch) common->wcmTouchResolX = @@ -692,7 +688,7 @@ int usbInitialize(WacomDevicePtr priv) common->wcmMinRing = 0; common->wcmMaxRing = 71; if (!ISBITSET(ev,EV_MSC) && ISBITSET(abs, ABS_WHEEL) && - !ioctl(pInfo->fd, EVIOCGABS(ABS_WHEEL), &absinfo)) + !ioctl(wcmGetFd(priv), EVIOCGABS(ABS_WHEEL), &absinfo)) { common->wcmMinRing = absinfo.minimum; common->wcmMaxRing = absinfo.maximum; @@ -700,7 +696,7 @@ int usbInitialize(WacomDevicePtr priv) /* X tilt range */ if (ISBITSET(abs, ABS_TILT_X) && - !ioctl(pInfo->fd, EVIOCGABS(ABS_TILT_X), &absinfo)) + !ioctl(wcmGetFd(priv), EVIOCGABS(ABS_TILT_X), &absinfo)) { /* If resolution is specified */ if (absinfo.resolution > 0) @@ -736,7 +732,7 @@ int usbInitialize(WacomDevicePtr priv) /* Y tilt range */ if (ISBITSET(abs, ABS_TILT_Y) && - !ioctl(pInfo->fd, EVIOCGABS(ABS_TILT_Y), &absinfo)) + !ioctl(wcmGetFd(priv), EVIOCGABS(ABS_TILT_Y), &absinfo)) { /* If resolution is specified */ if (absinfo.resolution > 0) @@ -773,7 +769,7 @@ int usbInitialize(WacomDevicePtr priv) /* max finger strip Y for tablets with Expresskeys * or physical Y for touch devices in hundredths of a mm */ if (ISBITSET(abs, ABS_RY) && - !ioctl(pInfo->fd, EVIOCGABS(ABS_RY), &absinfo)) + !ioctl(wcmGetFd(priv), EVIOCGABS(ABS_RY), &absinfo)) { if (is_touch) common->wcmTouchResolY = @@ -785,19 +781,19 @@ int usbInitialize(WacomDevicePtr priv) /* max z cannot be configured */ if (ISBITSET(abs, ABS_PRESSURE) && - !ioctl(pInfo->fd, EVIOCGABS(ABS_PRESSURE), &absinfo)) + !ioctl(wcmGetFd(priv), EVIOCGABS(ABS_PRESSURE), &absinfo)) common->wcmMaxZ = absinfo.maximum; /* max distance */ if (ISBITSET(abs, ABS_DISTANCE) && - !ioctl(pInfo->fd, EVIOCGABS(ABS_DISTANCE), &absinfo)) + !ioctl(wcmGetFd(priv), EVIOCGABS(ABS_DISTANCE), &absinfo)) common->wcmMaxDist = absinfo.maximum; if (ISBITSET(abs, ABS_MT_SLOT)) { private->wcmUseMT = 1; - if (!ioctl(pInfo->fd, EVIOCGABS(ABS_MT_SLOT), &absinfo)) + if (!ioctl(wcmGetFd(priv), EVIOCGABS(ABS_MT_SLOT), &absinfo)) common->wcmMaxContacts = absinfo.maximum + 1; /* pen and MT on the same logical port */ @@ -809,7 +805,7 @@ int usbInitialize(WacomDevicePtr priv) if (common->vendor_id != WACOM_VENDOR_ID || !ISBITSET(abs, ABS_MISC)) common->wcmProtocolLevel = WCM_PROTOCOL_GENERIC; - if (ioctl(pInfo->fd, EVIOCGBIT(EV_SW, sizeof(sw)), sw) < 0) + if (ioctl(wcmGetFd(priv), EVIOCGBIT(EV_SW, sizeof(sw)), sw) < 0) { wcmLog(priv, W_ERROR, "unable to ioctl sw bits.\n"); return 0; @@ -820,7 +816,7 @@ int usbInitialize(WacomDevicePtr priv) memset(sw, 0, sizeof(sw)); - if (ioctl(pInfo->fd, EVIOCGSW(sizeof(sw)), sw) < 0) + if (ioctl(wcmGetFd(priv), EVIOCGSW(sizeof(sw)), sw) < 0) wcmLog(priv, W_ERROR, "unable to ioctl sw state.\n"); if (ISBITSET(sw, SW_MUTE_DEVICE)) @@ -1835,7 +1831,6 @@ static void usbDispatchEvents(WacomDevicePtr priv) int i, c; WacomDeviceState *ds; struct input_event* event; - InputInfoPtr pInfo = priv->pInfo; WacomCommonPtr common = priv->common; int channel; wcmUSBData* private = common->private; @@ -1843,7 +1838,7 @@ static void usbDispatchEvents(WacomDevicePtr priv) DBG(6, common, "%d events received\n", private->wcmEventCnt); - private->wcmDeviceType = usbInitToolType(priv, pInfo->fd, + private->wcmDeviceType = usbInitToolType(priv, wcmGetFd(priv), private->wcmEvents, private->wcmEventCnt, dslast.device_type); @@ -1964,7 +1959,7 @@ static void usbDispatchEvents(WacomDevicePtr priv) struct input_absinfo absinfo; if (!ds->x) { - if (ioctl(priv->pInfo->fd, EVIOCGABS(ABS_X), &absinfo) < 0) + if (ioctl(wcmGetFd(priv), EVIOCGABS(ABS_X), &absinfo) < 0) { DBG(-1, common, "unable to ioctl current x value.\n"); return; @@ -1972,7 +1967,7 @@ static void usbDispatchEvents(WacomDevicePtr priv) ds->x = absinfo.value; } if (!ds->y) { - if (ioctl(priv->pInfo->fd, EVIOCGABS(ABS_Y), &absinfo) < 0) + if (ioctl(wcmGetFd(priv), EVIOCGABS(ABS_Y), &absinfo) < 0) { DBG(-1, common, "unable to ioctl current x value.\n"); return; @@ -2041,11 +2036,10 @@ static void usbGenericTouchscreenQuirks(unsigned long *keys, static int usbProbeKeys(WacomDevicePtr priv) { struct input_id wacom_id; - InputInfoPtr pInfo = priv->pInfo; WacomCommonPtr common = priv->common; unsigned long abs[NBITS(ABS_MAX)] = {0}; - if (ioctl(pInfo->fd, EVIOCGBIT(EV_KEY, (sizeof(unsigned long) + if (ioctl(wcmGetFd(priv), EVIOCGBIT(EV_KEY, (sizeof(unsigned long) * NBITS(KEY_MAX))), common->wcmKeys) < 0) { wcmLog(priv, W_ERROR, @@ -2053,21 +2047,21 @@ static int usbProbeKeys(WacomDevicePtr priv) return 0; } - if (ioctl(pInfo->fd, EVIOCGPROP(sizeof(common->wcmInputProps)), common->wcmInputProps) < 0) + if (ioctl(wcmGetFd(priv), EVIOCGPROP(sizeof(common->wcmInputProps)), common->wcmInputProps) < 0) { wcmLog(priv, W_ERROR, "usbProbeKeys unable to ioctl input properties.\n"); return 0; } - if (ioctl(pInfo->fd, EVIOCGID, &wacom_id) < 0) + if (ioctl(wcmGetFd(priv), EVIOCGID, &wacom_id) < 0) { wcmLog(priv, W_ERROR, "usbProbeKeys unable to ioctl Device ID.\n"); return 0; } - if (ioctl(pInfo->fd, EVIOCGBIT(EV_ABS, sizeof(abs)), abs) < 0) + if (ioctl(wcmGetFd(priv), EVIOCGBIT(EV_ABS, sizeof(abs)), abs) < 0) { wcmLog(priv, W_ERROR, "usbProbeKeys unable to ioctl abs bits.\n"); diff --git a/src/xf86Wacom.c b/src/xf86Wacom.c index 2302379..296ed5c 100644 --- a/src/xf86Wacom.c +++ b/src/xf86Wacom.c @@ -577,6 +577,16 @@ int wcmForeachDevice(WacomDevicePtr priv, WacomDeviceCallback func, void *data) return nmatch; } +int wcmGetFd(WacomDevicePtr priv) +{ + return priv->pInfo->fd; +} + +void wcmSetFd(WacomDevicePtr priv, int fd) +{ + priv->pInfo->fd = fd; +} + /***************************************************************************** * wcmOpen -- ****************************************************************************/ |