rogue
Loading...
Searching...
No Matches
Transaction.h
Go to the documentation of this file.
1
17#ifndef __ROGUE_INTERFACES_MEMORY_TRANSACTION_H__
18#define __ROGUE_INTERFACES_MEMORY_TRANSACTION_H__
19#include "rogue/Directives.h"
20
21#include <stdint.h>
22
23#include <condition_variable>
24#include <map>
25#include <memory>
26#include <mutex>
27#include <string>
28#include <thread>
29
31#include "rogue/Logging.h"
32
33#ifndef NO_PYTHON
34 #include <boost/python.hpp>
35#endif
36
37namespace rogue {
38namespace interfaces {
39namespace memory {
40
41class TransactionLock;
42class Transaction;
43class Master;
44class Hub;
45
46// using TransactionIDVec = std::vector<uint32_t>;
47// using TransactionQueue = std::queue<std::shared_ptr<rogue::interfaces::memory::Transaction>>;
48using TransactionMap = std::map<uint32_t, std::shared_ptr<rogue::interfaces::memory::Transaction>>;
49
79class Transaction : public rogue::EnableSharedFromThis<rogue::interfaces::memory::Transaction> {
80 friend class TransactionLock;
81 friend class Master;
82 friend class Hub;
83
84 public:
86 typedef uint8_t* iterator;
87
88 private:
89 // Class instance counter
90 static uint32_t classIdx_;
91
92 // Class instance lock
93 static std::mutex classMtx_;
94
95 // Conditional
96 std::condition_variable cond_;
97
98 protected:
99 // Transaction timeout
100 struct timeval timeout_;
101
102 // Transaction end time
103 struct timeval endTime_;
104
105 // Transaction start time
106 struct timeval startTime_;
107
108 // Transaction warn time
109 struct timeval warnTime_;
110
111#ifndef NO_PYTHON
112 // Transaction python buffer
113 Py_buffer pyBuf_;
114#endif
115
116 // Python buffer is valid
118
119 // Iterator (mapped to uint8_t * for now)
121
122 // Transaction address
123 uint64_t address_;
124
125 // Transaction size
126 uint32_t size_;
127
128 // Transaction type
129 uint32_t type_;
130
131 // Transaction error
132 std::string error_;
133
134 // Transaction id
135 uint32_t id_;
136
137 // Done state
138 bool done_;
139
140 // Transaction lock
141 std::mutex lock_;
142
143 // Sub-transactions vector
145
146 // Done creating subtransactions for this transaction
148
149 // Errors collected from completed sub-transactions, reported when the last one finishes
150 std::string subTranError_;
151
152 // Identify if it's a parent or a sub transaction
154
156 std::shared_ptr<rogue::Logging> log_;
157
158 // Weak pointer to parent transaction, where applicable
159 std::weak_ptr<rogue::interfaces::memory::Transaction> parentTransaction_;
160
171 static std::shared_ptr<rogue::interfaces::memory::Transaction> create(struct timeval timeout);
172
173 // Wait for the transaction to complete, called by Master
174 std::string wait();
175
188 void subTransactionDone(uint32_t subId, const std::string& subError);
189
190 public:
191 // Setup class for use in python
192 static void setup_python();
193
207 explicit Transaction(struct timeval timeout);
208
209 // Destroy the Transaction.
210 ~Transaction();
211
219 std::shared_ptr<rogue::interfaces::memory::TransactionLock> lock();
220
231 bool expired();
232
240 uint32_t id();
241
249 uint64_t address();
250
258 uint32_t size();
259
274 uint32_t type();
275
281 std::shared_ptr<rogue::interfaces::memory::Transaction> createSubTransaction();
282
284 void doneSubTransactions();
285
295 void refreshTimer(std::shared_ptr<rogue::interfaces::memory::Transaction> reference);
296
304 void done();
305
315 void errorStr(std::string error);
316
322 void error(const char* fmt, ...);
323
333 uint8_t* begin();
334
344 uint8_t* end();
345
346#ifndef NO_PYTHON
347
358 void getData(boost::python::object p, uint32_t offset);
359
370 void setData(boost::python::object p, uint32_t offset);
371#endif
372};
373
375typedef std::shared_ptr<rogue::interfaces::memory::Transaction> TransactionPtr;
376
377} // namespace memory
378} // namespace interfaces
379} // namespace rogue
380
381#endif
Typed shared-from-this helper for Rogue classes.
Memory interface Hub device.
Definition Hub.h:72
Master endpoint for memory transactions.
Definition Master.h:50
Scoped lock wrapper for a memory transaction.
Memory transaction container passed between master and slave.
Definition Transaction.h:79
uint64_t address()
Returns the transaction address.
void getData(boost::python::object p, uint32_t offset)
Copies transaction data into a Python byte-array-like object.
uint8_t * end()
Returns iterator to the end of transaction data.
void errorStr(std::string error)
Marks transaction completion with an error string (Python interface).
std::shared_ptr< rogue::Logging > log_
void doneSubTransactions()
Marks subtransaction creation as complete for this transaction.
uint32_t id()
Returns the transaction ID.
bool expired()
Returns whether this transaction has expired.
std::string wait()
Wait for the transaction to complete.
void refreshTimer(std::shared_ptr< rogue::interfaces::memory::Transaction > reference)
Refreshes the transaction timer.
uint32_t size()
Returns the transaction size.
uint8_t * begin()
Returns iterator to the beginning of transaction data.
std::weak_ptr< rogue::interfaces::memory::Transaction > parentTransaction_
void subTransactionDone(uint32_t subId, const std::string &subError)
Records completion of one sub-transaction.
void error(const char *fmt,...)
Marks transaction completion with a formatted C-string error.
uint8_t * iterator
Iterator alias for transaction byte access.
Definition Transaction.h:86
void setData(boost::python::object p, uint32_t offset)
Copies data from a Python byte-array-like object into the transaction.
uint32_t type()
Returns the transaction type constant.
static std::shared_ptr< rogue::interfaces::memory::Transaction > create(struct timeval timeout)
Creates a transaction container.
void done()
Marks transaction completion without error.
std::shared_ptr< rogue::interfaces::memory::TransactionLock > lock()
Locks the transaction and returns a lock wrapper.
std::shared_ptr< rogue::interfaces::memory::Transaction > createSubTransaction()
Creates a subtransaction linked to this parent transaction.
std::map< uint32_t, std::shared_ptr< rogue::interfaces::memory::Transaction > > TransactionMap
Definition Transaction.h:48
std::shared_ptr< rogue::interfaces::memory::Transaction > TransactionPtr
Shared pointer alias for Transaction.