Unverified Commit e7cf4afa authored by Tobias Winchen's avatar Tobias Winchen Committed by GitHub
Browse files

Merge pull request #6 from MPIfR-BDG/dbreset

Added dbreset executable to repo (including purge methods on the Dada…
parents 87c690ea 5e27a4ff
......@@ -61,11 +61,14 @@ target_link_libraries (fbfuse_output_db ${PSRDADA_CPP_LIBRARIES})
add_executable(file_to_dada src/file_to_dada_cli.cpp)
target_link_libraries (file_to_dada ${PSRDADA_CPP_LIBRARIES})
#dbnull
add_executable(dbnull examples/dbnull.cpp)
target_link_libraries (dbnull ${PSRDADA_CPP_LIBRARIES})
#dbreset
add_executable(dbreset examples/dbreset.cpp)
target_link_libraries (dbreset ${PSRDADA_CPP_LIBRARIES})
#dbisk
#add_executable(dbdisk examples/dbdisk.cpp)
#target_link_libraries (dbisk ${PSRDADA_CPP_LIBRARIES})
......
......@@ -52,6 +52,15 @@ namespace psrdada_cpp {
* @brief Check if we have read the last header block in buffer.
*/
bool at_end() const;
/**
* @brief Realease all full header blocks in the buffer
*
* @detail This method checks the number of full header
* blocks then calls next() release() that number
* of times.
*/
void purge();
};
class DataStream
......@@ -98,6 +107,15 @@ namespace psrdada_cpp {
* @brief Return the index of the currently open block
*/
std::size_t block_idx() const;
/**
* @brief Realease all full data blocks in the buffer
*
* @detail This method checks the number of full data
* blocks then calls next() release() that number
* of times.
*/
void purge();
};
private:
......
#include "psrdada_cpp/multilog.hpp"
#include "psrdada_cpp/dada_read_client.hpp"
#include "psrdada_cpp/cli_utils.hpp"
#include "boost/program_options.hpp"
#include <sys/types.h>
#include <iostream>
#include <string>
#include <sstream>
#include <ios>
#include <algorithm>
using namespace psrdada_cpp;
namespace
{
const size_t ERROR_IN_COMMAND_LINE = 1;
const size_t SUCCESS = 0;
const size_t ERROR_UNHANDLED_EXCEPTION = 2;
} // namespace
int main(int argc, char** argv)
{
try
{
key_t key;
/** Define and parse the program options
*/
namespace po = boost::program_options;
po::options_description desc("Options");
desc.add_options()
("help,h", "Print help messages")
("key,k", po::value<std::string>()
->default_value("dada")
->notifier([&key](std::string in)
{
key = string_to_key(in);
}),
"The shared memory key for the dada buffer to connect to (hex string)")
("log_level", po::value<std::string>()
->default_value("info")
->notifier([](std::string level)
{
set_log_level(level);
}),
"The logging level to use (debug, info, warning, error)");
po::variables_map vm;
try
{
po::store(po::parse_command_line(argc, argv, desc), vm);
if ( vm.count("help") )
{
std::cout << "dbreset -- Reset all DADA semaphores for a buffer"
<< std::endl << desc << std::endl;
return SUCCESS;
}
po::notify(vm);
}
catch(po::error& e)
{
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
std::cerr << desc << std::endl;
return ERROR_IN_COMMAND_LINE;
}
/**
* All the application code goes here
*/
MultiLog log("dbnull");
DadaReadClient client(key, log);
client.header_stream().purge();
client.data_stream().purge();
/**
* End of application code
*/
}
catch(std::exception& e)
{
std::cerr << "Unhandled Exception reached the top of main: "
<< e.what() << ", application will now exit" << std::endl;
return ERROR_UNHANDLED_EXCEPTION;
}
return SUCCESS;
}
\ No newline at end of file
......@@ -112,6 +112,17 @@ namespace psrdada_cpp {
return (bool) ipcbuf_eod(_parent._hdu->header_block);
}
void DadaReadClient::HeaderStream::purge()
{
std::size_t nheader = ipcbuf_get_nfull((ipcbuf_t *) _parent._hdu->header_block);
BOOST_LOG_TRIVIAL(debug) << _parent.id() << nheader << " header blocks are full";
for (std::size_t ii=0; ii < nheader; ++ii)
{
next();
release();
}
}
DadaReadClient::DataStream::DataStream(DadaReadClient& parent)
: _parent(parent)
, _current_block(nullptr)
......@@ -172,6 +183,19 @@ namespace psrdada_cpp {
return (bool) ipcbuf_eod((ipcbuf_t *)(_parent._hdu->data_block));
}
void DadaReadClient::DataStream::purge()
{
std::size_t ndata = ipcbuf_get_nfull((ipcbuf_t *) _parent._hdu->data_block);
BOOST_LOG_TRIVIAL(debug) << _parent.id() << ndata << " data blocks are full";
for (std::size_t ii=0; ii < ndata; ++ii)
{
next();
release();
if (at_end())
break;
}
}
} //namespace psrdada_cpp
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment