2017-05-22 05:54:27 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ipc.h"
|
2017-12-05 07:57:41 +00:00
|
|
|
#include "performance.h"
|
|
|
|
#include "query.h"
|
2017-05-22 05:54:27 +00:00
|
|
|
#include "threaded_queue.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2017-12-05 07:57:41 +00:00
|
|
|
// TODO/FIXME: Merge IpcManager and QueueManager.
|
|
|
|
|
2017-12-04 15:13:33 +00:00
|
|
|
struct lsBaseOutMessage;
|
2017-05-22 05:54:27 +00:00
|
|
|
|
2017-12-04 08:13:35 +00:00
|
|
|
struct IpcManager {
|
|
|
|
struct StdoutMessage {
|
|
|
|
IpcId id;
|
|
|
|
std::string content;
|
|
|
|
};
|
2017-05-22 05:54:27 +00:00
|
|
|
|
2017-12-04 08:13:35 +00:00
|
|
|
ThreadedQueue<StdoutMessage> for_stdout;
|
|
|
|
ThreadedQueue<std::unique_ptr<BaseIpcMessage>> for_querydb;
|
2017-05-22 05:54:27 +00:00
|
|
|
|
2017-12-04 08:13:35 +00:00
|
|
|
static IpcManager* instance();
|
|
|
|
static void CreateInstance(MultiQueueWaiter* waiter);
|
2017-05-22 05:54:27 +00:00
|
|
|
|
2017-12-04 08:13:35 +00:00
|
|
|
static void WriteStdout(IpcId id, lsBaseOutMessage& response);
|
2017-05-22 05:54:27 +00:00
|
|
|
|
2017-09-22 01:14:57 +00:00
|
|
|
private:
|
2017-12-04 08:13:35 +00:00
|
|
|
explicit IpcManager(MultiQueueWaiter* waiter);
|
|
|
|
|
|
|
|
static IpcManager* instance_;
|
2017-05-22 05:54:27 +00:00
|
|
|
};
|
2017-12-05 07:57:41 +00:00
|
|
|
|
|
|
|
struct Index_Request {
|
|
|
|
std::string path;
|
|
|
|
// TODO: make |args| a string that is parsed lazily.
|
|
|
|
std::vector<std::string> args;
|
|
|
|
bool is_interactive;
|
|
|
|
optional<std::string> contents; // Preloaded contents. Useful for tests.
|
|
|
|
|
|
|
|
Index_Request(const std::string& path,
|
|
|
|
const std::vector<std::string>& args,
|
|
|
|
bool is_interactive,
|
|
|
|
optional<std::string> contents);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Index_DoIdMap {
|
|
|
|
std::unique_ptr<IndexFile> current;
|
|
|
|
std::unique_ptr<IndexFile> previous;
|
|
|
|
|
|
|
|
PerformanceImportFile perf;
|
|
|
|
bool is_interactive = false;
|
|
|
|
bool write_to_disk = false;
|
|
|
|
bool load_previous = false;
|
|
|
|
|
|
|
|
Index_DoIdMap(std::unique_ptr<IndexFile> current,
|
|
|
|
PerformanceImportFile perf,
|
|
|
|
bool is_interactive,
|
|
|
|
bool write_to_disk);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Index_OnIdMapped {
|
|
|
|
struct File {
|
|
|
|
std::unique_ptr<IndexFile> file;
|
|
|
|
std::unique_ptr<IdMap> ids;
|
|
|
|
|
|
|
|
File(std::unique_ptr<IndexFile> file, std::unique_ptr<IdMap> ids);
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unique_ptr<File> previous;
|
|
|
|
std::unique_ptr<File> current;
|
|
|
|
|
|
|
|
PerformanceImportFile perf;
|
|
|
|
bool is_interactive;
|
|
|
|
bool write_to_disk;
|
|
|
|
|
|
|
|
Index_OnIdMapped(PerformanceImportFile perf,
|
|
|
|
bool is_interactive,
|
|
|
|
bool write_to_disk);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Index_OnIndexed {
|
|
|
|
IndexUpdate update;
|
|
|
|
PerformanceImportFile perf;
|
|
|
|
|
|
|
|
Index_OnIndexed(IndexUpdate& update, PerformanceImportFile perf);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct QueueManager {
|
|
|
|
using Index_RequestQueue = ThreadedQueue<Index_Request>;
|
|
|
|
using Index_DoIdMapQueue = ThreadedQueue<Index_DoIdMap>;
|
|
|
|
using Index_OnIdMappedQueue = ThreadedQueue<Index_OnIdMapped>;
|
|
|
|
using Index_OnIndexedQueue = ThreadedQueue<Index_OnIndexed>;
|
|
|
|
|
|
|
|
Index_RequestQueue index_request;
|
|
|
|
Index_DoIdMapQueue do_id_map;
|
|
|
|
Index_DoIdMapQueue load_previous_index;
|
|
|
|
Index_OnIdMappedQueue on_id_mapped;
|
|
|
|
Index_OnIndexedQueue on_indexed;
|
|
|
|
|
|
|
|
QueueManager(MultiQueueWaiter* waiter);
|
|
|
|
|
|
|
|
bool HasWork();
|
|
|
|
};
|