李国帅 2018/1/19
Darwin流媒体容器的使用例子
#include "Win32header.h"
#include "OSMemory.h"
#include "OS.h"
#include "OSQueue.h"
#include "OSHeap.h"
int main(int argc, char* argv[])
{
int* inObjectP = new int();//申请一个对象指针
*inObjectP = 100;
OSHeap fHeap;
OSHeapElem fTimerHeapElem;
fTimerHeapElem.SetValue(OS::Milliseconds());
fTimerHeapElem.SetEnclosingObject(inObjectP);
fHeap.Insert(&fTimerHeapElem);
if ((fHeap.PeekMin() != NULL) /*&& (fHeap.PeekMin()->GetValue() <= 1001)*/)
{
void * p = (void *)fHeap.PeekMin()->GetEnclosingObject();
int* pInt = (int*)fHeap.ExtractMin()->GetEnclosingObject();
OSHeapElem* pElem = fHeap.PeekMin();
qtss_printf("fHeap.CurrentHeapSize(%"_U32BITARG_") taskElem = %p enclose=%p\n",
fHeap.CurrentHeapSize(), (void *)fHeap.PeekMin(), *pInt);
if (NULL != fHeap.Remove(&fTimerHeapElem))
qtss_printf("TaskThread::Entry task still in heap before delete\n");
}
delete(inObjectP);
}
int main(int argc, char* argv[])
{
char url[100] = { 0 };//字符串Key
strcpy(url, "http://xxxx/sdp");
StrPtrLen theSourceUrl(url);
OSQueueElem fTaskQueueElem;
OSQueue_Blocking fTaskQueue;
fTaskQueueElem.SetEnclosingObject(&theSourceUrl);
fTaskQueue.EnQueue(&fTaskQueueElem);
if (NULL != fTaskQueueElem.InQueue())
qtss_printf("TaskThread::Entry task still in queue before delete\n");
SInt64 theTimeout = 0;
OSQueueElem* theElem = fTaskQueue.DeQueue();//移除并返回
if (theElem != NULL)
{
void * p = theElem->GetEnclosingObject();
int len = fTaskQueue.GetQueue()->GetLength();
qtss_printf(" taskElem = %p enclose=%p\n", (void *)theElem, p);
}
//fTaskQueueElem.Remove();//移除
}