From b904480c76c929b24a2552d8988de11f3062597c Mon Sep 17 00:00:00 2001 From: superjom Date: Tue, 28 Nov 2017 19:43:58 +0800 Subject: [PATCH] init read and write serivce --- visualdl/backend/logic/im.cc | 21 +++++++++++++++++++++ visualdl/backend/logic/im.h | 11 ++--------- visualdl/backend/storage/storage.h | 2 +- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/visualdl/backend/logic/im.cc b/visualdl/backend/logic/im.cc index 971a9f48..817ea6b1 100644 --- a/visualdl/backend/logic/im.cc +++ b/visualdl/backend/logic/im.cc @@ -25,6 +25,27 @@ int ReserviorSample(int num_samples, int num_records) { return -1; } +IM::IM(StorageBase::Type type, StorageBase::Mode mode) { + switch (type) { + case StorageBase::Type::kMemory: + storage_.reset(new MemoryStorage); + break; + default: + CHECK(false) << "Unsupported storage kind " << type; + } + + switch (mode) { + case StorageBase::Mode::kRead: + dynamic_cast(storage_.get())->StartReadService(); + break; + case StorageBase::Mode::kWrite: + dynamic_cast(storage_.get())->StartWriteSerice(); + break; + default: + break; + } +} + void IM::SetPersistDest(const std::string &path) { CHECK(storage_->mutable_data()->dir().empty()) << "duplicate set storage's path"; diff --git a/visualdl/backend/logic/im.h b/visualdl/backend/logic/im.h index 603f4294..1d8245c8 100644 --- a/visualdl/backend/logic/im.h +++ b/visualdl/backend/logic/im.h @@ -26,15 +26,8 @@ namespace visualdl { */ class IM final { public: - IM(StorageBase::Type type = StorageBase::Type::kMemory) { - switch (type) { - case StorageBase::Type::kMemory: - storage_.reset(new MemoryStorage); - break; - default: - CHECK(false) << "Unsupported storage kind " << type; - } - } + IM(StorageBase::Type type = StorageBase::Type::kMemory, + StorageBase::Mode mode = StorageBase::Mode::kNone); static IM &Global() { static IM *x = new IM(); diff --git a/visualdl/backend/storage/storage.h b/visualdl/backend/storage/storage.h index 5ccd4564..a827a6db 100644 --- a/visualdl/backend/storage/storage.h +++ b/visualdl/backend/storage/storage.h @@ -27,7 +27,7 @@ public: enum Type { kMemory = 0, kDisk = 1 }; // mode of the sevice, either reading or writing. - enum Mode { kRead = 0, kWrite = 1 }; + enum Mode { kRead = 0, kWrite = 1, kNone = 2 }; void SetStorage(const std::string &dir) { time_t t; -- GitLab