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 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright 2009 Pierre Ossman for Cendio AB
  3. *
  4. * This is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This software is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this software; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  17. * USA.
  18. */
  19. #include <rfb/PixelFormat.h>
  20. #include <rfb/msgTypes.h>
  21. #include <rfb/Exception.h>
  22. #include <rdr/InStream.h>
  23. #include <rfb/CMsgReaderV3.h>
  24. #include <rfb/CMsgHandler.h>
  25. #include <rfb/util.h>
  26. #include <stdio.h>
  27. using namespace rfb;
  28. CMsgReaderV3::CMsgReaderV3(CMsgHandler* handler, rdr::InStream* is)
  29. : CMsgReader(handler, is), nUpdateRectsLeft(0)
  30. {
  31. }
  32. CMsgReaderV3::~CMsgReaderV3()
  33. {
  34. }
  35. void CMsgReaderV3::readServerInit()
  36. {
  37. int width = is->readU16();
  38. int height = is->readU16();
  39. handler->setDesktopSize(width, height);
  40. PixelFormat pf;
  41. pf.read(is);
  42. handler->setPixelFormat(pf);
  43. CharArray name(is->readString());
  44. handler->setName(name.buf);
  45. handler->serverInit();
  46. }
  47. void CMsgReaderV3::readMsg()
  48. {
  49. if (nUpdateRectsLeft == 0) {
  50. int type = is->readU8();
  51. switch (type) {
  52. case msgTypeFramebufferUpdate: readFramebufferUpdate(); break;
  53. case msgTypeSetColourMapEntries: readSetColourMapEntries(); break;
  54. case msgTypeBell: readBell(); break;
  55. case msgTypeServerCutText: readServerCutText(); break;
  56. default:
  57. fprintf(stderr, "unknown message type %d\n", type);
  58. throw Exception("unknown message type");
  59. }
  60. } else {
  61. int x = is->readU16();
  62. int y = is->readU16();
  63. int w = is->readU16();
  64. int h = is->readU16();
  65. unsigned int encoding = is->readU32();
  66. switch (encoding) {
  67. case pseudoEncodingDesktopSize:
  68. handler->setDesktopSize(w, h);
  69. break;
  70. case pseudoEncodingExtendedDesktopSize:
  71. readExtendedDesktopSize(x, y, w, h);
  72. break;
  73. case pseudoEncodingDesktopName:
  74. readSetDesktopName(x, y, w, h);
  75. break;
  76. case pseudoEncodingCursor:
  77. readSetCursor(w, h, Point(x,y));
  78. break;
  79. case pseudoEncodingLastRect:
  80. nUpdateRectsLeft = 1; // this rectangle is the last one
  81. break;
  82. default:
  83. readRect(Rect(x, y, x+w, y+h), encoding);
  84. break;
  85. };
  86. nUpdateRectsLeft--;
  87. if (nUpdateRectsLeft == 0) handler->framebufferUpdateEnd();
  88. }
  89. }
  90. void CMsgReaderV3::readFramebufferUpdate()
  91. {
  92. is->skip(1);
  93. nUpdateRectsLeft = is->readU16();
  94. handler->framebufferUpdateStart();
  95. }
  96. void CMsgReaderV3::readSetDesktopName(int x, int y, int w, int h)
  97. {
  98. char* name = is->readString();
  99. if (x || y || w || h) {
  100. fprintf(stderr, "Ignoring DesktopName rect with non-zero position/size\n");
  101. } else {
  102. handler->setName(name);
  103. }
  104. delete [] name;
  105. }
  106. void CMsgReaderV3::readExtendedDesktopSize(int x, int y, int w, int h)
  107. {
  108. unsigned int screens;
  109. screens = is->readU8();
  110. is->skip(3);
  111. // XXX: We just ignore screen info right now
  112. is->skip(16 * screens);
  113. handler->setExtendedDesktopSize(x, y, w, h);
  114. }