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.

CMsgWriter.cxx 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 <stdio.h>
  19. #include <rdr/OutStream.h>
  20. #include <rfb/msgTypes.h>
  21. #include <rfb/PixelFormat.h>
  22. #include <rfb/Rect.h>
  23. #include <rfb/ConnParams.h>
  24. #include <rfb/Decoder.h>
  25. #include <rfb/CMsgWriter.h>
  26. using namespace rfb;
  27. CMsgWriter::CMsgWriter(ConnParams* cp_, rdr::OutStream* os_)
  28. : cp(cp_), os(os_)
  29. {
  30. }
  31. CMsgWriter::~CMsgWriter()
  32. {
  33. }
  34. void CMsgWriter::writeSetPixelFormat(const PixelFormat& pf)
  35. {
  36. startMsg(msgTypeSetPixelFormat);
  37. os->pad(3);
  38. pf.write(os);
  39. endMsg();
  40. }
  41. void CMsgWriter::writeSetEncodings(int nEncodings, rdr::U32* encodings)
  42. {
  43. startMsg(msgTypeSetEncodings);
  44. os->skip(1);
  45. os->writeU16(nEncodings);
  46. for (int i = 0; i < nEncodings; i++)
  47. os->writeU32(encodings[i]);
  48. endMsg();
  49. }
  50. // Ask for encodings based on which decoders are supported. Assumes higher
  51. // encoding numbers are more desirable.
  52. void CMsgWriter::writeSetEncodings(int preferredEncoding, bool useCopyRect)
  53. {
  54. int nEncodings = 0;
  55. rdr::U32 encodings[encodingMax+2];
  56. if (cp->supportsLocalCursor)
  57. encodings[nEncodings++] = pseudoEncodingCursor;
  58. if (cp->supportsDesktopResize)
  59. encodings[nEncodings++] = pseudoEncodingDesktopSize;
  60. if (Decoder::supported(preferredEncoding)) {
  61. encodings[nEncodings++] = preferredEncoding;
  62. }
  63. if (useCopyRect) {
  64. encodings[nEncodings++] = encodingCopyRect;
  65. }
  66. for (int i = encodingMax; i >= 0; i--) {
  67. if (i != preferredEncoding && Decoder::supported(i)) {
  68. encodings[nEncodings++] = i;
  69. }
  70. }
  71. writeSetEncodings(nEncodings, encodings);
  72. }
  73. void CMsgWriter::writeFramebufferUpdateRequest(const Rect& r, bool incremental)
  74. {
  75. startMsg(msgTypeFramebufferUpdateRequest);
  76. os->writeU8(incremental);
  77. os->writeU16(r.tl.x);
  78. os->writeU16(r.tl.y);
  79. os->writeU16(r.width());
  80. os->writeU16(r.height());
  81. endMsg();
  82. }
  83. void CMsgWriter::writeKeyEvent(rdr::U32 key, bool down)
  84. {
  85. startMsg(msgTypeKeyEvent);
  86. os->writeU8(down);
  87. os->pad(2);
  88. os->writeU32(key);
  89. endMsg();
  90. }
  91. void CMsgWriter::writePointerEvent(int x, int y, int buttonMask)
  92. {
  93. if (x < 0) x = 0;
  94. if (y < 0) y = 0;
  95. if (x >= cp->width) x = cp->width - 1;
  96. if (y >= cp->height) y = cp->height - 1;
  97. startMsg(msgTypePointerEvent);
  98. os->writeU8(buttonMask);
  99. os->writeU16(x);
  100. os->writeU16(y);
  101. endMsg();
  102. }
  103. void CMsgWriter::writeClientCutText(const char* str, int len)
  104. {
  105. startMsg(msgTypeClientCutText);
  106. os->pad(3);
  107. os->writeU32(len);
  108. os->writeBytes(str, len);
  109. endMsg();
  110. }
  111. void CMsgWriter::setOutStream(rdr::OutStream* os_)
  112. {
  113. os = os_;
  114. }