[Development] Add possibility to define viewer/server specific parameters via
Configuration class. Change needed viewer/server code appropriately.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4032 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/common/rfb/Configuration.cxx b/common/rfb/Configuration.cxx
index 9ebc20a..6811a79 100644
--- a/common/rfb/Configuration.cxx
+++ b/common/rfb/Configuration.cxx
@@ -22,7 +22,6 @@
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
-#include <assert.h>
#ifdef WIN32
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
@@ -55,14 +54,28 @@
static LogWriter vlog("Config");
-// -=- The Global Configuration object
+// -=- The Global/server/viewer Configuration objects
Configuration* Configuration::global_ = 0;
+Configuration* Configuration::server_ = 0;
+Configuration* Configuration::viewer_ = 0;
+
Configuration* Configuration::global() {
if (!global_)
global_ = new Configuration("Global");
return global_;
}
+Configuration* Configuration::server() {
+ if (!server_)
+ server_ = new Configuration("Server");
+ return server_;
+}
+
+Configuration* Configuration::viewer() {
+ if (!viewer_)
+ viewer_ = new Configuration("Viewer");
+ return viewer_;
+}
// -=- Configuration implementation
@@ -196,10 +209,21 @@
// -=- VoidParameter
-VoidParameter::VoidParameter(const char* name_, const char* desc_, Configuration* conf)
- : immutable(false), _hasBeenSet(false), name(name_), description(desc_) {
- if (!conf)
- conf = Configuration::global();
+VoidParameter::VoidParameter(const char* name_, const char* desc_,
+ ConfigurationObject co)
+ : immutable(false), _hasBeenSet(false), name(name_), description(desc_)
+{
+ Configuration *conf = NULL;
+
+ switch (co) {
+ case ConfGlobal: conf = Configuration::global();
+ break;
+ case ConfServer: conf = Configuration::server();
+ break;
+ case ConfViewer: conf = Configuration::viewer();
+ break;
+ }
+
_next = conf->head;
conf->head = this;
}
@@ -244,8 +268,8 @@
// -=- AliasParameter
AliasParameter::AliasParameter(const char* name_, const char* desc_,
- VoidParameter* param_, Configuration* conf)
- : VoidParameter(name_, desc_, conf), param(param_) {
+ VoidParameter* param_, ConfigurationObject co)
+ : VoidParameter(name_, desc_, co), param(param_) {
}
bool
@@ -279,8 +303,9 @@
// -=- BoolParameter
-BoolParameter::BoolParameter(const char* name_, const char* desc_, bool v, Configuration* conf)
-: VoidParameter(name_, desc_, conf), value(v), def_value(v) {
+BoolParameter::BoolParameter(const char* name_, const char* desc_, bool v,
+ ConfigurationObject co)
+: VoidParameter(name_, desc_, co), value(v), def_value(v) {
}
bool
@@ -333,8 +358,8 @@
// -=- IntParameter
IntParameter::IntParameter(const char* name_, const char* desc_, int v,
- int minValue_, int maxValue_, Configuration* conf)
- : VoidParameter(name_, desc_, conf), value(v), def_value(v),
+ int minValue_, int maxValue_, ConfigurationObject co)
+ : VoidParameter(name_, desc_, co), value(v), def_value(v),
minValue(minValue_), maxValue(maxValue_)
{
}
@@ -380,8 +405,8 @@
// -=- StringParameter
StringParameter::StringParameter(const char* name_, const char* desc_,
- const char* v, Configuration* conf)
- : VoidParameter(name_, desc_, conf), value(strDup(v)), def_value(v)
+ const char* v, ConfigurationObject co)
+ : VoidParameter(name_, desc_, co), value(strDup(v)), def_value(v)
{
if (!v) {
fprintf(stderr,"Default value <null> for %s not allowed\n",name_);
@@ -415,8 +440,9 @@
// -=- BinaryParameter
-BinaryParameter::BinaryParameter(const char* name_, const char* desc_, const void* v, int l, Configuration* conf)
-: VoidParameter(name_, desc_, conf), value(0), length(0), def_value((char*)v), def_length(l) {
+BinaryParameter::BinaryParameter(const char* name_, const char* desc_,
+ const void* v, int l, ConfigurationObject co)
+: VoidParameter(name_, desc_, co), value(0), length(0), def_value((char*)v), def_length(l) {
if (l) {
value = new char[l];
length = l;
diff --git a/common/rfb/Configuration.h b/common/rfb/Configuration.h
index e3b85b8..3e21b18 100644
--- a/common/rfb/Configuration.h
+++ b/common/rfb/Configuration.h
@@ -49,6 +49,8 @@
class VoidParameter;
struct ParameterIterator;
+ enum ConfigurationObject { ConfGlobal, ConfServer, ConfViewer };
+
// -=- Configuration
// Class used to access parameters.
@@ -98,6 +100,10 @@
// global() is called when only the main thread is running.
static Configuration* global();
+ // Enable server/viewer specific parameters
+ static void enableServerParams() { global()->appendConfiguration(server()); }
+ static void enableViewerParams() { global()->appendConfiguration(viewer()); }
+
// - Container for process-wide Global parameters
static bool setParam(const char* param, const char* value, bool immutable=false) {
return global()->set(param, value, immutable);
@@ -110,9 +116,11 @@
return global()->set(name, len, val, immutable);
}
static VoidParameter* getParam(const char* param) { return global()->get(param); }
- static void listParams(int width=79, int nameWidth=10) { global()->list(width, nameWidth); }
+ static void listParams(int width=79, int nameWidth=10) {
+ global()->list(width, nameWidth);
+ }
- protected:
+ private:
friend class VoidParameter;
friend struct ParameterIterator;
@@ -127,6 +135,22 @@
// The process-wide, Global Configuration object
static Configuration* global_;
+
+ // The server only Configuration object
+ static Configuration* server_;
+
+ // The viewer only Configuration object
+ static Configuration* viewer_;
+
+ // Get server/viewer specific configuration object
+ static Configuration* server();
+ static Configuration* viewer();
+
+ // Append configuration object to this instance.
+ // NOTE: conf instance can be only one configuration object
+ void appendConfiguration(Configuration *conf) {
+ conf->_next = _next; _next = conf;
+ }
};
// -=- VoidParameter
@@ -134,7 +158,7 @@
class VoidParameter {
public:
- VoidParameter(const char* name_, const char* desc_, Configuration* conf=0);
+ VoidParameter(const char* name_, const char* desc_, ConfigurationObject co=ConfGlobal);
virtual ~VoidParameter();
const char* getName() const;
const char* getDescription() const;
@@ -162,7 +186,8 @@
class AliasParameter : public VoidParameter {
public:
- AliasParameter(const char* name_, const char* desc_,VoidParameter* param_, Configuration* conf=0);
+ AliasParameter(const char* name_, const char* desc_,VoidParameter* param_,
+ ConfigurationObject co=ConfGlobal);
virtual bool setParam(const char* value);
virtual bool setParam();
virtual char* getDefaultStr() const;
@@ -175,7 +200,8 @@
class BoolParameter : public VoidParameter {
public:
- BoolParameter(const char* name_, const char* desc_, bool v, Configuration* conf=0);
+ BoolParameter(const char* name_, const char* desc_, bool v,
+ ConfigurationObject co=ConfGlobal);
virtual bool setParam(const char* value);
virtual bool setParam();
virtual void setParam(bool b);
@@ -191,7 +217,8 @@
class IntParameter : public VoidParameter {
public:
IntParameter(const char* name_, const char* desc_, int v,
- int minValue=INT_MIN, int maxValue=INT_MAX, Configuration* conf=0);
+ int minValue=INT_MIN, int maxValue=INT_MAX,
+ ConfigurationObject co=ConfGlobal);
virtual bool setParam(const char* value);
virtual bool setParam(int v);
virtual char* getDefaultStr() const;
@@ -207,7 +234,8 @@
public:
// StringParameter contains a null-terminated string, which CANNOT
// be Null, and so neither can the default value!
- StringParameter(const char* name_, const char* desc_, const char* v, Configuration* conf=0);
+ StringParameter(const char* name_, const char* desc_, const char* v,
+ ConfigurationObject co=ConfGlobal);
virtual ~StringParameter();
virtual bool setParam(const char* value);
virtual char* getDefaultStr() const;
@@ -223,7 +251,8 @@
class BinaryParameter : public VoidParameter {
public:
- BinaryParameter(const char* name_, const char* desc_, const void* v, int l, Configuration* conf=0);
+ BinaryParameter(const char* name_, const char* desc_, const void* v, int l,
+ ConfigurationObject co=ConfGlobal);
virtual ~BinaryParameter();
virtual bool setParam(const char* value);
virtual void setParam(const void* v, int l);