Beispiel #1
0
static void processCommand(ClientSocket &sock)
{
	SyncDocument *doc = trackView->getDocument();
	int strLen, serverIndex, newRow;
	std::string trackName;
	const sync_track *t;
	unsigned char cmd = 0;
	if (sock.recv((char*)&cmd, 1)) {
		switch (cmd) {
		case GET_TRACK:
			// read data
			sock.recv((char *)&strLen, sizeof(int));
			strLen = ntohl(strLen);
			if (!sock.connected())
				return;

			if (!strLen) {
				sock.disconnect();
				InvalidateRect(trackViewWin, NULL, FALSE);
				return;
			}

			trackName.resize(strLen);
			if (!sock.recv(&trackName[0], strLen))
				return;

			if (int(strlen(trackName.c_str())) != strLen) {
				sock.disconnect();
				InvalidateRect(trackViewWin, NULL, FALSE);
				return;
			}

			// find track
			serverIndex = sync_find_track(doc,
			    trackName.c_str());
			if (0 > serverIndex)
				serverIndex =
				    int(doc->createTrack(trackName));

			// setup remap
			doc->clientSocket.clientTracks[trackName] = clientIndex++;

			// send key-frames
			t = doc->tracks[serverIndex];
			for (int i = 0; i < (int)t->num_keys; ++i)
				doc->clientSocket.sendSetKeyCommand(trackName,
				    t->keys[i]);

			InvalidateRect(trackViewWin, NULL, FALSE);
			break;

		case SET_ROW:
			sock.recv((char*)&newRow, sizeof(int));
			trackView->setEditRow(ntohl(newRow));
			break;
		}
	}
}
void processCommand(NetworkSocket &sock)
{
	size_t clientIndex = 0;
	int strLen, serverIndex, newRow;
	std::string trackName;
	const sync_track *t;
	unsigned char cmd = 0;
	if (sock.recv((char*)&cmd, 1, 0)) {
		switch (cmd) {
		case GET_TRACK:
			// read data
			sock.recv((char *)&clientIndex, sizeof(int), 0);
			sock.recv((char *)&strLen, sizeof(int), 0);
			clientIndex = ntohl(clientIndex);
			strLen = ntohl(strLen);
			if (!sock.connected())
				return;

			trackName.resize(strLen);
			if (!sock.recv(&trackName[0], strLen, 0))
				return;

			// find track
			serverIndex = sync_find_track(&document,
			    trackName.c_str());
			if (0 > serverIndex)
				serverIndex =
				    int(document.createTrack(trackName));

			// setup remap
			document.clientRemap[serverIndex] = clientIndex;

			// send key-frames
			t = document.tracks[serverIndex];
			for (int i = 0; i < (int)t->num_keys; ++i)
				document.sendSetKeyCommand(int(serverIndex),
				    t->keys[i]);

			InvalidateRect(trackViewWin, NULL, FALSE);
			break;

		case SET_ROW:
			sock.recv((char*)&newRow, sizeof(int), 0);
			trackView->setEditRow(ntohl(newRow));
			break;
		}
	}
}
Beispiel #3
0
SyncDocument *SyncDocument::load(const QString &fileName)
{
	SyncDocument *ret = new SyncDocument;
	ret->fileName = fileName;

	QFile file(fileName);
	if (!file.open(QIODevice::ReadOnly)) {
		QMessageBox::critical(NULL, "Error", file.errorString());
		return NULL;
	}

	QDomDocument doc;
	QString err;
	if (!doc.setContent(&file, &err)) {
		file.close();
		QMessageBox::critical(NULL, "Error", err);
		return NULL;
	}
	file.close();

	QDomNamedNodeMap attribs = doc.documentElement().attributes();
	QDomNode rowsParam = attribs.namedItem("rows");
	if (!rowsParam.isNull()) {
		QString rowsString = rowsParam.nodeValue();
		ret->setRows(rowsString.toInt());
	}

	QDomNodeList trackNodes =
	    doc.documentElement().elementsByTagName("track");
	for (int i = 0; i < int(trackNodes.length()); ++i) {
		QDomNode trackNode = trackNodes.item(i);
		QDomNamedNodeMap attribs = trackNode.attributes();

		QString name = attribs.namedItem("name").nodeValue();

		// look up track-name, create it if it doesn't exist
		SyncTrack *t = ret->findTrack(name.toUtf8());
		if (!t)
			t = ret->createTrack(name.toUtf8().constData());

		QDomNodeList rowNodes = trackNode.childNodes();
		for (int i = 0; i < int(rowNodes.length()); ++i) {
			QDomNode keyNode = rowNodes.item(i);
			QString baseName = keyNode.nodeName();
			if (baseName == "key") {
				QDomNamedNodeMap rowAttribs = keyNode.attributes();
				QString rowString = rowAttribs.namedItem("row").nodeValue();
				QString valueString = rowAttribs.namedItem("value").nodeValue();
				QString interpolationString = rowAttribs.namedItem("interpolation").nodeValue();

				SyncTrack::TrackKey k;
				k.row = rowString.toInt();
				k.value = valueString.toFloat();
				k.type = SyncTrack::TrackKey::KeyType(interpolationString.toInt());

				Q_ASSERT(!t->isKeyFrame(k.row));
				t->setKey(k);
			}
		}
	}

	// YUCK: gathers from entire document
	QDomNodeList bookmarkNodes =
	    doc.documentElement().elementsByTagName("bookmark");
	for (int i = 0; i < int(bookmarkNodes.length()); ++i) {
		QDomNode bookmarkNode =
		    bookmarkNodes.item(i);
		QDomNamedNodeMap bookmarkAttribs =
		    bookmarkNode.attributes();
		QString str =
		    bookmarkAttribs.namedItem("row").nodeValue();
		int row = str.toInt();
		ret->toggleRowBookmark(row);
	}

	return ret;
}