Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DeviceManager.h « devices « include « audaspace « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 27a546630e8992287caaa3e9cb39e69a7de949ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*******************************************************************************
 * Copyright 2009-2016 Jörg Müller
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

#pragma once

/**
 * @file DeviceManager.h
 * @ingroup devices
 * The DeviceManager class.
 */

#include "Audaspace.h"

#include <memory>
#include <vector>
#include <unordered_map>

AUD_NAMESPACE_BEGIN

class IDevice;
class IDeviceFactory;
class I3DDevice;

/**
 * This class manages all device plugins and maintains a device if asked to do so.
 *
 * This enables applications to access their output device without having to carry
 * it through the whole application.
 */
class AUD_API DeviceManager
{
private:
	static std::unordered_map<std::string, std::shared_ptr<IDeviceFactory>> m_factories;

	static std::shared_ptr<IDevice> m_device;

	// delete copy constructor and operator=
	DeviceManager(const DeviceManager&) = delete;
	DeviceManager& operator=(const DeviceManager&) = delete;
	DeviceManager() = delete;

public:
	/**
	 * Registers a device factory.
	 *
	 * This method is mostly used by plugin developers to add their device implementation
	 * for general use by the library end users.
	 * @param name A representative name for the device.
	 * @param factory The factory that creates the device.
	 */
	static void registerDevice(std::string name, std::shared_ptr<IDeviceFactory> factory);

	/**
	 * Returns the factory for a specific device.
	 * @param name The representative name of the device.
	 * @return The factory if it was found, or nullptr otherwise.
	 */
	static std::shared_ptr<IDeviceFactory> getDeviceFactory(std::string name);

	/**
	 * Returns the default device based on the priorities of the registered factories.
	 * @return The default device or nullptr if no factory has been registered.
	 */
	static std::shared_ptr<IDeviceFactory> getDefaultDeviceFactory();


	/**
	 * Sets a device that should be handled by the manager.
	 *
	 * If a device is currently being handled it will be released.
	 * @param device The device the manager should take care of.
	 */
	static void setDevice(std::shared_ptr<IDevice> device);

	/**
	 * Opens a device which will then be handled by the manager.
	 *
	 * If a device is currently being handled it will be released.
	 * @param name The representative name of the device.
	 */
	static void openDevice(std::string name);

	/**
	 * Opens the default device which will then be handled by the manager.
	 *
	 * The device to open is selected based on the priority of the registered factories.
	 * If a device is currently being handled it will be released.
	 */
	static void openDefaultDevice();

	/**
	 * Releases the currently handled device.
	 */
	static void releaseDevice();

	/**
	 * Returns the currently handled device.
	 * @return The handled device or nullptr if no device has been registered.
	 */
	static std::shared_ptr<IDevice> getDevice();

	/**
	 * Returns the currently handled 3D device.
	 * @return The handled device or nullptr if no device has been registered
	 *         or the registered device is not an I3DDevice.
	 */
	static std::shared_ptr<I3DDevice> get3DDevice();

	/**
	 * Returns a list of available devices.
	 * @return A list of strings with the names of available devices.
	 */
	static std::vector<std::string> getAvailableDeviceNames();
};

AUD_NAMESPACE_END