From: Marcin Siodelski Date: Wed, 17 Apr 2019 12:56:47 +0000 (+0200) Subject: [#571,!306] Added factory functions to objects used in MySQL CB. X-Git-Tag: Kea-1.6.0-beta~230 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5a906b401a67ba9edd1af3ee135830e08f91f6e;p=thirdparty%2Fkea.git [#571,!306] Added factory functions to objects used in MySQL CB. --- diff --git a/src/lib/database/audit_entry.cc b/src/lib/database/audit_entry.cc index c4766487ee..b44c15ab62 100644 --- a/src/lib/database/audit_entry.cc +++ b/src/lib/database/audit_entry.cc @@ -6,6 +6,7 @@ #include #include +#include namespace isc { namespace db { @@ -37,6 +38,28 @@ AuditEntry::AuditEntry(const std::string& object_type, validate(); } +AuditEntryPtr +AuditEntry::create(const std::string& object_type, + const uint64_t object_id, + const ModificationType& modification_type, + const boost::posix_time::ptime& modification_time, + const std::string& log_message) { + return (boost::make_shared(object_type, object_id, + modification_type, + modification_time, + log_message)); +} + +AuditEntryPtr +AuditEntry::create(const std::string& object_type, + const uint64_t object_id, + const ModificationType& modification_type, + const std::string& log_message) { + return (boost::make_shared(object_type, object_id, + modification_type, + log_message)); +} + void AuditEntry::validate() const { // object type can't be empty diff --git a/src/lib/database/audit_entry.h b/src/lib/database/audit_entry.h index 70cc3dba54..47309cc946 100644 --- a/src/lib/database/audit_entry.h +++ b/src/lib/database/audit_entry.h @@ -19,6 +19,11 @@ namespace isc { namespace db { +class AuditEntry; + +/// @brief Pointer to the @c AuditEntry object. +typedef boost::shared_ptr AuditEntryPtr; + /// @brief Represents a single entry in the audit table. /// /// The audit tables are used in the databases to track incremental @@ -93,6 +98,46 @@ public: const ModificationType& modification_type, const std::string& log_message); + /// @brief Factory function creating an instance of @c AuditEntry. + /// + /// This function should be used to create an instance of the shared + /// network within a hooks library in cases when the library may be + /// unloaded before the object is destroyed. This ensures that the + /// ownership of the object by the Kea process is retained. + /// + /// @param object_type name of the table where data was modified. + /// @param object_id identifier of the modified record in this table. + /// @param modification_type type of the modification, e.g. DELETE. + /// @param modification_time time of modification for that record. + /// @param log_message optional log message associated with the + /// modification. + /// + /// @return Pointer to the @c AuditEntry instance. + static AuditEntryPtr create(const std::string& object_type, + const uint64_t object_id, + const ModificationType& modification_type, + const boost::posix_time::ptime& modification_time, + const std::string& log_message); + + /// @brief Factory function creating an instance of @c AuditEntry. + /// + /// This function should be used to create an instance of the shared + /// network within a hooks library in cases when the library may be + /// unloaded before the object is destroyed. This ensures that the + /// ownership of the object by the Kea process is retained. + /// + /// @param object_type name of the table where data was modified. + /// @param object_id identifier of the modified record in this table. + /// @param modification_type type of the modification, e.g. DELETE. + /// @param log_message optional log message associated with the + /// modification. + /// + /// @return Pointer to the @c AuditEntry instance. + static AuditEntryPtr create(const std::string& object_type, + const uint64_t object_id, + const ModificationType& modification_type, + const std::string& log_message); + /// @brief Returns object type. /// /// @return Name of the table in which the modification is present. @@ -152,9 +197,6 @@ private: std::string log_message_; }; -/// @brief Pointer to the @c AuditEntry object. -typedef boost::shared_ptr AuditEntryPtr; - /// @brief Tag used to access index by object type. struct AuditEntryObjectTypeTag { }; diff --git a/src/lib/database/tests/audit_entry_unittest.cc b/src/lib/database/tests/audit_entry_unittest.cc index 83dad417b9..a669949ab9 100644 --- a/src/lib/database/tests/audit_entry_unittest.cc +++ b/src/lib/database/tests/audit_entry_unittest.cc @@ -89,7 +89,7 @@ TEST_F(AuditEntryTest, create) { { SCOPED_TRACE("create with modification time"); - ASSERT_NO_THROW(audit_entry = boost::make_shared + ASSERT_NO_THROW(audit_entry = AuditEntry::create ("dhcp4_subnet", 10, AuditEntry::ModificationType::DELETE, fixedTime(), "deleted subnet 10")); EXPECT_EQ("dhcp4_subnet", audit_entry->getObjectType()); @@ -102,7 +102,7 @@ TEST_F(AuditEntryTest, create) { { SCOPED_TRACE("create with default modification time"); - ASSERT_NO_THROW(audit_entry = boost::make_shared + ASSERT_NO_THROW(audit_entry = AuditEntry::create ("dhcp4_option", 123, AuditEntry::ModificationType::CREATE, "")); EXPECT_EQ("dhcp4_option", audit_entry->getObjectType()); diff --git a/src/lib/dhcp/option.cc b/src/lib/dhcp/option.cc index 1fb18bfe46..c2485eb5ef 100644 --- a/src/lib/dhcp/option.cc +++ b/src/lib/dhcp/option.cc @@ -11,6 +11,8 @@ #include #include +#include + #include #include #include @@ -56,6 +58,16 @@ Option::Option(const Option& option) option.getOptionsCopy(options_); } +OptionPtr +Option::create(Universe u, uint16_t type) { + return (boost::make_shared