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

📄 openlist.h

📁 It permits simultaneous use of multiple USB Serial protocols.
💻 H
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
#pragma once

#include <sync.hxx>
#include <list.hxx>


// Keeps a list of context values generated from XXX_Open calls.
class COpenList : public ce::list<DWORD>, public ce::critical_section {
protected:
    typedef ce::list<DWORD>         _BaseList;
    typedef ce::critical_section    _BaseSync;

public:    
    COpenList() : _BaseList(), _BaseSync() {}
    ~COpenList() {
        DEBUGCHK(size() == 0);
    }

    // Call from XXX_Open. Add a context to the list. Returns false upon failure.
    bool AddContext(DWORD dwContext) {
        ce::gate<_BaseSync> gate(*this);
        return push_back(dwContext);
    }

    // Call from XXX_Close. Remove a context from the list. 
    // The context must be present in the list.
    void RemoveContext(DWORD dwContext) {
        ce::gate<_BaseSync> gate(*this);
        DEBUGCHK( std::find(begin(), end(), dwContext) != end() );
        remove(dwContext);
    }

    // Call from XXX_PreDeinit. Calls the provided PreClose routine for each
    // context in the list.
    template <class Fn>
    void PreDeinit(Fn PreClose) {
        ce::gate<_BaseSync> gate(*this);
        std::for_each(begin(), end(), PreClose);
    }

    // Call from XXX_Deinit. Calls the provided Close routine for each context
    // in the list. Note this this acts under the assumption that the provided
    // Close routine will actually remove the context from the list.
    template <class Fn>
    void Deinit(Fn Close) {
        // No real need to lock here, but it might help find problems.
        ce::gate<_BaseSync> gate(*this);
        while (!empty()) {
            Close(front());
        }
    }
};

⌨️ 快捷键说明

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