You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Configuration.h 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* Copyright (C) 2002-2004 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. // -=- Configuration.h
  19. //
  20. // This header defines a set of classes used to represent configuration
  21. // parameters of different types. Instances of the different parameter
  22. // types are associated with instances of the Configuration class, and
  23. // are each given a unique name. The Configuration class provides a
  24. // generic API through which parameters may be located by name and their
  25. // value set, thus removing the need to write platform-specific code.
  26. // Simply defining a new parameter and associating it with a Configuration
  27. // will allow it to be configured by the user.
  28. //
  29. // The Configuration class is used to allow multiple distinct configurations
  30. // to co-exist at the same time. A process serving several desktops, for
  31. // instance, can create a Configuration instance for each, to allow them
  32. // to be configured independently, from the command-line, registry, etc.
  33. #ifndef __RFB_CONFIGURATION_H__
  34. #define __RFB_CONFIGURATION_H__
  35. namespace rfb {
  36. class VoidParameter;
  37. // -=- Configuration
  38. // Class used to access parameters.
  39. class Configuration {
  40. public:
  41. // - Set named parameter to value
  42. static bool setParam(const char* param, const char* value, bool immutable=false);
  43. // - Set parameter to value (separated by "=")
  44. static bool setParam(const char* config, bool immutable=false);
  45. // - Set named parameter to value, with name truncated at len
  46. static bool setParam(const char* name, int len,
  47. const char* val, bool immutable);
  48. // - Get named parameter
  49. static VoidParameter* getParam(const char* param);
  50. static void listParams(int width=79, int nameWidth=10);
  51. static VoidParameter* head;
  52. };
  53. // -=- VoidParameter
  54. // Configuration parameter base-class.
  55. class VoidParameter {
  56. public:
  57. VoidParameter(const char* name_, const char* desc_);
  58. virtual ~VoidParameter();
  59. const char* getName() const;
  60. const char* getDescription() const;
  61. virtual bool setParam(const char* value) = 0;
  62. virtual bool setParam();
  63. virtual char* getDefaultStr() const = 0;
  64. virtual char* getValueStr() const = 0;
  65. virtual bool isBool() const;
  66. virtual void setImmutable();
  67. virtual void setHasBeenSet();
  68. bool hasBeenSet();
  69. VoidParameter* _next;
  70. protected:
  71. bool immutable;
  72. bool _hasBeenSet;
  73. const char* name;
  74. const char* description;
  75. };
  76. class AliasParameter : public VoidParameter {
  77. public:
  78. AliasParameter(const char* name_, const char* desc_,VoidParameter* param_);
  79. virtual bool setParam(const char* value);
  80. virtual bool setParam();
  81. virtual char* getDefaultStr() const;
  82. virtual char* getValueStr() const;
  83. virtual bool isBool() const;
  84. virtual void setImmutable();
  85. private:
  86. VoidParameter* param;
  87. };
  88. class BoolParameter : public VoidParameter {
  89. public:
  90. BoolParameter(const char* name_, const char* desc_, bool v);
  91. virtual bool setParam(const char* value);
  92. virtual bool setParam();
  93. virtual void setParam(bool b);
  94. virtual char* getDefaultStr() const;
  95. virtual char* getValueStr() const;
  96. virtual bool isBool() const;
  97. operator bool() const;
  98. protected:
  99. bool value;
  100. bool def_value;
  101. };
  102. class IntParameter : public VoidParameter {
  103. public:
  104. IntParameter(const char* name_, const char* desc_, int v);
  105. virtual bool setParam(const char* value);
  106. virtual bool setParam(int v);
  107. virtual char* getDefaultStr() const;
  108. virtual char* getValueStr() const;
  109. operator int() const;
  110. protected:
  111. int value;
  112. int def_value;
  113. };
  114. class StringParameter : public VoidParameter {
  115. public:
  116. // StringParameter contains a null-terminated string, which CANNOT
  117. // be Null, and so neither can the default value!
  118. StringParameter(const char* name_, const char* desc_, const char* v);
  119. virtual ~StringParameter();
  120. virtual bool setParam(const char* value);
  121. virtual char* getDefaultStr() const;
  122. virtual char* getValueStr() const;
  123. // getData() returns a copy of the data - it must be delete[]d by the
  124. // caller.
  125. char* getData() const { return getValueStr(); }
  126. protected:
  127. char* value;
  128. const char* def_value;
  129. };
  130. class BinaryParameter : public VoidParameter {
  131. public:
  132. BinaryParameter(const char* name_, const char* desc_, const void* v, int l);
  133. virtual ~BinaryParameter();
  134. virtual bool setParam(const char* value);
  135. virtual void setParam(const void* v, int l);
  136. virtual char* getDefaultStr() const;
  137. virtual char* getValueStr() const;
  138. void getData(void** data, int* length) const;
  139. protected:
  140. char* value;
  141. int length;
  142. char* def_value;
  143. int def_length;
  144. };
  145. };
  146. #endif // __RFB_CONFIGURATION_H__