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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. VoidParameter* _next;
  68. protected:
  69. bool immutable;
  70. const char* name;
  71. const char* description;
  72. };
  73. class AliasParameter : public VoidParameter {
  74. public:
  75. AliasParameter(const char* name_, const char* desc_,VoidParameter* param_);
  76. virtual bool setParam(const char* value);
  77. virtual bool setParam();
  78. virtual char* getDefaultStr() const;
  79. virtual char* getValueStr() const;
  80. virtual bool isBool() const;
  81. private:
  82. VoidParameter* param;
  83. };
  84. class BoolParameter : public VoidParameter {
  85. public:
  86. BoolParameter(const char* name_, const char* desc_, bool v);
  87. virtual bool setParam(const char* value);
  88. virtual bool setParam();
  89. virtual void setParam(bool b);
  90. virtual char* getDefaultStr() const;
  91. virtual char* getValueStr() const;
  92. virtual bool isBool() const;
  93. operator bool() const;
  94. protected:
  95. bool value;
  96. bool def_value;
  97. };
  98. class IntParameter : public VoidParameter {
  99. public:
  100. IntParameter(const char* name_, const char* desc_, int v);
  101. virtual bool setParam(const char* value);
  102. virtual bool setParam(int v);
  103. virtual char* getDefaultStr() const;
  104. virtual char* getValueStr() const;
  105. operator int() const;
  106. protected:
  107. int value;
  108. int def_value;
  109. };
  110. class StringParameter : public VoidParameter {
  111. public:
  112. // StringParameter contains a null-terminated string, which CANNOT
  113. // be Null, and so neither can the default value!
  114. StringParameter(const char* name_, const char* desc_, const char* v);
  115. virtual ~StringParameter();
  116. virtual bool setParam(const char* value);
  117. virtual char* getDefaultStr() const;
  118. virtual char* getValueStr() const;
  119. // getData() returns a copy of the data - it must be delete[]d by the
  120. // caller.
  121. char* getData() const { return getValueStr(); }
  122. protected:
  123. char* value;
  124. const char* def_value;
  125. };
  126. class BinaryParameter : public VoidParameter {
  127. public:
  128. BinaryParameter(const char* name_, const char* desc_, const void* v, int l);
  129. virtual ~BinaryParameter();
  130. virtual bool setParam(const char* value);
  131. virtual void setParam(const void* v, int l);
  132. virtual char* getDefaultStr() const;
  133. virtual char* getValueStr() const;
  134. void getData(void** data, int* length) const;
  135. protected:
  136. char* value;
  137. int length;
  138. char* def_value;
  139. int def_length;
  140. };
  141. };
  142. #endif // __RFB_CONFIGURATION_H__