43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
#include "EventQueue.h"
|
||
|
||
int main()
|
||
{
|
||
EventQueue queue;
|
||
|
||
/* 模拟事件数据 */
|
||
int cmd1 = 101;
|
||
std::string param1 = "事件一";
|
||
int cmd2 = 202;
|
||
std::string param2 = "事件二";
|
||
int cmd3 = 303;
|
||
std::string param3 = "事件三";
|
||
|
||
std::cout << "=== 添加事件 ===" << std::endl;
|
||
queue.EventQueue_AddEvent(cmd1, ¶m1); // 队尾
|
||
queue.EventQueue_AddEventToFront(cmd2, ¶m2); // 队头
|
||
queue.EventQueue_AddEvent(cmd3, ¶m3); // 队尾
|
||
|
||
/* 查看队头事件 */
|
||
int peekCmd;
|
||
void *peekParam;
|
||
if (queue.EventQueue_PeekEvent(&peekCmd, &peekParam))
|
||
{
|
||
std::cout << "[Peek] cmd=" << peekCmd
|
||
<< " param=" << *(std::string *)peekParam << std::endl;
|
||
}
|
||
|
||
std::cout << "=== 获取并移除事件 ===" << std::endl;
|
||
int getCmd;
|
||
void *getParam;
|
||
while (queue.EventQueue_GetEvent(&getCmd, &getParam))
|
||
{
|
||
std::cout << "[Get] cmd=" << getCmd
|
||
<< " param=" << *(std::string *)getParam << std::endl;
|
||
|
||
// queue.EventQueue_PopEvent(); // 队列中 Get 已经 pop 了,PopEvent 可省略
|
||
}
|
||
|
||
std::cout << "=== 队列已清空 ===" << std::endl;
|
||
|
||
return 0;
|
||
} |