Exemple #1
0
	void CFileReceiver::_dealWithReceivedFile(TProxyPtr sender,TFileRequestPtr theRequest,const NLNET::TBinBuffer& data)
	{
		// log progress..
		_clearDownloadLog(theRequest->FileName);
		_log("receivedFile: "+theRequest->FileName+NLMISC::toString("(%d bytes)",data.getBufferSize()));

		// call the user callback for the file data
		NLMISC::CMemStream memStream;
		memStream.fill(data.getBuffer(),data.getBufferSize());
		memStream.invert();
		cbFileDownloadSuccess(theRequest->FileName,memStream);

		// look for the proxy record for the emitter
		TProxies::iterator pit= _Proxies.find(sender);
		BOMB_IF(pit==_Proxies.end(),"ERROR: Failed to identify the sender for the received file: "+theRequest->FileName,return);

		// liberate this request
		for (TFileRequests::iterator fit=_FileRequests.begin(); fit!=_FileRequests.end();++fit)
		{
			if (*fit==theRequest)
			{
				_FileRequests.erase(fit);
				break;
			}
		}

		// cleanup the emitter
		pit->second.CurrentRequest= NULL;

		// look for a new job for the sender
		_lookForNewJob(pit->second);
	}
	// ***************************************************************************
	CInterfaceElement *CInterfaceElement::clone()
	{
		NLMISC::CMemStream dupStream;
		nlassert(!dupStream.isReading());
		CInterfaceGroup *oldParent = _Parent;
		_Parent = NULL;
		CInterfaceElement *oldParentPos = _ParentPos;
		CInterfaceElement *oldParentSize = _ParentSize;
		if (_ParentPos == oldParent) _ParentPos = NULL;
		if (_ParentSize == oldParent) _ParentSize = NULL;
		CInterfaceElement *begunThisCloneWarHas = NULL;
		try
		{
			if (dupStream.isReading())
			{
				dupStream.invert();
			}
			CInterfaceElement *self = this;
			dupStream.serialPolyPtr(self);
			std::vector<uint8> datas(dupStream.length());
			std::copy(dupStream.buffer(), dupStream.buffer() + dupStream.length(), datas.begin());
			dupStream.resetPtrTable();
			dupStream.invert();
			dupStream.fill(&datas[0], (uint32)datas.size());
			dupStream.serialPolyPtr(begunThisCloneWarHas);
		}
		catch(const NLMISC::EStream &)
		{
			// no-op -> caller has to handle the failure because NULL will be returned
		}
		//
		_Parent		  = oldParent;
		_ParentPos	  = oldParentPos;
		_ParentSize	  = oldParentSize;
		//
		return begunThisCloneWarHas;
	}
Exemple #3
0
static T	*DupSerializable(const T *in) throw(NLMISC::EStream)
{
	NLMISC::CMemStream ms;
	nlassert(!ms.isReading());
	T *nonConstIn = const_cast<T *>(in);
	TSerializePolicy::serial(nonConstIn, ms);
	std::vector<uint8> datas(ms.length());
	std::copy(ms.buffer(), ms.buffer() + ms.length(), datas.begin());
	ms.resetPtrTable();
	ms.invert();
	ms.fill(&datas[0], (uint)datas.size());
	nlassert(ms.isReading());
	T *newObj = NULL;
	TSerializePolicy::serial(newObj, ms);
	return newObj;
}