ccls/src/queue_manager.cc

62 lines
1.8 KiB
C++
Raw Normal View History

2017-12-24 00:25:18 +00:00
#include "queue_manager.h"
#include "cache_manager.h"
#include "lsp.h"
#include "query.h"
#include <sstream>
2018-02-22 07:34:32 +00:00
Index_Request::Index_Request(
const std::string& path,
const std::vector<std::string>& args,
bool is_interactive,
const std::string& contents,
const std::shared_ptr<ICacheManager>& cache_manager,
lsRequestId id)
: path(path),
args(args),
is_interactive(is_interactive),
2018-01-20 07:56:49 +00:00
contents(contents),
cache_manager(cache_manager),
2018-01-20 07:56:49 +00:00
id(id) {}
Index_OnIndexed::Index_OnIndexed(IndexUpdate&& update,
PerformanceImportFile perf)
2018-02-22 07:34:32 +00:00
: update(std::move(update)), perf(perf) {}
std::unique_ptr<QueueManager> QueueManager::instance_;
2017-12-24 00:25:18 +00:00
// static
void QueueManager::Init(MultiQueueWaiter* querydb_waiter,
MultiQueueWaiter* indexer_waiter,
MultiQueueWaiter* stdout_waiter) {
instance_ = std::unique_ptr<QueueManager>(
new QueueManager(querydb_waiter, indexer_waiter, stdout_waiter));
2017-12-24 00:25:18 +00:00
}
// static
void QueueManager::WriteStdout(MethodType method, lsBaseOutMessage& response) {
2017-12-24 00:25:18 +00:00
std::ostringstream sstream;
response.Write(sstream);
Stdout_Request out;
out.content = sstream.str();
out.method = method;
instance()->for_stdout.PushBack(std::move(out));
2017-12-24 00:25:18 +00:00
}
QueueManager::QueueManager(MultiQueueWaiter* querydb_waiter,
MultiQueueWaiter* indexer_waiter,
MultiQueueWaiter* stdout_waiter)
: for_stdout(stdout_waiter),
for_querydb(querydb_waiter),
index_request(indexer_waiter),
on_id_mapped(indexer_waiter),
// TODO on_indexed is shared by "querydb" and "indexer"
on_indexed(querydb_waiter, indexer_waiter) {}
bool QueueManager::HasWork() {
return !index_request.IsEmpty() || !on_id_mapped.IsEmpty() ||
!on_indexed.IsEmpty();
}