Skip to content

Commit f269180

Browse files
author
Razvan Becheriu
committed
[#3536] addressed review comments
1 parent f7329af commit f269180

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/lib/dhcpsrv/lease_mgr_factory.cc

+9-6
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ LeaseMgrFactory::create(const std::string& dbaccess) {
7777
LeaseMgrFactory::registerFactory("postgresql", pgsql_factory, true);
7878
#endif
7979

80-
if (parameters[type] == string("memfile")) {
81-
LOG_INFO(dhcpsrv_logger, DHCPSRV_MEMFILE_DB).arg(redacted);
82-
getLeaseMgrPtr().reset(new Memfile_LeaseMgr(parameters));
83-
return;
84-
}
80+
// Factory method
81+
auto memfile_factory = [](const DatabaseConnection::ParameterMap& parameters) -> TrackingLeaseMgrPtr {
82+
LOG_INFO(dhcpsrv_logger, DHCPSRV_MEMFILE_DB)
83+
.arg(DatabaseConnection::redactedAccessString(parameters));
84+
return (TrackingLeaseMgrPtr(new Memfile_LeaseMgr(parameters)));
85+
};
86+
LeaseMgrFactory::registerFactory("memfile", memfile_factory, true);
8587

8688
string db_type = it->second;
8789
auto index = map_.find(db_type);
@@ -121,6 +123,7 @@ LeaseMgrFactory::destroy() {
121123
.arg(getLeaseMgrPtr()->getType());
122124
}
123125
getLeaseMgrPtr().reset();
126+
LeaseMgrFactory::deregisterFactory("memfile", true);
124127
// Code will be moved to appropriate hook library.
125128
#ifdef HAVE_MYSQL
126129
LeaseMgrFactory::deregisterFactory("mysql", true);
@@ -152,7 +155,7 @@ LeaseMgrFactory::recreate(const std::string& dbaccess, bool preserve_callbacks)
152155

153156
bool
154157
LeaseMgrFactory::haveInstance() {
155-
return (getLeaseMgrPtr().get());
158+
return (!!getLeaseMgrPtr());
156159
}
157160

158161
TrackingLeaseMgr&

0 commit comments

Comments
 (0)