|
Boost Users : |
Subject: [Boost-users] directory monitoring with dynamically added dirs
From: Richard Langly (richard.ringo.langly_at_[hidden])
Date: 2013-05-14 19:42:12
I'm trying to dynamically add directories from a config file before I enter
my programs main loop using the ASIO dir monitor example. I've not been
able to understand the internals yet. Below is my current iteration of what
I'm trying. I have been able to get the simple examples running just like
in the async.cpp file. But I can't get adding dirs dynamically working and
was hoping someone could offer suggestions.
Any help much appreciated.
void my_file_handler(const boost::system::error_code &ec,
const boost::asio::dir_monitor_event &ev)
{
// event stuff ...
return;
}
boost::asio::dir_monitor *dm;
boost::asio::io_service io_service;
vector<boost::asio::dir_monitor *> vecdm;
for (vector<Directories>::iterator it = dirs->begin();
it != dirs->end(); ++it) {
dm = new boost::asio::dir_monitor(io_service);
dm->add_directory((*it).abs_dir_path);
vecdm.push_back(dm);
}
boost::thread t =
boost::thread(boost::bind(&boost::asio::io_service::run,
boost::ref(io_service)));
while (true) {
// MAIN PROGRAM LOOP
for (vector<boost::asio::dir_monitor *>::iterator it =
vecdm.begin(); it != vecdm.end(); ++it) {
(*it)->async_monitor(my_file_handler);
}
io_service.reset();
// DO PROGRAM STUFF ...
}
~
~
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net