[PATCH] xfree86: Split the working code of NIDR into new xf86NewInputDevice.
Peter Hutterer
peter.hutterer at who-t.net
Thu Nov 20 21:03:17 PST 2008
From: Peter Hutterer <peter.hutterer at redhat.com>
The xfree86 server previously hat NewInputDeviceRequest and InitInput, and
both basically did the same thing. Reduce NIDR to parameter checking and use
xf86NewInputDevice from both InitInput and NIDR to actually create the device.
Signed-off-by: Peter Hutterer <peter.hutterer at redhat.com>
---
hw/xfree86/common/xf86Init.c | 34 +---------
hw/xfree86/common/xf86Xinput.c | 143 ++++++++++++++++++++++------------------
hw/xfree86/common/xf86Xinput.h | 1 +
3 files changed, 83 insertions(+), 95 deletions(-)
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 45c116a..feab993 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -1239,8 +1239,7 @@ InitInput(argc, argv)
char **argv;
{
IDevPtr* pDev;
- InputDriverPtr pDrv;
- InputInfoPtr pInfo;
+ DeviceIntPtr dev;
xf86Info.vtRequestsPending = FALSE;
@@ -1251,36 +1250,7 @@ InitInput(argc, argv)
strcpy((*pDev)->driver, "kbd");
}
- if ((pDrv = xf86LookupInputDriver((*pDev)->driver)) == NULL) {
- xf86Msg(X_ERROR, "No Input driver matching `%s'\n", (*pDev)->driver);
- /* XXX For now, just continue. */
- continue;
- }
- if (!pDrv->PreInit) {
- xf86MsgVerb(X_WARNING, 0,
- "Input driver `%s' has no PreInit function (ignoring)\n",
- pDrv->driverName);
- continue;
- }
- pInfo = pDrv->PreInit(pDrv, *pDev, 0);
- if (!pInfo) {
- xf86Msg(X_ERROR, "PreInit returned NULL for \"%s\"\n",
- (*pDev)->identifier);
- continue;
- } else if (!(pInfo->flags & XI86_CONFIGURED)) {
- xf86Msg(X_ERROR, "PreInit failed for input device \"%s\"\n",
- (*pDev)->identifier);
- xf86DeleteInput(pInfo, 0);
- continue;
- }
- }
-
- /* Initialise all input devices. */
- pInfo = xf86InputDevs;
- while (pInfo) {
- xf86Msg(X_INFO, "evaluating device (%s)\n", pInfo->name);
- xf86ActivateDevice(pInfo);
- pInfo = pInfo->next;
+ xf86NewInputDevice(*pDev, &dev, TRUE);
}
mieqInit();
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 7d90891..2cb41e5 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -467,14 +467,87 @@ AddOtherInputDevices()
{
}
+/**
+ * Create a new input device, activate and enable it.
+ *
+ * @param idev The device, already set up with identifier, driver, and the
+ * options.
+ * @param pdev Pointer to the new device, if Success was reported.
+ * @param enable Enable the device after activating it.
+ *
+ * @return Success or an error code
+ */
+_X_INTERNAL int
+xf86NewInputDevice(IDevPtr idev, DeviceIntPtr *pdev, BOOL enable)
+{
+ InputDriverPtr drv = NULL;
+ InputInfoPtr pInfo = NULL;
+ DeviceIntPtr dev = NULL;
+ int rval;
+
+ /* Memory leak for every attached device if we don't
+ * test if the module is already loaded first */
+ drv = xf86LookupInputDriver(idev->driver);
+ if (!drv)
+ if (xf86LoadOneModule(idev->driver, NULL))
+ drv = xf86LookupInputDriver(idev->driver);
+ if (!drv) {
+ xf86Msg(X_ERROR, "No input driver matching `%s'\n", idev->driver);
+ rval = BadName;
+ goto unwind;
+ }
+
+ if (!drv->PreInit) {
+ xf86Msg(X_ERROR,
+ "Input driver `%s' has no PreInit function (ignoring)\n",
+ drv->driverName);
+ rval = BadImplementation;
+ goto unwind;
+ }
+
+ pInfo = drv->PreInit(drv, idev, 0);
+
+ if (!pInfo) {
+ xf86Msg(X_ERROR, "PreInit returned NULL for \"%s\"\n", idev->identifier);
+ rval = BadMatch;
+ goto unwind;
+ }
+ else if (!(pInfo->flags & XI86_CONFIGURED)) {
+ xf86Msg(X_ERROR, "PreInit failed for input device \"%s\"\n",
+ idev->identifier);
+ rval = BadMatch;
+ goto unwind;
+ }
+
+ xf86ActivateDevice(pInfo);
+
+ dev = pInfo->dev;
+ ActivateDevice(dev);
+ /* Enable it if it's properly initialised and we're currently in the VT */
+ if (enable && dev->inited && dev->startup && xf86Screens[0]->vtSema)
+ EnableDevice(dev);
+
+ /* send enter/leave event, update sprite window */
+ CheckMotion(NULL, dev);
+
+ *pdev = dev;
+ return Success;
+
+unwind:
+ if(pInfo) {
+ if(drv->UnInit)
+ drv->UnInit(drv, pInfo, 0);
+ else
+ xf86DeleteInput(pInfo, 0);
+ }
+ return rval;
+}
+
_X_EXPORT int
NewInputDeviceRequest (InputOption *options, DeviceIntPtr *pdev)
{
IDevRec *idev = NULL;
- InputDriverPtr drv = NULL;
- InputInfoPtr pInfo = NULL;
InputOption *option = NULL;
- DeviceIntPtr dev = NULL;
int rval = Success;
int is_auto = 0;
@@ -488,18 +561,6 @@ NewInputDeviceRequest (InputOption *options, DeviceIntPtr *pdev)
rval = BadRequest;
goto unwind;
}
- /* Memory leak for every attached device if we don't
- * test if the module is already loaded first */
- drv = xf86LookupInputDriver(option->value);
- if (!drv)
- if (xf86LoadOneModule(option->value, NULL))
- drv = xf86LookupInputDriver(option->value);
- if (!drv) {
- xf86Msg(X_ERROR, "No input driver matching `%s'\n",
- option->value);
- rval = BadName;
- goto unwind;
- }
idev->driver = xstrdup(option->value);
if (!idev->driver) {
rval = BadAlloc;
@@ -537,24 +598,11 @@ NewInputDeviceRequest (InputOption *options, DeviceIntPtr *pdev)
goto unwind;
}
- if (!drv) {
- xf86Msg(X_ERROR, "No input driver specified (ignoring)\n");
- return BadMatch;
- }
-
if (!idev->identifier) {
xf86Msg(X_ERROR, "No device identifier specified (ignoring)\n");
return BadMatch;
}
- if (!drv->PreInit) {
- xf86Msg(X_ERROR,
- "Input driver `%s' has no PreInit function (ignoring)\n",
- drv->driverName);
- rval = BadImplementation;
- goto unwind;
- }
-
for (option = options; option; option = option->next) {
/* Steal option key/value strings from the provided list.
* We need those strings, the InputOption list doesn't. */
@@ -564,43 +612,12 @@ NewInputDeviceRequest (InputOption *options, DeviceIntPtr *pdev)
option->value = NULL;
}
- pInfo = drv->PreInit(drv, idev, 0);
-
- if (!pInfo) {
- xf86Msg(X_ERROR, "PreInit returned NULL for \"%s\"\n", idev->identifier);
- rval = BadMatch;
- goto unwind;
- }
- else if (!(pInfo->flags & XI86_CONFIGURED)) {
- xf86Msg(X_ERROR, "PreInit failed for input device \"%s\"\n",
- idev->identifier);
- rval = BadMatch;
- goto unwind;
- }
-
- xf86ActivateDevice(pInfo);
-
- dev = pInfo->dev;
- ActivateDevice(dev);
- /* Enable it if it's properly initialised, we're currently in the VT, and
- * either it's a manual request, or we're automatically enabling devices. */
- if (dev->inited && dev->startup && xf86Screens[0]->vtSema &&
- (!is_auto || xf86Info.autoEnableDevices))
- EnableDevice(dev);
-
- /* send enter/leave event, update sprite window */
- CheckMotion(NULL, dev);
-
- *pdev = dev;
- return Success;
+ rval = xf86NewInputDevice(idev, pdev,
+ (!is_auto || (is_auto && xf86Info.autoEnableDevices)));
+ if (rval == Success)
+ return Success;
unwind:
- if(pInfo) {
- if(drv->UnInit)
- drv->UnInit(drv, pInfo, 0);
- else
- xf86DeleteInput(pInfo, 0);
- }
if(idev->driver)
xfree(idev->driver);
if(idev->identifier)
diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h
index 7617a3e..28a3315 100644
--- a/hw/xfree86/common/xf86Xinput.h
+++ b/hw/xfree86/common/xf86Xinput.h
@@ -185,6 +185,7 @@ void xf86AddEnabledDevice(InputInfoPtr pInfo);
void xf86RemoveEnabledDevice(InputInfoPtr pInfo);
void xf86DisableDevice(DeviceIntPtr dev, Bool panic);
void xf86EnableDevice(DeviceIntPtr dev);
+int xf86NewInputDevice(IDevPtr idev, DeviceIntPtr *pdev, BOOL is_auto);
/* xf86Helper.c */
void xf86AddInputDriver(InputDriverPtr driver, pointer module, int flags);
--
1.6.0.3
More information about the xorg
mailing list