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);
142 subTran->parentTransaction_ = shared_from_this();
143 subTran->isSubTransaction_ =
true;
144 subTranMap_[subTran->id()] = subTran;
145 log_->debug(
"Created subTransaction id=%" PRIu32
", parent=%" PRIu32, subTran->id_, this->id_);
226std::string rim::Transaction::wait() {
227 struct timeval currTime;
229 std::unique_lock<std::mutex> lock(lock_);
233 gettimeofday(&currTime, NULL);
234 if (endTime_.tv_sec != 0 && endTime_.tv_usec != 0 && timercmp(&currTime, &(endTime_), >)) {
236 error_ =
"Timeout waiting for register transaction " + std::to_string(id_) +
" message response.";
238 log_->debug(
"Transaction timeout. type=%" PRIu32
" id=%" PRIu32
239 ", address=0x%" PRIx64
", size=%" PRIu32
", timeout=%" PRId64
".%06" PRId64
"s",
244 static_cast<int64_t
>(timeout_.tv_sec),
245 static_cast<int64_t
>(timeout_.tv_usec));
247 cond_.wait_for(lock, std::chrono::microseconds(1000));
255 PyBuffer_Release(&(pyBuf_));
266 struct timeval currTime;
267 struct timeval nextTime;
269 gettimeofday(&currTime, NULL);
270 std::lock_guard<std::mutex> lock(lock_);
273 if (ref == NULL || timercmp(&startTime_, &(ref->startTime_), >=)) {
274 timeradd(&currTime, &timeout_, &endTime_);
276 if (warnTime_.tv_sec == 0 && warnTime_.tv_usec == 0) {
277 warnTime_ = endTime_;
278 }
else if (timercmp(&warnTime_, &currTime, >=)) {
279 log_->warning(
"Transaction timer refresh! Possible slow link! type=%" PRIu32
" id=%" PRIu32
280 ", address=0x%016" PRIx64
", size=%" PRIu32
", timeout=%" PRId64
".%06" PRId64
"s",
285 static_cast<int64_t
>(timeout_.tv_sec),
286 static_cast<int64_t
>(timeout_.tv_usec));
287 warnTime_ = endTime_;
307void rim::Transaction::setData(boost::python::object p, uint32_t offset) {
310 if (PyObject_GetBuffer(p.ptr(), &pyBuf, PyBUF_SIMPLE) < 0)
313 uint32_t count = pyBuf.len;
315 if ((offset + count) > size_) {
316 PyBuffer_Release(&pyBuf);
318 "Attempt to set %" PRIu32
" bytes at offset %" PRIu32
319 " to python buffer with size %" PRIu32,
325 std::memcpy(begin() + offset,
reinterpret_cast<uint8_t*
>(pyBuf.buf), count);
326 PyBuffer_Release(&pyBuf);
330void rim::Transaction::getData(boost::python::object p, uint32_t offset) {
333 if (PyObject_GetBuffer(p.ptr(), &pyBuf, PyBUF_CONTIG) < 0)
336 uint32_t count = pyBuf.len;
338 if ((offset + count) > size_) {
339 PyBuffer_Release(&pyBuf);
341 "Attempt to get %" PRIu32
" bytes from offset %" PRIu32
342 " to python buffer with size %" PRIu32,
348 std::memcpy(
reinterpret_cast<uint8_t*
>(pyBuf.buf), begin() + offset, count);
349 PyBuffer_Release(&pyBuf);