55void rim::Transaction::setup_python() {
57 bp::class_<rim::Transaction, rim::TransactionPtr, boost::noncopyable>(
"Transaction", bp::no_init)
58 .def(
"lock", &rim::Transaction::lock)
59 .def(
"id", &rim::Transaction::id)
60 .def(
"address", &rim::Transaction::address)
61 .def(
"size", &rim::Transaction::size)
62 .def(
"type", &rim::Transaction::type)
63 .def(
"done", &rim::Transaction::done)
64 .def(
"error", &rim::Transaction::errorStr)
65 .def(
"expired", &rim::Transaction::expired)
66 .def(
"setData", &rim::Transaction::setData)
67 .def(
"getData", &rim::Transaction::getData);
148 subTran->parentTransaction_ = shared_from_this();
149 subTran->isSubTransaction_ =
true;
150 subTranMap_[subTran->id()] = subTran;
151 log_->debug(
"Created subTransaction id=%" PRIu32
", parent=%" PRIu32, subTran->id_, this->id_);
203void rim::Transaction::subTransactionDone(uint32_t subId,
const std::string& subError) {
205 subTranMap_.erase(subId);
210 if (!subError.empty()) {
211 subTranError_ +=
"Transaction error. Subtransaction " + std::to_string(subId) +
" failed with error: " +
217 if (subTranMap_.empty() && doneCreatingSubTransactions_) {
218 if (subTranError_.empty())
221 errorStr(subTranError_);
238std::string rim::Transaction::wait() {
239 struct timeval currTime;
241 std::unique_lock<std::mutex> lock(lock_);
245 gettimeofday(&currTime, NULL);
246 if (timerisset(&endTime_) && timercmp(&currTime, &(endTime_), >)) {
248 error_ =
"Timeout waiting for register transaction " + std::to_string(id_) +
" message response.";
250 log_->debug(
"Transaction timeout. type=%" PRIu32
" id=%" PRIu32
251 ", address=0x%" PRIx64
", size=%" PRIu32
", timeout=%" PRId64
".%06" PRId64
"s",
256 static_cast<int64_t
>(timeout_.tv_sec),
257 static_cast<int64_t
>(timeout_.tv_usec));
259 cond_.wait_for(lock, std::chrono::microseconds(1000));
267 PyBuffer_Release(&(pyBuf_));
278 struct timeval currTime;
279 struct timeval nextTime;
281 gettimeofday(&currTime, NULL);
282 std::lock_guard<std::mutex> lock(lock_);
285 if (ref == NULL || timercmp(&startTime_, &(ref->startTime_), >=)) {
286 timeradd(&currTime, &timeout_, &endTime_);
288 if (warnTime_.tv_sec == 0 && warnTime_.tv_usec == 0) {
289 warnTime_ = endTime_;
290 }
else if (timercmp(&warnTime_, &currTime, >=)) {
291 log_->warning(
"Transaction timer refresh! Possible slow link! type=%" PRIu32
" id=%" PRIu32
292 ", address=0x%016" PRIx64
", size=%" PRIu32
", timeout=%" PRId64
".%06" PRId64
"s",
297 static_cast<int64_t
>(timeout_.tv_sec),
298 static_cast<int64_t
>(timeout_.tv_usec));
299 warnTime_ = endTime_;
319void rim::Transaction::setData(boost::python::object p, uint32_t offset) {
322 if (PyObject_GetBuffer(p.ptr(), &pyBuf, PyBUF_SIMPLE) < 0)
325 uint32_t count = pyBuf.len;
327 if ((offset + count) > size_) {
328 PyBuffer_Release(&pyBuf);
330 "Attempt to set %" PRIu32
" bytes at offset %" PRIu32
331 " to python buffer with size %" PRIu32,
337 std::memcpy(begin() + offset,
reinterpret_cast<uint8_t*
>(pyBuf.buf), count);
338 PyBuffer_Release(&pyBuf);
342void rim::Transaction::getData(boost::python::object p, uint32_t offset) {
345 if (PyObject_GetBuffer(p.ptr(), &pyBuf, PyBUF_CONTIG) < 0)
348 uint32_t count = pyBuf.len;
350 if ((offset + count) > size_) {
351 PyBuffer_Release(&pyBuf);
353 "Attempt to get %" PRIu32
" bytes from offset %" PRIu32
354 " to python buffer with size %" PRIu32,
360 std::memcpy(
reinterpret_cast<uint8_t*
>(pyBuf.buf), begin() + offset, count);
361 PyBuffer_Release(&pyBuf);