2013-08-07 11:43:45 +00:00
|
|
|
/* mbed Microcontroller Library
|
|
|
|
* Copyright (c) 2006-2013 ARM Limited
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2013-08-07 11:43:26 +00:00
|
|
|
#ifndef MBED_CALLCHAIN_H
|
|
|
|
#define MBED_CALLCHAIN_H
|
|
|
|
|
2016-10-01 07:11:36 +00:00
|
|
|
#include "platform/Callback.h"
|
2017-01-27 11:10:28 +00:00
|
|
|
#include "platform/mbed_toolchain.h"
|
2017-06-20 11:47:27 +00:00
|
|
|
#include "platform/NonCopyable.h"
|
2013-08-07 11:43:26 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
namespace mbed {
|
2017-10-24 15:05:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef Callback<void()> *pFunctionPointer_t;
|
|
|
|
class CallChainLink;
|
|
|
|
|
2016-10-04 20:02:44 +00:00
|
|
|
/** \addtogroup platform */
|
2017-10-24 15:05:45 +00:00
|
|
|
/** @{*/
|
|
|
|
/**
|
|
|
|
* \defgroup platform_CallChain CallChain class
|
|
|
|
* @{
|
|
|
|
*/
|
2013-08-07 11:43:26 +00:00
|
|
|
|
2013-08-07 11:43:45 +00:00
|
|
|
/** Group one or more functions in an instance of a CallChain, then call them in
|
|
|
|
* sequence using CallChain::call(). Used mostly by the interrupt chaining code,
|
|
|
|
* but can be used for other purposes.
|
|
|
|
*
|
2018-04-03 19:07:03 +00:00
|
|
|
* @deprecated Do not use this class. This class is not part of the public API of mbed-os and is being removed in the future.
|
2017-04-25 19:37:08 +00:00
|
|
|
* @note Synchronization level: Not protected
|
2016-06-08 12:52:14 +00:00
|
|
|
*
|
2013-08-07 11:43:45 +00:00
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* #include "mbed.h"
|
|
|
|
*
|
|
|
|
* CallChain chain;
|
|
|
|
*
|
|
|
|
* void first(void) {
|
|
|
|
* printf("'first' function.\n");
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* void second(void) {
|
|
|
|
* printf("'second' function.\n");
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* class Test {
|
|
|
|
* public:
|
|
|
|
* void f(void) {
|
|
|
|
* printf("A::f (class member).\n");
|
|
|
|
* }
|
|
|
|
* };
|
|
|
|
*
|
|
|
|
* int main() {
|
|
|
|
* Test test;
|
|
|
|
*
|
|
|
|
* chain.add(second);
|
|
|
|
* chain.add_front(first);
|
|
|
|
* chain.add(&test, &Test::f);
|
|
|
|
* chain.call();
|
|
|
|
* }
|
|
|
|
* @endcode
|
|
|
|
*/
|
2017-06-20 11:47:27 +00:00
|
|
|
class CallChain : private NonCopyable<CallChain> {
|
2013-08-07 11:43:26 +00:00
|
|
|
public:
|
2013-08-07 11:43:45 +00:00
|
|
|
/** Create an empty chain
|
2018-06-27 14:09:15 +00:00
|
|
|
* @deprecated
|
2018-04-03 19:07:03 +00:00
|
|
|
* Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
|
2013-08-07 11:43:45 +00:00
|
|
|
*
|
|
|
|
* @param size (optional) Initial size of the chain
|
2014-05-26 17:04:46 +00:00
|
|
|
*/
|
2017-10-27 19:49:16 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
|
2018-06-27 14:09:15 +00:00
|
|
|
"public API of mbed-os and is being removed in the future.")
|
2013-08-07 11:43:26 +00:00
|
|
|
CallChain(int size = 4);
|
2017-10-27 19:49:16 +00:00
|
|
|
|
2018-04-03 19:07:03 +00:00
|
|
|
/** Create an empty chain
|
2018-06-27 14:09:15 +00:00
|
|
|
* @deprecated
|
2018-04-03 19:07:03 +00:00
|
|
|
* Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
|
|
|
|
*/
|
2017-10-27 19:49:16 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
|
2018-06-27 14:09:15 +00:00
|
|
|
"public API of mbed-os and is being removed in the future.")
|
2013-08-07 11:43:45 +00:00
|
|
|
virtual ~CallChain();
|
2013-08-07 11:43:26 +00:00
|
|
|
|
2013-08-07 11:43:45 +00:00
|
|
|
/** Add a function at the end of the chain
|
2018-04-03 19:07:03 +00:00
|
|
|
*
|
2018-06-27 14:09:15 +00:00
|
|
|
* @deprecated
|
2018-04-03 19:07:03 +00:00
|
|
|
* Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
|
2013-08-07 11:43:45 +00:00
|
|
|
*
|
2016-05-15 21:17:47 +00:00
|
|
|
* @param func A pointer to a void function
|
2013-08-07 11:43:45 +00:00
|
|
|
*
|
|
|
|
* @returns
|
2016-05-15 21:17:47 +00:00
|
|
|
* The function object created for 'func'
|
2013-08-07 11:43:45 +00:00
|
|
|
*/
|
2017-10-27 19:49:16 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
|
2018-06-27 14:09:15 +00:00
|
|
|
"public API of mbed-os and is being removed in the future.")
|
2016-05-15 21:17:47 +00:00
|
|
|
pFunctionPointer_t add(Callback<void()> func);
|
2013-08-07 11:43:45 +00:00
|
|
|
|
|
|
|
/** Add a function at the end of the chain
|
|
|
|
*
|
2016-05-15 21:17:47 +00:00
|
|
|
* @param obj pointer to the object to call the member function on
|
|
|
|
* @param method pointer to the member function to be called
|
2013-08-07 11:43:45 +00:00
|
|
|
*
|
|
|
|
* @returns
|
2016-05-15 21:17:47 +00:00
|
|
|
* The function object created for 'obj' and 'method'
|
Added support for cv-qualifiers in Callback class
Additionally, the following changes were don to avoid combinatorial
explosion in function overloads as a result of adding cv-qualifiers:
- Added convenience function for inferred type
- Deprecated callback overloads qhere cv-qualifiers are not scalable
Supported overloads:
callback(void (*f)(A...));
callback(const Callback<R(A...)> &);
callback(T *t, void (*f)(T*, A...));
callback(const T *t, void (*f)(const T*, A...));
callback(volatile T *t, void (*f)(volatile T*, A...));
callback(const volatile T *t, void (*f)(const volatile T*, A...));
callback(T *t, void (T::*f)(A...));
callback(const T *t, void (T::*f)(A...) const);
callback(volatile T *t, void (T::*f)(A...) volatile);
callback(const volatile T *t, void (T::*f)(A...) const volatile);
2016-08-18 18:28:57 +00:00
|
|
|
*
|
|
|
|
* @deprecated
|
|
|
|
* The add function does not support cv-qualifiers. Replaced by
|
|
|
|
* add(callback(obj, method)).
|
2013-08-07 11:43:45 +00:00
|
|
|
*/
|
2016-05-15 21:17:47 +00:00
|
|
|
template<typename T, typename M>
|
Added support for cv-qualifiers in Callback class
Additionally, the following changes were don to avoid combinatorial
explosion in function overloads as a result of adding cv-qualifiers:
- Added convenience function for inferred type
- Deprecated callback overloads qhere cv-qualifiers are not scalable
Supported overloads:
callback(void (*f)(A...));
callback(const Callback<R(A...)> &);
callback(T *t, void (*f)(T*, A...));
callback(const T *t, void (*f)(const T*, A...));
callback(volatile T *t, void (*f)(volatile T*, A...));
callback(const volatile T *t, void (*f)(const volatile T*, A...));
callback(T *t, void (T::*f)(A...));
callback(const T *t, void (T::*f)(A...) const);
callback(volatile T *t, void (T::*f)(A...) volatile);
callback(const volatile T *t, void (T::*f)(A...) const volatile);
2016-08-18 18:28:57 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
2018-06-27 14:09:15 +00:00
|
|
|
"The add function does not support cv-qualifiers. Replaced by "
|
|
|
|
"add(callback(obj, method)).")
|
|
|
|
pFunctionPointer_t add(T *obj, M method)
|
|
|
|
{
|
Added support for cv-qualifiers in Callback class
Additionally, the following changes were don to avoid combinatorial
explosion in function overloads as a result of adding cv-qualifiers:
- Added convenience function for inferred type
- Deprecated callback overloads qhere cv-qualifiers are not scalable
Supported overloads:
callback(void (*f)(A...));
callback(const Callback<R(A...)> &);
callback(T *t, void (*f)(T*, A...));
callback(const T *t, void (*f)(const T*, A...));
callback(volatile T *t, void (*f)(volatile T*, A...));
callback(const volatile T *t, void (*f)(const volatile T*, A...));
callback(T *t, void (T::*f)(A...));
callback(const T *t, void (T::*f)(A...) const);
callback(volatile T *t, void (T::*f)(A...) volatile);
callback(const volatile T *t, void (T::*f)(A...) const volatile);
2016-08-18 18:28:57 +00:00
|
|
|
return add(callback(obj, method));
|
2013-08-07 11:43:26 +00:00
|
|
|
}
|
|
|
|
|
2013-08-07 11:43:45 +00:00
|
|
|
/** Add a function at the beginning of the chain
|
2018-06-27 14:09:15 +00:00
|
|
|
* @deprecated
|
2018-04-03 19:07:03 +00:00
|
|
|
* Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
|
|
|
|
*
|
2013-08-07 11:43:45 +00:00
|
|
|
*
|
2016-05-15 21:17:47 +00:00
|
|
|
* @param func A pointer to a void function
|
2013-08-07 11:43:45 +00:00
|
|
|
*
|
|
|
|
* @returns
|
2016-05-15 21:17:47 +00:00
|
|
|
* The function object created for 'func'
|
2013-08-07 11:43:45 +00:00
|
|
|
*/
|
2017-10-27 19:49:16 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
|
2018-06-27 14:09:15 +00:00
|
|
|
"public API of mbed-os and is being removed in the future.")
|
2016-05-15 21:17:47 +00:00
|
|
|
pFunctionPointer_t add_front(Callback<void()> func);
|
2014-05-26 17:04:46 +00:00
|
|
|
|
2013-08-07 11:43:45 +00:00
|
|
|
/** Add a function at the beginning of the chain
|
|
|
|
*
|
2017-04-26 23:39:59 +00:00
|
|
|
* @param obj pointer to the object to call the member function on
|
|
|
|
* @param method pointer to the member function to be called
|
2013-08-07 11:43:45 +00:00
|
|
|
*
|
|
|
|
* @returns
|
2018-11-01 16:57:44 +00:00
|
|
|
* The function object created for the object and method pointers
|
Added support for cv-qualifiers in Callback class
Additionally, the following changes were don to avoid combinatorial
explosion in function overloads as a result of adding cv-qualifiers:
- Added convenience function for inferred type
- Deprecated callback overloads qhere cv-qualifiers are not scalable
Supported overloads:
callback(void (*f)(A...));
callback(const Callback<R(A...)> &);
callback(T *t, void (*f)(T*, A...));
callback(const T *t, void (*f)(const T*, A...));
callback(volatile T *t, void (*f)(volatile T*, A...));
callback(const volatile T *t, void (*f)(const volatile T*, A...));
callback(T *t, void (T::*f)(A...));
callback(const T *t, void (T::*f)(A...) const);
callback(volatile T *t, void (T::*f)(A...) volatile);
callback(const volatile T *t, void (T::*f)(A...) const volatile);
2016-08-18 18:28:57 +00:00
|
|
|
*
|
|
|
|
* @deprecated
|
|
|
|
* The add_front function does not support cv-qualifiers. Replaced by
|
|
|
|
* add_front(callback(obj, method)).
|
2013-08-07 11:43:45 +00:00
|
|
|
*/
|
2016-05-15 21:17:47 +00:00
|
|
|
template<typename T, typename M>
|
Added support for cv-qualifiers in Callback class
Additionally, the following changes were don to avoid combinatorial
explosion in function overloads as a result of adding cv-qualifiers:
- Added convenience function for inferred type
- Deprecated callback overloads qhere cv-qualifiers are not scalable
Supported overloads:
callback(void (*f)(A...));
callback(const Callback<R(A...)> &);
callback(T *t, void (*f)(T*, A...));
callback(const T *t, void (*f)(const T*, A...));
callback(volatile T *t, void (*f)(volatile T*, A...));
callback(const volatile T *t, void (*f)(const volatile T*, A...));
callback(T *t, void (T::*f)(A...));
callback(const T *t, void (T::*f)(A...) const);
callback(volatile T *t, void (T::*f)(A...) volatile);
callback(const volatile T *t, void (T::*f)(A...) const volatile);
2016-08-18 18:28:57 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
2018-06-27 14:09:15 +00:00
|
|
|
"The add_front function does not support cv-qualifiers. Replaced by "
|
|
|
|
"add_front(callback(obj, method)).")
|
|
|
|
pFunctionPointer_t add_front(T *obj, M method)
|
|
|
|
{
|
Added support for cv-qualifiers in Callback class
Additionally, the following changes were don to avoid combinatorial
explosion in function overloads as a result of adding cv-qualifiers:
- Added convenience function for inferred type
- Deprecated callback overloads qhere cv-qualifiers are not scalable
Supported overloads:
callback(void (*f)(A...));
callback(const Callback<R(A...)> &);
callback(T *t, void (*f)(T*, A...));
callback(const T *t, void (*f)(const T*, A...));
callback(volatile T *t, void (*f)(volatile T*, A...));
callback(const volatile T *t, void (*f)(const volatile T*, A...));
callback(T *t, void (T::*f)(A...));
callback(const T *t, void (T::*f)(A...) const);
callback(volatile T *t, void (T::*f)(A...) volatile);
callback(const volatile T *t, void (T::*f)(A...) const volatile);
2016-08-18 18:28:57 +00:00
|
|
|
return add_front(callback(obj, method));
|
2013-08-07 11:43:26 +00:00
|
|
|
}
|
|
|
|
|
2013-08-07 11:43:45 +00:00
|
|
|
/** Get the number of functions in the chain
|
2018-06-27 14:09:15 +00:00
|
|
|
* @deprecated
|
2018-04-03 19:07:03 +00:00
|
|
|
* Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
|
|
|
|
*
|
2013-08-07 11:43:45 +00:00
|
|
|
*/
|
2017-10-27 19:49:16 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
|
2018-06-27 14:09:15 +00:00
|
|
|
"public API of mbed-os and is being removed in the future.")
|
2013-08-07 11:43:26 +00:00
|
|
|
int size() const;
|
2013-08-07 11:43:45 +00:00
|
|
|
|
|
|
|
/** Get a function object from the chain
|
2018-06-27 14:09:15 +00:00
|
|
|
* @deprecated
|
2018-04-03 19:07:03 +00:00
|
|
|
* Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
|
2013-08-07 11:43:45 +00:00
|
|
|
*
|
|
|
|
* @param i function object index
|
|
|
|
*
|
|
|
|
* @returns
|
|
|
|
* The function object at position 'i' in the chain
|
|
|
|
*/
|
2017-10-27 19:49:16 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
|
2018-06-27 14:09:15 +00:00
|
|
|
"public API of mbed-os and is being removed in the future.")
|
2013-08-07 11:43:26 +00:00
|
|
|
pFunctionPointer_t get(int i) const;
|
2013-08-07 11:43:45 +00:00
|
|
|
|
|
|
|
/** Look for a function object in the call chain
|
2018-06-27 14:09:15 +00:00
|
|
|
* @deprecated
|
2018-04-03 19:07:03 +00:00
|
|
|
* Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
|
2013-08-07 11:43:45 +00:00
|
|
|
*
|
|
|
|
* @param f the function object to search
|
|
|
|
*
|
|
|
|
* @returns
|
|
|
|
* The index of the function object if found, -1 otherwise.
|
|
|
|
*/
|
2017-10-27 19:49:16 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
|
2018-06-27 14:09:15 +00:00
|
|
|
"public API of mbed-os and is being removed in the future.")
|
2013-08-07 11:43:26 +00:00
|
|
|
int find(pFunctionPointer_t f) const;
|
2013-08-07 11:43:45 +00:00
|
|
|
|
|
|
|
/** Clear the call chain (remove all functions in the chain).
|
2018-04-03 19:07:03 +00:00
|
|
|
* @deprecated Do not use this function. This class is not part of the public API of mbed-os and is being removed in the future.
|
2013-08-07 11:43:45 +00:00
|
|
|
*/
|
2017-10-27 19:49:16 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
|
2018-06-27 14:09:15 +00:00
|
|
|
"public API of mbed-os and is being removed in the future.")
|
2013-08-07 11:43:26 +00:00
|
|
|
void clear();
|
2013-08-07 11:43:45 +00:00
|
|
|
|
|
|
|
/** Remove a function object from the chain
|
2018-06-27 14:09:15 +00:00
|
|
|
* @deprecated
|
2018-04-03 19:07:03 +00:00
|
|
|
* Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
|
2013-08-07 11:43:45 +00:00
|
|
|
*
|
|
|
|
* @arg f the function object to remove
|
|
|
|
*
|
|
|
|
* @returns
|
|
|
|
* true if the function object was found and removed, false otherwise.
|
|
|
|
*/
|
2017-10-27 19:49:16 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
|
2018-06-27 14:09:15 +00:00
|
|
|
"public API of mbed-os and is being removed in the future.")
|
2013-08-07 11:43:26 +00:00
|
|
|
bool remove(pFunctionPointer_t f);
|
2013-08-07 11:43:45 +00:00
|
|
|
|
|
|
|
/** Call all the functions in the chain in sequence
|
2018-06-27 14:09:15 +00:00
|
|
|
* @deprecated
|
2018-04-03 19:07:03 +00:00
|
|
|
* Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
|
|
|
|
*
|
2013-08-07 11:43:45 +00:00
|
|
|
*/
|
2017-10-27 19:49:16 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
|
2018-06-27 14:09:15 +00:00
|
|
|
"public API of mbed-os and is being removed in the future.")
|
2013-08-07 11:43:26 +00:00
|
|
|
void call();
|
2014-05-26 17:04:46 +00:00
|
|
|
|
2018-06-27 14:09:15 +00:00
|
|
|
/**
|
|
|
|
* @deprecated
|
2018-04-03 19:07:03 +00:00
|
|
|
* Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
|
|
|
|
*
|
|
|
|
*/
|
2017-10-27 19:49:16 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
|
2018-06-27 14:09:15 +00:00
|
|
|
"public API of mbed-os and is being removed in the future.")
|
|
|
|
void operator()(void)
|
|
|
|
{
|
2013-08-07 11:43:26 +00:00
|
|
|
call();
|
|
|
|
}
|
2017-10-27 19:49:16 +00:00
|
|
|
|
2018-06-27 14:09:15 +00:00
|
|
|
/**
|
|
|
|
* @deprecated
|
2018-04-03 19:07:03 +00:00
|
|
|
* Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
|
|
|
|
*
|
|
|
|
*/
|
2017-10-27 19:49:16 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
|
2018-06-27 14:09:15 +00:00
|
|
|
"public API of mbed-os and is being removed in the future.")
|
|
|
|
pFunctionPointer_t operator [](int i) const
|
|
|
|
{
|
2013-08-07 11:43:26 +00:00
|
|
|
return get(i);
|
|
|
|
}
|
|
|
|
|
2014-05-26 17:04:46 +00:00
|
|
|
private:
|
2016-05-31 22:57:41 +00:00
|
|
|
CallChainLink *_chain;
|
2013-08-07 11:43:26 +00:00
|
|
|
};
|
|
|
|
|
2017-10-24 15:05:45 +00:00
|
|
|
/**@}*/
|
|
|
|
|
|
|
|
/**@}*/
|
|
|
|
|
2013-08-07 11:43:26 +00:00
|
|
|
} // namespace mbed
|
|
|
|
|
|
|
|
#endif
|
2016-10-04 20:02:44 +00:00
|
|
|
|