SystemConfiguration.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // SystemConfiguration.h
  3. //
  4. // Library: Util
  5. // Package: Configuration
  6. // Module: SystemConfiguration
  7. //
  8. // Definition of the SystemConfiguration class.
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef Util_SystemConfiguration_INCLUDED
  16. #define Util_SystemConfiguration_INCLUDED
  17. #include "Poco/Util/Util.h"
  18. #include "Poco/Util/AbstractConfiguration.h"
  19. namespace Poco {
  20. namespace Util {
  21. class Util_API SystemConfiguration: public AbstractConfiguration
  22. /// This class implements a Configuration interface to
  23. /// various system properties and environment variables.
  24. ///
  25. /// The following properties are supported:
  26. /// - system.osName: the operating system name
  27. /// - system.osVersion: the operating system version
  28. /// - system.osArchitecture: the operating system architecture
  29. /// - system.nodeName: the node (or host) name
  30. /// - system.nodeId: system ID, based on the Ethernet address (format "xxxxxxxxxxxx")
  31. /// of the first Ethernet adapter found on the system.
  32. /// - system.currentDir: the current working directory
  33. /// - system.homeDir: the user's home directory
  34. /// - system.configHomeDir: the base directory relative to which user specific configuration files should be stored
  35. /// - system.cacheHomeDir: the base directory relative to which user specific non-essential data files should be stored
  36. /// - system.dataHomeDir: the base directory relative to which user specific data files should be stored
  37. /// - system.tempHomeDir: the base directory relative to which user-specific temporary files and other file objects should be placed
  38. /// - system.tempDir: the system's temporary directory
  39. /// - system.configDir: the system's configuration directory
  40. /// - system.dateTime: the current UTC date and time, formatted in ISO 8601 format.
  41. /// - system.pid: the current process ID.
  42. /// - system.env.<NAME>: the environment variable with the given <NAME>.
  43. ///
  44. /// An attempt to set a system variable will result in an
  45. /// InvalidAccessException being thrown.
  46. ///
  47. /// Enumerating environment variables is not supported.
  48. /// An attempt to call keys("system.env") will return an empty range.
  49. ///
  50. /// Removing key is not supported. An attempt to remove a key results
  51. /// in a NotImplementedException being thrown.
  52. {
  53. public:
  54. SystemConfiguration();
  55. /// Creates the SystemConfiguration.
  56. protected:
  57. bool getRaw(const std::string& key, std::string& value) const;
  58. void setRaw(const std::string& key, const std::string& value);
  59. void enumerate(const std::string& key, Keys& range) const;
  60. void removeRaw(const std::string& key);
  61. ~SystemConfiguration();
  62. private:
  63. static bool getEnv(const std::string& name, std::string& value);
  64. static const std::string OSNAME;
  65. static const std::string OSVERSION;
  66. static const std::string OSARCHITECTURE;
  67. static const std::string NODENAME;
  68. static const std::string NODEID;
  69. static const std::string CURRENTDIR;
  70. static const std::string HOMEDIR;
  71. static const std::string CONFIGHOMEDIR;
  72. static const std::string CACHEHOMEDIR;
  73. static const std::string DATAHOMEDIR;
  74. static const std::string TEMPHOMEDIR;
  75. static const std::string TEMPDIR;
  76. static const std::string CONFIGDIR;
  77. static const std::string DATETIME;
  78. #if !defined(POCO_VXWORKS)
  79. static const std::string PID;
  80. #endif
  81. static const std::string ENV;
  82. };
  83. } } // namespace Poco::Util
  84. #endif // Util_SystemConfiguration_INCLUDED