#include "ctestqlist.h"
#include <QDebug>
CTestQList::CTestQList(QWidget *parent)
: QWidget(parent)
{
int i;
unsigned char buf[20];
unsigned char buf1[20];
int len;
for(i=0;i<20;i++)
{
buf[i]=i+5;
buf1[i]=100;
}
addToList(buf,20);
//----------------------------
for(i=0;i<20;i++)
{
buf[i]=i+80;
buf1[i]=100;
}
addToList(buf,20);
//----------------------------
for(i=0;i<20;i++)
{
buf[i]=i+100;
buf1[i]=100;
}
addToList(buf,20);
//----------------------------
for(i=0;i<20;i++)
{
buf[i]=i+200;
buf1[i]=100;
}
addToList(buf,20);
//----------------------------
for(i=0;i<20;i++)
{
buf[i]=i+300;
buf1[i]=100;
}
addToList(buf,20);
//----------------------------
for(i=0;i<20;i++)
{
buf[i]=i+400;
buf1[i]=100;
}
addToList(buf,20);
qDebug()<<"get from buffer.....";
len=getFromList(buf1);
for(i=0;i<len;i++)
qDebug()<<buf1[i];
len=getFromList(buf1);
for(i=0;i<len;i++)
qDebug()<<buf1[i];
qDebug()<<"get from buffer.....";
len=getFromList(buf1);
for(i=0;i<len;i++)
qDebug()<<buf1[i];
qDebug()<<"get from buffer.....";
len=getFromList(buf1);
for(i=0;i<len;i++)
qDebug()<<buf1[i];
qDebug()<<"get from buffer.....";
len=getFromList(buf1);
for(i=0;i<len;i++)
qDebug()<<buf1[i];
qDebug()<<"get from buffer.....";
len=getFromList(buf1);
for(i=0;i<len;i++)
qDebug()<<buf1[i];
qDebug()<<"get from buffer.....";
len=getFromList(buf1);
for(i=0;i<len;i++)
qDebug()<<buf1[i];
qDebug()<<"get from buffer.....";
len=getFromList(buf1);
for(i=0;i<len;i++)
qDebug()<<buf1[i];
qDebug()<<"get from buffer.....";
}
CTestQList::~CTestQList()
{
}
void CTestQList::addToList(unsigned char *buf,int len)
{
rcvBuf_t rcvBuf;
if(buf==NULL)
{
return ;
}
rcvBuf.buf=(unsigned char *)malloc(len);
if(rcvBuf.buf!=NULL)
{
memcpy(rcvBuf.buf,buf,len);
rcvBuf.len=len;
}
m_list.append(rcvBuf);
}
int CTestQList::getFromList(unsigned char *buf)
{
int length;
if(buf==NULL)
{
return -1;
}
QList<rcvBuf_t>::iterator Iter;
for(Iter=m_list.begin();Iter!=m_list.end();Iter++)
{
if(Iter->buf!=NULL)
{
memcpy(buf,Iter->buf,Iter->len);
free(Iter->buf);
length=Iter->len;
m_list.erase(Iter);
return length;
}
}
return 0;
}
void CTestQList::clearList()
{
QList<rcvBuf_t>::iterator Iter;
for(Iter=m_list.begin();Iter!=m_list.end();Iter++)
{
m_list.erase(Iter);
}
}