]> source.dussan.org Git - tigervnc.git/commitdiff
Get rid of the register mechanism for encoders and decoders
authorPierre Ossman <ossman@cendio.se>
Wed, 15 Jan 2014 11:40:20 +0000 (12:40 +0100)
committerPierre Ossman <ossman@cendio.se>
Mon, 7 Jul 2014 11:27:08 +0000 (13:27 +0200)
We have no use for it, so let's keep things simple.

25 files changed:
common/rfb/CMsgWriter.cxx
common/rfb/Decoder.cxx
common/rfb/Decoder.h
common/rfb/Encoder.cxx
common/rfb/Encoder.h
common/rfb/HextileDecoder.cxx
common/rfb/HextileDecoder.h
common/rfb/HextileEncoder.cxx
common/rfb/HextileEncoder.h
common/rfb/RREDecoder.cxx
common/rfb/RREDecoder.h
common/rfb/RREEncoder.cxx
common/rfb/RREEncoder.h
common/rfb/RawDecoder.cxx
common/rfb/RawDecoder.h
common/rfb/RawEncoder.cxx
common/rfb/RawEncoder.h
common/rfb/TightDecoder.cxx
common/rfb/TightDecoder.h
common/rfb/TightEncoder.cxx
common/rfb/TightEncoder.h
common/rfb/ZRLEDecoder.cxx
common/rfb/ZRLEDecoder.h
common/rfb/ZRLEEncoder.cxx
common/rfb/ZRLEEncoder.h

index ddc25ff7e45b3e3ef7e84527502925eff2c17b9b..0ebd33e7b375e412d057eaa36a5502b2fb3a521f 100644 (file)
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <rdr/OutStream.h>
 #include <rfb/msgTypes.h>
+#include <rfb/encodings.h>
 #include <rfb/PixelFormat.h>
 #include <rfb/Rect.h>
 #include <rfb/ConnParams.h>
index 193b61c0149d0da1c5e0bbef0612b857bf8edfe5..e201821fcf456753a0207a5f71793034eaf996bf 100644 (file)
@@ -1,4 +1,5 @@
 /* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
+ * Copyright 2014 Pierre Ossman for Cendio AB
  * 
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -16,7 +17,7 @@
  * USA.
  */
 #include <stdio.h>
-#include <rfb/Exception.h>
+#include <rfb/encodings.h>
 #include <rfb/Decoder.h>
 #include <rfb/RawDecoder.h>
 #include <rfb/RREDecoder.h>
@@ -30,41 +31,34 @@ Decoder::~Decoder()
 {
 }
 
-DecoderCreateFnType Decoder::createFns[encodingMax+1] = { 0 };
-
 bool Decoder::supported(int encoding)
 {
-  return encoding >= 0 && encoding <= encodingMax && createFns[encoding];
+  switch (encoding) {
+  case encodingRaw:
+  case encodingRRE:
+  case encodingHextile:
+  case encodingZRLE:
+  case encodingTight:
+    return true;
+  default:
+    return false;
+  }
 }
 
 Decoder* Decoder::createDecoder(int encoding, CMsgReader* reader)
 {
-  if (supported(encoding))
-    return (*createFns[encoding])(reader);
-  return 0;
-}
-
-void Decoder::registerDecoder(int encoding,
-                              DecoderCreateFnType createFn)
-{
-  if (encoding > encodingMax)
-    throw Exception("Decoder::registerDecoder: encoding out of range");
-
-  if (createFns[encoding])
-    fprintf(stderr,"Replacing existing decoder for encoding %s (%d)\n",
-            encodingName(encoding), encoding);
-  createFns[encoding] = createFn;
-}
-
-int DecoderInit::count = 0;
-
-DecoderInit::DecoderInit()
-{
-  if (count++ != 0) return;
-
-  Decoder::registerDecoder(encodingRaw, RawDecoder::create);
-  Decoder::registerDecoder(encodingRRE, RREDecoder::create);
-  Decoder::registerDecoder(encodingHextile, HextileDecoder::create);
-  Decoder::registerDecoder(encodingZRLE, ZRLEDecoder::create);
-  Decoder::registerDecoder(encodingTight, TightDecoder::create);
+  switch (encoding) {
+  case encodingRaw:
+    return new RawDecoder(reader);
+  case encodingRRE:
+    return new RREDecoder(reader);
+  case encodingHextile:
+    return new HextileDecoder(reader);
+  case encodingZRLE:
+    return new ZRLEDecoder(reader);
+  case encodingTight:
+    return new TightDecoder(reader);
+  default:
+    return NULL;
+  }
 }
index 50aee82f89fa2937bd6bf2b58c6236e1eeb4947d..025d63f56a8dd292f30d83a04d69482d43874057 100644 (file)
@@ -1,4 +1,5 @@
 /* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
+ * Copyright 2014 Pierre Ossman for Cendio AB
  * 
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #define __RFB_DECODER_H__
 
 #include <rfb/Rect.h>
-#include <rfb/encodings.h>
 
 namespace rfb {
   class CMsgReader;
   class CMsgHandler;
-  class Decoder;
-  typedef Decoder* (*DecoderCreateFnType)(CMsgReader*);
 
   class Decoder {
   public:
@@ -34,19 +32,7 @@ namespace rfb {
 
     static bool supported(int encoding);
     static Decoder* createDecoder(int encoding, CMsgReader* reader);
-    static void registerDecoder(int encoding,
-                                DecoderCreateFnType createFn);
-  private:
-    static DecoderCreateFnType createFns[encodingMax+1];
   };
-
-  class DecoderInit {
-    static int count;
-  public:
-    DecoderInit();
-  };
-
-  static DecoderInit decoderInitObj;
 }
 
 #endif
index 5de75430af7645878025b243dda60531bb7e8cbd..1733c8ec8172ffbb44de008ddf711f93854f04fc 100644 (file)
@@ -1,4 +1,5 @@
 /* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
+ * Copyright 2014 Pierre Ossman for Cendio AB
  * 
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -16,6 +17,7 @@
  * USA.
  */
 #include <stdio.h>
+#include <rfb/encodings.h>
 #include <rfb/Exception.h>
 #include <rfb/Encoder.h>
 #include <rfb/RawEncoder.h>
@@ -30,48 +32,34 @@ Encoder::~Encoder()
 {
 }
 
-EncoderCreateFnType Encoder::createFns[encodingMax+1] = { 0 };
-
 bool Encoder::supported(int encoding)
 {
-  return encoding >= 0 && encoding <= encodingMax && createFns[encoding];
+  switch (encoding) {
+  case encodingRaw:
+  case encodingRRE:
+  case encodingHextile:
+  case encodingZRLE:
+  case encodingTight:
+    return true;
+  default:
+    return false;
+  }
 }
 
 Encoder* Encoder::createEncoder(int encoding, SMsgWriter* writer)
 {
-  if (supported(encoding))
-    return (*createFns[encoding])(writer);
-  return 0;
-}
-
-void Encoder::registerEncoder(int encoding,
-                              EncoderCreateFnType createFn)
-{
-  if (encoding > encodingMax)
-    throw Exception("Encoder::registerEncoder: encoding out of range");
-
-  if (createFns[encoding])
-    fprintf(stderr,"Replacing existing encoder for encoding %s (%d)\n",
-            encodingName(encoding), encoding);
-  createFns[encoding] = createFn;
-}
-
-void Encoder::unregisterEncoder(int encoding)
-{
-  if (encoding > encodingMax)
-    throw Exception("Encoder::unregisterEncoder: encoding out of range");
-  createFns[encoding] = 0;
-}
-
-int EncoderInit::count = 0;
-
-EncoderInit::EncoderInit()
-{
-  if (count++ != 0) return;
-
-  Encoder::registerEncoder(encodingRaw, RawEncoder::create);
-  Encoder::registerEncoder(encodingRRE, RREEncoder::create);
-  Encoder::registerEncoder(encodingHextile, HextileEncoder::create);
-  Encoder::registerEncoder(encodingZRLE, ZRLEEncoder::create);
-  Encoder::registerEncoder(encodingTight, TightEncoder::create);
+  switch (encoding) {
+  case encodingRaw:
+    return new RawEncoder(writer);
+  case encodingRRE:
+    return new RREEncoder(writer);
+  case encodingHextile:
+    return new HextileEncoder(writer);
+  case encodingZRLE:
+    return new ZRLEEncoder(writer);
+  case encodingTight:
+    return new TightEncoder(writer);
+  default:
+    return NULL;
+  }
 }
index 1a7935de19a20b5c0969f72c452ff4ee3dd6ebe2..882074d53e9bbf8fd7163487f9d0622857bbac4e 100644 (file)
@@ -1,5 +1,6 @@
 /* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
  * Copyright (C) 2011 D. R. Commander.  All Rights Reserved.
+ * Copyright 2014 Pierre Ossman for Cendio AB
  * 
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #define __RFB_ENCODER_H__
 
 #include <rfb/Rect.h>
-#include <rfb/encodings.h>
+#include <rfb/TransImageGetter.h>
 #include <rfb/JpegCompressor.h>
 
 namespace rfb {
   class SMsgWriter;
-  class Encoder;
   class TransImageGetter;
-  typedef Encoder* (*EncoderCreateFnType)(SMsgWriter*);
 
   class Encoder {
   public:
@@ -46,20 +45,7 @@ namespace rfb {
 
     static bool supported(int encoding);
     static Encoder* createEncoder(int encoding, SMsgWriter* writer);
-    static void registerEncoder(int encoding,
-                                EncoderCreateFnType createFn);
-    static void unregisterEncoder(int encoding);
-  private:
-    static EncoderCreateFnType createFns[encodingMax+1];
   };
-
-  class EncoderInit {
-    static int count;
-  public:
-    EncoderInit();
-  };
-
-  static EncoderInit encoderInitObj;
 }
 
 #endif
index e817c73267129354bb535e40ee0252a19038ce93..ae612676224cd867979cd5c6b786f85ed38ed9b9 100644 (file)
@@ -34,11 +34,6 @@ using namespace rfb;
 #include <rfb/hextileDecode.h>
 #undef BPP
 
-Decoder* HextileDecoder::create(CMsgReader* reader)
-{
-  return new HextileDecoder(reader);
-}
-
 HextileDecoder::HextileDecoder(CMsgReader* reader_) : reader(reader_)
 {
 }
index e7dd3d58af5553e7bfc363b75e72288e11040cd9..95a7f8a4a205f8d08cfddabeb01b28fec638cf9a 100644 (file)
@@ -24,11 +24,10 @@ namespace rfb {
 
   class HextileDecoder : public Decoder {
   public:
-    static Decoder* create(CMsgReader* reader);
-    virtual void readRect(const Rect& r, CMsgHandler* handler);
+    HextileDecoder(CMsgReader* reader);
     virtual ~HextileDecoder();
+    virtual void readRect(const Rect& r, CMsgHandler* handler);
   private:
-    HextileDecoder(CMsgReader* reader);
     CMsgReader* reader;
   };
 }
index 60833bdf6bb4b7eccda624518670121c763707db..0907bab8c4fddf4b420545dd3098cfb12fd2436c 100644 (file)
@@ -45,11 +45,6 @@ BoolParameter improvedHextile("ImprovedHextile",
 #include <rfb/hextileEncodeBetter.h>
 #undef BPP
 
-Encoder* HextileEncoder::create(SMsgWriter* writer)
-{
-  return new HextileEncoder(writer);
-}
-
 HextileEncoder::HextileEncoder(SMsgWriter* writer_) : writer(writer_)
 {
 }
index 6b89643dd969b01c37e2a3f3f352b6705e13b332..0c475a8e6e7868e99ab8b4274a50c1eec00488e6 100644 (file)
@@ -24,11 +24,10 @@ namespace rfb {
 
   class HextileEncoder : public Encoder {
   public:
-    static Encoder* create(SMsgWriter* writer);
-    virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
+    HextileEncoder(SMsgWriter* writer);
     virtual ~HextileEncoder();
+    virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
   private:
-    HextileEncoder(SMsgWriter* writer);
     SMsgWriter* writer;
   };
 }
index da56ee7c61f583832e372184a101ae7849aa1448..b81a4a8205c90a0c82cf381c4acc63556e059ce9 100644 (file)
@@ -34,11 +34,6 @@ using namespace rfb;
 #include <rfb/rreDecode.h>
 #undef BPP
 
-Decoder* RREDecoder::create(CMsgReader* reader)
-{
-  return new RREDecoder(reader);
-}
-
 RREDecoder::RREDecoder(CMsgReader* reader_) : reader(reader_)
 {
 }
index 2309f7540e96e86edc57bec60b44bab91d472d28..98abf98201ecfcd2040c1e437802fa37e9490f25 100644 (file)
@@ -24,11 +24,10 @@ namespace rfb {
 
   class RREDecoder : public Decoder {
   public:
-    static Decoder* create(CMsgReader* reader);
-    virtual void readRect(const Rect& r, CMsgHandler* handler);
+    RREDecoder(CMsgReader* reader);
     virtual ~RREDecoder();
+    virtual void readRect(const Rect& r, CMsgHandler* handler);
   private:
-    RREDecoder(CMsgReader* reader);
     CMsgReader* reader;
   };
 }
index 0bb2c7f9766f3637bfff6408abe8e04710e1702c..36d4695514003ad8cf1a92d89b06bede51d79720 100644 (file)
@@ -33,11 +33,6 @@ using namespace rfb;
 #include <rfb/rreEncode.h>
 #undef BPP
 
-Encoder* RREEncoder::create(SMsgWriter* writer)
-{
-  return new RREEncoder(writer);
-}
-
 RREEncoder::RREEncoder(SMsgWriter* writer_) : writer(writer_)
 {
 }
index 6178d57f49b774f0113f7b8b111d808757725d61..f7d576ebcd759b45961a49a1e800e5a5d15fde89 100644 (file)
@@ -25,11 +25,10 @@ namespace rfb {
 
   class RREEncoder : public Encoder {
   public:
-    static Encoder* create(SMsgWriter* writer);
-    virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
+    RREEncoder(SMsgWriter* writer);
     virtual ~RREEncoder();
+    virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
   private:
-    RREEncoder(SMsgWriter* writer);
     SMsgWriter* writer;
     rdr::MemOutStream mos;
   };
index 57cb37bcac283f887bb7d9e2467daac3789cb314..5fd3b7c1be2cd3cf448c545cd7f363ee2fc58801 100644 (file)
 
 using namespace rfb;
 
-Decoder* RawDecoder::create(CMsgReader* reader)
-{
-  return new RawDecoder(reader);
-}
-
 RawDecoder::RawDecoder(CMsgReader* reader_) : reader(reader_)
 {
 }
index 9fdbb22015a35f0f1a343a74161c7220f005ee35..e09cca2d4272edf676147c4bee15a0dcf72f25d0 100644 (file)
@@ -24,11 +24,10 @@ namespace rfb {
 
   class RawDecoder : public Decoder {
   public:
-    static Decoder* create(CMsgReader* reader);
-    virtual void readRect(const Rect& r, CMsgHandler* handler);
+    RawDecoder(CMsgReader* reader);
     virtual ~RawDecoder();
+    virtual void readRect(const Rect& r, CMsgHandler* handler);
   private:
-    RawDecoder(CMsgReader* reader);
     CMsgReader* reader;
   };
 }
index 81eea8b513b38e9695797487f738ae8cdfae767a..4b8de6ba2ce255ace2f96855a84a1f9d245f2449 100644 (file)
 
 using namespace rfb;
 
-Encoder* RawEncoder::create(SMsgWriter* writer)
-{
-  return new RawEncoder(writer);
-}
-
 RawEncoder::RawEncoder(SMsgWriter* writer_) : writer(writer_)
 {
 }
index 34dba0b56a8922189f4ae5befb2d92770e32ac8f..22d45dbf1a3078e5980c529bb574363c2ba7dd39 100644 (file)
@@ -24,11 +24,10 @@ namespace rfb {
 
   class RawEncoder : public Encoder {
   public:
-    static Encoder* create(SMsgWriter* writer);
-    virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
+    RawEncoder(SMsgWriter* writer);
     virtual ~RawEncoder();
+    virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
   private:
-    RawEncoder(SMsgWriter* writer);
     SMsgWriter* writer;
   };
 }
index b3d174a371250e814af6a67d1f7a86d11f46acb8..d4ee877f5fdeb6bd41842e6f783d07b6dba0fd6d 100644 (file)
@@ -37,11 +37,6 @@ using namespace rfb;
 #include <rfb/tightDecode.h>
 #undef BPP
 
-Decoder* TightDecoder::create(CMsgReader* reader)
-{
-  return new TightDecoder(reader);
-}
-
 TightDecoder::TightDecoder(CMsgReader* reader_) : reader(reader_)
 {
 }
index 5cdf873b7cf45340f5b0d8507242a30b4a40a941..8200d2b8d6ff7fbe36d3c56e8dab7c14f6d47bd0 100644 (file)
@@ -28,9 +28,9 @@ namespace rfb {
   class TightDecoder : public Decoder {
 
   public:
-    static Decoder* create(CMsgReader* reader);
-    virtual void readRect(const Rect& r, CMsgHandler* handler);
+    TightDecoder(CMsgReader* reader);
     virtual ~TightDecoder();
+    virtual void readRect(const Rect& r, CMsgHandler* handler);
 
   private:
     void tightDecode8(const Rect& r);
@@ -54,8 +54,6 @@ namespace rfb {
     void directFillRect16(const Rect& r, Pixel pix);
     void directFillRect32(const Rect& r, Pixel pix);
 
-    TightDecoder(CMsgReader* reader);
-
     CMsgReader* reader;
     CMsgHandler* handler;
     rdr::InStream* is;
index e9568f8cf0a4967377602e34ae51a1f016fbaeba..61a1c5904b3dba9c06d530dc4e1aa302abb0a38f 100644 (file)
@@ -92,11 +92,6 @@ const int TightEncoder::defaultCompressLevel = 2;
 #include <rfb/tightEncode.h>
 #undef BPP
 
-Encoder* TightEncoder::create(SMsgWriter* writer)
-{
-  return new TightEncoder(writer);
-} 
-
 TightEncoder::TightEncoder(SMsgWriter* writer_) : writer(writer_)
 {
   setCompressLevel(defaultCompressLevel);
index 465d8ed680d406aea5daf745af39aaaa79be7c96..5faef4441eb90b25543f6c4ad4dbcd47f513e266 100644 (file)
@@ -78,16 +78,16 @@ namespace rfb {
   
   class TightEncoder : public Encoder {
   public:
-    static Encoder* create(SMsgWriter* writer);
+    TightEncoder(SMsgWriter* writer);
+    virtual ~TightEncoder();
+
     virtual void setCompressLevel(int level);
     virtual void setQualityLevel(int level);
     virtual void setFineQualityLevel(int quality, JPEG_SUBSAMP subsampling);
     virtual int getNumRects(const Rect &r);
     virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
-    virtual ~TightEncoder();
 
   private:
-    TightEncoder(SMsgWriter* writer);
     bool checkSolidTile(Rect& r, rdr::U32* colorPtr, bool needSameColor);
     void extendSolidArea(const Rect& r, rdr::U32 colorValue, Rect& er);
     void findBestSolidArea(Rect& r, rdr::U32 colorValue, Rect& bestr);
index aba7fc9fd6ebe4f723df9c08c167c63afaee99b3..111e2de6c111304c955efd4d74ea1516c7a6a430 100644 (file)
@@ -40,11 +40,6 @@ using namespace rfb;
 #undef CPIXEL
 #undef BPP
 
-Decoder* ZRLEDecoder::create(CMsgReader* reader)
-{
-  return new ZRLEDecoder(reader);
-}
-
 ZRLEDecoder::ZRLEDecoder(CMsgReader* reader_) : reader(reader_)
 {
 }
index fe96c73768d647cec5b8535fa7406366582b2122..2128ab91a2b26e6e72657b1e9cb79c86932fec85 100644 (file)
@@ -25,11 +25,10 @@ namespace rfb {
 
   class ZRLEDecoder : public Decoder {
   public:
-    static Decoder* create(CMsgReader* reader);
-    virtual void readRect(const Rect& r, CMsgHandler* handler);
+    ZRLEDecoder(CMsgReader* reader);
     virtual ~ZRLEDecoder();
+    virtual void readRect(const Rect& r, CMsgHandler* handler);
   private:
-    ZRLEDecoder(CMsgReader* reader);
     CMsgReader* reader;
     rdr::ZlibInStream zis;
   };
index 5ef54d26c0e86dd7adb064589fcc4fddf27eb549..e70706b57ba22230a46a941902ceb90cbc3c54e4 100644 (file)
@@ -46,11 +46,6 @@ IntParameter zlibLevel("ZlibLevel","Zlib compression level",-1);
 #undef CPIXEL
 #undef BPP
 
-Encoder* ZRLEEncoder::create(SMsgWriter* writer)
-{
-  return new ZRLEEncoder(writer);
-}
-
 ZRLEEncoder::ZRLEEncoder(SMsgWriter* writer_)
   : writer(writer_), zos(0,0,zlibLevel), mos(129*1024)
 {
index 61ff6fb02113d23cda9e1785596deeadad56d2dc..e3517c135f3d823e1affec818429cff2ec7df591 100644 (file)
@@ -26,12 +26,10 @@ namespace rfb {
 
   class ZRLEEncoder : public Encoder {
   public:
-    static Encoder* create(SMsgWriter* writer);
-    virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
+    ZRLEEncoder(SMsgWriter* writer);
     virtual ~ZRLEEncoder();
-
+    virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
   private:
-    ZRLEEncoder(SMsgWriter* writer);
     SMsgWriter* writer;
     rdr::ZlibOutStream zos;
     rdr::MemOutStream mos;