本文整理汇总了C++中CBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ CBuffer类的具体用法?C++ CBuffer怎么用?C++ CBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onBufferReceived
/**
* Callback that should be invoked when the data is received
*/
void CNaviReceiverProfileImpl::onBufferReceived(const tChannelId channel, CBuffer const& buffer)
{
LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__);
UInt8 *incomingData = buffer.getBuffer();
int read_size = buffer.getSize();
std::string json((char*)incomingData, read_size);
LOG4CPLUS_TRACE(msLogger, "got string:");
LOG4CPLUS_TRACE(msLogger, json);
Json::Value root; // will contain the root value after parsing.
Json::Reader reader;
bool parsingSuccessful = reader.parse(json.c_str(), root);
if (parsingSuccessful) {
std::deque<std::string> tracks;
Json::Value list=root["play"];
Json::Value::UInt index=0;
LOG4CPLUS_TRACE(msLogger, "tracks to play:");
for(index=0;index<list.size();index++){
LOG4CPLUS_TRACE(msLogger, list[index].asString());
tracks.push_back(list[index].asString());
}
mpAppCallbacks->playTracks(tracks);
} else {
LOG4CPLUS_ERROR(msLogger, "Failed to parse tracklist!");
}
}
示例2: ASSERT
void CSelection::GetCaretRect( CEditView *pView, int nBuffCol, int nRow, RECT &rcCaret )
{
ASSERT( pView );
RECT rcView;
pView->GetRect( &rcView );
CBuffer *pBuffer = m_pCtrl->GetBuffer();
int nLastLine = pBuffer->GetLineCount() - 1;
int nViewCol = nBuffCol;
nRow = min( nLastLine, nRow );
if ( nRow < 0 )
{
nRow = 0;
}
else
{
nViewCol = pBuffer->ConvertBufferColToViewCol( nRow, nBuffCol );
}
rcCaret.left = rcView.left + pView->GetLeftMargin( TRUE, TRUE ) + ( ( nViewCol - pView->GetLeftIndex() ) * pView->GetCharWidth() );
rcCaret.right = rcCaret.left + m_cxCaretIns;
rcCaret.top = rcView.top + ( ( nRow - pView->GetTopIndex() ) * pView->GetLineHeight() );
rcCaret.bottom = rcCaret.top + m_cyCaret;
}
示例3: lock
CBuffer *CBuffer::Allocator::Allocate()
{
CCriticalSection::Owner lock( m_criticalSection );
CBuffer *pBuffer = 0;
if ( !m_freeList.Empty() )
{
pBuffer = m_freeList.PopNode();
pBuffer->AddRef();
}
else
{
pBuffer = new( m_bufferSize )CBuffer( *this, m_bufferSize );
if ( !pBuffer )
{
throw CException( _T("CBuffer::Allocator::Allocate()"), _T("Out of memory") );
}
OnBufferCreated();
}
m_activeList.PushNode( pBuffer );
OnBufferAllocated();
return pBuffer;
}
示例4: read
HRESULT read(void *data, UInt32 size, UInt32 *processedSize)
{
Lock lock(m_mutex);
if (m_read_size==m_total_size)
{
*processedSize = 0;
m_sealed=true;
return S_OK;
}
while (m_buffer.size()==0)
m_buffer_not_empty.wait(lock);
try
{
*processedSize = m_buffer.read(data, size);
m_read_size += *processedSize;
//printf("CBuffer[%p]: %u bytes read\n", this, *processedSize);
}
catch(...)
{
assert(false);
}
m_buffer_not_full.notify_all();
lock.unlock();
//if (m_read_size==m_total_size)
// finalize();
return S_OK;
}
示例5: newdata
void CMySocket::newdata()
{
CBuffer buffer;
CClientMsg climsg;
buffer.AddDataSize( GetData( buffer.GetDataEnd(), 255 ) );
if ( buffer.DataSize() == -1 )
return;
int nParseErr;
while(climsg.ParseData( &buffer, nParseErr ))
{
TVecChar vecMsg;
climsg.GetData( CClientMsg::etpCommand, &vecMsg );
if ( (climsg.GetTo() == 1 || climsg.GetTo() == 2) && ( int ) vecMsg[ 0 ] == 0 )
std::cout << "ok" << std::endl;
else
{
std::cout << "message from " << ( int ) climsg.GetTo() << " CMD: " << ( int ) climsg.GetCommand() << " ARG: ";
for ( TVecChar::const_iterator i = vecMsg.begin(); i != vecMsg.end(); ++i )
std::cout << (int) *i << " ";
std::cout << std::endl;
//sockclose();
}
if ( m_bAutoMode )
sendMsgFromList();
}
}
示例6: DoResourceFileCheck
// If file was downloaded with a resource, validate checksum
void CScriptFile::DoResourceFileCheck ( void )
{
if ( !m_pFile || m_bDoneResourceFileCheck )
return;
m_bDoneResourceFileCheck = true;
if ( g_pClientGame->GetResourceManager()->IsResourceFile( m_strFilename ) )
{
// Remember current position and seek to the end
long lCurrentPos = m_pFile->FTell ();
m_pFile->FSeek ( 0, SEEK_END );
// Retrieve size of file
long lSize = m_pFile->FTell ();
// Read data
CBuffer buffer;
buffer.SetSize( lSize );
m_pFile->FSeek ( 0, SEEK_SET );
m_pFile->FRead ( buffer.GetData(), buffer.GetSize() );
// Seek back to where the pointer was
m_pFile->FSeek ( lCurrentPos, SEEK_SET );
// Check file content
g_pClientGame->GetResourceManager()->ValidateResourceFile( m_strFilename, buffer );
}
}
示例7: CBuffer
void CNiThread::SendData(CBuffer& bufDataSnd,const CString& strClientAddr)
{
if(bufDataSnd.GetDataLen()<=0 || strClientAddr.GetLength()<=0)
return;
NI_TASK_PARAM_TYPE* pNiTask = new NI_TASK_PARAM_TYPE;
if(pNiTask != NULL)
{
//pNiTask->pSendData = &bufDataSnd;
pNiTask->pSendData = new CBuffer();
if(pNiTask->pSendData!=NULL)
{
//加装数据包头
if(pNiTask->pSendData->Alloc(bufDataSnd.GetDataLen()+PACKAGE_HEAD_LEN))
{
//填写数据包头部
DWORD* pPackageEntityLen = (DWORD*)pNiTask->pSendData->GetBufP();
*pPackageEntityLen=bufDataSnd.GetDataLen();
pNiTask->pSendData->SetDataLen(PACKAGE_HEAD_LEN);
pNiTask->pSendData->AppendData(bufDataSnd);
//memcpy(pNiTask->pSendData,bufDataSnd.GetBufP(),bufDataSnd.GetDataLen());
//pNiTask->pSendData->SetDataLen(bufDataSnd.GetDataLen()+PACKAGE_HEAD_LEN);
}
}
//填写发送地址
pNiTask->strClientAddr = strClientAddr;
//提交发送任务
CommitNiTask(NITASK_SEND,pNiTask);
}
}
示例8: SendBuffer
void CQuery::SendBuffer(CClient* pClient, const CBuffer& Buffer) {
if (m_pNetwork && m_pNetwork->IsUserAttached()) {
// Based on CChan::SendBuffer()
if (!Buffer.IsEmpty()) {
MCString msParams;
msParams["target"] = m_pNetwork->GetIRCNick().GetNick();
const vector<CClient*> & vClients = m_pNetwork->GetClients();
for (size_t uClient = 0; uClient < vClients.size(); ++uClient) {
CClient * pUseClient = (pClient ? pClient : vClients[uClient]);
size_t uSize = Buffer.Size();
for (size_t uIdx = 0; uIdx < uSize; uIdx++) {
CString sLine = Buffer.GetLine(uIdx, *pUseClient, msParams);
bool bContinue = false;
NETWORKMODULECALL(OnPrivBufferPlayLine(*pUseClient, sLine), m_pNetwork->GetUser(), m_pNetwork, NULL, &bContinue);
if (bContinue) continue;
m_pNetwork->PutUser(sLine, pUseClient);
}
if (pClient)
break;
}
}
}
}
示例9: RecvData
int CAppCtrl::RecvData(unsigned int uiDPKey, CBuffer& stBuff)
{
//找到key对应的管道
PCShmQ pstShm = GetShm(uiDPKey);
if(pstShm == NULL)
{
SL_ERROR("shm %u fand fails!", uiDPKey);
return -1;
}
else if(!pstShm->HasCode())
{
//管道里没有数据
return 0;
}
m_Stat.Put(app_stat_recvpkg);
stBuff.Clear();
int iCodeLen = 0;
//从管道里取出一个code
int iRet = pstShm->GetOneCode(stBuff.GetFreeBuf(), stBuff.GetFreeLen(), iCodeLen);
if(iRet || iCodeLen < (int)sizeof(CNetHead))
{
SL_ERROR("get one code but data fails (ret: %d, clen:%d)",iRet, iCodeLen);
return -2;
}
stBuff.Append(iCodeLen);
return iCodeLen;
}
示例10: GetPacket
void DecodeAsterix::GetPacket(CBuffer& rBuffer)
{
index = rBuffer.GetIndex();
rBuffer.ReadU8(&cat);
qDebug () << QString("CAT : %1").arg(cat);
if (cat == 4) { // Category - 004
cat004.Clear();
cat004.BufferPrint(rBuffer, index, rBuffer.GetIndex(), "000");
cat004.GetPacket(rBuffer);
}else if(cat == 62) { // Category - 062 System track
cat062.Clear();
cat062.BufferPrint(rBuffer, index, rBuffer.GetIndex(), "000");
cat062.GetPacket(rBuffer);
//qDebug() << cat062.toString();
}else if(cat == 21) { // Category - 021 ADSB
cat021.Clear();
cat021.BufferPrint(rBuffer, index, rBuffer.GetIndex(), "000");
cat021.GetPacket(rBuffer);
//qDebug() << cat021.toString();
}else {
qDebug() << "Not found category...";
}
}
示例11: RecordWith
int CCircuitry::RecordWith(int nChan, BYTE* pBuffer, DWORD dwStopOffset)
{
if ( ! m_pChain || ! m_pChain->IsConnected() ) return -1;
if ( m_pRecIoOver->Offset >= MAX_RECLST ) return -1;
if ( ! HasOverlappedIoCompleted(m_pRecIoOver) ) return -1;
CBuffer* pOutput = m_pChain->m_pOutput;
if ( dwStopOffset ) pOutput->Add( pBuffer, dwStopOffset + 1 );
Neighbour.m_pWakeup.SetEvent();
if ( int nResult = SsmRecordMemBlock(nChan, 6, pBuffer, TEMP_BUFFER, OnRecMemBlockDone, m_pRecIoOver) )
{
#ifdef _DEBUG
CHAR sError[1024];
SsmGetLastErrMsg( sError );
theApp.Message( MSG_ERROR, sError );
#endif
return nResult;
}
m_pRecIoOver->Offset++;
ResetEvent( m_pRecIoOver->hEvent );
//TRACE("%i-> RecordWith in [%i]\n", GetTickCount(), m_pRecIoOver->Offset);
return 0;
}
示例12: throw
void* CResox::InShellJob(void* pvThis) throw()
{
CResox* pResox = (CResox*) pvThis;
int nread;
try
{
CBuffer DataBuffer;
while(true)
{
pResox->XEPssh.ReceiveData(&DataBuffer);
nread = write(pResox->tun_fd, DataBuffer.GetBuffer(), DataBuffer.GetBufferSize());
if(nread < 0) {
perror("Write to interface");
close(pResox->tun_fd);
exit(1);
}
}
}
catch(exception& e)
{
pResox->ThreadOutShellJob.Stop();
pResox->XEPssh.Disconnect();
return NULL;
}
}
示例13: Uncompress
bool ZLibUtils::Uncompress(CBuffer& pSrc)
{
QMutexLocker l(&ZLibUtils::m_oMutex);
for(ulong nSize = qMax(pSrc.size() * 6u, 1024u); ; nSize *= 2)
{
ZLibUtils::m_oCompressBuffer.resize(nSize);
ulong nCompress = ZLibUtils::m_oCompressBuffer.size();
int nRet = ::uncompress((Bytef*)ZLibUtils::m_oCompressBuffer.data(), &nCompress, (Bytef*)pSrc.data(), pSrc.size());
if(nRet == Z_OK)
{
ZLibUtils::m_oCompressBuffer.resize(nCompress);
pSrc.clear();
pSrc.append(ZLibUtils::m_oCompressBuffer);
break;
}
if(nRet != Z_BUF_ERROR)
{
return false;
}
}
return true;
}
示例14: Compress
bool ZLibUtils::Compress(CBuffer& pSrc, bool bIfSmaller)
{
QMutexLocker l(&ZLibUtils::m_oMutex);
if(bIfSmaller && pSrc.size() < 64)
{
return false;
}
ulong nCompress = qMax(ZLibUtils::m_oCompressBuffer.size(), pSrc.size() * 2);
ZLibUtils::m_oCompressBuffer.resize(nCompress);
int nRet = ::compress((Bytef*)ZLibUtils::m_oCompressBuffer.data(), &nCompress, (const Bytef*)pSrc.data(), pSrc.size());
if(nRet != Z_OK)
{
Q_ASSERT(nRet != Z_BUF_ERROR);
return false;
}
ZLibUtils::m_oCompressBuffer.resize(nCompress);
if(bIfSmaller && ZLibUtils::m_oCompressBuffer.size() > pSrc.size())
{
return false;
}
pSrc.clear();
pSrc.append(ZLibUtils::m_oCompressBuffer);
return true;
}
示例15: LOG4CPLUS_TRACE_METHOD
bool PmpIpcProtocol::findProfilesResponse(const std::list<iviLink::Profile::Uid> & profiles,
iviLink::Ipc::DirectionID const& dirId)
{
LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ );
CBuffer writeBuf = mWriteBufMgr.getBuffer();
ProfileManager::Ipc::PmMessage* req = reinterpret_cast<ProfileManager::Ipc::PmMessage*>(writeBuf.get());
req->header.type = ProfileManager::Ipc::PMP_PMAL_FIND_PROFILES;
iviLink::Ipc::Helpers::CBufferWriter writer(req->data, writeBuf.getSize() - sizeof(req->header));
BaseError err = writer.write(profiles.begin(), profiles.end());
if (!err.isNoError())
{
LOG4CPLUS_ERROR(msLogger, static_cast<std::string>(err));
return false;
}
req->header.size = writer.getUsedSize();
iviLink::Ipc::MsgID id = mMsgIdGen.getNext();
UInt32 const reqSize = sizeof(ProfileManager::Ipc::PmMessage) + req->header.size;
err = mIpc->asyncRequest(id, writeBuf.get(), reqSize, &dirId);
if (!err.isNoError())
{
LOG4CPLUS_ERROR(msLogger, static_cast<std::string>(err));
return false;
}
return true;
}