diff --git a/psrdada_cpp/dada_client_base.hpp b/psrdada_cpp/dada_client_base.hpp index b0f84e38d9cc689250f5d4a4ce32bac90ef0c370..e990ef74e41b3a1bc15b3b02f23098d6bb677481 100644 --- a/psrdada_cpp/dada_client_base.hpp +++ b/psrdada_cpp/dada_client_base.hpp @@ -10,10 +10,8 @@ namespace psrdada_cpp { class DadaClientBase { - private: - key_t _key; - protected: + key_t _key; dada_hdu_t* _hdu; bool _connected; MultiLog& _log; diff --git a/psrdada_cpp/detail/dada_io_loop_reader.cpp b/psrdada_cpp/detail/dada_io_loop_reader.cpp index b8dfb7d0a41b8bf2fbfc3489e6ccc781604c46c7..b5cc7c888fab4f25e2f6d7bdaaafa23e64dbaf65 100644 --- a/psrdada_cpp/detail/dada_io_loop_reader.cpp +++ b/psrdada_cpp/detail/dada_io_loop_reader.cpp @@ -26,17 +26,9 @@ namespace psrdada_cpp { BOOST_LOG_TRIVIAL(info) << "Attaching new read client to buffer"; DadaReadClient client(_key,_log); - BOOST_LOG_TRIVIAL(debug) << "Header buffer is " << client.header_buffer_count() - << " x " << client.header_buffer_size() << " bytes"; - BOOST_LOG_TRIVIAL(debug) << "Data buffer is " << client.data_buffer_count() - << " x " << client.data_buffer_size() << " bytes"; auto& header_stream = client.header_stream(); - auto& block = header_stream.next(); - BOOST_LOG_TRIVIAL(debug) << "Acquired header block (" - << block.used_bytes() <<"/"<<block.total_bytes() << " bytes)"; - static_cast<ApplicationType*>(this)->on_connect(block); + static_cast<ApplicationType*>(this)->on_connect(header_stream.next()); header_stream.release(); - BOOST_LOG_TRIVIAL(debug) << "Released header block"; auto& data_stream = client.data_stream(); while (!_stop) { @@ -45,12 +37,8 @@ namespace psrdada_cpp BOOST_LOG_TRIVIAL(info) << "Reached end of data"; break; } - auto& data_block = data_stream.next(); - BOOST_LOG_TRIVIAL(debug) << "Acquired data block (" - << block.used_bytes() <<"/"<<block.total_bytes() << " bytes)"; - static_cast<ApplicationType*>(this)->on_next(data_block); + static_cast<ApplicationType*>(this)->on_next(data_stream.next()); data_stream.release(); - BOOST_LOG_TRIVIAL(debug) << "Released data block"; } } _running = false; diff --git a/psrdada_cpp/detail/dada_io_loop_writer.cpp b/psrdada_cpp/detail/dada_io_loop_writer.cpp index dc448d808075a341cbf3e4de25e07c9c6bf6e8d1..f5eb7b824270498b94d7e0bd76e3e3f264751bd9 100644 --- a/psrdada_cpp/detail/dada_io_loop_writer.cpp +++ b/psrdada_cpp/detail/dada_io_loop_writer.cpp @@ -26,29 +26,17 @@ namespace psrdada_cpp { BOOST_LOG_TRIVIAL(info) << "Attaching new write client to buffer"; DadaWriteClient client(_key,_log); - BOOST_LOG_TRIVIAL(debug) << "Header buffer is " << client.header_buffer_count() - << " x " << client.header_buffer_size() << " bytes"; - BOOST_LOG_TRIVIAL(debug) << "Data buffer is " << client.data_buffer_count() - << " x " << client.data_buffer_size() << " bytes"; auto& header_stream = client.header_stream(); - auto& block = header_stream.next(); - BOOST_LOG_TRIVIAL(debug) << "Acquired header block (" - << block.used_bytes() <<"/"<<block.total_bytes() << " bytes)"; - static_cast<ApplicationType*>(this)->on_connect(block); + static_cast<ApplicationType*>(this)->on_connect(header_stream.next()); header_stream.release(); - BOOST_LOG_TRIVIAL(debug) << "Released header block"; auto& data_stream = client.data_stream(); while (!_stop) { - auto& data_block = data_stream.next(); - BOOST_LOG_TRIVIAL(debug) << "Acquired data block (" - << block.used_bytes() <<"/"<<block.total_bytes() << " bytes)"; - bool eod = static_cast<ApplicationType*>(this)->on_next(data_block); + bool eod = static_cast<ApplicationType*>(this)->on_next(data_stream.next()); data_stream.release(eod); - BOOST_LOG_TRIVIAL(debug) << "Released data block"; if (eod) { - BOOST_LOG_TRIVIAL(info) << "EOD set on last buffer"; + BOOST_LOG_TRIVIAL(info) << "Final buffer written"; _stop = true; break; } diff --git a/psrdada_cpp/examples/dbnull.cpp b/psrdada_cpp/examples/dbnull.cpp index 7e756c4a98d3c9d134344fb82290f079f5ba4699..40bffb819794a18bd561ebf96de0c4ac06aabb8e 100644 --- a/psrdada_cpp/examples/dbnull.cpp +++ b/psrdada_cpp/examples/dbnull.cpp @@ -52,7 +52,6 @@ int main(int argc, char** argv) set_log_level(level); }), "The logging level to use (debug, info, warning, error)"); - po::variables_map vm; try { @@ -71,7 +70,6 @@ int main(int argc, char** argv) std::cerr << desc << std::endl; return ERROR_IN_COMMAND_LINE; } - MultiLog log("dbnull"); DbNull proc(key, log, nbytes); proc.run(); diff --git a/psrdada_cpp/src/cli_utils.cpp b/psrdada_cpp/src/cli_utils.cpp index 04487ba1a39283c1128f8e3713a8f21363341ba8..07c8285d1a1eb1daf4d2421e30ae990dab85d5ac 100644 --- a/psrdada_cpp/src/cli_utils.cpp +++ b/psrdada_cpp/src/cli_utils.cpp @@ -13,7 +13,6 @@ namespace psrdada_cpp { void set_log_level(std::string level) { using namespace boost::log; - if (level == "debug") { std::cout << "debug" << std::endl; diff --git a/psrdada_cpp/src/dada_client_base.cpp b/psrdada_cpp/src/dada_client_base.cpp index 0a53cf4c742a7b4162efd9fcf65521905dcdc6ab..35847311953ffd9044043520e83e8655e4bba2ee 100644 --- a/psrdada_cpp/src/dada_client_base.cpp +++ b/psrdada_cpp/src/dada_client_base.cpp @@ -39,17 +39,25 @@ namespace psrdada_cpp { void DadaClientBase::connect() { + BOOST_LOG_TRIVIAL(debug) << "Connecting to dada buffer [" + << std::hex << _key << std::dec << "]"; _hdu = dada_hdu_create(_log.native_handle()); dada_hdu_set_key(_hdu, _key); if (dada_hdu_connect (_hdu) < 0){ _log.write(LOG_ERR, "could not connect to hdu\n"); throw std::runtime_error("Unable to connect to hdu\n"); } + BOOST_LOG_TRIVIAL(debug) << "Header buffer is " << header_buffer_count() + << " x " << header_buffer_size() << " bytes"; + BOOST_LOG_TRIVIAL(debug) << "Data buffer is " << data_buffer_count() + << " x " << data_buffer_size() << " bytes"; _connected = true; } void DadaClientBase::disconnect() { + BOOST_LOG_TRIVIAL(debug) << "Disconnecting from dada buffer [" + << std::hex << _key << std::dec << "]"; if (dada_hdu_disconnect (_hdu) < 0){ _log.write(LOG_ERR, "could not disconnect from hdu\n"); throw std::runtime_error("Unable to disconnect from hdu\n"); diff --git a/psrdada_cpp/src/dada_io_loop.cpp b/psrdada_cpp/src/dada_io_loop.cpp index 563fbf1cbc2dbd21a416789a0abaa252c7841823..70046dc4396fd47941e0464c7bc64d66d73a21bd 100644 --- a/psrdada_cpp/src/dada_io_loop.cpp +++ b/psrdada_cpp/src/dada_io_loop.cpp @@ -17,6 +17,7 @@ namespace psrdada_cpp void DadaIoLoop::stop() { + BOOST_LOG_TRIVIAL(debug) << "Stop requested on IO loop"; _stop = true; } diff --git a/psrdada_cpp/src/dada_read_client.cpp b/psrdada_cpp/src/dada_read_client.cpp index 929684a5e2682cae2ff35b33e25c671c893a1c5b..146d332d7858f4b1d8061bacbde8e20dd217bb81 100644 --- a/psrdada_cpp/src/dada_read_client.cpp +++ b/psrdada_cpp/src/dada_read_client.cpp @@ -19,7 +19,11 @@ namespace psrdada_cpp { void DadaReadClient::lock() { if (!_connected) + { throw std::runtime_error("Lock requested on unconnected HDU\n"); + } + BOOST_LOG_TRIVIAL(debug) << "Acquiring reading lock on dada buffer [" + << std::hex << _key << std::dec << "]"; if (dada_hdu_lock_read (_hdu) < 0) { _log.write(LOG_ERR, "open_hdu: could not lock read\n"); @@ -30,8 +34,12 @@ namespace psrdada_cpp { void DadaReadClient::release() { - if (!_locked) + if (!_locked) + { throw std::runtime_error("Release requested on unlocked HDU\n"); + } + BOOST_LOG_TRIVIAL(debug) << "Releasing reading lock on dada buffer [" + << std::hex << _key << std::dec << "]"; if (dada_hdu_unlock_read (_hdu) < 0) { _log.write(LOG_ERR, "open_hdu: could not release read\n"); @@ -66,6 +74,7 @@ namespace psrdada_cpp { { throw std::runtime_error("Previous header block not released"); } + BOOST_LOG_TRIVIAL(debug) << "Acquiring next header block"; std::size_t nbytes = 0; char* tmp = ipcbuf_get_next_read(_parent._hdu->header_block, &nbytes); if (!tmp) @@ -74,6 +83,8 @@ namespace psrdada_cpp { throw std::runtime_error("Could not get header"); } _current_block.reset(new RawBytes(tmp, _parent.header_buffer_size(), nbytes)); + BOOST_LOG_TRIVIAL(debug) << "Header block used/total bytes = " + << _current_block->used_bytes() <<"/"<<_current_block->total_bytes(); return *_current_block; } @@ -83,7 +94,7 @@ namespace psrdada_cpp { { throw std::runtime_error("No header block to be released"); } - + BOOST_LOG_TRIVIAL(debug) << "Releasing header block"; if (ipcbuf_mark_cleared(_parent._hdu->header_block) < 0) { _parent._log.write(LOG_ERR, "Could not mark cleared header block\n"); @@ -114,6 +125,7 @@ namespace psrdada_cpp { { throw std::runtime_error("Previous data block not released"); } + BOOST_LOG_TRIVIAL(debug) << "Acquiring next data block"; std::size_t nbytes = 0; char* tmp = ipcio_open_block_read(_parent._hdu->data_block, &nbytes, &_block_idx); if (!tmp) @@ -122,6 +134,9 @@ namespace psrdada_cpp { throw std::runtime_error("Could not open block to read"); } _current_block.reset(new RawBytes(tmp, _parent.data_buffer_size(), nbytes)); + BOOST_LOG_TRIVIAL(debug) << "Data block used/total bytes = " + << _current_block->used_bytes() <<"/"<<_current_block->total_bytes(); + return *_current_block; } void DadaReadClient::DataStream::release() @@ -130,6 +145,7 @@ namespace psrdada_cpp { { throw std::runtime_error("No data block to be released"); } + BOOST_LOG_TRIVIAL(debug) << "Releasing data block"; if (ipcio_close_block_read (_parent._hdu->data_block, _current_block->used_bytes()) < 0) { _parent._log.write(LOG_ERR, "close_buffer: ipcio_close_block_read failed\n"); diff --git a/psrdada_cpp/src/dada_write_client.cpp b/psrdada_cpp/src/dada_write_client.cpp index f0d31a6039fe368fec1e67da28c502f48fb21de8..de0b88c7224564dc38b1c2a1b8304fa521f098e5 100644 --- a/psrdada_cpp/src/dada_write_client.cpp +++ b/psrdada_cpp/src/dada_write_client.cpp @@ -19,7 +19,11 @@ namespace psrdada_cpp { void DadaWriteClient::lock() { if (!_connected) + { throw std::runtime_error("Lock requested on unconnected HDU\n"); + } + BOOST_LOG_TRIVIAL(debug) << "Acquiring writing lock on dada buffer [" + << std::hex << _key << std::dec << "]"; if (dada_hdu_lock_write (_hdu) < 0) { _log.write(LOG_ERR, "open_hdu: could not lock write\n"); @@ -30,8 +34,12 @@ namespace psrdada_cpp { void DadaWriteClient::release() { - if (!_locked) + if (!_locked) + { throw std::runtime_error("Release requested on unlocked HDU\n"); + } + BOOST_LOG_TRIVIAL(debug) << "Releasing writing lock on dada buffer [" + << std::hex << _key << std::dec << "]"; if (dada_hdu_unlock_write (_hdu) < 0) { _log.write(LOG_ERR, "open_hdu: could not release write\n"); @@ -66,6 +74,7 @@ namespace psrdada_cpp { { throw std::runtime_error("Previous header block not released"); } + BOOST_LOG_TRIVIAL(debug) << "Acquiring next header block"; char* tmp = ipcbuf_get_next_write(_parent._hdu->header_block); _current_block.reset(new RawBytes(tmp, _parent.header_buffer_size())); return *_current_block; @@ -77,7 +86,7 @@ namespace psrdada_cpp { { throw std::runtime_error("No header block to be released"); } - + BOOST_LOG_TRIVIAL(debug) << "Releasing header block"; if (ipcbuf_mark_filled(_parent._hdu->header_block, _current_block->used_bytes()) < 0) { _parent._log.write(LOG_ERR, "Could not mark filled header block\n"); @@ -103,8 +112,10 @@ namespace psrdada_cpp { { throw std::runtime_error("Previous data block not released"); } + BOOST_LOG_TRIVIAL(debug) << "Acquiring next header block"; char* tmp = ipcio_open_block_write(_parent._hdu->data_block, &_block_idx); _current_block.reset(new RawBytes(tmp, _parent.data_buffer_size())); + BOOST_LOG_TRIVIAL(debug) << "Acquired data block " << _block_idx; return *_current_block; } @@ -114,8 +125,10 @@ namespace psrdada_cpp { { throw std::runtime_error("No data block to be released"); } + BOOST_LOG_TRIVIAL(debug) << "Releasing data block"; if (eod) { + BOOST_LOG_TRIVIAL(debug) << "Setting EOD markers"; if (ipcio_update_block_write (_parent._hdu->data_block, _current_block->used_bytes()) < 0) { _parent._log.write(LOG_ERR, "close_buffer: ipcio_update_block_write failed\n");