20 #include "llvm/DenseMap.h"
21 #include "llvm/StringMap.h"
22 #include "atomic_static.h"
25 #include "ntcore_cpp.h"
26 #include "RpcServer.h"
27 #include "SequenceNumber.h"
31 class NetworkConnection;
35 friend class StorageTest;
38 ATOMIC_STATIC(
Storage, instance);
47 typedef std::function<void(std::shared_ptr<Message> msg,
50 void SetOutgoing(QueueOutgoingFunc queue_outgoing,
bool server);
56 NT_Type GetEntryType(
unsigned int id)
const;
59 std::weak_ptr<NetworkConnection> conn_weak);
61 std::vector<std::shared_ptr<Message>>* msgs);
65 std::vector<std::shared_ptr<Message>>* out_msgs);
69 std::shared_ptr<Value> GetEntryValue(
StringRef name)
const;
70 bool SetEntryValue(
StringRef name, std::shared_ptr<Value> value);
71 void SetEntryTypeValue(
StringRef name, std::shared_ptr<Value> value);
72 void SetEntryFlags(
StringRef name,
unsigned int flags);
73 unsigned int GetEntryFlags(
StringRef name)
const;
75 void DeleteAllEntries();
76 std::vector<EntryInfo> GetEntryInfo(
StringRef prefix,
unsigned int types);
78 EntryListenerCallback only =
nullptr)
const;
82 const char* SavePersistent(
StringRef filename,
bool periodic)
const;
83 const char* LoadPersistent(
85 std::function<
void(std::size_t line,
const char* msg)> warn);
89 void SavePersistent(std::ostream& os,
bool periodic)
const;
92 std::function<
void(std::size_t line,
const char* msg)> warn);
100 bool GetRpcResult(
bool blocking,
unsigned int call_uid, std::string* result);
111 : name(name_), flags(0), id(0xffff), rpc_call_uid(0) {}
112 bool IsPersistent()
const {
return (flags & NT_PERSISTENT) != 0; }
119 std::shared_ptr<Value> value;
132 RpcCallback rpc_callback;
136 unsigned int rpc_call_uid;
140 typedef std::vector<Entry*> IdMap;
144 mutable std::mutex m_mutex;
149 mutable bool m_persistent_dirty =
false;
152 std::atomic_bool m_terminating;
153 std::condition_variable m_rpc_results_cond;
156 QueueOutgoingFunc m_queue_outgoing;
157 bool m_server =
true;
163 bool GetPersistentEntries(
165 std::vector<std::pair<std::string, std::shared_ptr<Value>>>* entries)
173 #endif // NT_STORAGE_H_
Definition: DenseMap.h:539
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:54
Definition: NetworkConnection.h:26
Definition: SequenceNumber.h:14
Definition: Notifier.h:19
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:190
Definition: RpcServer.h:25
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:39