IOTIO
Dependencies: Nucleo_BLE_API_IOTIO Nucleo_BLE_BlueNRG Nucleo_BLE_DemoApp Nucleo_Sensor_Shield mbed
Dependents: Nucleo_BLE_Demo_IOTIO
Fork of Nucleo_BLE_Demo by
mbed/Transaction.h@1:4bdfa7d7e8bf, 2016-10-29 (annotated)
- Committer:
- 16038618
- Date:
- Sat Oct 29 15:11:28 2016 +0000
- Revision:
- 1:4bdfa7d7e8bf
IOTIO
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
16038618 | 1:4bdfa7d7e8bf | 1 | /* mbed Microcontroller Library |
16038618 | 1:4bdfa7d7e8bf | 2 | * Copyright (c) 2015 ARM Limited |
16038618 | 1:4bdfa7d7e8bf | 3 | * |
16038618 | 1:4bdfa7d7e8bf | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
16038618 | 1:4bdfa7d7e8bf | 5 | * you may not use this file except in compliance with the License. |
16038618 | 1:4bdfa7d7e8bf | 6 | * You may obtain a copy of the License at |
16038618 | 1:4bdfa7d7e8bf | 7 | * |
16038618 | 1:4bdfa7d7e8bf | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
16038618 | 1:4bdfa7d7e8bf | 9 | * |
16038618 | 1:4bdfa7d7e8bf | 10 | * Unless required by applicable law or agreed to in writing, software |
16038618 | 1:4bdfa7d7e8bf | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
16038618 | 1:4bdfa7d7e8bf | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16038618 | 1:4bdfa7d7e8bf | 13 | * See the License for the specific language governing permissions and |
16038618 | 1:4bdfa7d7e8bf | 14 | * limitations under the License. |
16038618 | 1:4bdfa7d7e8bf | 15 | */ |
16038618 | 1:4bdfa7d7e8bf | 16 | #ifndef MBED_TRANSACTION_H |
16038618 | 1:4bdfa7d7e8bf | 17 | #define MBED_TRANSACTION_H |
16038618 | 1:4bdfa7d7e8bf | 18 | |
16038618 | 1:4bdfa7d7e8bf | 19 | #include "platform.h" |
16038618 | 1:4bdfa7d7e8bf | 20 | #include "FunctionPointer.h" |
16038618 | 1:4bdfa7d7e8bf | 21 | |
16038618 | 1:4bdfa7d7e8bf | 22 | namespace mbed { |
16038618 | 1:4bdfa7d7e8bf | 23 | |
16038618 | 1:4bdfa7d7e8bf | 24 | /** Transaction structure |
16038618 | 1:4bdfa7d7e8bf | 25 | */ |
16038618 | 1:4bdfa7d7e8bf | 26 | typedef struct { |
16038618 | 1:4bdfa7d7e8bf | 27 | void *tx_buffer; /**< Tx buffer */ |
16038618 | 1:4bdfa7d7e8bf | 28 | size_t tx_length; /**< Length of Tx buffer*/ |
16038618 | 1:4bdfa7d7e8bf | 29 | void *rx_buffer; /**< Rx buffer */ |
16038618 | 1:4bdfa7d7e8bf | 30 | size_t rx_length; /**< Length of Rx buffer */ |
16038618 | 1:4bdfa7d7e8bf | 31 | uint32_t event; /**< Event for a transaction */ |
16038618 | 1:4bdfa7d7e8bf | 32 | event_callback_t callback; /**< User's callback */ |
16038618 | 1:4bdfa7d7e8bf | 33 | uint8_t width; /**< Buffer's word width (8, 16, 32, 64) */ |
16038618 | 1:4bdfa7d7e8bf | 34 | } transaction_t; |
16038618 | 1:4bdfa7d7e8bf | 35 | |
16038618 | 1:4bdfa7d7e8bf | 36 | /** Transaction class defines a transaction. |
16038618 | 1:4bdfa7d7e8bf | 37 | */ |
16038618 | 1:4bdfa7d7e8bf | 38 | template<typename Class> |
16038618 | 1:4bdfa7d7e8bf | 39 | class Transaction { |
16038618 | 1:4bdfa7d7e8bf | 40 | public: |
16038618 | 1:4bdfa7d7e8bf | 41 | Transaction(Class *tpointer, const transaction_t& transaction) : _obj(tpointer), _data(transaction) { |
16038618 | 1:4bdfa7d7e8bf | 42 | } |
16038618 | 1:4bdfa7d7e8bf | 43 | |
16038618 | 1:4bdfa7d7e8bf | 44 | Transaction() : _obj(), _data() { |
16038618 | 1:4bdfa7d7e8bf | 45 | } |
16038618 | 1:4bdfa7d7e8bf | 46 | |
16038618 | 1:4bdfa7d7e8bf | 47 | ~Transaction() { |
16038618 | 1:4bdfa7d7e8bf | 48 | } |
16038618 | 1:4bdfa7d7e8bf | 49 | |
16038618 | 1:4bdfa7d7e8bf | 50 | /** Get object's instance for the transaction |
16038618 | 1:4bdfa7d7e8bf | 51 | * |
16038618 | 1:4bdfa7d7e8bf | 52 | * @return The object which was stored |
16038618 | 1:4bdfa7d7e8bf | 53 | */ |
16038618 | 1:4bdfa7d7e8bf | 54 | Class* get_object() { |
16038618 | 1:4bdfa7d7e8bf | 55 | return _obj; |
16038618 | 1:4bdfa7d7e8bf | 56 | } |
16038618 | 1:4bdfa7d7e8bf | 57 | |
16038618 | 1:4bdfa7d7e8bf | 58 | /** Get the transaction |
16038618 | 1:4bdfa7d7e8bf | 59 | * |
16038618 | 1:4bdfa7d7e8bf | 60 | * @return The transaction which was stored |
16038618 | 1:4bdfa7d7e8bf | 61 | */ |
16038618 | 1:4bdfa7d7e8bf | 62 | transaction_t* get_transaction() { |
16038618 | 1:4bdfa7d7e8bf | 63 | return &_data; |
16038618 | 1:4bdfa7d7e8bf | 64 | } |
16038618 | 1:4bdfa7d7e8bf | 65 | |
16038618 | 1:4bdfa7d7e8bf | 66 | private: |
16038618 | 1:4bdfa7d7e8bf | 67 | Class* _obj; |
16038618 | 1:4bdfa7d7e8bf | 68 | transaction_t _data; |
16038618 | 1:4bdfa7d7e8bf | 69 | }; |
16038618 | 1:4bdfa7d7e8bf | 70 | |
16038618 | 1:4bdfa7d7e8bf | 71 | } |
16038618 | 1:4bdfa7d7e8bf | 72 | |
16038618 | 1:4bdfa7d7e8bf | 73 | #endif |