Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
CallChain.cpp
00001 00002 // Suppress deprecation warnings since this whole 00003 // class is deprecated already 00004 #include "mbed_toolchain.h" 00005 #undef MBED_DEPRECATED_SINCE 00006 #define MBED_DEPRECATED_SINCE(...) 00007 00008 #include "platform/CallChain.h" 00009 #include "cmsis.h" 00010 #include "platform/mbed_critical.h" 00011 00012 namespace mbed { 00013 00014 class CallChainLink { 00015 public: 00016 CallChainLink(): cb(), next(NULL) { 00017 // No work to do 00018 } 00019 00020 CallChainLink(Callback<void()> &callback): cb(callback), next(NULL) { 00021 // No work to do 00022 } 00023 Callback<void()> cb; 00024 CallChainLink * next; 00025 }; 00026 00027 CallChain::CallChain(int size) : _chain(NULL) { 00028 // No work to do 00029 } 00030 00031 CallChain::~CallChain() { 00032 clear(); 00033 } 00034 00035 pFunctionPointer_t CallChain::add(Callback<void()> func) { 00036 CallChainLink *new_link = new CallChainLink(func); 00037 if (NULL == _chain) { 00038 _chain = new_link; 00039 return &new_link->cb; 00040 } 00041 00042 CallChainLink *link = _chain; 00043 while (true) { 00044 if (NULL == link->next) { 00045 link->next = new_link; 00046 return &new_link->cb; 00047 } 00048 link = link->next; 00049 } 00050 } 00051 00052 pFunctionPointer_t CallChain::add_front(Callback<void()> func) { 00053 CallChainLink *link = new CallChainLink(func); 00054 link->next = _chain; 00055 _chain = link; 00056 return &link->cb; 00057 } 00058 00059 int CallChain::size() const { 00060 CallChainLink *link = _chain; 00061 int elements = 0; 00062 while (link != NULL) { 00063 elements++; 00064 link = link->next; 00065 } 00066 return elements; 00067 } 00068 00069 pFunctionPointer_t CallChain::get(int idx) const { 00070 CallChainLink *link = _chain; 00071 for (int i = 0; i < idx; i++) { 00072 if (NULL == link) { 00073 break; 00074 } 00075 link = link->next; 00076 } 00077 return &link->cb; 00078 } 00079 00080 int CallChain::find(pFunctionPointer_t f) const { 00081 CallChainLink *link = _chain; 00082 int i = 0; 00083 while (link != NULL) { 00084 if (f == &link->cb) { 00085 return i; 00086 } 00087 i++; 00088 link = link->next; 00089 } 00090 return -1; 00091 } 00092 00093 void CallChain::clear() { 00094 CallChainLink *link = _chain; 00095 _chain = NULL; 00096 while (link != NULL) { 00097 CallChainLink *temp = link->next; 00098 delete link; 00099 link = temp; 00100 } 00101 } 00102 00103 bool CallChain::remove(pFunctionPointer_t f) { 00104 CallChainLink *link = _chain; 00105 while (link != NULL) { 00106 if (f == &link->cb) { 00107 delete link; 00108 return true; 00109 } 00110 link = link->next; 00111 } 00112 return false; 00113 } 00114 00115 void CallChain::call() { 00116 CallChainLink *link = _chain; 00117 while (link != NULL) { 00118 link->cb.call(); 00119 link = link->next; 00120 } 00121 } 00122 00123 } // namespace mbed
Generated on Tue Jul 12 2022 12:43:37 by
