示例#1
0
	void dumpTime(std::ostream &stream, bool raw)
	{
		if (raw)
			stream << UnifiedTime().toRawTimeString();
		else
			stream << UnifiedTime().toHumanReadableStringFromEpoch();
		stream << " ";
	}
示例#2
0
	UnifiedTime UnifiedTime::fromRawTimeString(const std::string& rawTimeString)
	{
		size_t dotPos(rawTimeString.find('.'));
		assert(dotPos != std::string::npos);
		return UnifiedTime(atoll(rawTimeString.substr(0, dotPos).c_str()), atoll(rawTimeString.substr(dotPos + 1, std::string::npos).c_str()));
	}
示例#3
0
	void NodesManager::processMessage(const Message* message)
	{
		// check whether the node is known
		NodesMap::iterator nodeIt(nodes.find(message->source));
		if (nodeIt == nodes.end())
		{
			// node is not known, so ignore excepted if the message type 
			// is node present and it is not a known mismatch protocol,
			// in that case, request description...
			if ((message->type == ASEBA_MESSAGE_NODE_PRESENT) &&
				mismatchingNodes.find(message->source) == mismatchingNodes.end())
			{
				GetNodeDescription getNodeDescription(message->source);
				sendMessage(getNodeDescription);
			}
			// or if message type is description, in that case, proceed further
			if (message->type != ASEBA_MESSAGE_DESCRIPTION)
				return;
		}
		else
		{
			// node is known, check if connected...
			if (!nodeIt->second.connected)
			{
				// if not, build complete, set as connected and notify client
				nodeIt->second.connected = true;
				if (nodeIt->second.isComplete())
				{
					// only notify connections of completed known nodes
					nodeConnected(nodeIt->first);
				}
			}
			// update last seen time
			nodeIt->second.lastSeen = UnifiedTime();
		}
		
		// if we have a disconnection message
		{
			// FIXME: handle disconnected state
			const Disconnected *disconnected = dynamic_cast<const Disconnected *>(message);
			if (disconnected)
			{
				NodesMap::iterator nodeIt = nodes.find(disconnected->source);
				assert (nodeIt != nodes.end());
				nodes.erase(nodeIt);
			}
		}
		
		// if we have an initial description
		{
			const Description *description = dynamic_cast<const Description *>(message);
			if (description)
			{
				NodesMap::iterator nodeIt = nodes.find(description->source);
				
				// We can receive a description twice, for instance if there is another IDE connected
				if (nodeIt != nodes.end() || (mismatchingNodes.find(description->source) != mismatchingNodes.end()))
					return;
				
				// Call a user function when a node protocol version mismatches
				if ((description->protocolVersion < ASEBA_MIN_TARGET_PROTOCOL_VERSION) ||
					(description->protocolVersion > ASEBA_PROTOCOL_VERSION))
				{
					nodeProtocolVersionMismatch(description->source, description->name, description->protocolVersion);
					mismatchingNodes.insert(description->source);
					return;
				}
				
				// create node and copy description into it
				nodes[description->source] = Node(*description);
				checkIfNodeDescriptionComplete(description->source, nodes[description->source]);
			}
		}
		
		// if we have a named variable description
		{
			const NamedVariableDescription *description = dynamic_cast<const NamedVariableDescription *>(message);
			if (description)
			{
				NodesMap::iterator nodeIt = nodes.find(description->source);
				assert (nodeIt != nodes.end());
				
				// copy description into array if array is empty
				if (nodeIt->second.namedVariablesReceptionCounter < nodeIt->second.namedVariables.size())
				{
					nodeIt->second.namedVariables[nodeIt->second.namedVariablesReceptionCounter++] = *description;
					checkIfNodeDescriptionComplete(nodeIt->first, nodeIt->second);
				}
			}
		}
		
		// if we have a local event description
		{
			const LocalEventDescription *description = dynamic_cast<const LocalEventDescription *>(message);
			if (description)
			{
				NodesMap::iterator nodeIt = nodes.find(description->source);
				assert (nodeIt != nodes.end());
				
				// copy description into array if array is empty
				if (nodeIt->second.localEventsReceptionCounter < nodeIt->second.localEvents.size())
				{
					nodeIt->second.localEvents[nodeIt->second.localEventsReceptionCounter++] = *description;
					checkIfNodeDescriptionComplete(nodeIt->first, nodeIt->second);
				}
			}
		}
		
		// if we have a native function description
		{
			const NativeFunctionDescription *description = dynamic_cast<const NativeFunctionDescription *>(message);
			if (description)
			{
				NodesMap::iterator nodeIt = nodes.find(description->source);
				assert (nodeIt != nodes.end());
				
				// copy description into array
				if (nodeIt->second.nativeFunctionReceptionCounter < nodeIt->second.nativeFunctions.size())
				{
					nodeIt->second.nativeFunctions[nodeIt->second.nativeFunctionReceptionCounter++] = *description;
					checkIfNodeDescriptionComplete(nodeIt->first, nodeIt->second);
				}
			}
		}
	}