/**
	 * 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);
				}
			}
		}
	}
Exemplo n.º 2
0
void NetworkTableConnection::read(ConnectionAdapter& adapter) {
	int messageType = ioStream->readByte();
	switch (messageType) {
	case KEEP_ALIVE:
		adapter.keepAlive();
		return;
	case CLIENT_HELLO: {
		uint16_t protocolRevision = ioStream->read2BytesBE();
		adapter.clientHello(protocolRevision);
		return;
	}
	case SERVER_HELLO_COMPLETE: {
		adapter.serverHelloComplete();
		return;
	}
	case PROTOCOL_VERSION_UNSUPPORTED: {
		uint16_t protocolRevision = ioStream->read2BytesBE();
		adapter.protocolVersionUnsupported(protocolRevision);
		return;
	}
	case ENTRY_ASSIGNMENT: {
		std::string* entryName = ioStream->readString();
		TypeId typeId = ioStream->readByte();
		NetworkTableEntryType* entryType = typeManager.GetType(typeId);
		if (!entryType){
			char exceptionMessageBuffer[50];
			sprintf (exceptionMessageBuffer, "Unknown data type: %#x", typeId);
			throw BadMessageException(exceptionMessageBuffer);
		}
		EntryId entryId = ioStream->read2BytesBE();
		SequenceNumber entrySequenceNumber = ioStream->read2BytesBE();
		EntryValue value = entryType->readValue(*ioStream);
		adapter.offerIncomingAssignment(new NetworkTableEntry(entryId, *entryName, entrySequenceNumber, entryType, value));
		entryType->deleteValue(value);
		delete entryName;
		return;
	}
	case FIELD_UPDATE: {
		EntryId entryId = ioStream->read2BytesBE();
		SequenceNumber entrySequenceNumber = ioStream->read2BytesBE();
		NetworkTableEntry* entry = adapter.GetEntry(entryId);
		if (!entry){
			char exceptionMessageBuffer[50];
			sprintf (exceptionMessageBuffer, "Received update for unknown entry id: %d", entryId);
			throw BadMessageException(exceptionMessageBuffer);
		}
		EntryValue value = entry->GetType()->readValue(*ioStream);

		adapter.offerIncomingUpdate(entry, entrySequenceNumber, value);
		entry->GetType()->deleteValue(value);
		return;
	}
	default:
		char exceptionMessageBuffer[50];
		sprintf (exceptionMessageBuffer, "Unknown Network Table Message Type: %d", messageType);
		throw BadMessageException(exceptionMessageBuffer);
	}
}
Exemplo n.º 3
0
void NetworkTableConnection::sendEntryAssignment(NetworkTableEntry& entry) {
	{
		Synchronized sync(WRITE_LOCK);
		sendMessageHeader(ENTRY_ASSIGNMENT);
		ioStream->writeString(entry.name);
		ioStream->writeByte(entry.GetType()->id);
		ioStream->write2BytesBE(entry.GetId());
		ioStream->write2BytesBE(entry.GetSequenceNumber());
		entry.SendValue(*ioStream);
	}
}
Exemplo n.º 4
0
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);
	}
}