1 Star 0 Fork 121

blog/kbengine

forked from likecg/kbengine 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
data_downloads.cpp 2.66 KB
一键复制 编辑 原始数据 按行查看 历史
liquidx 提交于 2013-01-23 15:53 +08:00 . 对部分cpp加入license。
/*
This source file is part of KBEngine
For the latest info, see http://www.kbengine.org/
Copyright (c) 2008-2012 KBEngine.
KBEngine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
KBEngine 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "baseapp.hpp"
#include "data_download.hpp"
#include "data_downloads.hpp"
namespace KBEngine{
//-------------------------------------------------------------------------------------
DataDownload * DataDownloadFactory::create(DataDownloadType dltype, PyObjectPtr objptr,
const std::string & desc, int16 id)
{
switch(dltype)
{
case DATA_DOWNLOAD_STREAM_STRING:
return new StringDataDownload(objptr, desc, id);
case DATA_DOWNLOAD_STREAM_FILE:
return new FileDataDownload(objptr, desc, id);
default:
break;
};
return NULL;
}
//-------------------------------------------------------------------------------------
DataDownloads::DataDownloads():
downloads_(),
usedIDs_()
{
}
//-------------------------------------------------------------------------------------
DataDownloads::~DataDownloads()
{
}
//-------------------------------------------------------------------------------------
int16 DataDownloads::freeID(int16 id)
{
if(id > 0 && usedIDs_.find(id) != usedIDs_.end())
return id;
for(int16 i=2; i< 32767; i++)
{
if(usedIDs_.find(id + i) == usedIDs_.end())
return id + i;
}
return id;
}
//-------------------------------------------------------------------------------------
int16 DataDownloads::pushDownload(DataDownload* pdl)
{
pdl->id(freeID(pdl->id()));
usedIDs_.insert(pdl->id());
downloads_[pdl->id()] = pdl;
pdl->pDataDownloads(this);
Baseapp::getSingleton().threadPool().addTask(pdl);
return pdl->id();
}
//-------------------------------------------------------------------------------------
void DataDownloads::onDownloadCompleted(DataDownload* pdl)
{
INFO_MSG(boost::format("DataDownloads::onDownloadCompleted: proxy(%1%), downloadID(%2%), type(%4%), sentTotalBytes=%3%.\n") %
pdl->entityID() % pdl->id() % pdl->totalBytes() % pdl->type());
downloads_.erase(pdl->id());
usedIDs_.erase(pdl->id());
}
//-------------------------------------------------------------------------------------
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/blog/kbengine.git
git@gitee.com:blog/kbengine.git
blog
kbengine
kbengine
a1b691f57f98fa0bff1bcfb0210ebd07e318c0cd

搜索帮助