| 434 | } |
| 435 | |
| 436 | void RGPInterop::ProcessReadBuffer() |
| 437 | { |
| 438 | // we might have partial data, so wait until we have a full command |
| 439 | do |
| 440 | { |
| 441 | int idx = m_ReadBuffer.indexOf("endcommand="); |
| 442 | |
| 443 | // if we don't have endcommand= yet, we don't have a full command |
| 444 | if(idx < 0) |
| 445 | return; |
| 446 | |
| 447 | idx = m_ReadBuffer.indexOf('\n', idx); |
| 448 | |
| 449 | // also break if we don't have the full line yet including newline. |
| 450 | if(idx < 0) |
| 451 | return; |
| 452 | |
| 453 | // extract the command and decode as UTF-8 |
| 454 | QString command = QString::fromUtf8(m_ReadBuffer.data(), idx + 1); |
| 455 | |
| 456 | // remove the command from our buffer, to retain any partial subsequent command we might have |
| 457 | m_ReadBuffer.remove(0, idx + 1); |
| 458 | |
| 459 | // process this command |
| 460 | DecodeCommand(command); |
| 461 | |
| 462 | // loop again - we might have read multiple commands |
| 463 | } while(true); |
| 464 | } |