2 #include "networktables/NetworkTable.h"
4 #include "networktables2/thread/NTThreadManager.h"
5 #include "networktables2/thread/DefaultThreadManager.h"
6 #include "networktables2/NetworkTableEntry.h"
7 #include "networktables2/util/StringCache.h"
8 #include "networktables/NetworkTableProvider.h"
9 #include "networktables/NetworkTableMode.h"
10 #include "Synchronized.h"
11 #include "tables/TableKeyNotDefinedException.h"
12 #include "networktables2/type/DefaultEntryTypes.h"
13 #include "tables/ITableListener.h"
14 #include "networktables/NetworkTableConnectionListenerAdapter.h"
15 #include "networktables/NetworkTableKeyListenerAdapter.h"
16 #include "networktables/NetworkTableListenerAdapter.h"
17 #include "networktables/NetworkTableSubListenerAdapter.h"
20 const char NetworkTable::PATH_SEPARATOR_CHAR =
'/';
27 int NetworkTable::port = DEFAULT_PORT;
28 std::string NetworkTable::ipAddress;
36 void NetworkTable::CheckInit(){
39 if(staticProvider!=NULL)
51 staticProvider = provider;
56 mode = &NetworkTableMode::Server;
61 mode = &NetworkTableMode::Server;
66 sprintf(tmp,
"%d.%d.%d.%d\n", 10, team/100, team%100, 2);
76 if(staticProvider==NULL){
87 path(_path), entryCache(_path), absoluteKeyCache(_path), provider(_provider), node(provider.GetNode()) {
89 NetworkTable::~NetworkTable(){
92 bool NetworkTable::IsConnected() {
96 bool NetworkTable::IsServer() {
102 map<IRemoteConnectionListener*, NetworkTableConnectionListenerAdapter*>::iterator itr = connectionListenerMap.find(listener);
103 if(itr != connectionListenerMap.end()){
108 connectionListenerMap[listener] = adapter;
114 map<IRemoteConnectionListener*, NetworkTableConnectionListenerAdapter*>::iterator itr = connectionListenerMap.find(listener);
115 if(itr != connectionListenerMap.end()){
118 connectionListenerMap.erase(itr);
124 AddTableListener(listener,
false);
127 void NetworkTable::AddTableListener(
ITableListener* listener,
bool immediateNotify) {
128 std::string tmp(path);
131 listenerMap.insert ( pair<ITableListener*,ITableListener*>(listener, adapter) );
132 node.AddTableListener(adapter, immediateNotify);
134 void NetworkTable::AddTableListener(std::string key,
ITableListener* listener,
bool immediateNotify) {
136 listenerMap.insert ( pair<ITableListener*,ITableListener*>(listener, adapter) );
137 node.AddTableListener(adapter, immediateNotify);
139 void NetworkTable::AddSubTableListener(
ITableListener* listener) {
141 listenerMap.insert ( pair<ITableListener*,ITableListener*>(listener, adapter) );
142 node.AddTableListener(adapter,
true);
145 void NetworkTable::RemoveTableListener(
ITableListener* listener) {
146 multimap<ITableListener*,ITableListener*>::iterator itr;
147 pair<multimap<ITableListener*,ITableListener*>::iterator,multimap<ITableListener*,ITableListener*>::iterator> itrs = listenerMap.equal_range(listener);
148 for (itr=itrs.first; itr!=itrs.second; ++itr){
149 node.RemoveTableListener(itr->second);
152 listenerMap.erase(itrs.first, itrs.second);
158 return entryCache.Get(key);
172 return node.
ContainsKey(absoluteKeyCache.Get(key));
175 bool NetworkTable::ContainsSubTable(std::string key){
176 std::string subtablePrefix(absoluteKeyCache.Get(key));
178 std::vector<std::string>* keys = node.
GetEntryStore().keys();
179 for(
unsigned int i = 0; i<keys->size(); ++i){
180 if(keys->at(i).compare(0, subtablePrefix.size(), subtablePrefix)==0){
193 PutValue(key, &DefaultEntryTypes::DOUBLE, eValue);
198 return node.GetDouble(absoluteKeyCache.Get(key));
204 return node.GetDouble(absoluteKeyCache.Get(key));
214 PutValue(key, &DefaultEntryTypes::STRING, eValue);
219 return node.GetString(absoluteKeyCache.Get(key));
225 return node.GetString(absoluteKeyCache.Get(key));
235 PutValue(key, &DefaultEntryTypes::BOOLEAN, eValue);
240 return node.GetBoolean(absoluteKeyCache.Get(key));
246 return node.GetBoolean(absoluteKeyCache.Get(key));
257 node.
PutValue(absoluteKeyCache.Get(key), type, value);
260 void NetworkTable::RetrieveValue(std::string key,
ComplexData& externalValue) {
261 node.retrieveValue(absoluteKeyCache.Get(key), externalValue);
268 PutValue(key, &value.GetType(), eValue);
273 return node.GetValue(absoluteKeyCache.Get(key));
278 return node.GetValue(absoluteKeyCache.Get(key));
290 NetworkTableKeyCache::NetworkTableKeyCache(std::string _path):path(_path){}
291 NetworkTableKeyCache::~NetworkTableKeyCache(){}
293 std::string tmp(path);
299 EntryCache::EntryCache(std::string& _path):path(_path){}
300 EntryCache::~EntryCache(){}