BufferMgr.h
资源名称:p2p_vod.rar [点击查看]
上传用户:liguizhu
上传日期:2015-11-01
资源大小:2422k
文件大小:3k
源码类别:
P2P编程
开发平台:
Visual C++
- /*
- * Openmysee
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
- #ifndef __BUFFERMGR_H_
- #define __BUFFERMGR_H_
- #include "BaseResource.h"
- namespace NPLayer1 {
- class BufferMgr {
- public:
- // 构造函数
- BufferMgr();
- // 析构函数
- ~BufferMgr();
- // 是否已经初始化
- bool HasInited() {return (blockArray != NULL);};
- // 取得缓冲文件的大小
- UINT GetBufferFileSize() { return bufferFileSize; };
- // 取得缓冲文件名
- string GetBufferFileName() { return bufferFileName; };
- // 初始化缓冲文件,只能调用一次
- P2P_RETURN_TYPE Init(string fullPath, bool& bufFileModified, UINT randNum, UINT bufferSize = BUFFER_SPACE);
- // 取得一个未使用的块, 并将其置为已使用
- UINT GetEmptyIndex(UINT randNum);
- // 将一个块置为未使用
- void EraseIndex(UINT index);
- // 获取剩余空间大小
- UINT GetEmptySpace();
- // 取得一个块的数据
- P2P_RETURN_TYPE GetIndexData(UINT index, UINT offset, LPVOID data, UINT size);
- // 填充一个块
- P2P_RETURN_TYPE PutIndexData(UINT index, LPVOID data, UINT size);
- public:
- static BOOL ExCreateFile(HANDLE&, LPCTSTR lpFileName, DWORD dwDesiredAccess,
- DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
- DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
- HANDLE hTemplateFile);
- static BOOL ExCreateFile(HANDLE&, LPCTSTR lpFileName, DWORD dwCreationDisposition);
- static UINT ExReadFile(HANDLE, LPVOID buf, UINT toBeRead);
- static UINT ExWriteFile(HANDLE, LPCVOID buf, UINT toBeWrite);
- static BOOL ExSetFilePointer(HANDLE, UINT offset);
- static BOOL ExSetFileSize(HANDLE, UINT size);
- static BOOL GetSelfModulePath(LPTSTR buf, DWORD nSize);
- private:
- enum {
- // 默认缓冲文件大小24MB
- BUFFER_SPACE = 1048576*24,
- };
- // 缓冲文件的句柄
- HANDLE hBufferFile;
- // 缓冲文件名
- string bufferFileName;
- // 缓冲文件大小
- UINT bufferFileSize;
- // 记录缓冲文件的使用情况,按分块
- bool* blockArray;
- // 缓冲文件的分块个数
- UINT blockNum;
- };
- }
- #endif