Async  1.3.1
AsyncAudioDeviceFactory.h
Go to the documentation of this file.
1 
28 #ifndef ASYNC_AUDIO_DEVICE_FACTORY_INCLUDED
29 #define ASYNC_AUDIO_DEVICE_FACTORY_INCLUDED
30 
31 
32 /****************************************************************************
33  *
34  * System Includes
35  *
36  ****************************************************************************/
37 
38 #include <string>
39 #include <map>
40 
41 
42 /****************************************************************************
43  *
44  * Project Includes
45  *
46  ****************************************************************************/
47 
48 
49 
50 /****************************************************************************
51  *
52  * Local Includes
53  *
54  ****************************************************************************/
55 
56 
57 
58 /****************************************************************************
59  *
60  * Forward declarations
61  *
62  ****************************************************************************/
63 
64 
65 
66 /****************************************************************************
67  *
68  * Namespace
69  *
70  ****************************************************************************/
71 
72 namespace Async
73 {
74 
75 
76 /****************************************************************************
77  *
78  * Forward declarations of classes inside of the declared namespace
79  *
80  ****************************************************************************/
81 
82 class AudioDevice;
83 
84 
85 /****************************************************************************
86  *
87  * Defines & typedefs
88  *
89  ****************************************************************************/
90 
96 #define REGISTER_AUDIO_DEVICE_TYPE(_name, _class) \
97  AudioDevice *create_ ## _class(const string& dev_name) \
98  { return new _class(dev_name); } \
99  static bool _class ## _creator_registered = \
100  AudioDeviceFactory::instance()->registerCreator(_name, \
101  create_ ## _class)
102 
103 
104 
105 /****************************************************************************
106  *
107  * Exported Global Variables
108  *
109  ****************************************************************************/
110 
111 
112 
113 /****************************************************************************
114  *
115  * Class definitions
116  *
117  ****************************************************************************/
118 
129 {
130  public:
131  typedef AudioDevice* (*CreatorFunc)(const std::string &dev_designator);
132 
138  {
139  if (_instance == 0)
140  {
141  _instance = new AudioDeviceFactory;
142  }
143  return _instance;
144  }
145 
149  ~AudioDeviceFactory(void);
150 
157  bool registerCreator(const std::string &name, CreatorFunc creator);
158 
165  AudioDevice *create(const std::string &name, const std::string &dev_name);
166 
171  std::string validDevTypes(void) const;
172 
173  protected:
177  AudioDeviceFactory(void);
178 
179 
180  private:
181  typedef std::map<std::string, CreatorFunc> CreatorMap;
182 
183  static AudioDeviceFactory *_instance;
184 
185  CreatorMap creator_map;
186 
188  AudioDeviceFactory& operator=(const AudioDeviceFactory&);
189 
190 }; /* class AudioDeviceFactory */
191 
192 
193 } /* namespace */
194 
195 #endif /* ASYNC_AUDIO_DEVICE_FACTORY_INCLUDED */
196 
197 
198 
199 /*
200  * This file has not been truncated
201  */
202 
~AudioDeviceFactory(void)
Destructor.
AudioDevice * create(const std::string &name, const std::string &dev_name)
Create a new instance of the specified audio device type.
bool registerCreator(const std::string &name, CreatorFunc creator)
Register a new audio device type.
AudioDevice *(* CreatorFunc)(const std::string &dev_designator)
Base class for handling audio devices.
std::string validDevTypes(void) const
List valid device types.
A factory class for audio devices.
static AudioDeviceFactory * instance(void)
Get the factory singleton instance.
Namespace for the asynchronous programming classes.
AudioDeviceFactory(void)
Default constuctor.