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.

ConnParams.cxx 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 <rdr/InStream.h>
  19. #include <rdr/OutStream.h>
  20. #include <rfb/Exception.h>
  21. #include <rfb/encodings.h>
  22. #include <rfb/Encoder.h>
  23. #include <rfb/ConnParams.h>
  24. #include <rfb/util.h>
  25. using namespace rfb;
  26. ConnParams::ConnParams()
  27. : majorVersion(0), minorVersion(0), width(0), height(0), useCopyRect(false),
  28. supportsLocalCursor(false), supportsDesktopResize(false),
  29. name_(0), nEncodings_(0), encodings_(0),
  30. currentEncoding_(encodingRaw), verStrPos(0)
  31. {
  32. setName("");
  33. }
  34. ConnParams::~ConnParams()
  35. {
  36. delete [] name_;
  37. delete [] encodings_;
  38. }
  39. bool ConnParams::readVersion(rdr::InStream* is, bool* done)
  40. {
  41. if (verStrPos >= 12) return false;
  42. while (is->checkNoWait(1) && verStrPos < 12) {
  43. verStr[verStrPos++] = is->readU8();
  44. }
  45. if (verStrPos < 12) {
  46. *done = false;
  47. return true;
  48. }
  49. *done = true;
  50. verStr[12] = 0;
  51. return (sscanf(verStr, "RFB %03d.%03d\n", &majorVersion,&minorVersion) == 2);
  52. }
  53. void ConnParams::writeVersion(rdr::OutStream* os)
  54. {
  55. char str[13];
  56. sprintf(str, "RFB %03d.%03d\n", majorVersion, minorVersion);
  57. os->writeBytes(str, 12);
  58. os->flush();
  59. }
  60. void ConnParams::setPF(const PixelFormat& pf)
  61. {
  62. pf_ = pf;
  63. if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32)
  64. throw Exception("setPF: not 8, 16 or 32 bpp?");
  65. }
  66. void ConnParams::setName(const char* name)
  67. {
  68. delete [] name_;
  69. name_ = strDup(name);
  70. }
  71. void ConnParams::setEncodings(int nEncodings, const rdr::U32* encodings)
  72. {
  73. if (nEncodings > nEncodings_) {
  74. delete [] encodings_;
  75. encodings_ = new rdr::U32[nEncodings];
  76. }
  77. nEncodings_ = nEncodings;
  78. useCopyRect = false;
  79. supportsLocalCursor = false;
  80. currentEncoding_ = encodingRaw;
  81. for (int i = nEncodings-1; i >= 0; i--) {
  82. encodings_[i] = encodings[i];
  83. if (encodings[i] == encodingCopyRect)
  84. useCopyRect = true;
  85. else if (encodings[i] == pseudoEncodingCursor)
  86. supportsLocalCursor = true;
  87. else if (encodings[i] == pseudoEncodingDesktopSize)
  88. supportsDesktopResize = true;
  89. else if (encodings[i] <= encodingMax && Encoder::supported(encodings[i]))
  90. currentEncoding_ = encodings[i];
  91. }
  92. }