mbed library sources

Fork of mbed-src by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Transaction.h Source File

Transaction.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2015 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #ifndef MBED_TRANSACTION_H
00017 #define MBED_TRANSACTION_H
00018 
00019 #include "platform.h"
00020 #include "FunctionPointer.h"
00021 
00022 namespace mbed {
00023 
00024 /** Transaction structure
00025  */
00026 typedef struct {
00027     void *tx_buffer;           /**< Tx buffer */
00028     size_t tx_length;          /**< Length of Tx buffer*/
00029     void *rx_buffer;           /**< Rx buffer */
00030     size_t rx_length;          /**< Length of Rx buffer */
00031     uint32_t event;            /**< Event for a transaction */
00032     event_callback_t  callback; /**< User's callback */
00033     uint8_t width;             /**< Buffer's word width (8, 16, 32, 64) */
00034 } transaction_t;
00035 
00036 /** Transaction class defines a transaction.
00037  */
00038 template<typename Class>
00039 class Transaction {
00040 public:
00041     Transaction(Class *tpointer, const transaction_t& transaction) : _obj(tpointer), _data(transaction) {
00042     }
00043 
00044     Transaction() : _obj(), _data() {
00045     }
00046 
00047     ~Transaction() {
00048     }
00049 
00050     /** Get object's instance for the transaction
00051      *
00052      * @return The object which was stored
00053      */
00054     Class* get_object() {
00055         return _obj;
00056     }
00057 
00058     /** Get the transaction
00059      *
00060      * @return The transaction which was stored
00061      */
00062     transaction_t* get_transaction() {
00063         return &_data;
00064     }
00065 
00066 private:
00067     Class* _obj;
00068     transaction_t _data;
00069 };
00070 
00071 }
00072 
00073 #endif