]> source.dussan.org Git - tigervnc.git/commitdiff
Move serialisation of pseudorects into separate functions
authorPierre Ossman <ossman@cendio.se>
Thu, 16 Jan 2014 12:39:05 +0000 (13:39 +0100)
committerPierre Ossman <ossman@cendio.se>
Mon, 7 Jul 2014 12:42:08 +0000 (14:42 +0200)
Keeps the code clearer.

common/rfb/SMsgWriter.cxx
common/rfb/SMsgWriter.h

index c21f8bc54b0f80ac8a48816d6589d0abd1b79966..2a31f03e094ca5ff374b354d668c06f6248f7004 100644 (file)
@@ -446,18 +446,7 @@ void SMsgWriter::writePseudoRects()
   }
 
   if (needSetDesktopName) {
-    if (!cp->supportsDesktopRename)
-      throw Exception("Client does not support desktop rename");
-    if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader)
-      throw Exception("SMsgWriter::setDesktopName: nRects out of sync");
-
-    os->writeS16(0);
-    os->writeS16(0);
-    os->writeU16(0);
-    os->writeU16(0);
-    os->writeU32(pseudoEncodingDesktopName);
-    os->writeString(cp->name());
-
+    writeSetDesktopNameRect(cp->name());
     needSetDesktopName = false;
   }
 }
@@ -467,31 +456,10 @@ void SMsgWriter::writeNoDataRects()
   // Start with specific ExtendedDesktopSize messages
   if (!extendedDesktopSizeMsgs.empty()) {
     std::list<ExtendedDesktopSizeMsg>::const_iterator ri;
-    ScreenSet::const_iterator si;
-
-    if (!cp->supportsExtendedDesktopSize)
-      throw Exception("Client does not support extended desktop resize");
-    if ((nRectsInUpdate += extendedDesktopSizeMsgs.size()) > nRectsInHeader && nRectsInHeader)
-      throw Exception("SMsgWriter::SetDesktopSize reply: nRects out of sync");
 
     for (ri = extendedDesktopSizeMsgs.begin();ri != extendedDesktopSizeMsgs.end();++ri) {
-      os->writeU16(ri->reason);
-      os->writeU16(ri->result);
-      os->writeU16(ri->fb_width);
-      os->writeU16(ri->fb_height);
-      os->writeU32(pseudoEncodingExtendedDesktopSize);
-
-      os->writeU8(ri->layout.num_screens());
-      os->pad(3);
-
-      for (si = ri->layout.begin();si != ri->layout.end();++si) {
-        os->writeU32(si->id);
-        os->writeU16(si->dimensions.tl.x);
-        os->writeU16(si->dimensions.tl.y);
-        os->writeU16(si->dimensions.width());
-        os->writeU16(si->dimensions.height());
-        os->writeU32(si->flags);
-      }
+      writeExtendedDesktopSizeRect(ri->reason, ri->result,
+                                   ri->fb_width, ri->fb_height, ri->layout);
     }
 
     extendedDesktopSizeMsgs.clear();
@@ -499,47 +467,76 @@ void SMsgWriter::writeNoDataRects()
 
   // Send this before SetDesktopSize to make life easier on the clients
   if (needExtendedDesktopSize) {
-    if (!cp->supportsExtendedDesktopSize)
-      throw Exception("Client does not support extended desktop resize");
-    if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader)
-      throw Exception("SMsgWriter::setExtendedDesktopSize: nRects out of sync");
-
-    os->writeU16(0);
-    os->writeU16(0);
-    os->writeU16(cp->width);
-    os->writeU16(cp->height);
-    os->writeU32(pseudoEncodingExtendedDesktopSize);
-
-    os->writeU8(cp->screenLayout.num_screens());
-    os->pad(3);
-
-    ScreenSet::const_iterator iter;
-    for (iter = cp->screenLayout.begin();iter != cp->screenLayout.end();++iter) {
-      os->writeU32(iter->id);
-      os->writeU16(iter->dimensions.tl.x);
-      os->writeU16(iter->dimensions.tl.y);
-      os->writeU16(iter->dimensions.width());
-      os->writeU16(iter->dimensions.height());
-      os->writeU32(iter->flags);
-    }
-
+    writeExtendedDesktopSizeRect(0, 0, cp->width, cp->height,
+                                 cp->screenLayout);
     needExtendedDesktopSize = false;
   }
 
   // Some clients assume this is the last rectangle so don't send anything
   // more after this
   if (needSetDesktopSize) {
-    if (!cp->supportsDesktopResize)
-      throw Exception("Client does not support desktop resize");
-    if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader)
-      throw Exception("SMsgWriter::setDesktopSize: nRects out of sync");
+    writeSetDesktopSizeRect(cp->width, cp->height);
+    needSetDesktopSize = false;
+  }
+}
 
-    os->writeS16(0);
-    os->writeS16(0);
-    os->writeU16(cp->width);
-    os->writeU16(cp->height);
-    os->writeU32(pseudoEncodingDesktopSize);
+void SMsgWriter::writeSetDesktopSizeRect(int width, int height)
+{
+  if (!cp->supportsDesktopResize)
+    throw Exception("Client does not support desktop resize");
+  if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader)
+    throw Exception("SMsgWriter::writeSetDesktopSizeRect: nRects out of sync");
 
-    needSetDesktopSize = false;
+  os->writeS16(0);
+  os->writeS16(0);
+  os->writeU16(width);
+  os->writeU16(height);
+  os->writeU32(pseudoEncodingDesktopSize);
+}
+
+void SMsgWriter::writeExtendedDesktopSizeRect(rdr::U16 reason,
+                                              rdr::U16 result,
+                                              int fb_width,
+                                              int fb_height,
+                                              const ScreenSet& layout)
+{
+  ScreenSet::const_iterator si;
+
+  if (!cp->supportsExtendedDesktopSize)
+    throw Exception("Client does not support extended desktop resize");
+  if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader)
+    throw Exception("SMsgWriter::writeExtendedDesktopSizeRect: nRects out of sync");
+
+  os->writeU16(reason);
+  os->writeU16(result);
+  os->writeU16(fb_width);
+  os->writeU16(fb_height);
+  os->writeU32(pseudoEncodingExtendedDesktopSize);
+
+  os->writeU8(layout.num_screens());
+  os->pad(3);
+
+  for (si = layout.begin();si != layout.end();++si) {
+    os->writeU32(si->id);
+    os->writeU16(si->dimensions.tl.x);
+    os->writeU16(si->dimensions.tl.y);
+    os->writeU16(si->dimensions.width());
+    os->writeU16(si->dimensions.height());
+    os->writeU32(si->flags);
   }
 }
+
+void SMsgWriter::writeSetDesktopNameRect(const char *name)
+{
+  if (!cp->supportsDesktopRename)
+    throw Exception("Client does not support desktop rename");
+  if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader)
+    throw Exception("SMsgWriter::writeSetDesktopNameRect: nRects out of sync");
+
+  os->writeS16(0);
+  os->writeS16(0);
+  os->writeU16(0);
+  os->writeU16(0);
+  os->writeU32(pseudoEncodingDesktopName);
+  os->writeString(name);
+}
index a39cc4f75a304c1f2ab87679b92aa0ed19b693ac..01141af342ce95b31057caa8c6a2b2ec1d886b36 100644 (file)
@@ -164,6 +164,12 @@ namespace rfb {
     void writePseudoRects();
     void writeNoDataRects();
 
+    void writeSetDesktopSizeRect(int width, int height);
+    void writeExtendedDesktopSizeRect(rdr::U16 reason, rdr::U16 result,
+                                      int fb_width, int fb_height,
+                                      const ScreenSet& layout);
+    void writeSetDesktopNameRect(const char *name);
+
     ConnParams* cp;
     rdr::OutStream* os;