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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* Copyright (C) 2002-2005 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. #include <rfb/util.h>
  25. #include <stdio.h>
  26. using namespace rfb;
  27. CMsgReaderV3::CMsgReaderV3(CMsgHandler* handler, rdr::InStream* is)
  28. : CMsgReader(handler, is), nUpdateRectsLeft(0)
  29. {
  30. }
  31. CMsgReaderV3::~CMsgReaderV3()
  32. {
  33. }
  34. void CMsgReaderV3::readServerInit()
  35. {
  36. int width = is->readU16();
  37. int height = is->readU16();
  38. handler->setDesktopSize(width, height);
  39. PixelFormat pf;
  40. pf.read(is);
  41. handler->setPixelFormat(pf);
  42. CharArray name(is->readString());
  43. handler->setName(name.buf);
  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. case msgTypeFileListData:
  56. case msgTypeFileDownloadData:
  57. case msgTypeFileUploadCancel:
  58. case msgTypeFileDownloadFailed:
  59. case msgTypeFileDirSizeData:
  60. case msgTypeFileLastRequestFailed:
  61. handler->processFTMsg(type); break;
  62. default:
  63. fprintf(stderr, "unknown message type %d\n", type);
  64. throw Exception("unknown message type");
  65. }
  66. } else {
  67. int x = is->readU16();
  68. int y = is->readU16();
  69. int w = is->readU16();
  70. int h = is->readU16();
  71. unsigned int encoding = is->readU32();
  72. switch (encoding) {
  73. case pseudoEncodingDesktopSize:
  74. handler->setDesktopSize(w, h);
  75. break;
  76. case pseudoEncodingDesktopName:
  77. readSetDesktopName(x, y, w, h);
  78. break;
  79. case pseudoEncodingCursor:
  80. readSetCursor(w, h, Point(x,y));
  81. break;
  82. case pseudoEncodingLastRect:
  83. nUpdateRectsLeft = 1; // this rectangle is the last one
  84. break;
  85. default:
  86. readRect(Rect(x, y, x+w, y+h), encoding);
  87. break;
  88. };
  89. nUpdateRectsLeft--;
  90. if (nUpdateRectsLeft == 0) handler->framebufferUpdateEnd();
  91. }
  92. }
  93. void CMsgReaderV3::readFramebufferUpdate()
  94. {
  95. is->skip(1);
  96. nUpdateRectsLeft = is->readU16();
  97. handler->framebufferUpdateStart();
  98. }