mbed-os5 only for TYBLE16
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
drivers/internal/AsyncOp.h@1:9db0e321a9f4, 2019-12-31 (annotated)
- Committer:
- kenjiArai
- Date:
- Tue Dec 31 06:02:27 2019 +0000
- Revision:
- 1:9db0e321a9f4
updated based on mbed-os5.15.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 1:9db0e321a9f4 | 1 | /* |
kenjiArai | 1:9db0e321a9f4 | 2 | * Copyright (c) 2018-2019, Arm Limited and affiliates. |
kenjiArai | 1:9db0e321a9f4 | 3 | * SPDX-License-Identifier: Apache-2.0 |
kenjiArai | 1:9db0e321a9f4 | 4 | * |
kenjiArai | 1:9db0e321a9f4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kenjiArai | 1:9db0e321a9f4 | 6 | * you may not use this file except in compliance with the License. |
kenjiArai | 1:9db0e321a9f4 | 7 | * You may obtain a copy of the License at |
kenjiArai | 1:9db0e321a9f4 | 8 | * |
kenjiArai | 1:9db0e321a9f4 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
kenjiArai | 1:9db0e321a9f4 | 10 | * |
kenjiArai | 1:9db0e321a9f4 | 11 | * Unless required by applicable law or agreed to in writing, software |
kenjiArai | 1:9db0e321a9f4 | 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
kenjiArai | 1:9db0e321a9f4 | 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kenjiArai | 1:9db0e321a9f4 | 14 | * See the License for the specific language governing permissions and |
kenjiArai | 1:9db0e321a9f4 | 15 | * limitations under the License. |
kenjiArai | 1:9db0e321a9f4 | 16 | */ |
kenjiArai | 1:9db0e321a9f4 | 17 | |
kenjiArai | 1:9db0e321a9f4 | 18 | #ifndef MBED_ASYNC_OP_H |
kenjiArai | 1:9db0e321a9f4 | 19 | #define MBED_ASYNC_OP_H |
kenjiArai | 1:9db0e321a9f4 | 20 | |
kenjiArai | 1:9db0e321a9f4 | 21 | #include "Mutex.h" |
kenjiArai | 1:9db0e321a9f4 | 22 | #include "Semaphore.h" |
kenjiArai | 1:9db0e321a9f4 | 23 | #include "Callback.h" |
kenjiArai | 1:9db0e321a9f4 | 24 | |
kenjiArai | 1:9db0e321a9f4 | 25 | #include "LinkEntry.h" |
kenjiArai | 1:9db0e321a9f4 | 26 | #include "OperationListBase.h" |
kenjiArai | 1:9db0e321a9f4 | 27 | |
kenjiArai | 1:9db0e321a9f4 | 28 | /** \defgroup mbed-os-internal Internal API */ |
kenjiArai | 1:9db0e321a9f4 | 29 | |
kenjiArai | 1:9db0e321a9f4 | 30 | /** \addtogroup drivers-internal-api Drivers |
kenjiArai | 1:9db0e321a9f4 | 31 | * \ingroup mbed-os-internal |
kenjiArai | 1:9db0e321a9f4 | 32 | */ |
kenjiArai | 1:9db0e321a9f4 | 33 | |
kenjiArai | 1:9db0e321a9f4 | 34 | /** \defgroup drivers-internal-api-usb USB |
kenjiArai | 1:9db0e321a9f4 | 35 | * \ingroup drivers-internal-api |
kenjiArai | 1:9db0e321a9f4 | 36 | */ |
kenjiArai | 1:9db0e321a9f4 | 37 | |
kenjiArai | 1:9db0e321a9f4 | 38 | /** |
kenjiArai | 1:9db0e321a9f4 | 39 | * \defgroup drivers_AsyncOp AsyncOp class |
kenjiArai | 1:9db0e321a9f4 | 40 | * \ingroup drivers-internal-api-usb |
kenjiArai | 1:9db0e321a9f4 | 41 | * @{ |
kenjiArai | 1:9db0e321a9f4 | 42 | */ |
kenjiArai | 1:9db0e321a9f4 | 43 | class AsyncOp: public LinkEntry { |
kenjiArai | 1:9db0e321a9f4 | 44 | public: |
kenjiArai | 1:9db0e321a9f4 | 45 | |
kenjiArai | 1:9db0e321a9f4 | 46 | /** |
kenjiArai | 1:9db0e321a9f4 | 47 | * Construct a new AsyncOp object |
kenjiArai | 1:9db0e321a9f4 | 48 | */ |
kenjiArai | 1:9db0e321a9f4 | 49 | AsyncOp(); |
kenjiArai | 1:9db0e321a9f4 | 50 | |
kenjiArai | 1:9db0e321a9f4 | 51 | /** |
kenjiArai | 1:9db0e321a9f4 | 52 | * Construct a new AsyncOp object |
kenjiArai | 1:9db0e321a9f4 | 53 | * |
kenjiArai | 1:9db0e321a9f4 | 54 | * @param callback Completion callback |
kenjiArai | 1:9db0e321a9f4 | 55 | */ |
kenjiArai | 1:9db0e321a9f4 | 56 | AsyncOp(mbed::Callback<void()> &callback); |
kenjiArai | 1:9db0e321a9f4 | 57 | |
kenjiArai | 1:9db0e321a9f4 | 58 | /** |
kenjiArai | 1:9db0e321a9f4 | 59 | * Cleanup resources used by this AsyncOp |
kenjiArai | 1:9db0e321a9f4 | 60 | */ |
kenjiArai | 1:9db0e321a9f4 | 61 | virtual ~AsyncOp(); |
kenjiArai | 1:9db0e321a9f4 | 62 | |
kenjiArai | 1:9db0e321a9f4 | 63 | /** |
kenjiArai | 1:9db0e321a9f4 | 64 | * Wait for this asynchronous operation to complete |
kenjiArai | 1:9db0e321a9f4 | 65 | * |
kenjiArai | 1:9db0e321a9f4 | 66 | * If the timeout expires then this asynchronous operation is |
kenjiArai | 1:9db0e321a9f4 | 67 | * aborted and the timeout flag is set. |
kenjiArai | 1:9db0e321a9f4 | 68 | * |
kenjiArai | 1:9db0e321a9f4 | 69 | * @note - the host object's lock MUST NOT be held when this call is made |
kenjiArai | 1:9db0e321a9f4 | 70 | */ |
kenjiArai | 1:9db0e321a9f4 | 71 | void wait(rtos::Mutex *host_mutex, uint32_t milliseconds = osWaitForever); |
kenjiArai | 1:9db0e321a9f4 | 72 | |
kenjiArai | 1:9db0e321a9f4 | 73 | /** |
kenjiArai | 1:9db0e321a9f4 | 74 | * Abort this asynchronous operation |
kenjiArai | 1:9db0e321a9f4 | 75 | * |
kenjiArai | 1:9db0e321a9f4 | 76 | * This function has no effect if the operation is complete. Otherwise |
kenjiArai | 1:9db0e321a9f4 | 77 | * the aborted flag is set. |
kenjiArai | 1:9db0e321a9f4 | 78 | * |
kenjiArai | 1:9db0e321a9f4 | 79 | * @note - the host object's lock MUST be held when this call is made |
kenjiArai | 1:9db0e321a9f4 | 80 | */ |
kenjiArai | 1:9db0e321a9f4 | 81 | void abort(); |
kenjiArai | 1:9db0e321a9f4 | 82 | |
kenjiArai | 1:9db0e321a9f4 | 83 | /** |
kenjiArai | 1:9db0e321a9f4 | 84 | * Check if this operation timed out |
kenjiArai | 1:9db0e321a9f4 | 85 | * |
kenjiArai | 1:9db0e321a9f4 | 86 | * @return true if this operation timed out, false otherwise |
kenjiArai | 1:9db0e321a9f4 | 87 | */ |
kenjiArai | 1:9db0e321a9f4 | 88 | bool timeout(); |
kenjiArai | 1:9db0e321a9f4 | 89 | |
kenjiArai | 1:9db0e321a9f4 | 90 | /** |
kenjiArai | 1:9db0e321a9f4 | 91 | * Check if this operation was aborted |
kenjiArai | 1:9db0e321a9f4 | 92 | * |
kenjiArai | 1:9db0e321a9f4 | 93 | * @return true if this operation was aborted, false otherwise |
kenjiArai | 1:9db0e321a9f4 | 94 | */ |
kenjiArai | 1:9db0e321a9f4 | 95 | bool aborted(); |
kenjiArai | 1:9db0e321a9f4 | 96 | |
kenjiArai | 1:9db0e321a9f4 | 97 | protected: |
kenjiArai | 1:9db0e321a9f4 | 98 | |
kenjiArai | 1:9db0e321a9f4 | 99 | /** |
kenjiArai | 1:9db0e321a9f4 | 100 | * Callback indicating that something changed |
kenjiArai | 1:9db0e321a9f4 | 101 | * |
kenjiArai | 1:9db0e321a9f4 | 102 | * @return true if finished false if not |
kenjiArai | 1:9db0e321a9f4 | 103 | */ |
kenjiArai | 1:9db0e321a9f4 | 104 | virtual bool process() = 0; |
kenjiArai | 1:9db0e321a9f4 | 105 | |
kenjiArai | 1:9db0e321a9f4 | 106 | /** |
kenjiArai | 1:9db0e321a9f4 | 107 | * Callback indicating that this event finished |
kenjiArai | 1:9db0e321a9f4 | 108 | */ |
kenjiArai | 1:9db0e321a9f4 | 109 | virtual void complete(); |
kenjiArai | 1:9db0e321a9f4 | 110 | |
kenjiArai | 1:9db0e321a9f4 | 111 | private: |
kenjiArai | 1:9db0e321a9f4 | 112 | friend class OperationListBase; |
kenjiArai | 1:9db0e321a9f4 | 113 | |
kenjiArai | 1:9db0e321a9f4 | 114 | mbed::Callback<void()> _callback; |
kenjiArai | 1:9db0e321a9f4 | 115 | OperationListBase *_list; |
kenjiArai | 1:9db0e321a9f4 | 116 | rtos::Semaphore *_wait; |
kenjiArai | 1:9db0e321a9f4 | 117 | bool _aborted; |
kenjiArai | 1:9db0e321a9f4 | 118 | bool _timeout; |
kenjiArai | 1:9db0e321a9f4 | 119 | |
kenjiArai | 1:9db0e321a9f4 | 120 | void _abort(bool timeout); |
kenjiArai | 1:9db0e321a9f4 | 121 | |
kenjiArai | 1:9db0e321a9f4 | 122 | static void _host_lock(rtos::Mutex *host_mutex); |
kenjiArai | 1:9db0e321a9f4 | 123 | |
kenjiArai | 1:9db0e321a9f4 | 124 | static void _host_unlock(rtos::Mutex *host_mutex); |
kenjiArai | 1:9db0e321a9f4 | 125 | }; |
kenjiArai | 1:9db0e321a9f4 | 126 | |
kenjiArai | 1:9db0e321a9f4 | 127 | /** @}*/ |
kenjiArai | 1:9db0e321a9f4 | 128 | |
kenjiArai | 1:9db0e321a9f4 | 129 | #endif |