mirror of
https://github.com/MaskRay/ccls.git
synced 2025-02-20 15:40:57 +00:00
fixes
This commit is contained in:
parent
b3a544e880
commit
253414f29b
@ -96,7 +96,7 @@ indexer.exe --index-file /work2/chrome/src/chrome/foo.cc
|
||||
*/
|
||||
|
||||
|
||||
struct IpcMessage_IsAlive : public IpcMessage<IpcMessage_IsAlive> {
|
||||
struct IpcMessage_IsAlive : public BaseIpcMessage {
|
||||
static IpcMessageId id;
|
||||
};
|
||||
|
||||
@ -307,7 +307,7 @@ void main2() {
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
IpcMessage_IsAlive _;
|
||||
IpcRegistry::instance()->RegisterAllocator<IpcMessage_IsAlive>();
|
||||
|
||||
//main2();
|
||||
//return 0;
|
||||
|
14
ipc.cc
14
ipc.cc
@ -24,7 +24,12 @@ void JsonMessage::SetPayload(size_t payload_size, const char* payload) {
|
||||
memcpy(payload_dest, payload, payload_size);
|
||||
}
|
||||
|
||||
BaseIpcMessage::BaseIpcMessage(BaseIpcMessage::DoNotDeriveDirectly) {}
|
||||
BaseIpcMessage::BaseIpcMessage() {
|
||||
assert(!runtime_id_.empty() && "Message is not registered using IpcRegistry::RegisterAllocator");
|
||||
|
||||
runtime_id = runtime_id_;
|
||||
hashed_runtime_id = hashed_runtime_id_;
|
||||
}
|
||||
|
||||
BaseIpcMessage::~BaseIpcMessage() {}
|
||||
|
||||
@ -32,8 +37,11 @@ void BaseIpcMessage::Serialize(Writer& writer) {}
|
||||
|
||||
void BaseIpcMessage::Deserialize(Reader& reader) {}
|
||||
|
||||
IpcMessageId BaseIpcMessage::runtime_id_;
|
||||
|
||||
IpcRegistry IpcRegistry::Instance;
|
||||
int BaseIpcMessage::hashed_runtime_id_ = -1;
|
||||
|
||||
IpcRegistry* IpcRegistry::instance_ = nullptr;
|
||||
|
||||
std::unique_ptr<BaseIpcMessage> IpcRegistry::Allocate(int id) {
|
||||
return std::unique_ptr<BaseIpcMessage>((*allocators)[id]());
|
||||
@ -108,7 +116,7 @@ std::vector<std::unique_ptr<BaseIpcMessage>> IpcDirectionalChannel::TakeMessages
|
||||
|
||||
char* message = local_block;
|
||||
while (remaining_bytes > 0) {
|
||||
std::unique_ptr<BaseIpcMessage> base_message = IpcRegistry::Instance.Allocate(as_message(message)->message_id);
|
||||
std::unique_ptr<BaseIpcMessage> base_message = IpcRegistry::instance()->Allocate(as_message(message)->message_id);
|
||||
|
||||
rapidjson::Document document;
|
||||
document.Parse(as_message(message)->payload(), as_message(message)->payload_size);
|
||||
|
35
ipc.h
35
ipc.h
@ -32,24 +32,24 @@ struct JsonMessage {
|
||||
using IpcMessageId = std::string;
|
||||
|
||||
struct BaseIpcMessage {
|
||||
BaseIpcMessage();
|
||||
virtual ~BaseIpcMessage();
|
||||
|
||||
virtual void Serialize(Writer& writer);
|
||||
virtual void Deserialize(Reader& reader);
|
||||
|
||||
IpcMessageId runtime_id;
|
||||
int hashed_runtime_id;
|
||||
int hashed_runtime_id = -1;
|
||||
|
||||
// Populated by IpcRegistry::RegisterAllocator.
|
||||
static IpcMessageId runtime_id_;
|
||||
static int hashed_runtime_id_;
|
||||
|
||||
/*
|
||||
private:
|
||||
template<typename T>
|
||||
friend struct IpcMessage;
|
||||
*/
|
||||
|
||||
enum class DoNotDeriveDirectly {
|
||||
DeriveFromIpcMessageInstead
|
||||
};
|
||||
BaseIpcMessage(DoNotDeriveDirectly);
|
||||
};
|
||||
|
||||
struct IpcRegistry {
|
||||
@ -66,7 +66,8 @@ struct IpcRegistry {
|
||||
std::unique_ptr<BaseIpcMessage> Allocate(int id);
|
||||
|
||||
static IpcRegistry* instance() {
|
||||
// TODO: Remove static magic. Just call register explicitly.
|
||||
if (!instance_)
|
||||
instance_ = new IpcRegistry();
|
||||
return instance_;
|
||||
}
|
||||
static IpcRegistry* instance_;
|
||||
@ -90,26 +91,12 @@ int IpcRegistry::RegisterAllocator() {
|
||||
return new T();
|
||||
};
|
||||
|
||||
T::runtime_id_ = id;
|
||||
T::hashed_runtime_id_ = hash;
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
template<typename TChild>
|
||||
struct IpcMessage : public BaseIpcMessage {
|
||||
IpcMessage();
|
||||
|
||||
static int hashed_id_;
|
||||
};
|
||||
|
||||
template<typename TChild>
|
||||
int IpcMessage<TChild>::hashed_id_ = IpcRegistry::Instance.RegisterAllocator<TChild>();
|
||||
|
||||
template<typename TChild>
|
||||
IpcMessage<TChild>::IpcMessage()
|
||||
: BaseIpcMessage(DoNotDeriveDirectly::DeriveFromIpcMessageInstead) {
|
||||
runtime_id = TChild::id;
|
||||
hashed_runtime_id = hashed_id_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user