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

📄 async.c

📁 winddk src目录下的WDM源码压缩!
💻 C
📖 第 1 页 / 共 4 页
字号:
/*++

Copyright (c) 1998  Microsoft Corporation

Module Name:

    async.c

Abstract

    1394 async wrappers

Author:

    Peter Binder (pbinder) 5/13/98

Revision History:
Date     Who       What
-------- --------- ------------------------------------------------------------
05/13/98 pbinder   birth
08/18/98 pbinder   changed for new dialogs
--*/

#define _ASYNC_C
#include "pch.h"
#undef _ASYNC_C

INT_PTR CALLBACK
AllocateAddressRangeDlgProc(
    HWND        hDlg,
    UINT        uMsg,
    WPARAM      wParam,
    LPARAM      lParam
    )
{
    static PALLOCATE_ADDRESS_RANGE      pAllocateAddressRange;
    static CHAR                         tmpBuff[STRING_SIZE];

    switch (uMsg) {

        case WM_INITDIALOG:

            pAllocateAddressRange = (PALLOCATE_ADDRESS_RANGE)lParam;

            _ultoa(pAllocateAddressRange->nLength, tmpBuff, 16);
            SetDlgItemText(hDlg, IDC_ASYNC_ALLOC_LENGTH, tmpBuff);

            _ultoa(pAllocateAddressRange->MaxSegmentSize, tmpBuff, 16);
            SetDlgItemText(hDlg, IDC_ASYNC_ALLOC_MAX_SEGMENT_SIZE, tmpBuff);

            _ultoa(pAllocateAddressRange->Required1394Offset.Off_High, tmpBuff, 16);
            SetDlgItemText(hDlg, IDC_ASYNC_ALLOC_OFFSET_HIGH, tmpBuff);

            _ultoa(pAllocateAddressRange->Required1394Offset.Off_Low, tmpBuff, 16);
            SetDlgItemText(hDlg, IDC_ASYNC_ALLOC_OFFSET_LOW, tmpBuff);

            CheckRadioButton( hDlg,
                              IDC_ASYNC_ALLOC_USE_MDL,
                              IDC_ASYNC_ALLOC_USE_NONE,
                              pAllocateAddressRange->fulAllocateFlags + (IDC_ASYNC_ALLOC_USE_MDL-1)
                              );

            if (pAllocateAddressRange->fulFlags & BIG_ENDIAN_ADDRESS_RANGE)
                CheckDlgButton( hDlg, IDC_ASYNC_ALLOC_USE_BIG_ENDIAN, BST_CHECKED);

            if (pAllocateAddressRange->fulAccessType & ACCESS_FLAGS_TYPE_READ)
                CheckDlgButton( hDlg, IDC_ASYNC_ALLOC_ACCESS_READ, BST_CHECKED);

            if (pAllocateAddressRange->fulAccessType & ACCESS_FLAGS_TYPE_WRITE)
                CheckDlgButton( hDlg, IDC_ASYNC_ALLOC_ACCESS_WRITE, BST_CHECKED);

            if (pAllocateAddressRange->fulAccessType & ACCESS_FLAGS_TYPE_LOCK)
                CheckDlgButton( hDlg, IDC_ASYNC_ALLOC_ACCESS_LOCK, BST_CHECKED);

            if (pAllocateAddressRange->fulAccessType & ACCESS_FLAGS_TYPE_BROADCAST)
                CheckDlgButton( hDlg, IDC_ASYNC_ALLOC_ACCESS_BROADCAST, BST_CHECKED);

            if (pAllocateAddressRange->fulNotificationOptions & NOTIFY_FLAGS_AFTER_READ)
                CheckDlgButton( hDlg, IDC_ASYNC_ALLOC_NOTIFY_READ, BST_CHECKED);

            if (pAllocateAddressRange->fulNotificationOptions & NOTIFY_FLAGS_AFTER_WRITE)
                CheckDlgButton( hDlg, IDC_ASYNC_ALLOC_NOTIFY_WRITE, BST_CHECKED);

            if (pAllocateAddressRange->fulNotificationOptions & NOTIFY_FLAGS_AFTER_LOCK)
                CheckDlgButton( hDlg, IDC_ASYNC_ALLOC_NOTIFY_LOCK, BST_CHECKED);

            return(TRUE); // WM_INITDIALOG

        case WM_COMMAND:

            switch (LOWORD(wParam)) {

                case IDOK:

                    GetDlgItemText(hDlg, IDC_ASYNC_ALLOC_LENGTH, tmpBuff, STRING_SIZE);
                    pAllocateAddressRange->nLength = strtoul(tmpBuff, NULL, 16);

                    GetDlgItemText(hDlg, IDC_ASYNC_ALLOC_MAX_SEGMENT_SIZE, tmpBuff, STRING_SIZE);
                    pAllocateAddressRange->MaxSegmentSize = strtoul(tmpBuff, NULL, 16);

                    GetDlgItemText(hDlg, IDC_ASYNC_ALLOC_OFFSET_HIGH, tmpBuff, STRING_SIZE);
                    pAllocateAddressRange->Required1394Offset.Off_High = (USHORT)strtoul(tmpBuff, NULL, 16);

                    GetDlgItemText(hDlg, IDC_ASYNC_ALLOC_OFFSET_LOW, tmpBuff, STRING_SIZE);
                    pAllocateAddressRange->Required1394Offset.Off_Low = strtoul(tmpBuff, NULL, 16);

                    // fulAllocateFlags
                    if (IsDlgButtonChecked(hDlg, IDC_ASYNC_ALLOC_USE_MDL))
                        pAllocateAddressRange->fulAllocateFlags = ASYNC_ALLOC_USE_MDL;

                    if (IsDlgButtonChecked(hDlg, IDC_ASYNC_ALLOC_USE_FIFO))
                        pAllocateAddressRange->fulAllocateFlags = ASYNC_ALLOC_USE_FIFO;

                    if (IsDlgButtonChecked(hDlg, IDC_ASYNC_ALLOC_USE_NONE))
                        pAllocateAddressRange->fulAllocateFlags = ASYNC_ALLOC_USE_NONE;                                                          

                    // fulFlags
                    if (IsDlgButtonChecked(hDlg, IDC_ASYNC_ALLOC_USE_BIG_ENDIAN))
                        pAllocateAddressRange->fulFlags = BIG_ENDIAN_ADDRESS_RANGE;

                    // fulAccessType
                    if (IsDlgButtonChecked(hDlg, IDC_ASYNC_ALLOC_ACCESS_READ))
                        pAllocateAddressRange->fulAccessType |= ACCESS_FLAGS_TYPE_READ;

                    if (IsDlgButtonChecked(hDlg, IDC_ASYNC_ALLOC_ACCESS_WRITE))
                        pAllocateAddressRange->fulAccessType |= ACCESS_FLAGS_TYPE_WRITE;

                    if (IsDlgButtonChecked(hDlg, IDC_ASYNC_ALLOC_ACCESS_LOCK))
                        pAllocateAddressRange->fulAccessType |= ACCESS_FLAGS_TYPE_LOCK;

                    if (IsDlgButtonChecked(hDlg, IDC_ASYNC_ALLOC_ACCESS_BROADCAST))
                        pAllocateAddressRange->fulAccessType |= ACCESS_FLAGS_TYPE_BROADCAST;                                                             

                    // fulNotifcationOptions
                    pAllocateAddressRange->fulNotificationOptions = NOTIFY_FLAGS_NEVER;
                    if (IsDlgButtonChecked(hDlg, IDC_ASYNC_ALLOC_NOTIFY_READ))
                        pAllocateAddressRange->fulNotificationOptions |= NOTIFY_FLAGS_AFTER_READ;

                    if (IsDlgButtonChecked(hDlg, IDC_ASYNC_ALLOC_NOTIFY_WRITE))
                        pAllocateAddressRange->fulNotificationOptions |= NOTIFY_FLAGS_AFTER_WRITE;

                    if (IsDlgButtonChecked(hDlg, IDC_ASYNC_ALLOC_NOTIFY_LOCK))
                        pAllocateAddressRange->fulNotificationOptions |= NOTIFY_FLAGS_AFTER_LOCK;

                    EndDialog(hDlg, TRUE);
                    return(TRUE); // IDOK

                case IDCANCEL:
                    EndDialog(hDlg, FALSE);
                    return(TRUE); // IDCANCEL

                default:
                    return(TRUE); // default

            } // switch

            break; // WM_COMMAND

        default:
            break; // default

    } // switch

    return(FALSE);
} // AllocateAddressRangeDlgProc

void
w1394_AllocateAddressRange(
    HWND    hWnd,
    PSTR    szDeviceName
    )
{
    ALLOCATE_ADDRESS_RANGE      allocateAddressRange;
    DWORD                       dwRet;

    TRACE(TL_TRACE, (hWnd, "Enter w1394_AllocateAddressRange\r\n"));

    allocateAddressRange.fulAllocateFlags = ASYNC_ALLOC_USE_MDL;
    allocateAddressRange.fulFlags = 0;
    allocateAddressRange.nLength = 512;
    allocateAddressRange.MaxSegmentSize = 0;
    allocateAddressRange.fulAccessType = ACCESS_FLAGS_TYPE_READ | ACCESS_FLAGS_TYPE_WRITE |
         ACCESS_FLAGS_TYPE_LOCK | ACCESS_FLAGS_TYPE_BROADCAST;
    allocateAddressRange.fulNotificationOptions = NOTIFY_FLAGS_NEVER;
    allocateAddressRange.Required1394Offset.Off_High = 0;
    allocateAddressRange.Required1394Offset.Off_Low = 0;

    if (DialogBoxParam( (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),
                        "AllocateAddressRange",
                        hWnd,
                        AllocateAddressRangeDlgProc,
                        (LPARAM)&allocateAddressRange
                        )) {

        dwRet = AllocateAddressRange( hWnd,
                                      szDeviceName,
                                      &allocateAddressRange,
                                      TRUE
                                      );
    }

    TRACE(TL_TRACE, (hWnd, "Exit w1394_AllocateAddressRange\r\n"));
    return;
} // w1394_AllocateAddressRange


INT_PTR CALLBACK
FreeAddressRangeDlgProc(
    HWND        hDlg,
    UINT        uMsg,
    WPARAM      wParam,
    LPARAM      lParam
    )
{
    static PHANDLE      phAddressRange;
    static CHAR         tmpBuff[STRING_SIZE];

    switch (uMsg) {

        case WM_INITDIALOG:

            phAddressRange = (PHANDLE)lParam;

            // put offset low and high and buffer length in edit controls
            //_ultoa(PtrToUlong(*pHandle), tmpBuff, 16);
            sprintf (tmpBuff, "%.1p", *phAddressRange);
            SetDlgItemText(hDlg, IDC_ASYNC_FREE_ADDRESS_HANDLE, tmpBuff);

            return(TRUE); // WM_INITDIALOG

        case WM_COMMAND:

            switch (LOWORD(wParam)) {

                case IDOK:

                    GetDlgItemText(hDlg, IDC_ASYNC_FREE_ADDRESS_HANDLE, tmpBuff, STRING_SIZE);
                    if (!sscanf (tmpBuff, "%p", phAddressRange))
                    {
                        // failed to get the handle, just return here
                        EndDialog(hDlg, TRUE);
                        return FALSE;
                    }

                    EndDialog(hDlg, TRUE);
                    return(TRUE); // IDOK

                case IDCANCEL:
                    EndDialog(hDlg, FALSE);
                    return(TRUE); // IDCANCEL

                default:
                    return(TRUE); // default

            } // switch

            break; // WM_COMMAND

        default:
            break; // default

    } // switch

    return(FALSE);
} // FreeAddressRangeDlgProc

void
w1394_FreeAddressRange(
    HWND    hWnd,
    PSTR    szDeviceName
    )
{
    HANDLE      hAddress;
    DWORD       dwRet;

    TRACE(TL_TRACE, (hWnd, "Enter w1394_FreeAddressRange\r\n"));

    hAddress = NULL;

    if (DialogBoxParam( (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),
                        "FreeAddressRange",
                        hWnd,
                        FreeAddressRangeDlgProc,
                        (LPARAM)&hAddress
                        )) {

        dwRet = FreeAddressRange( hWnd,
                                  szDeviceName,
                                  hAddress
                                  );
    }

    TRACE(TL_TRACE, (hWnd, "Exit w1394_FreeAddressRange\r\n"));
    return;
} // w1394_FreeAddressRange

INT_PTR CALLBACK
AsyncReadDlgProc(
    HWND        hDlg,
    UINT        uMsg,
    WPARAM      wParam,
    LPARAM      lParam
    )
{
    static PASYNC_READ      pAsyncRead;
    static CHAR             tmpBuff[STRING_SIZE];

    switch (uMsg) {

        case WM_INITDIALOG:

            pAsyncRead = (PASYNC_READ)lParam;

            if (pAsyncRead->bRawMode)
                CheckDlgButton( hDlg, IDC_ASYNC_READ_USE_BUS_NODE_NUMBER, BST_CHECKED);

            _ultoa(pAsyncRead->DestinationAddress.IA_Destination_ID.NA_Bus_Number, tmpBuff, 16);
            SetDlgItemText(hDlg, IDC_ASYNC_READ_BUS_NUMBER, tmpBuff);

            _ultoa(pAsyncRead->DestinationAddress.IA_Destination_ID.NA_Node_Number, tmpBuff, 16);
            SetDlgItemText(hDlg, IDC_ASYNC_READ_NODE_NUMBER, tmpBuff);

            _ultoa(pAsyncRead->DestinationAddress.IA_Destination_Offset.Off_High, tmpBuff, 16);
            SetDlgItemText(hDlg, IDC_ASYNC_READ_OFFSET_HIGH, tmpBuff);

            _ultoa(pAsyncRead->DestinationAddress.IA_Destination_Offset.Off_Low, tmpBuff, 16);
            SetDlgItemText(hDlg, IDC_ASYNC_READ_OFFSET_LOW, tmpBuff);

            _ultoa(pAsyncRead->nNumberOfBytesToRead, tmpBuff, 16);
            SetDlgItemText(hDlg, IDC_ASYNC_READ_BYTES_TO_READ, tmpBuff);

⌨️ 快捷键说明

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