cfg_db_access.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #ifndef CFG_DBACCESS_H
  7. #define CFG_DBACCESS_H
  8. #include <boost/shared_ptr.hpp>
  9. #include <string>
  10. namespace isc {
  11. namespace dhcp {
  12. /// @brief Holds access parameters and the configuration of the
  13. /// lease and hosts database connection.
  14. ///
  15. /// The database access strings use the same format as the strings
  16. /// passed to the @ref isc::dhcp::LeaseMgrFactory::create function.
  17. class CfgDbAccess {
  18. public:
  19. /// @brief Constructor.
  20. CfgDbAccess();
  21. /// @brief Sets parameters which will be appended to the database
  22. /// access strings.
  23. ///
  24. /// @param appended_parameters String holding collection of parameters
  25. /// in the following format: "parameter0=value0 parameter1=value1 ...".
  26. void setAppendedParameters(const std::string& appended_parameters) {
  27. appended_parameters_ = appended_parameters;
  28. }
  29. /// @brief Retrieves lease database access string.
  30. ///
  31. /// @return Lease database access string with additional parameters
  32. /// specified with @ref CfgDbAccess::setAppendedParameters.
  33. std::string getLeaseDbAccessString() const;
  34. /// @brief Sets lease database access string.
  35. ///
  36. /// @param lease_db_access New lease database access string.
  37. void setLeaseDbAccessString(const std::string& lease_db_access) {
  38. lease_db_access_ = lease_db_access;
  39. }
  40. /// @brief Retrieves host database access string.
  41. ///
  42. /// @return Host database access string with additional parameters
  43. /// specified with @ref CfgDbAccess::setAppendedParameters.
  44. std::string getHostDbAccessString() const;
  45. /// @brief Sets host database access string.
  46. ///
  47. /// @param host_db_access New host database access string.
  48. void setHostDbAccessString(const std::string& host_db_access) {
  49. host_db_access_ = host_db_access;
  50. }
  51. /// @brief Creates instance of lease manager and host data source
  52. /// according to the configuration specified.
  53. void createManagers() const;
  54. private:
  55. /// @brief Returns lease or host database access string.
  56. ///
  57. /// @param Access string without additional (appended) parameters.
  58. std::string getAccessString(const std::string& access_string) const;
  59. /// @brief Parameters to be appended to the database access
  60. /// strings.
  61. std::string appended_parameters_;
  62. /// @brief Holds lease database access string.
  63. std::string lease_db_access_;
  64. /// @brief Holds host database access string.
  65. std::string host_db_access_;
  66. };
  67. /// @brief A pointer to the @c CfgDbAccess.
  68. typedef boost::shared_ptr<CfgDbAccess> CfgDbAccessPtr;
  69. /// @brief A pointer to the const @c CfgDbAccess.
  70. typedef boost::shared_ptr<const CfgDbAccess> ConstCfgDbAccessPtr;
  71. }
  72. }
  73. #endif // CFG_DBACCESS_H