storage.h 1.2 KB
Newer Older
S
superjom 已提交
1 2 3
#ifndef VISUALDL_STORAGE_H
#define VISUALDL_STORAGE_H

S
superjom 已提交
4 5 6 7 8 9 10 11
#include <string>
#include <time.h>

#include "visualdl/backend/storage/storage.pb.h"

namespace visualdl {

class Storage final {
S
superjom 已提交
12
 public:
S
superjom 已提交
13 14 15 16 17
  /*
   * There should be only one Storage instance in memory.
   */
  Storage &Global() {
    static Storage *instance = new Storage();
S
superjom 已提交
18 19
    return *instance;
  }
S
superjom 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

  /*
   * Add a new tablet named `tag`, the newly added instance will be returned.
   */
  storage::Tablet *Add(const std::string &tag);

  /*
   * Search the tablet named `tag`, if not exist, return nullptr.
   */
  const storage::Tablet *Find(const std::string &tag) const;

  /*
   * Serialize this object to string and save it to a file.
   */
  void Save(const std::string &path) const;

  /*
   * Load the Protobuf message from a file.
   */
  void Load(const std::string &path);

 protected:
  /*
   * Serialize the Storage instance to string.
   */
  std::string Serialize() const;

  /*
   * De-serialize from a string and update this Storage instance.
   */
  void DeSerialize(const std::string &data);

  Storage() {
    // set time stamp
    time_t time0;
    time(&time0);
    proto_.set_timestamp(time0);
  }

 private:
  storage::Storage proto_;
S
superjom 已提交
61 62
};

S
superjom 已提交
63 64
} // namespace visualdl

S
superjom 已提交
65
#endif //VISUALDL_STORAGE_H