/// \brief
 ///   Assignment operator. Deep copies the buffer.
 inline IVConstantBuffer &operator = (const IVConstantBuffer &other)
 {
   AllocateBuffer(other.m_iFirstRegister,other.m_iAllocatedEntries);
   if (m_iAllocatedEntries>0)
     memcpy(m_pBuffer,other.m_pBuffer,GetByteCount());
   m_spTable = ((IVConstantBuffer &)other).m_spTable; ///< no assignment operator!
   return *this;
 }
示例#2
0
CVoiceDataPacket::CVoiceDataPacket ( void )
{
    m_pBuffer = NULL;
    m_usDataBufferSize = 0;
    m_usActualDataLength = 0;

    AllocateBuffer ( 1024 );
}
示例#3
0
static ParserObjectRecordT* parseObjRecord1(ParserObjectRecordT* parent)
{
    ParserObjectT* curObj;
    ParserObjectRecordT *res, *tmp;
    int wasEnd = 0;
    int i;
    res = AllocateBuffer(sizeof(ParserObjectRecordT));
    res->n = 0; res->seq = 0; res->parent = parent;

    while ((curObj = parseNextObject(res))) {
        if (curObj->objKind == PARSER_OBJECT_KIND_END) {
            if (!parent) {
                genParseError(E_UNEXPECTED_END);
            } else {
                objDestructor(curObj);
                wasEnd = 1;
            }
            break;
        }
        res->n++;
        tmp = AllocateBuffer(sizeof(ParserObjectRecordT));
        tmp->seq = AllocateArray(res->n, sizeof(ParserObjectT));
        for (i = 0; i < res->n - 1; i++) {
            copyObjToObj(tmp->seq + i, res->seq + i);
            tmp->seq[i].parent = tmp;
            if (tmp->seq[i].objKind == PARSER_OBJECT_KIND_SEQUENCE) tmp->seq[i].rec->parent = tmp;
        }
        tmp->parent = res->parent; tmp->n = res->n;
        res->n--; ParserDestroyObjectRecord(res);
        copyObjToObj(tmp->seq + tmp->n - 1, curObj);
        tmp->seq[tmp->n - 1].parent = tmp;
        if (tmp->seq[tmp->n - 1].objKind == PARSER_OBJECT_KIND_SEQUENCE)
            tmp->seq[tmp->n - 1].rec->parent = tmp;
        res = tmp;
        objDestructor(curObj);
    }

    if (!wasEnd && parent) {
        genParseError(E_END_EXPECTED);
    }

    if (ParserIsErrorRaised()) {ParserDestroyObjectRecord(res); return 0;}
    return res;
}
示例#4
0
static void allocWithCopyExpr(struct expr** a, struct expr* b)
{
    if (!b) {*a = 0; return;}
    *a = AllocateBuffer(sizeof(struct expr));
    (*a)->intConst = b->intConst;
    (*a)->opCode = b->opCode;
    allocWithCopyStr(&((*a)->varName), b->varName);
    allocWithCopyExpr(&((*a)->op1), b->op1);
    allocWithCopyExpr(&((*a)->op2), b->op2);
}
uint8_t*
PlanarYCbCrImage::AllocateAndGetNewBuffer(uint32_t aSize)
{
  // update buffer size
  mBufferSize = aSize;

  // get new buffer
  mBuffer = AllocateBuffer(mBufferSize); 
  return mBuffer;
}
示例#6
0
BOOL CIOCPServer::SendText(CIOCPContext *pContext, char *pszText, int nLen)
{
	CIOCPBuffer *pBuffer = AllocateBuffer(nLen);
	if(pBuffer != NULL)
	{
		memcpy(pBuffer->buff, pszText, nLen);
		return PostSend(pContext, pBuffer);
	}
	return FALSE;
}
int main(int argc, char *argv[])
{
	assert(argc == 2);
	char * outFileName = argv[1];
	FILE *outFile = fopen(outFileName, "w");
	
	
	int dtFlyPinitStatus = InitDevice(userIntHandler);
	assert(dtFlyPinitStatus == 0);	
	int status;
/*	
	uint32_t regData[1];
	uint32_t regAddress = 513;
	
	// Read, write, then read again register 0
	// ReadWriteConfigRegs(direction, registerNumber, registerDataBuffer, numberOfRegisters)
	status = ReadWriteConfigRegs(READ, regAddress, regData, 1);
	printf("Read status is %d, value is %08lx\n", status, regData[0]);

	regData[0] = 0x12345678;
	status = ReadWriteConfigRegs(WRITE, regAddress, regData, 1);
	printf("Write status is %d\n", status);

	status = ReadWriteConfigRegs(READ, regAddress, regData, 1);
	printf("Read status is %d, value is %08lx\n", status, regData[0]);

	*/
	
	/*
	 * Read and dump to file
	 */ 
	SBufferInit buffer;
	unsigned bufferIndex = 0;
	AllocateBuffer(bufferIndex, &buffer);
	
	for(int nReads = 0; nReads < 10; nReads += 1) {
		status = ReceiveDMAbyBufIndex(DMA1, bufferIndex, 1);
		if(status > 0) {
			uint64_t *wordBuffer = (uint64_t *)buffer.UserAddr;
			int nWords = status / sizeof(uint64_t);
			
			for(int i = 0; i < nWords; i++) {
				fprintf(outFile, "%016llx\n", wordBuffer[i]);
			}
		}
	}	
	ReleaseBuffer(bufferIndex);	
	
	
	
	ReleaseDevice();
	fclose(outFile);
	return 0;
}
示例#8
0
static char* getSubString(const char* string, size_t left, size_t right)
{
    char* substr = NULL;
    if (right >= left) {
        size_t len = right - left;
        substr = AllocateBuffer(len + 2);
        substr[0] = 0;
        strncat(substr, string + left, len + 1);
    }
    return substr;
}
示例#9
0
文件: RingBuffer.cpp 项目: Lingrui/TS
RingBuffer<T>::RingBuffer(int numBuf, int bufSize):
   _numBuffers(numBuf), _bufSize(bufSize)
{
  AllocateBuffer();
  _readPos = 0;
  _writePos = 0;

  pthread_mutex_init(&_lock, NULL);
  pthread_cond_init(&_rdcond, NULL);
  pthread_cond_init(&_wrcond, NULL);
}
示例#10
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	AUInputElement::SetInputCallback
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void	AUInputElement::SetInputCallback(AURenderCallback proc, void *refCon)
{
	if (proc == NULL)
		Disconnect();
	else {
		mInputType = kFromCallback;
		mInputProc = proc;
		mInputProcRefCon = refCon;
		AllocateBuffer();
	}
}
示例#11
0
void BPFlow::AllocateMessage()
{
	// delete the buffers for the messages
	for(int i=0;i<2;i++)
	{
		_Release1DBuffer(pSpatialMessage[i]);
		_Release1DBuffer(ptrSpatialMessage[i]);
		_Release1DBuffer(pDualMessage[i]);
		_Release1DBuffer(ptrDualMessage[i]);
		_Release1DBuffer(pBelief[i]);
		_Release1DBuffer(ptrBelief[i]);
	}
	// allocate the buffers for the messages
	for(int i=0;i<2;i++)
	{
		nTotalSpatialElements[i]=AllocateBuffer(pSpatialMessage[i],nNeighbors,ptrSpatialMessage[i],pWinSize[i]);
		nTotalDualElements[i]=AllocateBuffer(pDualMessage[i],1,ptrDualMessage[i],pWinSize[i]);
		nTotalBelifElements[i]=AllocateBuffer(pBelief[i],1,ptrBelief[i],pWinSize[i]);
	}
}
示例#12
0
static char* parseSingleToken(int tokenType)
{
    char* res = NULL;
    if (curToken && curToken->type == tokenType) {
        res = AllocateBuffer(strlen(curToken->str) + 1);
        strcpy(res, curToken->str);
        moveToNextToken();
    } else {
        genParseError(E_UNEXPECTED_TOKEN);
    }
    return res;
}
示例#13
0
	void VolumePassword::Set (const byte *password, size_t size)
	{
		AllocateBuffer ();
		
		if (size > MaxSize)
			throw PasswordTooLong (SRC_POS);
		
		PasswordBuffer.CopyFrom (ConstBufferPtr (password, size));
		PasswordSize = size;

		Unportable = !IsPortable();
	}
示例#14
0
D3DStreamBuffer::D3DStreamBuffer(size_t initial_size, size_t max_size, bool* buffer_reallocation_notification) :
	m_buffer_size(initial_size),
	m_buffer_max_size(max_size),
	m_buffer_reallocation_notification(buffer_reallocation_notification)
{
	CHECK(initial_size <= max_size, "Error: Initial size for D3DStreamBuffer is greater than max_size.");

	AllocateBuffer(initial_size);

	// Register for callback from D3DCommandListManager each time a fence is queued to be signaled.
	m_buffer_tracking_fence = D3D::command_list_mgr->RegisterQueueFenceCallback(this, &D3DStreamBuffer::QueueFenceCallback);
}
示例#15
0
void CVoiceDataPacket::SetData ( const unsigned char * pbSrcBuffer, unsigned short usLength )
{
    // Allocate new buffer.
    AllocateBuffer ( usLength );

    // Copy in the data.
    if ( m_pBuffer )
    {
        memcpy ( m_pBuffer, pbSrcBuffer, usLength );
        m_usActualDataLength = usLength;
    }
}
示例#16
0
BOOL CIOCPServer::SendText(CIOCPContext *pContext, char *pszText, int nLen)
{
	CIOCPBuffer *pBuffer = AllocateBuffer(nLen);
	if(pBuffer != NULL)
	{
		memcpy(pBuffer->buff, pszText, nLen);
		if (PostSend(pContext, pBuffer))
			return true;
  	    ReleaseBuffer(pBuffer);
	}
	return false;
}
示例#17
0
Connection* NewConnection(BufferPool* pool, Address* address, bool freeAddress) {
    Connection* connection = NULL;

    if ((connection = aio4c_malloc(sizeof(Connection))) == NULL) {
        return NULL;
    }


    connection->readBuffer = AllocateBuffer(pool);
    connection->writeBuffer = AllocateBuffer(pool);
    BufferLimit(connection->writeBuffer, 0);
    connection->dataBuffer = NULL;
    connection->socket = -1;
    connection->state = AIO4C_CONNECTION_STATE_NONE;
    connection->stateLock = NewLock();
    connection->systemHandlers = NewEventQueue();
    connection->userHandlers = NewEventQueue();
    connection->address = address;
    connection->closedForError = false;
    connection->string = AddressGetString(address);
    connection->stringAllocated = false;
    memset(connection->closedBy, 0, AIO4C_CONNECTION_OWNER_MAX * sizeof(bool));
    connection->closedBy[AIO4C_CONNECTION_OWNER_ACCEPTOR] = true;
    connection->closedByLock = NewLock();
    memset(connection->managedBy, 0, AIO4C_CONNECTION_OWNER_MAX * sizeof(bool));
    connection->managedBy[AIO4C_CONNECTION_OWNER_ACCEPTOR] = true;
    connection->managedBy[AIO4C_CONNECTION_OWNER_CLIENT] = true;
    connection->managedByLock = NewLock();
    connection->readKey = NULL;
    connection->writeKey = NULL;
    connection->pool = NULL;
    connection->freeAddress = freeAddress;
    connection->dataFactory = NULL;
    connection->dataFactoryArg = NULL;
    connection->canRead = false;
    connection->canWrite = false;
    connection->isFactory = false;

    return connection;
}
HRESULT
SoundD3D::StreamOggFile()
{
	DWORD buf_size    = wfex.nAvgBytesPerSec / 2;
	DWORD safety_zone = buf_size * 2;

	if (stream) {
		delete[] transfer;
		fclose(stream);

		transfer = 0;
		stream   = 0;
	}

	status         = UNINITIALIZED;
	stream_left    = (DWORD) ov_pcm_total(ov_file,-1);
	stream_offset  = 0;

	eos_written    = false;
	eos_latch      = 0;
	min_safety     = safety_zone;
	read_size      = buf_size;

	total_time     = (double) stream_left /
	(double) wfex.nAvgBytesPerSec;

	if (stream_left < read_size) {
		read_size = stream_left;
	}

	HRESULT hr = AllocateBuffer(read_size + min_safety);

	if (FAILED(hr))
	return hr;

	flags |= STREAMED | OGGVORBIS;

	// preload the buffer:
	w = r = 0;
	transfer = new(__FILE__,__LINE__) BYTE[read_size + 1024];

	if (!transfer) {
		hr = E_FAIL;
	}

	else {
		ZeroMemory(transfer, read_size+1024);
		StreamOggBlock();
	}

	return hr;
}
示例#19
0
BOOL SecureChatIOCP::SendTextMessageTo(ClientContext* pContext, CString sMsg)
{

	if ( !pContext->m_bGotSessionKey )
	{
		//AppendLog("Client is not authorized");
		return FALSE;
	}

	UINT nBufLen = sMsg.GetLength();
	// Add one to the size header for the null termination byte. 
	nBufLen++;
	// Add one for the Payload type (text)
	nBufLen++;

	if ( nBufLen>=MaxEncyptedPayloadSize(MAXIMUMPAYLOADSIZE-2) )
	{
		AppendLog("SendMessageTo FAILED Message to long for encryption..");
		return FALSE;
	}

	if ( nBufLen>=MAXIMUMPAYLOADSIZE || nBufLen<=0 )
	{
		AppendLog("SendMessageTo FAILED Message to long or zero..");
		return FALSE;
	}

	CIOCPBuffer *pBuff=AllocateBuffer(IOWrite);

	if ( !pBuff )
	{
		AppendLog("SendMessageTo FAILED pOverlapBuff=NULL");
		return FALSE;
	}

	pBuff->EmptyUsed();
	// Size Header
	pBuff->AddData(nBufLen);
	// Payload Header 
	pBuff->AddData((BYTE)PKG_TEXT_TO_ALL);
	// Add the string. 
	int length=sMsg.GetLength();
	pBuff->AddData((PBYTE) sMsg.GetBuffer(length),length);
	//Extra Null Teriminate (for Strings) 
	pBuff->AddData((BYTE)'\0');
	// Encrypt the buffer
	pBuff=EnCryptBuffer(pBuff,pContext);
	// Send it. 
	ASend(pContext,pBuff);
	return TRUE;

}
示例#20
0
void CMatlabEngine::ProcessString( LPCTSTR szName, BSTR& bstrName)
{
	::SysFreeString(bstrName);

#ifndef _UNICODE
	int nChar;
	AllocateBuffer(_tcslen(szName));
	nChar=MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,szName,-1,m_pBuffer,m_uBufferSize);
	bstrName = ::SysAllocString(m_pBuffer);
#else
	bstrName = ::SysAllocString(OLESTR(szName));
#endif
}
HRESULT
SoundD3D::Load(DWORD bytes, BYTE* data)
{
	status = UNINITIALIZED;

	HRESULT hr;

	if (!buffer) {
		hr = AllocateBuffer(bytes);
		if (FAILED(hr)) {
			return hr;
		}
	}

	LPVOID   dest1, dest2;
	DWORD    size1, size2;

	hr = buffer->Lock(w, bytes, &dest1, &size1, &dest2, &size2, 0);

	if (hr == DSERR_BUFFERLOST) {
		buffer->Restore();
		hr = buffer->Lock(w, bytes, &dest1, &size1, &dest2, &size2, 0);
	}

	if (SUCCEEDED(hr)) {
		CopyMemory(dest1, data, size1);
		if (dest2) {
			CopyMemory(dest2, data + size1, size2);
		}

		if (flags & STREAMED)
		w = (w + size1 + size2) % (read_size + min_safety);
		else
		w += size1 + size2;

		hr = buffer->Unlock(dest1, size1, dest2, size2);
		if (FAILED(hr)) {
			SoundD3DError("Load: could not unlock buffer", hr);
		}
	}
	else {
		SoundD3DError("Load: could not lock buffer", hr);
	}

	if (SUCCEEDED(hr)) {
		status = READY;
	}

	return hr;
}
示例#22
0
void SecureChatIOCP::BuildAndSend(ClientContext *pContext, BYTE _pkgtype, UINT nBufferSize1,const BYTE *_pBuff1, UINT nBufferSize2, const BYTE *_pBuff2)
{

	if ( !pContext->m_bGotSessionKey )
	{
		AppendLog("BuildAndSend FAILED, no Session key..");
		return;
	}

	UINT nPayLoadLen=sizeof(BYTE)+sizeof(UINT)+nBufferSize1+sizeof(UINT)+nBufferSize2+2; // two null termination. 

	if ( nPayLoadLen > MAXIMUMPAYLOADSIZE)
	{
		AppendLog("BuildAndSend FAILED, nPayLoadLen > MAXIMUMPAYLOADSIZE");
		return;
	}

	if ( nPayLoadLen > MaxEncyptedPayloadSize(MAXIMUMPAYLOADSIZE-1) )
	{
		AppendLog("BuildAndSend FAILED, nPayLoadLen > MaxEncyptedPayloadSize");
		return;  
	}


	CIOCPBuffer *pBuff=AllocateBuffer(IOWrite);
	if ( !pBuff )
	{
		AppendLog("BuildAndSend FAILED pBuff=NULL");
		return;
	}

	pBuff->EmptyUsed();
	// Size Header
	pBuff->AddData(nPayLoadLen);
	// Payload type 
	pBuff->AddData((BYTE)_pkgtype);
	// The size of the buffer
	pBuff->AddData(nBufferSize1);	
	// add the buffer. 
	pBuff->AddData(_pBuff1,nBufferSize1);
	pBuff->AddData((BYTE)0);
	// The size of the buffer
	pBuff->AddData(nBufferSize2);	
	// add the buffer. 
	pBuff->AddData(_pBuff2,nBufferSize2);
	pBuff->AddData((BYTE)0);
	// Encrypt the data.. 
	pBuff=EnCryptBuffer(pBuff,pContext);
	ASend(pContext,pBuff);
}
示例#23
0
static void allocWithCopyObjRecord(ParserObjectRecordT** a, ParserObjectRecordT* b)
{
    int i;
    if (!b) {*a = 0; return;}
    *a = AllocateBuffer(sizeof(ParserObjectRecordT));
    (*a)->n = b->n;
    (*a)->parent = b->parent;
    (*a)->seq = AllocateArray(b->n, sizeof(ParserObjectT));
    for (i = 0; i < b->n; i++) {
        copyObjToObj((*a)->seq + i, b->seq + i);
        (*a)->seq[i].parent = *a;
        if ((*a)->seq[i].objKind == PARSER_OBJECT_KIND_SEQUENCE) (*a)->seq[i].rec->parent = *a;
    }
}
示例#24
0
void* DiGLTextureDrv::LockLevel(uint32 level, uint32 surface, DiLockFlag lockflag)
{
    DiBox lockbox(0, 0, mBuffer->GetWidth(), mBuffer->GetHeight());

    AllocateBuffer();

    mCurrentLockFlag = lockflag;
    if (lockflag != LOCK_DISCARD)
    {
        Download(*mBuffer, level, surface);
    }

    return mBuffer->data;
}
示例#25
0
文件: Mime.cpp 项目: SeekingFor/FMS
// initialize the content with text
int CMimeBody::SetText(const char* pbText, int nLength/*=0*/)
{
	ASSERT(pbText != NULL);
	if (!nLength)
		nLength = (int)::strlen((char*)pbText);

	if (!AllocateBuffer(nLength+4))
		return -1;

	::memcpy(m_pbText, pbText, nLength);
	m_pbText[nLength] = 0;
	m_nTextSize = nLength;
	return nLength;
}
示例#26
0
static ParserObjectT* parseNextObject(ParserObjectRecordT* curSeq)
{
    ParserObjectKindT objKind;
    ParserObjectT* res;
    ParserObjectAttrT* attrList;
    char* name;
    ParserObjectRecordWithDataT tmp;

    if (!curToken) return NULL;
    if (curToken->type != ttObject) {
        genParseError(E_OBJECT_KIND_EXPECTED);
        return NULL;
    }
    objKind = curToken->value;
    moveToNextToken();

    attrList = parseAttrList(objKind, curSeq);

    if (attrList) {
        name = attrList[PARSER_OBJECT_ATTR_NAME].strVal;
        if (name) { // if name doesn't exist, than it's unnamed objKind
            tmp.pointerToData = 0; tmp.recPart = curSeq;
            if (ParserFindObject(name, tmp, 0).objPart) {
                genParseError(E_DUPLICATE_OBJECT);
                attrListDestructor(attrList);
                return NULL;
            }
        }
    }

    if (attrList ||
        objKind == PARSER_OBJECT_KIND_END ||
        objKind == PARSER_OBJECT_KIND_NEWLINE ||
        objKind == PARSER_OBJECT_KIND_SOFTLINE)
    {
            res = AllocateBuffer(sizeof(ParserObjectT));
            res->attrList = attrList; res->objKind = objKind;
            if (objKind == PARSER_OBJECT_KIND_SEQUENCE) {
                res->rec = parseObjRecord1(curSeq);
                if (!res->rec) {objDestructor(res); return 0;}
            } else res->rec = 0;
            if (ParserIsErrorRaised()) {objDestructor(res); return 0;}
            //res->parent = curSeq;  <- curSeq will reallocate anyway
            return res;
    }

    genParseError(E_INVALID_ATTRIBUTE_LIST);
    return NULL;
}
示例#27
0
void
AnalyserNode::SetFftSize(uint32_t aValue, ErrorResult& aRv)
{
  // Disallow values that are not a power of 2 and outside the [32,2048] range
  if (aValue < 32 ||
      aValue > 2048 ||
      (aValue & (aValue - 1)) != 0) {
    aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
    return;
  }
  if (FftSize() != aValue) {
    mAnalysisBlock.SetFFTSize(aValue);
    AllocateBuffer();
  }
}
int MightyTCPCompletionPortServer::InsertSocketObj(PCompletionPortIOObject pSocket)
{

		//GUID guid_val;
		string guid_strkey=P2PUtilTools::GetStringUuid();
		pSocket->identityIDKey=guid_strkey;
		m_ActiveSocketMap.insert(map<string,PCompletionPortIOObject>::value_type(guid_strkey,pSocket));
		//nSocketCount++;
		PCompletionPort_BufObj pIOBuf=AllocateBuffer(pSocket,4096);
		PostRecv(pIOBuf);
		m_pNotifyCallBack->OnAccept(guid_strkey);
		return 0;

	
}
示例#29
0
   // initialize the content of this body part with a mail message
   bool MimeBody::SetMessage(const MimeBody* pMM)
   {
      ASSERT(pMM != NULL);
      int nSize = pMM->GetLength();
      if (!AllocateBuffer(nSize+4))
         return false;

      pMM->Store(m_pbText);

      const char* pszType = GetContentType();
      if (!pszType || ::_memicmp(pszType, "message", 7) != 0)
         SetContentType("message/rfc822", "");

      return true;
   }
示例#30
0
void autoGenInt(ParserObjectWithDataT info)
{
    int64_t l, r, tmp;
    if (info.objPart->objKind != PARSER_OBJECT_KIND_INTEGER) {
        genParseError(E_GENERATE_NON_INT);
        return;
    }
    if (!info.pointerToData->value) {
        ParserEvaluateIntRange(info, &l, &r);
        if (ParserIsErrorRaised()) return;
        tmp = GenerateRandInt(l, r);
        info.pointerToData->value = AllocateBuffer(sizeof(tmp));
        memcpy(info.pointerToData->value, &tmp, sizeof(tmp));
    }
}