#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
#include "forkedcontr.h"
#include "forkedcall.h"
#include "lyxfunctional.h"
using std::strerror;
#endif
+namespace lyx {
+namespace support {
+
// Ensure, that only one controller exists inside process
ForkedcallsController & ForkedcallsController::get()
{
}
-// Add child process information to the list of controlled processes
-void ForkedcallsController::addCall(Forkedcall const &newcall)
+void ForkedcallsController::addCall(ForkedProcess const & newcall)
{
if (!timeout_->running())
timeout_->start();
- Forkedcall * call = new Forkedcall(newcall);
- forkedCalls.push_back(call);
+ forkedCalls.push_back(newcall.clone());
childrenChanged();
}
{
ListType::size_type start_size = forkedCalls.size();
- for (ListType::iterator it = forkedCalls.begin();
- it != forkedCalls.end(); ++it) {
- Forkedcall * actCall = *it;
+ ListType::iterator it = forkedCalls.begin();
+ ListType::iterator end = forkedCalls.end();
+ while (it != end) {
+ ForkedProcess * actCall = *it;
pid_t pid = actCall->pid();
int stat_loc;
} else if (waitrpid == 0) {
// Still running. Move on to the next child.
- continue;
} else if (WIFEXITED(stat_loc)) {
// Ok, the return value goes into retval.
}
if (remove_it) {
- // Emit signal and remove the item from the list
+ forkedCalls.erase(it);
+
actCall->emitSignal();
delete actCall;
- // erase returns the next iterator, so decrement it
- // to continue the loop.
- ListType::iterator prev = it;
- --prev;
- forkedCalls.erase(it);
- it = prev;
+
+ /* start all over: emiting the signal can result
+ * in changing the list (Ab)
+ */
+ it = forkedCalls.begin();
+ } else {
+ ++it;
}
}
- if (!forkedCalls.empty()) {
+ if (!forkedCalls.empty() && !timeout_->running()) {
timeout_->start();
}
timeout_->stop();
}
}
+
+} // namespace support
+} // namespace lyx