]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1959] Use factory function to create option's instance.
authorMarcin Siodelski <marcin@isc.org>
Wed, 1 Aug 2012 16:08:05 +0000 (18:08 +0200)
committerMarcin Siodelski <marcin@isc.org>
Wed, 1 Aug 2012 16:08:05 +0000 (18:08 +0200)
src/lib/dhcp/option.h
tests/tools/perfdhcp/test_control.cc
tests/tools/perfdhcp/test_control.h

index 051b15dd4e23ba9bb2e340de40126d6e02833c47..37069d6df52e402670d1eceb20c0774bbfa2f98d 100644 (file)
@@ -82,6 +82,23 @@ public:
                              uint16_t type,
                              const OptionBuffer& buf);
 
+    /// @brief Factory function to create instance of option.
+    ///
+    /// Factory method creates instance of specified option. The option
+    /// to be created has to have corresponding factory function
+    /// registered with \ref LibDHCP::OptionFactoryRegister.
+    /// This method creates empty \ref OptionBuffer object. Use this
+    /// factory function if it is not needed to pass custom buffer.
+    ///
+    /// @param u universe of the option (V4 or V6)
+    /// @param type option-type
+    /// @throw isc::InvalidOperation if there is no factory function
+    /// registered for specified option type.
+    /// @return instance of option.
+    static OptionPtr factory(Option::Universe u, uint16_t type) {
+        return factory(u, type, OptionBuffer());
+    }
+
 
     /// @brief ctor, used for options constructed, usually during transmission
     ///
index 728d4d58ec4b31a7953c9407eee81475993d59a6..8072e75461f835898227a15e3c00ac5323915898 100644 (file)
@@ -58,14 +58,18 @@ TestControl::checkExitConditions() const {
     return(false);
 }
 
-Pkt4*
-TestControl::createDiscoverPkt4() {
+boost::shared_ptr<Pkt4>
+TestControl::createDiscoverPkt4() const {
     const uint32_t transid = static_cast<uint32_t>(random());
-    Pkt4* pkt4 = new Pkt4(DHCPDISCOVER, transid);
+    boost::shared_ptr<Pkt4> pkt4(new Pkt4(DHCPDISCOVER, transid));
+    if (!pkt4) {
+        isc_throw(isc::Unexpected, "failed to create DISCOVER packet");
+    }
 
-    OptionBuffer opt_request_list_buf();
-    // createRequestListBuffer4(opt_request_list_buf);
-    return NULL;
+    OptionPtr request_list_option =
+        Option::factory(Option::V4, DHO_DHCP_PARAMETER_REQUEST_LIST);
+    pkt4->addOption(request_list_option);
+    return pkt4;
 }
 
 OptionPtr
@@ -85,8 +89,7 @@ TestControl::factoryRequestList4(Option::Universe u,
 
     OptionBuffer buf_with_options(buf_array, buf_array + sizeof(buf_array));
     Option* opt = new Option(u, type, buf);
-    opt->setData(buf_with_options.begin(),
-                 buf_with_options.end());
+    opt->setData(buf_with_options.begin(), buf_with_options.end());
     return OptionPtr(opt);
 }
 
index b1d7d27d3247ce10fb0264c1dc8e3f72d36b671e..ce5aa4c4b6dda98a24334e6190052e8c42c9d57b 100644 (file)
@@ -69,7 +69,7 @@ private:
     /// \return true if any of the exit conditions is fulfiled.
     bool checkExitConditions() const;
 
-    dhcp::Pkt4* createDiscoverPkt4();
+    boost::shared_ptr<dhcp::Pkt4> createDiscoverPkt4() const;
 
     static dhcp::OptionPtr factoryRequestList4(dhcp::Option::Universe u,
                                                uint16_t type,