factory.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include "factory.h"
  15. #include "data_source.h"
  16. #include "database.h"
  17. #include "sqlite3_accessor.h"
  18. #include "memory_datasrc.h"
  19. namespace isc {
  20. namespace datasrc {
  21. boost::shared_ptr<DataSourceClient>
  22. createDataSourceClient(const std::string& type,
  23. const isc::dns::RRClass& rrclass,
  24. isc::data::ConstElementPtr config) {
  25. // For now, mapping hardcoded
  26. // config is assumed to be ok
  27. if (type == "sqlite3") {
  28. boost::shared_ptr<DatabaseAccessor> sqlite3_accessor(
  29. new SQLite3Accessor(config->get("dbfile")->stringValue(), rrclass));
  30. return boost::shared_ptr<DataSourceClient>(
  31. new DatabaseClient(rrclass, sqlite3_accessor));
  32. } else if (type == "memory") {
  33. return boost::shared_ptr<DataSourceClient>(new InMemoryClient());
  34. } else {
  35. isc_throw(DataSourceError, "Unknown datasource type: " << type);
  36. }
  37. }
  38. } // end namespace datasrc
  39. } // end namespace isc