driver_manager.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2010-2011 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // Distributed under:
  6. //
  7. // the Boost Software License, Version 1.0.
  8. // (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. // or (at your opinion) under:
  12. //
  13. // The MIT License
  14. // (See accompanying file MIT.txt or a copy at
  15. // http://www.opensource.org/licenses/mit-license.php)
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #ifndef CPPDB_DRIVER_MANAGER_H
  19. #define CPPDB_DRIVER_MANAGER_H
  20. #include <cppdb/defs.h>
  21. #include <cppdb/ref_ptr.h>
  22. #include <mutex>
  23. #include <map>
  24. #include <string>
  25. #include <vector>
  26. namespace cppdb {
  27. namespace backend {
  28. class connection;
  29. class driver;
  30. }
  31. class connection_info;
  32. ///
  33. /// \brief this class is used to handle all drivers, loading them, unloading them etc.
  34. ///
  35. /// All its member functions are thread safe
  36. ///
  37. class CPPDB_API driver_manager {
  38. public:
  39. ///
  40. /// Get the singleton instance of the class
  41. ///
  42. static driver_manager &instance();
  43. ///
  44. /// Install new driver \a drv named \a name to the manager.
  45. ///
  46. void install_driver(std::string const &name,ref_ptr<backend::driver> drv);
  47. ///
  48. /// Unload all drivers that have no more open connections.
  49. ///
  50. void collect_unused();
  51. ///
  52. /// Add a path were the driver should search for loadable modules
  53. ///
  54. void add_search_path(std::string const &);
  55. ///
  56. /// Clear previously added a paths
  57. ///
  58. void clear_search_paths();
  59. ///
  60. /// Search the library under default directory (i.e. empty path prefix) or not, default is true
  61. ///
  62. void use_default_search_path(bool v);
  63. ///
  64. /// Create a new connection object using parsed connection string \a ci
  65. ///
  66. backend::connection *connect(connection_info const &ci);
  67. ///
  68. /// Create a new connection object using connection string \a connectoin_string
  69. ///
  70. backend::connection *connect(std::string const &connectoin_string);
  71. private:
  72. driver_manager(driver_manager const &);
  73. void operator=(driver_manager const &);
  74. // Borland erros on hidden destructors in classes without only static methods.
  75. #ifndef __BORLANDC__
  76. ~driver_manager();
  77. #endif
  78. driver_manager();
  79. ref_ptr<backend::driver> load_driver(connection_info const &ci);
  80. typedef std::map<std::string,ref_ptr<backend::driver> > drivers_type;
  81. std::vector<std::string> search_paths_;
  82. bool no_default_directory_;
  83. drivers_type drivers_;
  84. std::mutex lock_;
  85. };
  86. }
  87. #endif