⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keyq.cpp

📁 完整的基于Conxant平台的USB电视棒的WIN驱动程序。
💻 CPP
字号:
/*+++ *******************************************************************\ 
* 
*  Copyright and Disclaimer: 
*  
*     --------------------------------------------------------------- 
*     This software is provided "AS IS" without warranty of any kind, 
*     either expressed or implied, including but not limited to the 
*     implied warranties of noninfringement, merchantability and/or 
*     fitness for a particular purpose.
*     --------------------------------------------------------------- 
*   
*     Copyright (c) 2008 Conexant Systems, Inc. 
*     All rights reserved. 
*
\******************************************************************* ---*/ 

#include "keyq.h"

KeystrokeQueue::KeystrokeQueue(USHORT Size):
                m_ReadIndex(0xFF),
                m_WriteIndex(0),
                m_BufferSize(Size)
{
    KeInitializeSpinLock(&m_SpinLock);
}

NTSTATUS KeystrokeQueue::init()
{
    m_Buffer = new KEYSTROKE[m_BufferSize];

    if(m_Buffer)
    {
        RtlZeroMemory(m_Buffer, m_BufferSize * sizeof(KEYSTROKE));
        return STATUS_SUCCESS;
    }
    else
    {
        return STATUS_UNSUCCESSFUL;
    }
}

KeystrokeQueue::~KeystrokeQueue()
{    
    delete [] m_Buffer;   
}

VOID KeystrokeQueue::Insert(KEYSTROKE& Keystroke)
{
    KIRQL OldIrql;
    KeAcquireSpinLock(&m_SpinLock, &OldIrql);

    m_Buffer[m_WriteIndex].dwAddress = Keystroke.dwAddress ;
    m_Buffer[m_WriteIndex].dwCommand = Keystroke.dwCommand ;

    if(m_ReadIndex == 0xFF)
        m_ReadIndex = m_WriteIndex;
    else if(m_WriteIndex == m_ReadIndex)
    {
        //We just discarded a keystroke.  Update the
        // read index to point to the oldest keystroke
       if(m_ReadIndex < m_BufferSize-1)
            m_ReadIndex++;
        else 
            m_ReadIndex = 0;
    }

    if(m_WriteIndex < m_BufferSize-1)
        m_WriteIndex++;
    else 
        m_WriteIndex = 0;	
    
    KeReleaseSpinLock(&m_SpinLock, OldIrql);    
  
}

KEYSTROKE KeystrokeQueue::Remove()
{
    KEYSTROKE key ;
    RtlZeroMemory(&key, sizeof(KEYSTROKE));

    if(m_ReadIndex == 0xFF)
        return key; //No Keystroke available

    KIRQL OldIrql;
    KeAcquireSpinLock(&m_SpinLock, &OldIrql);

    key = m_Buffer[m_ReadIndex];
    if(m_ReadIndex < m_BufferSize-1)
        m_ReadIndex++;
    else 
        m_ReadIndex = 0;

    if(m_ReadIndex == m_WriteIndex)
    {
        //Mark the queue as empty
        m_ReadIndex = 0xFF;             
    }

    KeReleaseSpinLock(&m_SpinLock, OldIrql);
    return key;
}

VOID KeystrokeQueue::Flush()
{
    KIRQL OldIrql;

    KeAcquireSpinLock(&m_SpinLock, &OldIrql);
    
    // Initialize the array
    RtlZeroMemory(m_Buffer, m_BufferSize * sizeof(KEYSTROKE));
    
    //Mark the queue as empty
    m_ReadIndex = 0xFF;

    KeReleaseSpinLock(&m_SpinLock, OldIrql);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -