20 #include "llvm/DenseMap.h"
21 #include "llvm/SmallSet.h"
22 #include "llvm/StringMap.h"
23 #include "support/atomic_static.h"
26 #include "ntcore_cpp.h"
27 #include "RpcServer.h"
28 #include "SequenceNumber.h"
32 class NetworkConnection;
36 friend class StorageTest;
40 ATOMIC_STATIC(
Storage, instance);
49 typedef std::function<void(std::shared_ptr<Message> msg,
53 void SetOutgoing(QueueOutgoingFunc queue_outgoing,
bool server);
59 NT_Type GetEntryType(
unsigned int id)
const;
62 std::weak_ptr<NetworkConnection> conn_weak);
64 std::vector<std::shared_ptr<Message>>* msgs);
66 llvm::ArrayRef<std::shared_ptr<Message>> msgs,
68 std::vector<std::shared_ptr<Message>>* out_msgs);
72 std::shared_ptr<Value> GetEntryValue(StringRef name)
const;
73 bool SetDefaultEntryValue(StringRef name, std::shared_ptr<Value> value);
74 bool SetEntryValue(StringRef name, std::shared_ptr<Value> value);
75 void SetEntryTypeValue(StringRef name, std::shared_ptr<Value> value);
76 void SetEntryFlags(StringRef name,
unsigned int flags);
77 unsigned int GetEntryFlags(StringRef name)
const;
78 void DeleteEntry(StringRef name);
79 void DeleteAllEntries();
80 std::vector<EntryInfo> GetEntryInfo(StringRef prefix,
unsigned int types);
81 void NotifyEntries(StringRef prefix,
82 EntryListenerCallback only =
nullptr)
const;
86 const char* SavePersistent(StringRef filename,
bool periodic)
const;
87 const char* LoadPersistent(
89 std::function<
void(std::size_t line,
const char* msg)> warn);
93 void SavePersistent(std::ostream& os,
bool periodic)
const;
96 std::function<
void(std::size_t line,
const char* msg)> warn);
100 void CreateRpc(StringRef name, StringRef def, RpcCallback callback);
101 void CreatePolledRpc(StringRef name, StringRef def);
103 unsigned int CallRpc(StringRef name, StringRef params);
104 bool GetRpcResult(
bool blocking,
unsigned int call_uid, std::string* result);
105 bool GetRpcResult(
bool blocking,
unsigned int call_uid,
double time_out,
106 std::string* result);
107 void CancelBlockingRpcResult(
unsigned int call_uid);
117 Entry(llvm::StringRef name_)
118 : name(name_), flags(0), id(0xffff), rpc_call_uid(0) {}
119 bool IsPersistent()
const {
return (flags & NT_PERSISTENT) != 0; }
126 std::shared_ptr<Value> value;
139 RpcCallback rpc_callback;
143 unsigned int rpc_call_uid;
146 typedef llvm::StringMap<std::unique_ptr<Entry>> EntriesMap;
147 typedef std::vector<Entry*> IdMap;
148 typedef llvm::DenseMap<std::pair<unsigned int, unsigned int>, std::string>
150 typedef llvm::SmallSet<unsigned int, 12> RpcBlockingCallSet;
152 mutable std::mutex m_mutex;
153 EntriesMap m_entries;
155 RpcResultMap m_rpc_results;
156 RpcBlockingCallSet m_rpc_blocking_calls;
158 mutable bool m_persistent_dirty =
false;
161 std::atomic_bool m_terminating;
162 std::condition_variable m_rpc_results_cond;
165 QueueOutgoingFunc m_queue_outgoing;
166 bool m_server =
true;
172 bool GetPersistentEntries(
174 std::vector<std::pair<std::string, std::shared_ptr<Value>>>* entries)
176 void DeleteAllEntriesImpl();
183 #endif // NT_STORAGE_H_
Definition: NetworkConnection.h:28
Definition: SequenceNumber.h:14
Definition: Notifier.h:19
Definition: RpcServer.h:25