12 #include <condition_variable> 18 #include "llvm/DenseMap.h" 19 #include "llvm/SmallSet.h" 20 #include "llvm/StringMap.h" 22 #include "ntcore_cpp.h" 23 #include "SequenceNumber.h" 39 class INetworkConnection;
44 friend class StorageTest;
56 void SetDispatcher(
IDispatcher* dispatcher,
bool server)
override;
57 void ClearDispatcher()
override;
62 NT_Type GetMessageEntryType(
unsigned int id)
const override;
65 std::weak_ptr<INetworkConnection> conn_weak)
override;
66 void GetInitialAssignments(
68 std::vector<std::shared_ptr<Message>>* msgs)
override;
69 void ApplyInitialAssignments(
72 std::vector<std::shared_ptr<Message>>* out_msgs)
override;
77 std::shared_ptr<Value>
GetEntryValue(
unsigned int local_id)
const;
81 std::shared_ptr<Value> value);
84 bool SetEntryValue(
unsigned int local_id, std::shared_ptr<Value> value);
90 void SetEntryFlags(
unsigned int local_id,
unsigned int flags);
103 unsigned int AddListener(
106 unsigned int flags)
const;
107 unsigned int AddListener(
108 unsigned int local_id,
110 unsigned int flags)
const;
112 unsigned int AddPolledListener(
unsigned int poller_uid,
StringRef prefix,
113 unsigned int flags)
const;
114 unsigned int AddPolledListener(
unsigned int poller_uid,
unsigned int local_id,
115 unsigned int flags)
const;
130 std::function<
void(std::size_t line,
const char* msg)> warn)
override;
135 std::function<
void(std::size_t line,
const char* msg)> warn);
141 std::function<
void(std::size_t line,
const char* msg)> warn);
149 bool GetRpcResult(
unsigned int local_id,
unsigned int call_uid,
150 std::string* result);
151 bool GetRpcResult(
unsigned int local_id,
unsigned int call_uid,
152 std::string* result,
double timeout,
bool* timed_out);
159 bool IsPersistent()
const {
return (flags & NT_PERSISTENT) != 0; }
166 std::shared_ptr<Value> value;
167 unsigned int flags{0};
172 unsigned int id{0xffff};
175 unsigned int local_id{UINT_MAX};
182 bool local_write{
false};
185 unsigned int rpc_uid{UINT_MAX};
189 unsigned int rpc_call_uid{0};
193 typedef std::vector<Entry*> IdMap;
194 typedef std::vector<std::unique_ptr<Entry>> LocalMap;
195 typedef std::pair<unsigned int, unsigned int> RpcIdPair;
199 mutable std::mutex m_mutex;
200 EntriesMap m_entries;
203 RpcResultMap m_rpc_results;
204 RpcBlockingCallSet m_rpc_blocking_calls;
206 mutable bool m_persistent_dirty =
false;
209 std::atomic_bool m_terminating;
210 std::condition_variable m_rpc_results_cond;
214 bool m_server =
true;
220 void ProcessIncomingEntryAssign(std::shared_ptr<Message> msg,
222 void ProcessIncomingEntryUpdate(std::shared_ptr<Message> msg,
224 void ProcessIncomingFlagsUpdate(std::shared_ptr<Message> msg,
226 void ProcessIncomingEntryDelete(std::shared_ptr<Message> msg,
228 void ProcessIncomingClearEntries(std::shared_ptr<Message> msg,
230 void ProcessIncomingExecuteRpc(std::shared_ptr<Message> msg,
232 std::weak_ptr<INetworkConnection> conn_weak);
233 void ProcessIncomingRpcResponse(std::shared_ptr<Message> msg,
236 bool GetPersistentEntries(
238 std::vector<std::pair<std::string, std::shared_ptr<Value>>>* entries)
241 std::vector<std::pair<std::string, std::shared_ptr<Value>>>*
243 void SetEntryValueImpl(Entry* entry, std::shared_ptr<Value> value,
244 std::unique_lock<std::mutex>& lock,
bool local);
245 void SetEntryFlagsImpl(Entry* entry,
unsigned int flags,
246 std::unique_lock<std::mutex>& lock,
bool local);
247 void DeleteEntryImpl(Entry* entry, std::unique_lock<std::mutex>& lock,
251 template <
typename F>
252 void DeleteAllEntriesImpl(
bool local, F should_delete);
253 void DeleteAllEntriesImpl(
bool local);
259 #endif // NT_STORAGE_H_ void SetEntryFlags(StringRef name, unsigned int flags)
Set Entry Flags.
Definition: ntcore_cpp.cpp:156
bool SetEntryValue(StringRef name, std::shared_ptr< Value > value)
Set Entry Value.
Definition: ntcore_cpp.cpp:130
unsigned int GetEntryFlags(StringRef name)
Get Entry Flags.
Definition: ntcore_cpp.cpp:169
bool SetDefaultEntryValue(StringRef name, std::shared_ptr< Value > value)
Set Default Entry Value Returns copy of current entry value if it exists.
Definition: ntcore_cpp.cpp:117
NetworkTables Entry Notification.
Definition: ntcore_cpp.h:165
Definition: SocketError.cpp:18
const char * LoadEntries(NT_Inst inst, StringRef filename, StringRef prefix, std::function< void(size_t line, const char *msg)> warn)
Load table values from a file.
Definition: ntcore_cpp.cpp:946
Definition: IStorage.h:26
void CancelRpcResult(NT_Entry entry, NT_RpcCall call)
Ignore the result of a RPC call.
Definition: ntcore_cpp.cpp:617
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:32
std::vector< NT_Entry > GetEntries(NT_Inst inst, StringRef prefix, unsigned int types)
Get Entry Handles.
Definition: ntcore_cpp.cpp:65
NT_RpcCall CallRpc(NT_Entry entry, StringRef params)
Call a RPC function.
Definition: ntcore_cpp.cpp:575
void SetEntryTypeValue(StringRef name, std::shared_ptr< Value > value)
Set Entry Type and Value.
Definition: ntcore_cpp.cpp:143
const char * LoadPersistent(StringRef filename, std::function< void(size_t line, const char *msg)> warn)
Load persistent values from a file.
Definition: ntcore_cpp.cpp:924
void CreateRpc(NT_Entry entry, StringRef def, std::function< void(const RpcAnswer &answer)> callback)
Create a callback-based RPC entry point.
Definition: ntcore_cpp.cpp:476
Definition: raw_istream.h:23
NT_Entry GetEntry(NT_Inst inst, StringRef name)
Get Entry Handle.
Definition: ntcore_cpp.cpp:55
Definition: SequenceNumber.h:14
Definition: IEntryNotifier.h:15
NT_Type GetEntryType(NT_Entry entry)
Gets the type for the specified entry, or unassigned if non existent.
Definition: ntcore_cpp.cpp:86
NetworkTables Entry Information.
Definition: ntcore_cpp.h:30
std::vector< EntryInfo > GetEntryInfo(StringRef prefix, unsigned int types)
Get Entry Information.
Definition: ntcore_cpp.cpp:207
const char * SavePersistent(StringRef filename)
Save persistent values to a file.
Definition: ntcore_cpp.cpp:913
Definition: IDispatcher.h:21
void DeleteAllEntries()
Delete All Entries.
Definition: ntcore_cpp.cpp:195
std::shared_ptr< Value > GetEntryValue(StringRef name)
Get Entry Value.
Definition: ntcore_cpp.cpp:104
Definition: IRpcServer.h:18
Definition: INetworkConnection.h:18
bool GetRpcResult(NT_Entry entry, NT_RpcCall call, std::string *result)
Get the result (return value) of a RPC call.
Definition: ntcore_cpp.cpp:587
const char * SaveEntries(NT_Inst inst, StringRef filename, StringRef prefix)
Save table values to a file.
Definition: ntcore_cpp.cpp:939
void DeleteEntry(StringRef name)
Delete Entry.
Definition: ntcore_cpp.cpp:182
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:33
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42
Definition: IEntryNotifier.h:17
std::string GetEntryName(NT_Entry entry)
Gets the name of the specified entry.
Definition: ntcore_cpp.cpp:77
unsigned long long GetEntryLastChange(NT_Entry entry)
Gets the last time the entry was changed.
Definition: ntcore_cpp.cpp:95