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 { 00018 // No work to do 00019 } 00020 00021 CallChainLink(Callback<void()> &callback): cb(callback), next(NULL) 00022 { 00023 // No work to do 00024 } 00025 Callback<void()> cb; 00026 CallChainLink *next; 00027 }; 00028 00029 CallChain::CallChain(int size) : _chain(NULL) 00030 { 00031 // No work to do 00032 } 00033 00034 CallChain::~CallChain() 00035 { 00036 clear(); 00037 } 00038 00039 pFunctionPointer_t CallChain::add(Callback<void()> func) 00040 { 00041 CallChainLink *new_link = new CallChainLink(func); 00042 if (NULL == _chain) { 00043 _chain = new_link; 00044 return &new_link->cb; 00045 } 00046 00047 CallChainLink *link = _chain; 00048 while (true) { 00049 if (NULL == link->next) { 00050 link->next = new_link; 00051 return &new_link->cb; 00052 } 00053 link = link->next; 00054 } 00055 } 00056 00057 pFunctionPointer_t CallChain::add_front(Callback<void()> func) 00058 { 00059 CallChainLink *link = new CallChainLink(func); 00060 link->next = _chain; 00061 _chain = link; 00062 return &link->cb; 00063 } 00064 00065 int CallChain::size() const 00066 { 00067 CallChainLink *link = _chain; 00068 int elements = 0; 00069 while (link != NULL) { 00070 elements++; 00071 link = link->next; 00072 } 00073 return elements; 00074 } 00075 00076 pFunctionPointer_t CallChain::get(int idx) const 00077 { 00078 CallChainLink *link = _chain; 00079 for (int i = 0; i < idx; i++) { 00080 if (NULL == link) { 00081 break; 00082 } 00083 link = link->next; 00084 } 00085 return &link->cb; 00086 } 00087 00088 int CallChain::find(pFunctionPointer_t f) const 00089 { 00090 CallChainLink *link = _chain; 00091 int i = 0; 00092 while (link != NULL) { 00093 if (f == &link->cb) { 00094 return i; 00095 } 00096 i++; 00097 link = link->next; 00098 } 00099 return -1; 00100 } 00101 00102 void CallChain::clear() 00103 { 00104 CallChainLink *link = _chain; 00105 _chain = NULL; 00106 while (link != NULL) { 00107 CallChainLink *temp = link->next; 00108 delete link; 00109 link = temp; 00110 } 00111 } 00112 00113 bool CallChain::remove(pFunctionPointer_t f) 00114 { 00115 CallChainLink *link = _chain; 00116 while (link != NULL) { 00117 if (f == &link->cb) { 00118 delete link; 00119 return true; 00120 } 00121 link = link->next; 00122 } 00123 return false; 00124 } 00125 00126 void CallChain::call() 00127 { 00128 CallChainLink *link = _chain; 00129 while (link != NULL) { 00130 link->cb.call(); 00131 link = link->next; 00132 } 00133 } 00134 00135 } // namespace mbed
Generated on Tue Aug 9 2022 00:37:03 by
1.7.2