VirtualBox

Ignore:
Timestamp:
Sep 9, 2008 10:07:14 AM (16 years ago)
Author:
vboxsync
Message:

Additions/linux: added support for polling /dev/vboxadd for mouse movement in absolute mode

Location:
trunk/src/VBox/Additions/linux/module
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/linux/module/vboxmod.c

    r11642 r12280  
    7373#include <iprt/assert.h>
    7474#include <linux/miscdevice.h>
     75#include <linux/poll.h>
    7576
    7677#define xstr(s) str(s)
     
    206207}
    207208
    208 
    209209/**
    210210 * File open handler
     
    215215    /* no checks required */
    216216    return 0;
    217 }
    218 
    219 /**
    220  * File close handler.  Clean up any HGCM connections associated with the open file
    221  * which might still be open.
    222  */
    223 static int vboxadd_release(struct inode *inode, struct file * filp)
    224 {
    225         vboxadd_unregister_all_hgcm_connections(filp);
    226         return 0;
    227217}
    228218
     
    585575}
    586576
    587 #ifdef DEBUG
     577/**
     578 * Poll function.  This returns "ready to read" if the guest is in absolute
     579 * mouse pointer mode and the pointer position has changed since the last
     580 * poll.
     581 */
     582unsigned int
     583vboxadd_poll (struct file *file, poll_table *wait)
     584{
     585    int result = 0;
     586    poll_wait(file, &vboxDev->eventq, wait);
     587    if (vboxDev->u32Events & VMMDEV_EVENT_MOUSE_POSITION_CHANGED)
     588        result = (POLLIN | POLLRDNORM);
     589    vboxDev->u32Events &= ~VMMDEV_EVENT_MOUSE_POSITION_CHANGED;
     590    return result;
     591}
     592
     593/** Asynchronous notification activation method. */
     594static int
     595vboxadd_fasync(int fd, struct file *file, int mode)
     596{
     597    return fasync_helper(fd, file, mode, &vboxDev->async_queue);
     598}
     599
     600/**
     601 * Dummy read function - we only supply this because we implement poll and
     602 * fasync.
     603 */
    588604static ssize_t
    589605vboxadd_read (struct file *file, char *buf, size_t count, loff_t *loff)
    590606{
    591     if (count != 8 || *loff != 0)
     607    if (0 == count || *loff != 0)
    592608    {
    593609        return -EINVAL;
    594610    }
    595     *(uint32_t *) buf = vboxDev->pVMMDevMemory->V.V1_04.fHaveEvents;
    596     *(uint32_t *) (buf + 4) = vboxDev->u32Events;
    597     *loff += 8;
    598     return 8;
    599 }
    600 #endif
     611    buf[0] = 0;
     612    return 1;
     613}
     614
     615/**
     616 * File close handler.  Clean up any HGCM connections associated with the open file
     617 * which might still be open.
     618 */
     619static int vboxadd_release(struct inode *inode, struct file * filp)
     620{
     621        vboxadd_unregister_all_hgcm_connections(filp);
     622        /* Deactivate our asynchronous queue. */
     623        vboxadd_fasync(-1, filp, 0);
     624        return 0;
     625}
    601626
    602627/** strategy handlers (file operations) */
     
    605630    .owner   = THIS_MODULE,
    606631    .open    = vboxadd_open,
     632    .ioctl   = vboxadd_ioctl,
     633    .poll    = vboxadd_poll,
     634    .fasync  = vboxadd_fasync,
     635    .read    = vboxadd_read,
    607636    .release = vboxadd_release,
    608     .ioctl   = vboxadd_ioctl,
    609 #ifdef DEBUG
    610     .read    = vboxadd_read,
    611 #endif
    612637    .llseek  = no_llseek
    613638};
     
    666691            {
    667692                vboxDev->u32Events |= vboxDev->irqAckRequest->events;
     693                if (  vboxDev->irqAckRequest->events
     694                    & VMMDEV_EVENT_MOUSE_POSITION_CHANGED)
     695                    kill_fasync(&vboxDev->async_queue, SIGIO, POLL_IN);
    668696                wake_up (&vboxDev->eventq);
    669697            }
     
    824852    if (vboxDev)
    825853    {
    826         /* at first detach from IRQ! */
     854        {
     855            /* Unregister notifications when the host absolute pointer
     856             * position changes. */
     857            VBoxGuestFilterMaskInfo info;
     858            info.u32OrMask = 0;
     859            info.u32NotMask = VMMDEV_EVENT_MOUSE_POSITION_CHANGED;
     860            vboxadd_control_filter_mask(&info);
     861        }
     862        /* Detach from IRQ before cleaning up! */
    827863        if (vboxDev->irq)
    828864            free_irq(vboxDev->irq, vboxDev);
     
    10611097
    10621098    init_waitqueue_head (&vboxDev->eventq);
     1099
     1100    {
     1101        /* Register for notification when the host absolute pointer position
     1102         * changes. */
     1103        VBoxGuestFilterMaskInfo info;
     1104        info.u32OrMask = VMMDEV_EVENT_MOUSE_POSITION_CHANGED;
     1105        info.u32NotMask = 0;
     1106        rcVBox = vboxadd_control_filter_mask(&info);
     1107        if (!RT_SUCCESS(rcVBox))
     1108        {
     1109            LogRelFunc(("failed to register for VMMDEV_EVENT_MOUSE_POSITION_CHANGED events\n"));
     1110            err = -RTErrConvertToErrno(rcVBox);
     1111            goto fail;
     1112        }
     1113    }
    10631114
    10641115    /* some useful information for the user but don't show this on the console */
  • trunk/src/VBox/Additions/linux/module/vboxmod.h

    r8155 r12280  
    5959        event. */
    6060    uint32_t u32GuestInterruptions;
     61    /** Queue structure */
     62    struct fasync_struct *async_queue;
    6163};
    6264
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette