Browse Source

[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
tags/v1.0.90
Adam Tkac 14 years ago
parent
commit
c58b3d11f7

+ 42
- 16
common/rfb/Configuration.cxx View File

@@ -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 @@ using namespace rfb;
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 @@ void Configuration::list(int width, int nameWidth) {

// -=- 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 @@ VoidParameter::hasBeenSet() {
// -=- 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 @@ AliasParameter::setImmutable() {

// -=- 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 @@ BoolParameter::operator bool() const {
// -=- 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 @@ IntParameter::operator int() const {
// -=- 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 @@ char* StringParameter::getValueStr() const {

// -=- 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;

+ 37
- 8
common/rfb/Configuration.h View File

@@ -49,6 +49,8 @@ namespace rfb {
class VoidParameter;
struct ParameterIterator;

enum ConfigurationObject { ConfGlobal, ConfServer, ConfViewer };

// -=- Configuration
// Class used to access parameters.

@@ -98,6 +100,10 @@ namespace rfb {
// 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 @@ namespace rfb {
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 @@ namespace rfb {

// 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 @@ namespace rfb {

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 @@ namespace rfb {

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 @@ namespace rfb {

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 @@ namespace rfb {
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 @@ namespace rfb {
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 @@ namespace rfb {

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);

+ 2
- 0
unix/vncviewer/vncviewer.cxx View File

@@ -303,6 +303,8 @@ int main(int argc, char** argv)
char* vncServerName = 0;
Display* dpy = 0;

Configuration::enableViewerParams();

for (int i = 1; i < argc; i++) {
if (Configuration::setParam(argv[i]))
continue;

+ 2
- 0
unix/x0vncserver/x0vncserver.cxx View File

@@ -398,6 +398,8 @@ int main(int argc, char** argv)
programName = argv[0];
Display* dpy;

Configuration::enableServerParams();

for (int i = 1; i < argc; i++) {
if (Configuration::setParam(argv[i]))
continue;

+ 1
- 0
unix/xserver/hw/vnc/xf86vncModule.cc View File

@@ -83,6 +83,7 @@ static void vncExtensionInitWithParams(INITARGS)
{
rfb::initStdIOLoggers();
rfb::LogWriter::setLogParams("*:stderr:30");
rfb::Configuration::enableServerParams();

for (int scr = 0; scr < screenInfo.numScreens; scr++) {
ScrnInfoPtr pScrn = xf86Screens[scr];

+ 1
- 0
unix/xserver/hw/vnc/xvnc.cc View File

@@ -335,6 +335,7 @@ ddxProcessArgument(int argc, char *argv[], int i)
firstTime = FALSE;
rfb::initStdIOLoggers();
rfb::LogWriter::setLogParams("*:stderr:30");
rfb::Configuration::enableServerParams();
}

if (argv[i][0] == ':')

+ 1
- 1
win/vncviewer/vncviewer.cxx View File

@@ -106,7 +106,7 @@ programUsage() {
printf("\nLog destinations:\n");
Logger::listLoggers();
printf("\nParameters:\n");
Configuration::listParams();
Configuration::listParams(ConfViewer);
printf("Press Enter/Return key to continue\n");
getchar();
exit(1);

+ 1
- 1
win/winvnc/winvnc.cxx View File

@@ -81,7 +81,7 @@ static void programUsage() {
printf("\nLog destinations:\n");
Logger::listLoggers();
printf("\nAvailable configuration parameters:\n");
Configuration::listParams();
Configuration::listParams(ConfServer);
}

static void MsgBoxOrLog(const char* msg, bool isError=false) {

Loading…
Cancel
Save