blob: 617145bec04f710a8ecbce7ac752f629b25bdabf
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[3072]; |
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 | void clearMsg(); |
31 | private: |
32 | bool threadLoop(); |
33 | nsecs_t getNowMs();//get system time , MS |
34 | virtual void handleMessage(CMessage &msg) = 0; |
35 | |
36 | // |
37 | Vector<CMessage> m_v_msg; |
38 | CCondition mGetMsgCondition; |
39 | CMutex mLockQueue; |
40 | }; |
41 | |
42 | /*class CHandler |
43 | { |
44 | pubulic: |
45 | CHandler(CMsgQueueThread& msgQueue); |
46 | ~CHandler(); |
47 | void sendMsg(); |
48 | void removeMsg(); |
49 | private: |
50 | virtual void handleMessage(CMessage &msg); |
51 | };*/ |
52 | |
53 | #endif |
54 |