/** * Stores the given value under the given name and queues it for * transmission to the server. * * @param name The name under which to store the given value. * @param type The type of the given value. * @param value The value to store. * @throws TableKeyExistsWithDifferentTypeException Thrown if an * entry already exists with the given name and is of a different type. */ void AbstractNetworkTableEntryStore::PutOutgoing(std::string& name, NetworkTableEntryType* type, EntryValue value){ { NTSynchronized sync(LOCK); std::map<std::string, NetworkTableEntry*>::iterator index = namedEntries.find(name); NetworkTableEntry* tableEntry; if(index == namedEntries.end())//if the name does not exist in the current entries { tableEntry = new NetworkTableEntry(name, type, value); if(addEntry(tableEntry)) { tableEntry->FireListener(listenerManager); outgoingReceiver->offerOutgoingAssignment(tableEntry); } } else { tableEntry = index->second; if(tableEntry->GetType()->id != type->id){ throw TableKeyExistsWithDifferentTypeException(name, tableEntry->GetType()); } EntryValue oldValue = tableEntry->GetValue(); if(!type->areEqual(value, oldValue)){ if(updateEntry(tableEntry, (SequenceNumber)(tableEntry->GetSequenceNumber() + 1), value)){ outgoingReceiver->offerOutgoingUpdate(tableEntry); } tableEntry->FireListener(listenerManager); } } } }
EntryValue NetworkTableNode::GetValue(std::string& name){//TODO don't allow get of complex types { NTSynchronized sync(entryStore.LOCK); NetworkTableEntry* entry = entryStore.GetEntry(name); if(entry==NULL) throw TableKeyNotDefinedException(name); return entry->GetValue(); } }
/** * Called to say that a listener should notify the listener manager of all of the entries * @param listener * @param table */ void AbstractNetworkTableEntryStore::notifyEntries(ITable* table, ITableListener* listener){ { Synchronized sync(LOCK); std::map<std::string, NetworkTableEntry*>::iterator itr; for(itr = namedEntries.begin(); itr != namedEntries.end(); itr++) { NetworkTableEntry* entry = itr->second; listener->ValueChanged(table, itr->first, entry->GetValue(), true); } } }
void NetworkTableNode::retrieveValue(std::string& name, ComplexData& externalData){ { NTSynchronized sync(entryStore.LOCK); NetworkTableEntry* entry = entryStore.GetEntry(name); if(entry==NULL) throw TableKeyNotDefinedException(name); NetworkTableEntryType* entryType = entry->GetType(); if(!entryType->isComplex()) throw TableKeyExistsWithDifferentTypeException(name, entryType, "Is not a complex data type"); ComplexEntryType* complexType = (ComplexEntryType*)entryType; complexType->exportValue(name, entry->GetValue(), externalData); } }
void NetworkTableNode::PutValue(std::string& name, NetworkTableEntryType* type, EntryValue value){ if(type->isComplex()){ { NTSynchronized sync(entryStore.LOCK); ComplexData* complexData = (ComplexData*)value.ptr; ComplexEntryType* entryType = (ComplexEntryType*)type; NetworkTableEntry* entry = entryStore.GetEntry(name); if(entry!=NULL) entryStore.PutOutgoing(entry, entryType->internalizeValue(entry->name, *complexData, entry->GetValue())); else{ EntryValue nullValue = {0}; EntryValue entryValue = entryType->internalizeValue(name, *complexData, nullValue); entryStore.PutOutgoing(name, type, entryValue);//TODO the entry gets copied when creating the entry should make lifecycle cleaner type->deleteValue(entryValue); } } } else entryStore.PutOutgoing(name, type, value); }
std::string& NetworkTableNode::GetString(std::string& name) { NetworkTableEntry* entry = entryStore.GetEntry(name); if(entry==NULL) throw TableKeyNotDefinedException(name); return *(std::string*)(entry->GetValue().ptr); }
double NetworkTableNode::GetDouble(std::string& name){ NetworkTableEntry* entry = entryStore.GetEntry(name); if(entry==NULL) throw TableKeyNotDefinedException(name); return entry->GetValue().f; }