Opencv 3.1 project on GR-PEACH board

Fork of gr-peach-opencv-project by the do

Committer:
thedo
Date:
Thu Jun 29 11:01:39 2017 +0000
Revision:
167:1657b442184c
Opencv 3.1 project on GR-PEACH board, 4 apps

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thedo 167:1657b442184c 1 #include "platform/CallChain.h"
thedo 167:1657b442184c 2 #include "cmsis.h"
thedo 167:1657b442184c 3 #include "platform/mbed_critical.h"
thedo 167:1657b442184c 4
thedo 167:1657b442184c 5 namespace mbed {
thedo 167:1657b442184c 6
thedo 167:1657b442184c 7 class CallChainLink {
thedo 167:1657b442184c 8 public:
thedo 167:1657b442184c 9 CallChainLink(): cb(), next(NULL) {
thedo 167:1657b442184c 10 // No work to do
thedo 167:1657b442184c 11 }
thedo 167:1657b442184c 12
thedo 167:1657b442184c 13 CallChainLink(Callback<void()> &callback): cb(callback), next(NULL) {
thedo 167:1657b442184c 14 // No work to do
thedo 167:1657b442184c 15 }
thedo 167:1657b442184c 16 Callback<void()> cb;
thedo 167:1657b442184c 17 CallChainLink * next;
thedo 167:1657b442184c 18 };
thedo 167:1657b442184c 19
thedo 167:1657b442184c 20 CallChain::CallChain(int size) : _chain(NULL) {
thedo 167:1657b442184c 21 // No work to do
thedo 167:1657b442184c 22 }
thedo 167:1657b442184c 23
thedo 167:1657b442184c 24 CallChain::~CallChain() {
thedo 167:1657b442184c 25 clear();
thedo 167:1657b442184c 26 }
thedo 167:1657b442184c 27
thedo 167:1657b442184c 28 pFunctionPointer_t CallChain::add(Callback<void()> func) {
thedo 167:1657b442184c 29 CallChainLink *new_link = new CallChainLink(func);
thedo 167:1657b442184c 30 if (NULL == _chain) {
thedo 167:1657b442184c 31 _chain = new_link;
thedo 167:1657b442184c 32 return &new_link->cb;
thedo 167:1657b442184c 33 }
thedo 167:1657b442184c 34
thedo 167:1657b442184c 35 CallChainLink *link = _chain;
thedo 167:1657b442184c 36 while (true) {
thedo 167:1657b442184c 37 if (NULL == link->next) {
thedo 167:1657b442184c 38 link->next = new_link;
thedo 167:1657b442184c 39 return &new_link->cb;
thedo 167:1657b442184c 40 }
thedo 167:1657b442184c 41 link = link->next;
thedo 167:1657b442184c 42 }
thedo 167:1657b442184c 43 }
thedo 167:1657b442184c 44
thedo 167:1657b442184c 45 pFunctionPointer_t CallChain::add_front(Callback<void()> func) {
thedo 167:1657b442184c 46 CallChainLink *link = new CallChainLink(func);
thedo 167:1657b442184c 47 link->next = _chain;
thedo 167:1657b442184c 48 _chain = link;
thedo 167:1657b442184c 49 return &link->cb;
thedo 167:1657b442184c 50 }
thedo 167:1657b442184c 51
thedo 167:1657b442184c 52 int CallChain::size() const {
thedo 167:1657b442184c 53 CallChainLink *link = _chain;
thedo 167:1657b442184c 54 int elements = 0;
thedo 167:1657b442184c 55 while (link != NULL) {
thedo 167:1657b442184c 56 elements++;
thedo 167:1657b442184c 57 link = link->next;
thedo 167:1657b442184c 58 }
thedo 167:1657b442184c 59 return elements;
thedo 167:1657b442184c 60 }
thedo 167:1657b442184c 61
thedo 167:1657b442184c 62 pFunctionPointer_t CallChain::get(int idx) const {
thedo 167:1657b442184c 63 CallChainLink *link = _chain;
thedo 167:1657b442184c 64 for (int i = 0; i < idx; i++) {
thedo 167:1657b442184c 65 if (NULL == link) {
thedo 167:1657b442184c 66 break;
thedo 167:1657b442184c 67 }
thedo 167:1657b442184c 68 link = link->next;
thedo 167:1657b442184c 69 }
thedo 167:1657b442184c 70 return &link->cb;
thedo 167:1657b442184c 71 }
thedo 167:1657b442184c 72
thedo 167:1657b442184c 73 int CallChain::find(pFunctionPointer_t f) const {
thedo 167:1657b442184c 74 CallChainLink *link = _chain;
thedo 167:1657b442184c 75 int i = 0;
thedo 167:1657b442184c 76 while (link != NULL) {
thedo 167:1657b442184c 77 if (f == &link->cb) {
thedo 167:1657b442184c 78 return i;
thedo 167:1657b442184c 79 }
thedo 167:1657b442184c 80 i++;
thedo 167:1657b442184c 81 link = link->next;
thedo 167:1657b442184c 82 }
thedo 167:1657b442184c 83 return -1;
thedo 167:1657b442184c 84 }
thedo 167:1657b442184c 85
thedo 167:1657b442184c 86 void CallChain::clear() {
thedo 167:1657b442184c 87 CallChainLink *link = _chain;
thedo 167:1657b442184c 88 _chain = NULL;
thedo 167:1657b442184c 89 while (link != NULL) {
thedo 167:1657b442184c 90 CallChainLink *temp = link->next;
thedo 167:1657b442184c 91 delete link;
thedo 167:1657b442184c 92 link = temp;
thedo 167:1657b442184c 93 }
thedo 167:1657b442184c 94 }
thedo 167:1657b442184c 95
thedo 167:1657b442184c 96 bool CallChain::remove(pFunctionPointer_t f) {
thedo 167:1657b442184c 97 CallChainLink *link = _chain;
thedo 167:1657b442184c 98 while (link != NULL) {
thedo 167:1657b442184c 99 if (f == &link->cb) {
thedo 167:1657b442184c 100 delete link;
thedo 167:1657b442184c 101 return true;
thedo 167:1657b442184c 102 }
thedo 167:1657b442184c 103 link = link->next;
thedo 167:1657b442184c 104 }
thedo 167:1657b442184c 105 return false;
thedo 167:1657b442184c 106 }
thedo 167:1657b442184c 107
thedo 167:1657b442184c 108 void CallChain::call() {
thedo 167:1657b442184c 109 CallChainLink *link = _chain;
thedo 167:1657b442184c 110 while (link != NULL) {
thedo 167:1657b442184c 111 link->cb.call();
thedo 167:1657b442184c 112 link = link->next;
thedo 167:1657b442184c 113 }
thedo 167:1657b442184c 114 }
thedo 167:1657b442184c 115
thedo 167:1657b442184c 116 } // namespace mbed
thedo 167:1657b442184c 117