DeviceManager.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*******************************************************************************
  2. * Copyright 2009-2016 Jörg Müller
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. ******************************************************************************/
  16. #pragma once
  17. /**
  18. * @file DeviceManager.h
  19. * @ingroup devices
  20. * The DeviceManager class.
  21. */
  22. #include "Audaspace.h"
  23. #include <memory>
  24. #include <vector>
  25. #include <unordered_map>
  26. AUD_NAMESPACE_BEGIN
  27. class IDevice;
  28. class IDeviceFactory;
  29. class I3DDevice;
  30. /**
  31. * This class manages all device plugins and maintains a device if asked to do so.
  32. *
  33. * This enables applications to access their output device without having to carry
  34. * it through the whole application.
  35. */
  36. class AUD_API DeviceManager
  37. {
  38. private:
  39. static std::unordered_map<std::string, std::shared_ptr<IDeviceFactory>> m_factories;
  40. static std::shared_ptr<IDevice> m_device;
  41. // delete copy constructor and operator=
  42. DeviceManager(const DeviceManager&) = delete;
  43. DeviceManager& operator=(const DeviceManager&) = delete;
  44. DeviceManager() = delete;
  45. public:
  46. /**
  47. * Registers a device factory.
  48. *
  49. * This method is mostly used by plugin developers to add their device implementation
  50. * for general use by the library end users.
  51. * @param name A representative name for the device.
  52. * @param factory The factory that creates the device.
  53. */
  54. static void registerDevice(std::string name, std::shared_ptr<IDeviceFactory> factory);
  55. /**
  56. * Returns the factory for a specific device.
  57. * @param name The representative name of the device.
  58. * @return The factory if it was found, or nullptr otherwise.
  59. */
  60. static std::shared_ptr<IDeviceFactory> getDeviceFactory(std::string name);
  61. /**
  62. * Returns the default device based on the priorities of the registered factories.
  63. * @return The default device or nullptr if no factory has been registered.
  64. */
  65. static std::shared_ptr<IDeviceFactory> getDefaultDeviceFactory();
  66. /**
  67. * Sets a device that should be handled by the manager.
  68. *
  69. * If a device is currently being handled it will be released.
  70. * @param device The device the manager should take care of.
  71. */
  72. static void setDevice(std::shared_ptr<IDevice> device);
  73. /**
  74. * Opens a device which will then be handled by the manager.
  75. *
  76. * If a device is currently being handled it will be released.
  77. * @param name The representative name of the device.
  78. */
  79. static void openDevice(std::string name);
  80. /**
  81. * Opens the default device which will then be handled by the manager.
  82. *
  83. * The device to open is selected based on the priority of the registered factories.
  84. * If a device is currently being handled it will be released.
  85. */
  86. static void openDefaultDevice();
  87. /**
  88. * Releases the currently handled device.
  89. */
  90. static void releaseDevice();
  91. /**
  92. * Returns the currently handled device.
  93. * @return The handled device or nullptr if no device has been registered.
  94. */
  95. static std::shared_ptr<IDevice> getDevice();
  96. /**
  97. * Returns the currently handled 3D device.
  98. * @return The handled device or nullptr if no device has been registered
  99. * or the registered device is not an I3DDevice.
  100. */
  101. static std::shared_ptr<I3DDevice> get3DDevice();
  102. /**
  103. * Returns a list of available devices.
  104. * @return A list of strings with the names of available devices.
  105. */
  106. static std::vector<std::string> getAvailableDeviceNames();
  107. };
  108. AUD_NAMESPACE_END