コード例 #1
0
ファイル: OnlineStateFilterI.cpp プロジェクト: goby/oce
ByteSeq OnlineStateFilterManagerI::getOnlineStateMinMax(int min, int max, const Ice::Current& current) {
    MCE_INFO("OnlineStateFilterManagerI::getOnlineStateMinMax -> min: "<<min << " max: "<<max
             << " " << current.con->toString().substr(current.con->toString().find("remote", 25)));
    ByteSeq result;
    if (max <= min) {
        MCE_WARN("OnlineStateFilterManagerI::getOnlineStateMinMax -> min >= max");
        return result;
    }
    int n=(max-min)/8;
    MCE_DEBUG("OnlineStateFilterManagerI::getOnlineStateMinMax -> n: "<<n);
    for (int i=0; i<n; i++) {
        result.push_back(Ice::Byte());
    }
    for(int i = min; i < max; ++i) {
        if (_online_state[i]) {
            result[(i-min)/8]|=(1<<(i-min)%8);
        }
    }
    MCE_DEBUG("OnlineStateFilterManagerI::getOnlineStateMinMax -> size: "<<result.size());
    return result;
}
コード例 #2
0
ファイル: StatusCacheI.cpp プロジェクト: bradenwu/oce
ByteSeq StatusCacheManagerI::getStatusMinMax(int min, int max, const Ice::Current& current){

	ostringstream inMsg;
	inMsg<<"StatusCacheManagerI::getStatusMinMax min: " <<min << " max: "<< max << " " << current.con->toString().substr(current.con->toString().find("remote",25));
	TimeCost tc = TimeCost::create(inMsg.str(), TimeCost::LOG_LEVEL_INFO);
	
	ByteSeq result;
	if (max <= min) {
		MCE_WARN("StatusCacheManagerI::getStatusMinMax -> min >= max");
		return result;
	}
	int n=(max-min)/8;
	MCE_DEBUG("StatusCacheManagerI::getStatusMinMax -> n: "<<n);
	for (int i=0;i<n;i++){
		result.push_back(Ice::Byte());
	}
	for(int i = min; i < max; ++i) {
		if (_status[i]) {
			result[(i-min)/8]|=(1<<(i-min)%8);
		}
	}
	MCE_DEBUG("StatusCacheManagerI::getStatusMinMax -> size: "<<result.size());
	return result;
}
コード例 #3
0
ファイル: ClientUtil.cpp プロジェクト: sbesson/zeroc-ice
bool
IcePatch2::Patcher::updateFilesInternal(const FileInfoSeq& files, const DecompressorPtr& decompressor)
{
    Long total = 0;
    Long updated = 0;
    
    for(FileInfoSeq::const_iterator p = files.begin(); p != files.end(); ++p)
    {
        if(p->size > 0) // Regular, non-empty file?
        {
            total += p->size;
        }
    }
    
    AsyncResultPtr curCB;
    AsyncResultPtr nxtCB;

    for(FileInfoSeq::const_iterator p = files.begin(); p != files.end(); ++p)
    {
        if(p->size < 0) // Directory?
        {
            createDirectoryRecursive(_dataDir + '/' + p->path);
            if(fputc('+', _log) == EOF || !writeFileInfo(_log, *p))
            {
                throw "error writing log file:\n" + IceUtilInternal::lastErrorToString();
            }
        }
        else // Regular file.
        {
            if(!_feedback->patchStart(p->path, p->size, updated, total))
            {
                return false;
            }

            if(p->size == 0)
            {
                string path = simplify(_dataDir + '/' + p->path);
                FILE* fp = IceUtilInternal::fopen(path, "wb");
                if(fp == 0)
                {
                    throw "cannot open `" + path +"' for writing:\n" + IceUtilInternal::lastErrorToString();
                }
                fclose(fp);
            }
            else
            {
                string pathBZ2 = simplify(_dataDir + '/' + p->path + ".bz2");
            
                string dir = getDirname(pathBZ2);
                if(!dir.empty())
                {
                    createDirectoryRecursive(dir);
                }
                
                try
                {
                    removeRecursive(pathBZ2);
                }
                catch(...)
                {
                }
                
                FILE* fileBZ2 = IceUtilInternal::fopen(pathBZ2, "wb");
                if(fileBZ2 == 0)
                {
                    throw "cannot open `" + pathBZ2 + "' for writing:\n" + IceUtilInternal::lastErrorToString();
                }

                try
                {
                    Int pos = 0;

                    while(pos < p->size)
                    {
                        if(!curCB)
                        {
                            assert(!nxtCB);
                            curCB = _serverNoCompress->begin_getFileCompressed(p->path, pos, _chunkSize);
                        }
                        else
                        {
                            assert(nxtCB);
                            swap(nxtCB, curCB);
                        }

                        if(pos + _chunkSize < p->size)
                        {
                            nxtCB = _serverNoCompress->begin_getFileCompressed(p->path, pos + _chunkSize, _chunkSize);
                        }
                        else
                        {
                            FileInfoSeq::const_iterator q = p + 1;

                            while(q != files.end() && q->size <= 0)
                            {
                                ++q;
                            }

                            if(q != files.end())
                            {
                                nxtCB = _serverNoCompress->begin_getFileCompressed(q->path, 0, _chunkSize);
                            }
                        }

                        ByteSeq bytes;

                        try
                        {
                            bytes = _serverNoCompress->end_getFileCompressed(curCB);
                        }
                        catch(const FileAccessException& ex)
                        {
                            throw "error from IcePatch2 server for `" + p->path + "': " + ex.reason;
                        }

                        if(bytes.empty())
                        {
                            throw "size mismatch for `" + p->path + "'";
                        }

                        if(fwrite(reinterpret_cast<char*>(&bytes[0]), bytes.size(), 1, fileBZ2) != 1)
                        {
                            throw ": cannot write `" + pathBZ2 + "':\n" + IceUtilInternal::lastErrorToString();
                        }

                        pos += static_cast<int>(bytes.size());
                        updated += bytes.size();

                        if(!_feedback->patchProgress(pos, p->size, updated, total))
                        {
                            fclose(fileBZ2);
                            return false;
                        }
                    }
                }
                catch(...)
                {
                    fclose(fileBZ2);
                    throw;
                }
                
                fclose(fileBZ2);
                
                decompressor->log(_log);
                decompressor->add(*p);
            }
            
            if(!_feedback->patchEnd())
            {
                return false;
            }
        }
    }

    FileInfoSeq newLocalFiles;
    newLocalFiles.reserve(_localFiles.size());
        
    set_union(_localFiles.begin(),
              _localFiles.end(),
              files.begin(),
              files.end(),
              back_inserter(newLocalFiles),
              FileInfoLess());
        
    _localFiles.swap(newLocalFiles);

    FileInfoSeq newUpdateFiles;

    set_difference(_updateFiles.begin(),
                   _updateFiles.end(),
                   files.begin(),
                   files.end(),
                   back_inserter(newUpdateFiles),
                   FileInfoLess());
        
    _updateFiles.swap(newUpdateFiles);

    return true;
}
コード例 #4
0
ファイル: UserStateFilterI.cpp プロジェクト: bradenwu/oce
ByteSeq UserStateFilterManagerI::getStateGuideMinMax(int min, int max, const Ice::Current& current){
	ByteSeq result;
	if (max <= min) {
		MCE_WARN("UserStateFilterManagerI::getStateGuideMinMax -> min >= max"
                	<< " " << current.con->toString().substr(current.con->toString().find("remote", 25)));
		return result;
	}
	int n=(max-min)/8;
	for (int i=0;i<n;i++){
		result.push_back(Ice::Byte());
	}
	for(int i = min; i < max; ++i) {
		if (_user_state_guide[i]) {
			result[(i-min)/8]|=(1<<(i-min)%8);
		}
	}
	MCE_INFO("UserStateFilterManagerI::getStateGuideMinMax -> min: "<<min << " max: "<<max<<" size:"<<result.size()
                << " " << current.con->toString().substr(current.con->toString().find("remote", 25)));
	return result;
}