You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CMsgReaderV3.cxx 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* Copyright (C) 2002-2003 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. #include <rfb/PixelFormat.h>
  19. #include <rfb/msgTypes.h>
  20. #include <rfb/Exception.h>
  21. #include <rdr/InStream.h>
  22. #include <rfb/CMsgReaderV3.h>
  23. #include <rfb/CMsgHandler.h>
  24. using namespace rfb;
  25. CMsgReaderV3::CMsgReaderV3(CMsgHandler* handler, rdr::InStream* is)
  26. : CMsgReader(handler, is), nUpdateRectsLeft(0)
  27. {
  28. }
  29. CMsgReaderV3::~CMsgReaderV3()
  30. {
  31. }
  32. void CMsgReaderV3::readServerInit()
  33. {
  34. int width = is->readU16();
  35. int height = is->readU16();
  36. handler->setDesktopSize(width, height);
  37. PixelFormat pf;
  38. pf.read(is);
  39. handler->setPixelFormat(pf);
  40. char* name = is->readString();
  41. handler->setName(name);
  42. delete [] name;
  43. endMsg();
  44. handler->serverInit();
  45. }
  46. void CMsgReaderV3::readMsg()
  47. {
  48. if (nUpdateRectsLeft == 0) {
  49. int type = is->readU8();
  50. switch (type) {
  51. case msgTypeFramebufferUpdate: readFramebufferUpdate(); break;
  52. case msgTypeSetColourMapEntries: readSetColourMapEntries(); break;
  53. case msgTypeBell: readBell(); break;
  54. case msgTypeServerCutText: readServerCutText(); break;
  55. default:
  56. fprintf(stderr, "unknown message type %d\n", type);
  57. throw Exception("unknown message type");
  58. }
  59. } else {
  60. int x = is->readU16();
  61. int y = is->readU16();
  62. int w = is->readU16();
  63. int h = is->readU16();
  64. unsigned int encoding = is->readU32();
  65. switch (encoding) {
  66. case pseudoEncodingDesktopSize:
  67. handler->setDesktopSize(w, h);
  68. break;
  69. case pseudoEncodingCursor:
  70. readSetCursor(Point(x, y), Point(w, h));
  71. break;
  72. default:
  73. readRect(Rect(x, y, x+w, y+h), encoding);
  74. break;
  75. };
  76. nUpdateRectsLeft--;
  77. if (nUpdateRectsLeft == 0) handler->framebufferUpdateEnd();
  78. }
  79. }
  80. void CMsgReaderV3::readFramebufferUpdate()
  81. {
  82. is->skip(1);
  83. nUpdateRectsLeft = is->readU16();
  84. endMsg();
  85. handler->framebufferUpdateStart();
  86. }