audioApi.h
Go to the documentation of this file.
1 
3 #pragma once
4 
8 #include <boost/function.hpp>
9 #include <boost/system/error_code.hpp>
10 #include <boost/shared_ptr.hpp>
11 #include <vector>
12 #include <list>
13 
14 #include "iAudioTask.h"
15 #include "audioConfig.h"
16 
17 class AudioClient;
18 
19 #ifndef AUDIO_TYPES
20 #define AUDIO_TYPES
21 
27 namespace dpyAudio {
28 
34 
35 public:
40  virtual void updateAvailability(const bool &available) = 0;
41 
46  {
47  }
48 };
49 
55 typedef boost::function<void(boost::system::error_code&, std::list<dpyAudio::Port> portList)> port_list_handler_function;
56 
62 typedef boost::function<void(boost::system::error_code&, std::list<dpyAudio::AudioConfig> configurations)> audio_configuration_handler_function;
63 
69 typedef boost::function<void(boost::system::error_code&, std::list<dpyAudio::Connection> ConnectionList)> connection_list_handler_function;
70 
76 typedef boost::function<void(boost::system::error_code&, dpyAudio::Port& port)> port_handler_function;
77 
83 typedef boost::function<void(boost::system::error_code&, dpyAudio::Connection connection)> connection_handler_function;
84 
89 typedef boost::function<void(const boost::system::error_code&)> result_handler_function;
90 
98 typedef boost::function<void(boost::system::error_code error_code, ConnectionListEventType type, Connection con)> connection_list_event_handler_function;
99 
107 typedef boost::function<void(boost::system::error_code error_code, ConnectionStatusEventType type, Connection con)> connection_status_event_handler_function;
108 
116 typedef boost::function<void(boost::system::error_code error_code, PortEventType type, dpyAudio::Port port)> port_event_handler_function;
117 
125 typedef boost::function<void(boost::system::error_code error_code, int taskId, dpyAudio::TaskType type, dpyAudio::AudioTaskStatus status)> task_event_handler_function;
126 
134 typedef boost::function<void(boost::system::error_code error_code, PortGpioEventType type, dpyAudio::PortGpio port_gpio)> port_gpio_event_handler_function;
135 
141 typedef boost::function<void(boost::system::error_code, int ID)> audio_task_handler_function;
142 
148 typedef boost::function<void(boost::system::error_code, int ID)> stop_task_handler;
149 
157 typedef boost::function<void(boost::system::error_code ec, int taskId, dpyAudio::TaskType taskType, dpyAudio::AudioTaskStatus taskStatus)> audio_task_status_handler_function;
158 
164 typedef boost::function<void(boost::system::error_code ec, std::list<std::pair<int, dpyAudio::AudioTaskInformation>> taskinfolist)> all_audio_task_info_handler_function;
165 
166 
172 typedef boost::function<void(boost::system::error_code&)> audio_set_configuration_handler_function;
173 
180 typedef boost::function<void(boost::system::error_code&, dpyAudio::Connection connection, unsigned int volume)> set_connection_volume_handler_function;
181 
188 typedef boost::function<void(boost::system::error_code&, dpyAudio::Connection connection, unsigned int gain)> set_connection_gain_handler_function;
189 
195 typedef boost::function<void(boost::system::error_code& ec, std::list<dpyAudio::PortGpio> portgpiolist)> get_port_gpio_handler_function;
196 
202 typedef boost::function<void(boost::system::error_code& ec, std::list<dpyAudio::PortMicBias> portmiclist)> get_mic_bias_handler_function;
203 
204 }//dpyAudio
205 
206 
207 #endif
208 
209 
215 class Audio
216 {
217 
218 private:
219  boost::shared_ptr<AudioClient> mClient;
220  std::vector<dpyAudio::ServiceAvailabilityObserver*> mAvailObserverList;
221 public:
222 
223  explicit Audio(std::string ip = "127.0.0.1");
224  ~Audio();
225 
226 
227  bool isAlive();
228  boost::system::error_code monitorServiceAvailability_S(dpyAudio::ServiceAvailabilityObserver* observer);
229  boost::system::error_code monitorServiceAvailability_U(dpyAudio::ServiceAvailabilityObserver* observer);
230 
234  void asyncGetPortList(dpyAudio::port_list_handler_function handler);
236  void asyncGetConnectionList(dpyAudio::connection_list_handler_function handler);
237  void asyncCreatePort(const dpyAudio::Port& port, dpyAudio::port_handler_function handler);
238  void asyncRemovePort(const dpyAudio::Port& port, dpyAudio::port_handler_function handler);
240 
241  void asyncCreateConnection(const dpyAudio::Connection& connection, dpyAudio::connection_handler_function handler);
242  void asyncRemoveConnection(const dpyAudio::Connection& connection, dpyAudio::connection_handler_function handler);
243  void asyncPlay(const dpyAudio::Port& port, std::string audioFilePath, std::list<dpyAudio::AudioConfig> configurations, dpyAudio::audio_task_handler_function handler);
244  void asyncRecord(const dpyAudio::Port& port, std::string outputAudioFile, std::list<dpyAudio::AudioConfig> configurations, dpyAudio::audio_task_handler_function handler);
245  void asyncStop(const int recordId,dpyAudio::stop_task_handler handler);
246  void getTaskStatus(int taskId, dpyAudio::audio_task_status_handler_function handler);
247  void asyncGetAllTaskInfo(dpyAudio::all_audio_task_info_handler_function handler);
248 
249  void asyncSetAudioConfiguration(dpyAudio::AudioConfig configuration, dpyAudio::audio_set_configuration_handler_function handler);
250  void asyncGetAudioConfiguration(dpyAudio::audio_configuration_handler_function handler);
251 
252  void portEvents_S(dpyAudio::port_event_handler_function handler);
253  void portEvents_U();
254  void connectionListEvents_S(dpyAudio::connection_list_event_handler_function handler);
255  void connectionStatusEvents_S(dpyAudio::connection_status_event_handler_function handler);
256  void connectionListEvents_U();
257  void connectionStatusEvents_U();
258  void taskEvents_S(dpyAudio::task_event_handler_function handler);
259  void taskEvents_U();
260  void portGpioEvents_S(dpyAudio::port_gpio_event_handler_function handler);
261  void portGpioEvents_U();
262 
263  void asyncSetVolume(const dpyAudio::Connection &connection, int volume, dpyAudio::set_connection_volume_handler_function handler);
264  void asyncSetGain(const dpyAudio::Connection &connection, int gain, dpyAudio::set_connection_gain_handler_function handler);
265  void asyncSetPortGpio(const dpyAudio::PortGpio &port_gpio, dpyAudio::result_handler_function handler);
266  void asyncUnsetPortGpio(const dpyAudio::Port &port, dpyAudio::result_handler_function handler);
267  void asyncGetPortGpio(dpyAudio::get_port_gpio_handler_function handler);
268  void asyncSetMicBias(const dpyAudio::PortMicBias &port_mic, dpyAudio::result_handler_function handler);
269  void asyncGetMicBias(dpyAudio::get_mic_bias_handler_function handler);
270 
271 };
virtual void updateAvailability(const bool &available)=0
Method called when service availability changes.
Struct defining a port.
Definition: audioTypes.h:79
Struct defining an assignment between a port and a MIC Bias.
Definition: audioTypes.h:154
boost::function< void(boost::system::error_code &, std::list< dpyAudio::Connection > ConnectionList)> connection_list_handler_function
Handler for get connection list method.
Definition: audioApi.h:69
boost::function< void(boost::system::error_code &, std::list< dpyAudio::AudioConfig > configurations)> audio_configuration_handler_function
Prototype of the handler function for getting the audio configuration.
Definition: audioApi.h:62
boost::function< void(boost::system::error_code &, dpyAudio::Connection connection, unsigned int gain)> set_connection_gain_handler_function
Handler for set connection gain method.
Definition: audioApi.h:188
boost::function< void(boost::system::error_code &, dpyAudio::Port &port)> port_handler_function
Handler for create/remove port.
Definition: audioApi.h:76
Deepsy Audio namespace that includes the different enums, structs or method signatures that should be...
Service Availability observer class.
Definition: audioApi.h:33
boost::function< void(boost::system::error_code &, std::list< dpyAudio::Port > portList)> port_list_handler_function
Handler for get port list method.
Definition: audioApi.h:55
Struct defining audio configuration.
Definition: audioConfig.h:38
boost::function< void(boost::system::error_code &ec, std::list< dpyAudio::PortMicBias > portmiclist)> get_mic_bias_handler_function
Prototype of the handler function for getting all mic bias assigned to ports.
Definition: audioApi.h:202
boost::function< void(boost::system::error_code ec, std::list< std::pair< int, dpyAudio::AudioTaskInformation >> taskinfolist)> all_audio_task_info_handler_function
Prototype of the handler function for getting the status of all tasks.
Definition: audioApi.h:164
boost::function< void(boost::system::error_code error_code, PortGpioEventType type, dpyAudio::PortGpio port_gpio)> port_gpio_event_handler_function
Handler for PortGpio event callback This type of function is called when an event happens...
Definition: audioApi.h:134
virtual ~ServiceAvailabilityObserver()
Destructor.
Definition: audioApi.h:45
boost::function< void(boost::system::error_code error_code, int taskId, dpyAudio::TaskType type, dpyAudio::AudioTaskStatus status)> task_event_handler_function
Handler for audio track event callback This type of function is called when an event happens...
Definition: audioApi.h:125
boost::function< void(boost::system::error_code error_code, PortEventType type, dpyAudio::Port port)> port_event_handler_function
Handler for port event callback This type of function is called when an event happens.
Definition: audioApi.h:116
boost::function< void(boost::system::error_code &, dpyAudio::Connection connection)> connection_handler_function
Handler for create/remove connection method.
Definition: audioApi.h:83
Struct defining a connection between two ports.
Definition: audioTypes.h:130
boost::function< void(boost::system::error_code, int ID)> audio_task_handler_function
Prototype of the handler function for playing or recording audio.
Definition: audioApi.h:141
boost::function< void(boost::system::error_code &)> audio_set_configuration_handler_function
Prototype of the handler function for getting the audio configuration.
Definition: audioApi.h:172
boost::function< void(boost::system::error_code &ec, std::list< dpyAudio::PortGpio > portgpiolist)> get_port_gpio_handler_function
Prototype of the handler function for getting all gpios assigned to ports.
Definition: audioApi.h:195
Interacts with Audio service.
Definition: audioClient.h:13
boost::function< void(boost::system::error_code error_code, ConnectionStatusEventType type, Connection con)> connection_status_event_handler_function
Handler for connection status event function callback This type of function is called when an event h...
Definition: audioApi.h:107
Struct defining an assignment between a port and a gpio.
Definition: audioTypes.h:145
boost::function< void(boost::system::error_code ec, int taskId, dpyAudio::TaskType taskType, dpyAudio::AudioTaskStatus taskStatus)> audio_task_status_handler_function
Prototype of the handler function for getting the status of the task.
Definition: audioApi.h:157
boost::function< void(boost::system::error_code error_code, ConnectionListEventType type, Connection con)> connection_list_event_handler_function
Handler for connection list event function callback This type of function is called when an event hap...
Definition: audioApi.h:98
boost::function< void(boost::system::error_code &, dpyAudio::Connection connection, unsigned int volume)> set_connection_volume_handler_function
Handler for set connection volume method.
Definition: audioApi.h:180
boost::function< void(const boost::system::error_code &)> result_handler_function
Handler for a method which needs a result.
Definition: audioApi.h:89
Allows to interact with a Audio service.
Definition: audioApi.h:215
boost::function< void(boost::system::error_code, int ID)> stop_task_handler
Prototype of the handler function for stopping an audio recording.
Definition: audioApi.h:148