blob: 6d085be82bfff121e15b9c320240dc6aef683b8f
1 | /* |
2 | * showboz |
3 | * 单(线程)消费者 |
4 | * 一个简单的MSG handler |
5 | */ |
6 | #include "CThread.h" |
7 | #include <utils/Vector.h> |
8 | using namespace android; |
9 | #if !defined(_C_MSG_QUEUE_H) |
10 | #define _C_MSG_QUEUE_H |
11 | |
12 | class CMessage { |
13 | public: |
14 | CMessage(); |
15 | ~CMessage(); |
16 | nsecs_t mDelayMs;//delay times , MS |
17 | nsecs_t mWhenMs;//when, the msg will handle |
18 | int mType; |
19 | void *mpData; |
20 | unsigned char mpPara[2048]; |
21 | }; |
22 | |
23 | class CMsgQueueThread: public CThread { |
24 | public: |
25 | CMsgQueueThread(); |
26 | virtual ~CMsgQueueThread(); |
27 | int startMsgQueue(); |
28 | void sendMsg(CMessage &msg); |
29 | void removeMsg(CMessage &msg); |
30 | private: |
31 | bool threadLoop(); |
32 | nsecs_t getNowMs();//get system time , MS |
33 | virtual void handleMessage(CMessage &msg) = 0; |
34 | |
35 | // |
36 | Vector<CMessage> m_v_msg; |
37 | CCondition mGetMsgCondition; |
38 | CMutex mLockQueue; |
39 | }; |
40 | |
41 | /*class CHandler |
42 | { |
43 | pubulic: |
44 | CHandler(CMsgQueueThread& msgQueue); |
45 | ~CHandler(); |
46 | void sendMsg(); |
47 | void removeMsg(); |
48 | private: |
49 | virtual void handleMessage(CMessage &msg); |
50 | };*/ |
51 | |
52 | #endif |
53 |