cosmetics

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21864 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-11-29 19:56:25 +00:00
parent 1aafa6ff77
commit 0ef0cbbf1a
5 changed files with 84 additions and 130 deletions

View File

@ -79,7 +79,6 @@ using std::string;
namespace lyx {
using support::FileName;
using support::ForkedCallsController;
/// return the LyX mouse button state from Qt's
@ -458,8 +457,7 @@ void GuiWorkArea::toggleCursor()
// Use this opportunity to deal with any child processes that
// have finished but are waiting to communicate this fact
// to the rest of LyX.
ForkedCallsController & fcc = ForkedCallsController::get();
fcc.handleCompletedProcesses();
support::ForkedCallsController::handleCompletedProcesses();
}

View File

@ -34,7 +34,6 @@ using support::addExtension;
using support::changeExtension;
using support::FileName;
using support::ForkedCall;
using support::ForkedCallQueue;
using support::getExtension;
using support::libScriptSearch;
using support::onlyPath;
@ -193,9 +192,8 @@ void Converter::Impl::startConversion()
return;
}
ForkedCall::SignalTypePtr
ptr = ForkedCallQueue::get().add(script_command_);
ForkedCall::SignalTypePtr ptr =
support::ForkedCallQueue::add(script_command_);
ptr->connect(boost::bind(&Impl::converted, this, _1, _2));
}

View File

@ -383,7 +383,7 @@ InProgress::InProgress(string const & filename_base,
void InProgress::stop() const
{
if (pid)
lyx::support::ForkedCallsController::get().kill(pid, 0);
lyx::support::ForkedCallsController::kill(pid, 0);
if (!metrics_file.empty())
metrics_file.removeFile();
@ -421,9 +421,8 @@ PreviewLoader::Impl::~Impl()
InProgressProcesses::iterator ipit = in_progress_.begin();
InProgressProcesses::iterator ipend = in_progress_.end();
for (; ipit != ipend; ++ipit) {
for (; ipit != ipend; ++ipit)
ipit->second.stop();
}
}
@ -437,7 +436,7 @@ PreviewLoader::Impl::preview(string const & latex_snippet) const
namespace {
class FindSnippet : public std::unary_function<InProgressProcess, bool> {
class FindSnippet {
public:
FindSnippet(string const & s) : snippet_(s) {}
bool operator()(InProgressProcess const & process) const

View File

@ -23,9 +23,11 @@
#include <boost/bind.hpp>
#include <vector>
#include <cerrno>
#include <queue>
#include <sstream>
#include <utility>
#include <vector>
#ifdef _WIN32
# define SIGHUP 1
@ -145,8 +147,7 @@ int ForkedProcess::run(Starttype type)
break;
case DontWait: {
// Integrate into the Controller
ForkedCallsController & contr = ForkedCallsController::get();
contr.addCall(*this);
ForkedCallsController::addCall(*this);
break;
}
}
@ -399,15 +400,31 @@ int ForkedCall::generateChild()
//
/////////////////////////////////////////////////////////////////////
namespace ForkedCallQueue {
ForkedCallQueue & ForkedCallQueue::get()
{
static ForkedCallQueue singleton;
return singleton;
}
/// A process in the queue
typedef std::pair<std::string, ForkedCall::SignalTypePtr> Process;
/** Add a process to the queue. Processes are forked sequentially
* only one is running at a time.
* Connect to the returned signal and you'll be informed when
* the process has ended.
*/
ForkedCall::SignalTypePtr add(std::string const & process);
/// in-progress queue
static std::queue<Process> callQueue_;
ForkedCall::SignalTypePtr ForkedCallQueue::add(string const & process)
/// flag whether queue is running
static bool running_ = 0;
///
void startCaller();
///
void stopCaller();
///
void callback(pid_t, int);
ForkedCall::SignalTypePtr add(string const & process)
{
ForkedCall::SignalTypePtr ptr;
ptr.reset(new ForkedCall::SignalType);
@ -418,15 +435,14 @@ ForkedCall::SignalTypePtr ForkedCallQueue::add(string const & process)
}
void ForkedCallQueue::callNext()
void callNext()
{
if (callQueue_.empty())
return;
Process pro = callQueue_.front();
callQueue_.pop();
// Bind our chain caller
pro.second->connect(boost::bind(&ForkedCallQueue::callback,
this, _1, _2));
pro.second->connect(boost::bind(&ForkedCallQueue::callback, _1, _2));
ForkedCall call;
// If we fail to fork the process, then emit the signal
// to tell the outside world that it failed.
@ -435,7 +451,7 @@ void ForkedCallQueue::callNext()
}
void ForkedCallQueue::callback(pid_t, int)
void callback(pid_t, int)
{
if (callQueue_.empty())
stopCaller();
@ -444,12 +460,7 @@ void ForkedCallQueue::callback(pid_t, int)
}
ForkedCallQueue::ForkedCallQueue()
: running_(false)
{}
void ForkedCallQueue::startCaller()
void startCaller()
{
LYXERR(Debug::GRAPHICS, "ForkedCallQueue: waking up");
running_ = true ;
@ -457,18 +468,21 @@ void ForkedCallQueue::startCaller()
}
void ForkedCallQueue::stopCaller()
void stopCaller()
{
running_ = false ;
LYXERR(Debug::GRAPHICS, "ForkedCallQueue: I'm going to sleep");
}
bool ForkedCallQueue::running() const
bool running()
{
return running_ ;
return running_;
}
} // namespace ForkedCallsQueue
/////////////////////////////////////////////////////////////////////
//
@ -504,33 +518,33 @@ string const getChildErrorMessage()
#endif
// Ensure, that only one controller exists inside process
ForkedCallsController & ForkedCallsController::get()
namespace ForkedCallsController {
typedef boost::shared_ptr<ForkedProcess> ForkedProcessPtr;
typedef std::list<ForkedProcessPtr> ListType;
typedef ListType::iterator iterator;
/// The child processes
static ListType forkedCalls;
iterator find_pid(pid_t pid)
{
static ForkedCallsController singleton;
return singleton;
return find_if(forkedCalls.begin(), forkedCalls.end(),
bind(equal_to<pid_t>(),
bind(&ForkedCall::pid, _1),
pid));
}
ForkedCallsController::ForkedCallsController()
{}
// open question: should we stop childs here?
// Asger says no: I like to have my xdvi open after closing LyX. Maybe
// I want to print or something.
ForkedCallsController::~ForkedCallsController()
{}
void ForkedCallsController::addCall(ForkedProcess const & newcall)
void addCall(ForkedProcess const & newcall)
{
forkedCalls.push_back(newcall.clone());
}
// Check the list of dead children and emit any associated signals.
void ForkedCallsController::handleCompletedProcesses()
void handleCompletedProcesses()
{
ListType::iterator it = forkedCalls.begin();
ListType::iterator end = forkedCalls.end();
@ -624,18 +638,9 @@ void ForkedCallsController::handleCompletedProcesses()
}
ForkedCallsController::iterator ForkedCallsController::find_pid(pid_t pid)
{
return find_if(forkedCalls.begin(), forkedCalls.end(),
bind(equal_to<pid_t>(),
bind(&ForkedCall::pid, _1),
pid));
}
// Kill the process prematurely and remove it from the list
// within tolerance secs
void ForkedCallsController::kill(pid_t pid, int tolerance)
void kill(pid_t pid, int tolerance)
{
ListType::iterator it = find_pid(pid);
if (it == forkedCalls.end())
@ -645,5 +650,7 @@ void ForkedCallsController::kill(pid_t pid, int tolerance)
forkedCalls.erase(it);
}
} // namespace ForkedCallsController
} // namespace support
} // namespace lyx

View File

@ -21,12 +21,7 @@
# include <sys/types.h>
#endif
#include <list>
#include <queue>
#include <string>
#include <utility>
#include <vector>
namespace lyx {
namespace support {
@ -172,87 +167,44 @@ private:
/**
* This class implements a queue of forked processes. In order not to
* This interfaces a queue of forked processes. In order not to
* hose the system with multiple processes running simultaneously, you can
* request the addition of your process to this queue and it will be
* executed when its turn comes.
*
*/
class ForkedCallQueue {
public:
/// A process in the queue
typedef std::pair<std::string, ForkedCall::SignalTypePtr> Process;
/** Add a process to the queue. Processes are forked sequentially
* only one is running at a time.
* Connect to the returned signal and you'll be informed when
* the process has ended.
*/
ForkedCall::SignalTypePtr add(std::string const & process);
/// Query whether the queue is running a forked process now.
bool running() const;
/// Get the and only instance of the class
static ForkedCallQueue & get();
namespace ForkedCallQueue {
private:
/** this class is a singleton class... use
* ForkedCallQueue::get() instead
*/
ForkedCallQueue();
/// in-progress queue
std::queue<Process> callQueue_;
///
bool running_;
///
void callNext();
///
void startCaller();
///
void stopCaller();
///
void callback(pid_t, int);
};
ForkedCall::SignalTypePtr add(std::string const & process);
/// Query whether the queue is running a forked process now.
bool running();
}
/**
* A class for the control of child processes launched using
* fork() and execvp().
* Control of child processes launched using fork() and execvp().
*/
class ForkedCallsController {
public:
/// Get hold of the only controller that can exist inside the process.
static ForkedCallsController & get();
namespace ForkedCallsController {
/// Add a new child process to the list of controlled processes.
void addCall(ForkedProcess const &);
/// Add a new child process to the list of controlled processes.
void addCall(ForkedProcess const &);
/** Those child processes that are found to have finished are removed
* from the list and their callback function is passed the final
* return state.
*/
void handleCompletedProcesses();
/** Those child processes that are found to have finished are removed
* from the list and their callback function is passed the final
* return state.
*/
void handleCompletedProcesses();
/** Kill this process prematurely and remove it from the list.
* The process is killed within tolerance secs.
* See forkedcall.[Ch] for details.
*/
void kill(pid_t, int tolerance = 5);
/** Kill this process prematurely and remove it from the list.
* The process is killed within tolerance secs.
* See forkedcall.[Ch] for details.
*/
void kill(pid_t, int tolerance = 5);
private:
ForkedCallsController();
ForkedCallsController(ForkedCallsController const &);
~ForkedCallsController();
typedef boost::shared_ptr<ForkedProcess> ForkedProcessPtr;
typedef std::list<ForkedProcessPtr> ListType;
typedef ListType::iterator iterator;
iterator find_pid(pid_t);
/// The child processes
ListType forkedCalls;
};
} // namespace ForkedCallsController
#if defined(_WIN32)