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
78class Transaction : public rogue::EnableSharedFromThis<rogue::interfaces::memory::Transaction> {
79 friend class TransactionLock;
80 friend class Master;
81 friend class Hub;
82
83 public:
85 typedef uint8_t* iterator;
86
87 private:
88 // Class instance counter
89 static uint32_t classIdx_;
90
91 // Class instance lock
92 static std::mutex classMtx_;
93
94 // Conditional
95 std::condition_variable cond_;
96
97 protected:
98 // Transaction timeout
99 struct timeval timeout_;
100
101 // Transaction end time
102 struct timeval endTime_;
103
104 // Transaction start time
105 struct timeval startTime_;
106
107 // Transaction warn time
108 struct timeval warnTime_;
109
110#ifndef NO_PYTHON
111 // Transaction python buffer
112 Py_buffer pyBuf_;
113#endif
114
115 // Python buffer is valid
117
118 // Iterator (mapped to uint8_t * for now)
120
121 // Transaction address
122 uint64_t address_;
123
124 // Transaction size
125 uint32_t size_;
126
127 // Transaction type
128 uint32_t type_;
129
130 // Transaction error
131 std::string error_;
132
133 // Transaction id
134 uint32_t id_;
135
136 // Done state
137 bool done_;
138
139 // Transaction lock
140 std::mutex lock_;
141
142 // Sub-transactions vector
144
145 // Done creating subtransactions for this transaction
147
148 // Identify if it's a parent or a sub transaction
150
152 std::shared_ptr<rogue::Logging> log_;
153
154 // Weak pointer to parent transaction, where applicable
155 std::weak_ptr<rogue::interfaces::memory::Transaction> parentTransaction_;
156
167 static std::shared_ptr<rogue::interfaces::memory::Transaction> create(struct timeval timeout);
168
169 // Wait for the transaction to complete, called by Master
170 std::string wait();
171
172 public:
173 // Setup class for use in python
174 static void setup_python();
175
189 explicit Transaction(struct timeval timeout);
190
191 // Destroy the Transaction.
192 ~Transaction();
193
201 std::shared_ptr<rogue::interfaces::memory::TransactionLock> lock();
202
213 bool expired();
214
222 uint32_t id();
223
231 uint64_t address();
232
240 uint32_t size();
241
256 uint32_t type();
257
263 std::shared_ptr<rogue::interfaces::memory::Transaction> createSubTransaction();
264
266 void doneSubTransactions();
267
277 void refreshTimer(std::shared_ptr<rogue::interfaces::memory::Transaction> reference);
278
286 void done();
287
297 void errorStr(std::string error);
298
304 void error(const char* fmt, ...);
305
315 uint8_t* begin();
316
326 uint8_t* end();
327
328#ifndef NO_PYTHON
329
340 void getData(boost::python::object p, uint32_t offset);
341
352 void setData(boost::python::object p, uint32_t offset);
353#endif
354};
355
357typedef std::shared_ptr<rogue::interfaces::memory::Transaction> TransactionPtr;
358
359} // namespace memory
360} // namespace interfaces
361} // namespace rogue
362
363#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:78
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 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:85
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.