Skip to content
Snippets Groups Projects
Commit 2c466926 authored by Stephane Poirier's avatar Stephane Poirier
Browse files

[DataStreamer] New option 'throw_if_file_exists'

parent 888b410a
No related branches found
No related tags found
No related merge requests found
......@@ -91,6 +91,25 @@ private:
std::vector<std::size_t> dims_;
};
*/
//=============================================================================
/// OverwriteError
///
/// This class may be used by the DataStreamer in case of
/// a buffer file already exists before the acquisition start
//=============================================================================
class NEXUSCPP_DECL OverwriteError: public NexusException
{
public:
OverwriteError():NexusException() {}
OverwriteError(const char *pcszDesc, const char *pcszOrigin):
NexusException(pcszDesc, pcszOrigin) {}
OverwriteError(const std::string& desc, const char *pcszOrigin):
NexusException(desc.c_str(), pcszOrigin) {}
};
//==============================================================================
/// DataItemCategory
///==============================================================================
......@@ -203,6 +222,9 @@ public:
/// Messages logging handler
IMessageHandler* message_handler_p;
/// Throw an exception if destination buffer file already exists ?
bool throw_if_file_exists;
// ----------------
// error management
// ----------------
......@@ -227,6 +249,7 @@ public:
exception_handler_p = 0;
max_attempts = 10;
retry_delay = 250;
throw_if_file_exists = false;
}
} Config;
......
......@@ -1240,7 +1240,18 @@ void DataStreamer::PrivOpenNewbuffer()
std::string sFileName;
{
yat::AutoMutex<> _lock(s_indexLock);
sFileName = GenerateBufferName(m_cfg.buffer_name, s_mapFileIndex[m_cfg.buffer_name], m_cfg.data_source);
sFileName = GenerateBufferName(m_cfg.buffer_name, s_mapFileIndex[m_cfg.buffer_name],
m_cfg.data_source);
yat::FileName fn(m_cfg.target_path, sFileName);
if( fn.file_access() )
{
yat::Format msg("Buffer file {} already exists!");
msg.arg(fn);
if( m_cfg.throw_if_file_exists )
throw OverwriteError(msg, "DataStreamer::PrivOpenNewbuffer");
else if( m_cfg.message_handler_p )
m_cfg.message_handler_p->OnNexusMessage(yat::LOG_WARNING, msg);
}
s_mapFileIndex[m_cfg.buffer_name] += 1;
}
......
......@@ -102,8 +102,6 @@ public:
{
YAT_LOG_EXCEPTION(e);
m_error_flag = true;
//YAT_LOG_ERROR("Kill process!");
//exit(0);
}
virtual void OnNexusMessage(yat::ELogLevel lvl, const yat::String& msg)
{
......@@ -585,6 +583,9 @@ void Simu::run_acq(NexusDataStreamerFinalizerPtr finalizer_ptr)
cfg.exception_handler_p = this;
cfg.message_handler_p = this;
OUT_LN("compress level: " << m_config.compress_level);
// cfg.throw_if_file_exists = true;
nx::DataStreamer* streamer_p = new nx::DataStreamer(cfg);
stream_map[stream.name] = streamer_p;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment