2017-12-24 00:25:18 +00:00
|
|
|
#include "queue_manager.h"
|
2017-05-22 05:54:27 +00:00
|
|
|
|
2018-01-30 05:34:28 +00:00
|
|
|
#include "cache_manager.h"
|
2018-02-24 00:12:39 +00:00
|
|
|
#include "lsp.h"
|
2017-12-05 07:57:41 +00:00
|
|
|
#include "query.h"
|
2017-12-04 08:13:35 +00:00
|
|
|
|
|
|
|
#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)
|
2017-12-05 07:57:41 +00:00
|
|
|
: path(path),
|
|
|
|
args(args),
|
|
|
|
is_interactive(is_interactive),
|
2018-01-20 07:56:49 +00:00
|
|
|
contents(contents),
|
2018-01-30 05:34:28 +00:00
|
|
|
cache_manager(cache_manager),
|
2018-01-20 07:56:49 +00:00
|
|
|
id(id) {}
|
2017-12-05 07:57:41 +00:00
|
|
|
|
2018-02-22 07:34:32 +00:00
|
|
|
Index_DoIdMap::Index_DoIdMap(
|
|
|
|
std::unique_ptr<IndexFile> current,
|
|
|
|
const std::shared_ptr<ICacheManager>& cache_manager,
|
|
|
|
PerformanceImportFile perf,
|
|
|
|
bool is_interactive,
|
|
|
|
bool write_to_disk)
|
2017-12-05 07:57:41 +00:00
|
|
|
: current(std::move(current)),
|
2018-01-30 05:34:28 +00:00
|
|
|
cache_manager(cache_manager),
|
2017-12-05 07:57:41 +00:00
|
|
|
perf(perf),
|
|
|
|
is_interactive(is_interactive),
|
|
|
|
write_to_disk(write_to_disk) {
|
|
|
|
assert(this->current);
|
|
|
|
}
|
|
|
|
|
|
|
|
Index_OnIdMapped::File::File(std::unique_ptr<IndexFile> file,
|
|
|
|
std::unique_ptr<IdMap> ids)
|
|
|
|
: file(std::move(file)), ids(std::move(ids)) {}
|
|
|
|
|
2018-02-22 07:34:32 +00:00
|
|
|
Index_OnIdMapped::Index_OnIdMapped(
|
|
|
|
const std::shared_ptr<ICacheManager>& cache_manager,
|
|
|
|
PerformanceImportFile perf,
|
|
|
|
bool is_interactive,
|
|
|
|
bool write_to_disk)
|
2018-01-30 05:34:28 +00:00
|
|
|
: cache_manager(cache_manager),
|
|
|
|
perf(perf),
|
2017-12-05 07:57:41 +00:00
|
|
|
is_interactive(is_interactive),
|
|
|
|
write_to_disk(write_to_disk) {}
|
|
|
|
|
2018-02-06 07:22:44 +00:00
|
|
|
Index_OnIndexed::Index_OnIndexed(IndexUpdate&& update,
|
2017-12-05 07:57:41 +00:00
|
|
|
PerformanceImportFile perf)
|
2018-02-22 07:34:32 +00:00
|
|
|
: update(std::move(update)), perf(perf) {}
|
2017-12-05 07:57:41 +00:00
|
|
|
|
2018-03-10 23:40:27 +00:00
|
|
|
std::unique_ptr<QueueManager> QueueManager::instance_;
|
2017-12-24 00:25:18 +00:00
|
|
|
|
|
|
|
// static
|
2018-03-10 23:40:27 +00:00
|
|
|
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(IpcId id, lsBaseOutMessage& response) {
|
|
|
|
std::ostringstream sstream;
|
|
|
|
response.Write(sstream);
|
|
|
|
|
|
|
|
Stdout_Request out;
|
|
|
|
out.content = sstream.str();
|
|
|
|
out.id = id;
|
2018-02-05 06:03:22 +00:00
|
|
|
instance()->for_stdout.PushBack(std::move(out));
|
2017-12-24 00:25:18 +00:00
|
|
|
}
|
|
|
|
|
2018-01-02 07:40:36 +00:00
|
|
|
QueueManager::QueueManager(MultiQueueWaiter* querydb_waiter,
|
|
|
|
MultiQueueWaiter* indexer_waiter,
|
|
|
|
MultiQueueWaiter* stdout_waiter)
|
|
|
|
: for_stdout(stdout_waiter),
|
|
|
|
for_querydb(querydb_waiter),
|
|
|
|
do_id_map(querydb_waiter),
|
|
|
|
index_request(indexer_waiter),
|
|
|
|
load_previous_index(indexer_waiter),
|
|
|
|
on_id_mapped(indexer_waiter),
|
|
|
|
// TODO on_indexed is shared by "querydb" and "indexer"
|
|
|
|
on_indexed(querydb_waiter, indexer_waiter) {}
|
2017-12-05 07:57:41 +00:00
|
|
|
|
|
|
|
bool QueueManager::HasWork() {
|
|
|
|
return !index_request.IsEmpty() || !do_id_map.IsEmpty() ||
|
|
|
|
!load_previous_index.IsEmpty() || !on_id_mapped.IsEmpty() ||
|
|
|
|
!on_indexed.IsEmpty();
|
|
|
|
}
|