summaryrefslogtreecommitdiffstats
path: root/common/rfb/Decoder.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'common/rfb/Decoder.cxx')
-rw-r--r--common/rfb/Decoder.cxx58
1 files changed, 26 insertions, 32 deletions
diff --git a/common/rfb/Decoder.cxx b/common/rfb/Decoder.cxx
index 193b61c0..e201821f 100644
--- a/common/rfb/Decoder.cxx
+++ b/common/rfb/Decoder.cxx
@@ -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;
+ }
}