BLE fota Lamp Demo
Dependencies: mbed-rtos mbed mbed_fota_fan_control
Fork of mbed_fota_fan_control by
ext_fota/MsgQueue.cpp@1:5cf3a6c969be, 2015-06-22 (annotated)
- Committer:
- dudnwjs
- Date:
- Mon Jun 22 07:36:06 2015 +0000
- Revision:
- 1:5cf3a6c969be
- Parent:
- 0:a1f6b1ba8a1e
- Child:
- 8:9eec2c246a85
Basic Program Coding Complete
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dudnwjs | 1:5cf3a6c969be | 1 | #include "MsgQueue.h" |
dudnwjs | 0:a1f6b1ba8a1e | 2 | #include "mbed.h" |
dudnwjs | 0:a1f6b1ba8a1e | 3 | |
dudnwjs | 0:a1f6b1ba8a1e | 4 | namespace sevencore_fota{ |
dudnwjs | 0:a1f6b1ba8a1e | 5 | |
dudnwjs | 1:5cf3a6c969be | 6 | MsgQueue::MsgQueue(int MaxSize):MaxNum(MaxSize) |
dudnwjs | 0:a1f6b1ba8a1e | 7 | { |
dudnwjs | 0:a1f6b1ba8a1e | 8 | Front = NULL; |
dudnwjs | 0:a1f6b1ba8a1e | 9 | Rear = NULL; |
dudnwjs | 0:a1f6b1ba8a1e | 10 | ElemCnt = 0; |
dudnwjs | 0:a1f6b1ba8a1e | 11 | } |
dudnwjs | 0:a1f6b1ba8a1e | 12 | |
dudnwjs | 1:5cf3a6c969be | 13 | MsgQueue::~MsgQueue(void) |
dudnwjs | 0:a1f6b1ba8a1e | 14 | { |
dudnwjs | 0:a1f6b1ba8a1e | 15 | } |
dudnwjs | 0:a1f6b1ba8a1e | 16 | |
dudnwjs | 1:5cf3a6c969be | 17 | void MsgQueue::EnQueue(void *vData) |
dudnwjs | 0:a1f6b1ba8a1e | 18 | { |
dudnwjs | 0:a1f6b1ba8a1e | 19 | Element *tmp = new Element; |
dudnwjs | 0:a1f6b1ba8a1e | 20 | tmp->Data = vData; |
dudnwjs | 0:a1f6b1ba8a1e | 21 | tmp->Next = NULL; |
dudnwjs | 0:a1f6b1ba8a1e | 22 | ElemCnt++; |
dudnwjs | 0:a1f6b1ba8a1e | 23 | if( Front == NULL) |
dudnwjs | 0:a1f6b1ba8a1e | 24 | { |
dudnwjs | 0:a1f6b1ba8a1e | 25 | Front = tmp; |
dudnwjs | 0:a1f6b1ba8a1e | 26 | Rear = tmp; |
dudnwjs | 0:a1f6b1ba8a1e | 27 | }else |
dudnwjs | 0:a1f6b1ba8a1e | 28 | { |
dudnwjs | 0:a1f6b1ba8a1e | 29 | Rear->Next = tmp; |
dudnwjs | 0:a1f6b1ba8a1e | 30 | Rear = tmp; |
dudnwjs | 0:a1f6b1ba8a1e | 31 | } |
dudnwjs | 0:a1f6b1ba8a1e | 32 | } |
dudnwjs | 0:a1f6b1ba8a1e | 33 | |
dudnwjs | 1:5cf3a6c969be | 34 | void *MsgQueue::DeQueue(void) |
dudnwjs | 0:a1f6b1ba8a1e | 35 | { |
dudnwjs | 0:a1f6b1ba8a1e | 36 | void *tmp; |
dudnwjs | 0:a1f6b1ba8a1e | 37 | Element *tmpElem; |
dudnwjs | 0:a1f6b1ba8a1e | 38 | |
dudnwjs | 0:a1f6b1ba8a1e | 39 | if(Front == NULL) |
dudnwjs | 0:a1f6b1ba8a1e | 40 | return NULL; |
dudnwjs | 0:a1f6b1ba8a1e | 41 | |
dudnwjs | 0:a1f6b1ba8a1e | 42 | ElemCnt--; |
dudnwjs | 0:a1f6b1ba8a1e | 43 | tmpElem = Front; |
dudnwjs | 0:a1f6b1ba8a1e | 44 | Front = tmpElem->Next; |
dudnwjs | 0:a1f6b1ba8a1e | 45 | tmp = tmpElem->Data; |
dudnwjs | 0:a1f6b1ba8a1e | 46 | free(tmpElem); |
dudnwjs | 0:a1f6b1ba8a1e | 47 | |
dudnwjs | 0:a1f6b1ba8a1e | 48 | return tmp; |
dudnwjs | 0:a1f6b1ba8a1e | 49 | } |
dudnwjs | 0:a1f6b1ba8a1e | 50 | |
dudnwjs | 1:5cf3a6c969be | 51 | int MsgQueue::GetElementCount(void) |
dudnwjs | 0:a1f6b1ba8a1e | 52 | { |
dudnwjs | 0:a1f6b1ba8a1e | 53 | return ElemCnt; |
dudnwjs | 0:a1f6b1ba8a1e | 54 | } |
dudnwjs | 0:a1f6b1ba8a1e | 55 | |
dudnwjs | 1:5cf3a6c969be | 56 | bool MsgQueue::IsEmpty(void) |
dudnwjs | 0:a1f6b1ba8a1e | 57 | { |
dudnwjs | 0:a1f6b1ba8a1e | 58 | if( Front == NULL) |
dudnwjs | 0:a1f6b1ba8a1e | 59 | return false; |
dudnwjs | 0:a1f6b1ba8a1e | 60 | else |
dudnwjs | 0:a1f6b1ba8a1e | 61 | return true; |
dudnwjs | 0:a1f6b1ba8a1e | 62 | } |
dudnwjs | 0:a1f6b1ba8a1e | 63 | |
dudnwjs | 0:a1f6b1ba8a1e | 64 | }//namespace |