2 * Copyright (C) 2011, BMW AG
6 * \file AudioManagerCore.h
9 * \author Christian Müller (christian.ei.mueller@bmw.de)
12 * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
13 * Copyright (C) 2011, BMW AG – Christian Müller Christian.ei.mueller@bmw.de
15 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 2.1, for more details.
17 * You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
18 * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense.
19 * Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception.
20 * As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned.
21 * Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception.
26 #ifndef AUDIOMANAGERCORE_H_
27 #define AUDIOMANAGERCORE_H_
29 #include <QtCore/QObject>
31 #include "audioManagerIncludes.h"
33 /**CONSTANT for the Connection timeout when using asynchronous connect. In mseconds.
36 #define CONNECT_TIMEOUT 3000
39 class AudioManagerCore;
43 class DBusCommandInterface;
47 * \brief Base Class for all Tasks
48 * \details a Base Class for a basic operation together with a set of parameters
49 * Every Task that can be created by the Hook Plugins is derived from this class
50 * Be sure to implement executeTask() because this will be called when the task is executed
51 * Whenever the task is finished, you need to emit the signal signal_nextTask() that will call the next
53 * \fn virtual void Task::executeTask(Queue* queue)=0
54 * \brief This needs to be overwritten in implementation of the class
55 * The queue calls this function to start the execution of the task
56 * \param queue pointer to the queue
57 * \fn void Task::signal_nextTask()
58 * \brief by emitting this signal, the next task in the queue is triggered
60 class Task: public QObject {
64 Task(AudioManagerCore* core);
66 virtual void executeTask(Queue* queue)=0;
69 void signal_nextTask();
71 AudioManagerCore* m_core; //!< pointer to the core
75 * \class TaskAsyncConnect
76 * \brief This task is used to connect a source and a sink asynchronous
78 * \fn TaskAsyncConnect::TaskAsyncConnect(AudioManagerCore* core, sink_t sink, source_t source)
80 * \param core pointer to the core
81 * \param sink the sink to be connected
82 * \param source the source to be connected
84 * \fn void TaskAsyncConnect::setSink(sink_t sink)
85 * \brief Sets the Sink that should be connected to
86 * \param sink the sink
88 * \fn void TaskAsyncConnect::setSource(source_t source)
89 * \brief sets the source
90 * \param source the source
92 * \fn sink_t TaskAsyncConnect::getSink()
93 * \brief returns the sink
95 * \fn source_t TaskAsyncConnect::getSource()
96 * \brief returns the source
98 * \fn void TaskAsyncConnect::slot_connect_finished(genHandle_t handle, genError_t error)
99 * \brief is used to receive the asynchronous answer.
101 * \fn void TaskAsyncConnect::slot_timeout()
102 * \brief used to handle the timeout
104 class TaskAsyncConnect: public Task {
107 TaskAsyncConnect(AudioManagerCore* core, sink_t sink, source_t source);
108 virtual ~TaskAsyncConnect();
109 void setSink(sink_t sink);
110 void setSource(source_t source);
112 source_t getSource();
113 void executeTask(Queue* queue);
116 void slot_connect_finished(genHandle_t handle, genError_t error);
119 sink_t m_ParamSink; //!< the sink to be connected
120 source_t m_ParamSource; //!< the source to be connected
121 genHandle_t m_handle; //!< the handle (ConnectionID)
122 QTimer* m_timer; //!< pointer to a timer used for timeout tracking
127 * \brief This task is used to connect a source and a sink synchronous
129 * \fn TaskConnect::TaskConnect(AudioManagerCore* core, sink_t sink, source_t source)
131 * \param core pointer to the core
132 * \param sink the sink to be connected
133 * \param source the source to be connected
136 class TaskConnect: public Task {
139 TaskConnect(AudioManagerCore* core, sink_t sink, source_t source);
140 virtual ~TaskConnect();
141 void executeTask(Queue* queue);
144 sink_t m_ParamSink; //!< the sink to be connected
145 source_t m_ParamSource; //!< the source to be connected
149 * \class TaskDisconnect
150 * \brief This task is used to connect a source and a sink synchronous
152 * \fn TaskDisconnect::TaskDisconnect(AudioManagerCore* core, connection_t ID)
154 * \param core pointer to the core
155 * \param ID the connection ID to be disconnected
158 class TaskDisconnect: public Task {
161 TaskDisconnect(AudioManagerCore* core, connection_t ID);
162 virtual ~TaskDisconnect();
163 void executeTask(Queue* queue);
165 connection_t m_ParamConnectionID; //!< the connection to disconnect
169 * \class TaskInterruptWait
170 * \brief this class waits for an interrupt to be resumed
172 * \fn TaskInterruptWait::TaskInterruptWait(AudioManagerCore* core, genInt_t connectionID)
174 * \param core link to AudioManagercore
175 * \param connectionID the connection ID to be waited for
177 * \fn void TaskInterruptWait::slot_interrupt_ready(genInt_t ID)
178 * \brief slot that is called when the interrupt resumes
179 * \param ID the interrupt ID of the interrupt that resumed
181 class TaskInterruptWait: public Task {
184 TaskInterruptWait(AudioManagerCore* core, genInt_t connectionID);
185 virtual ~TaskInterruptWait();
186 void executeTask(Queue* queue);
188 void slot_interrupt_ready(genInt_t ID);
190 genInt_t m_interruptID; //!< the interrupt ID that should be waited for
194 * \class TaskSetVolume
195 * \brief a task that sets the volume for a sink
197 * \fn TaskSetVolume::TaskSetVolume(AudioManagerCore* core, volume_t newVolume=0, sink_t sink=0)
199 * \param core the pointer to the AudioManagerCore
200 * \param newVolume the volume to be set
201 * \param sink the sink that the volume shall be applied to
203 * \fn void TaskSetVolume::setVolume(volume_t newVolume)
204 * \brief sets the volume
206 * \fn void TaskSetVolume::setSink(sink_t sink)
207 * \brief sets the sink
209 * \fn volume_t TaskSetVolume::getVolume()
210 * \brief returns the volume
212 * \fn sink_t TaskSetVolume::getSink()
213 * \brief returns the volume
215 class TaskSetVolume: public Task {
218 TaskSetVolume(AudioManagerCore* core, volume_t newVolume=0, sink_t sink=0);
219 virtual ~TaskSetVolume();
221 void setVolume(volume_t newVolume);
222 void setSink(sink_t sink);
224 volume_t getVolume();
227 void executeTask(Queue* queue);
229 volume_t m_volume; //!< the volume
230 sink_t m_sink; //!< the sink
234 * \class TaskSetSourceVolume
235 * \brief sets the volume of a source
237 * \fn TaskSetSourceVolume::TaskSetSourceVolume(AudioManagerCore* core, volume_t newVolume=0, source_t source=0)
239 * \param core the pointer to the AudioManagerCore
240 * \param newVolume the volumesink_t to be set
241 * \param source the source that the volume shall be applied to
243 * * \fn void TaskSetSourceVolume::setVolume(volume_t newVolume)
244 * \brief sets the volume
246 * \fn void TaskSetSourceVolume::setSource (source_t source)
247 * \brief sets the sink
249 * \fn volume_t TaskSetSourceVolume::getVolume()
250 * \brief returns the volume
252 class TaskSetSourceVolume: public Task {
255 TaskSetSourceVolume(AudioManagerCore* core, volume_t newVolume=0, source_t source=0);
256 virtual ~TaskSetSourceVolume();
258 void setVolume(volume_t newVolume);
259 void setSource(source_t source);
261 volume_t getVolume();
262 source_t getSource();
264 void executeTask(Queue* queue);
266 volume_t m_volume; //!< the volume
267 source_t m_source; //!< the source
272 * \brief implements a wait in msecons
274 * \fn TaskWait::TaskWait(AudioManagerCore* core, int mseconds)
276 * \param core the pointer to the AudioManagerCore
277 * \param mseconds delay in milliseconds
279 * \fn void TaskWait::setTime(int mseconds)
280 * \brief sets the time
282 * \fn int TaskWait::getTime()
283 * \brief returns the time
285 * \fn void TaskWait::slot_timeIsup()
286 * \brief slot called when the time is up
288 class TaskWait: public Task {
291 TaskWait(AudioManagerCore* core, int mseconds);
293 void setTime(int mseconds);
295 void executeTask(Queue* queue);
298 void slot_timeIsup();
300 int m_ParamMSeconds;//!< time to be delayed in milli seconds
301 QTimer* m_timer; //!< pointer to timer
305 * \class TaskEnterUserConnect
306 * \brief This task enters the user connection into the struct of the AudioManagerCore
307 * \details We need this because the connection shall be entered not before it is build up
309 * \fn TaskEnterUserConnect::TaskEnterUserConnect(AudioManagerCore* core, genRoute_t route, connection_t connID=0)
310 * \brief enters a user connect into the database
312 class TaskEnterUserConnect: public Task {
315 TaskEnterUserConnect(AudioManagerCore* core, genRoute_t route, connection_t connID=0);
316 virtual ~TaskEnterUserConnect();
317 void setConnection(genRoute_t route, connection_t connID);
318 genRoute_t returnConnection();
319 void executeTask(Queue* queue);
321 genRoute_t m_route; //!< the route to be entered
322 connection_t m_connectionID; //!< the connection ID
326 * \class TaskRemoveUserConnect
327 * \brief removes a user Connect
329 * \fn TaskRemoveUserConnect::TaskRemoveUserConnect(AudioManagerCore* core, connection_t connID)
332 class TaskRemoveUserConnect : public Task {
335 TaskRemoveUserConnect(AudioManagerCore* core, connection_t connID);
336 virtual ~TaskRemoveUserConnect();
337 void setConnectionID(connection_t connID);
338 connection_t returnConnectionID();
339 void executeTask(Queue* queue);
341 connection_t m_connectionID; //!< the connection ID
345 * \class TaskEnterInterrupt
346 * \brief enters an interrupt into the database
348 class TaskEnterInterrupt: public Task {
351 TaskEnterInterrupt(AudioManagerCore* core, genInt_t ID,bool mixed, connection_t connID, QList<source_t> listInterruptedSources);
352 virtual ~TaskEnterInterrupt();
353 void executeTask(Queue* queue);
355 genInt_t m_intID; //!< the interrupt ID
356 bool m_mixed; //!< true if mixed
357 connection_t m_connectionID; //!< the connection ID
358 QList<source_t> m_interruptedSourcesList; //!< the list of interrupted sources
362 * \class TaskRemoveInterrupt
363 * \brief removes an interrupt
365 class TaskRemoveInterrupt: public Task {
368 TaskRemoveInterrupt(AudioManagerCore* core, genInt_t ID);
369 virtual ~TaskRemoveInterrupt();
370 void executeTask(Queue* queue);
372 genInt_t m_intID; //!< the interrupt ID
376 * \class TaskSetSourceMute
377 * \brief mutes a source
379 class TaskSetSourceMute: public Task {
382 TaskSetSourceMute(AudioManagerCore* core, source_t source);
383 virtual ~TaskSetSourceMute();
384 void executeTask(Queue* queue);
386 source_t m_source; //!< the source to be muted
390 * \class TaskSetSourceUnmute
391 * \brief unmutes a source
393 class TaskSetSourceUnmute: public Task {
396 TaskSetSourceUnmute(AudioManagerCore* core, source_t source);
397 virtual ~TaskSetSourceUnmute();
398 void executeTask(Queue* queue);
400 source_t m_source; //!< the source to be unmuted
404 * \class TaskEmitSignalConnect
405 * \brief emits the signal connect
407 class TaskEmitSignalConnect: public Task {
410 TaskEmitSignalConnect(AudioManagerCore* core);
411 virtual ~TaskEmitSignalConnect();
412 void executeTask(Queue* queue);
417 * \brief With the help of this class, all events that need to be processed are organized and queued
418 * \details tasks to be added have to be created with new, after the queue is done all tasks will be deleted and the memory freed.
419 * \todo error handling
420 * \todo sorting of tasks
421 * \todo add some function to attach parameters to the Queue so that organizing and handling is possible
423 * \fn Queue::Queue(AudioManagerCore* core,QString name="")
425 * \param name give the queue a name
426 * \param core pointer to AudioManagerCore
428 * \fn void Queue::run()
429 * \brief starts the queue
431 * \fn void Queue::addTask(Task* task)
432 * \brief add a task to the queue
433 * \param task pointer to the task
435 * \fn genError_t Queue::removeTask(Task* task)
436 * \brief removes a task
437 * \param task pointer to the task
438 * \return GEN_OK on success
440 * \fn QList<Task*> Queue::getTaskList()
441 * \brief returns the actual task list
442 * \return list with pointers to the tasks
444 * \fn QString Queue::returnName()
445 * \brief returns the name of the Queue
446 * \return the name in QString format
448 * \fn void Queue::slot_nextTask()
449 * \brief is called when a task is finished and the next task can be called
451 class Queue: public QObject {
454 Queue(AudioManagerCore* core,QString name="");
457 void addTask(Task* task);
458 genError_t removeTask(Task* task);
459 QList<Task*> getTaskList();
460 QString returnName();
463 void slot_nextTask();
465 AudioManagerCore* m_core; //!< pointer to AudioManagerCore
466 int m_currentIndex; //!< the index of the list wich is currently worked on
467 QString m_name; //!< name of the Queue
468 QList<Task*> m_taskList; //!< the list with pointers to the tasks
472 * \class AudioManagerCore
473 * \brief The central Managing Class of the AudioManager
475 * \fn genError_t AudioManagerCore::UserConnect(source_t source, sink_t sink)
476 * \brief does a user connect
478 * \fn genError_t AudioManagerCore::UserDisconnect(connection_t connID)
479 * \brief does a user disconnect
481 * \fn genError_t AudioManagerCore::UserSetVolume(sink_t sink, volume_t volume)
482 * \brief set the user volume (on sink level)
484 * \fn genError_t AudioManagerCore::connect(source_t source, sink_t sink, genHandle_t* handle = NULL)
485 * \brief connects sources and sinks
487 * \fn genError_t AudioManagerCore::disconnect(connection_t ID)
488 * \brief disconnects sources and sinks
490 * \fn genError_t AudioManagerCore::setVolume(sink_t sink, volume_t volume)
491 * \brief sets the volume to a sink
493 * \fn genError_t AudioManagerCore::interruptRequest(source_t interruptSource, sink_t sink, genInt_t* interruptID)
494 * \brief via this call, an interrupt is requested
496 * \fn genError_t AudioManagerCore::setSourceVolume (source_t source, volume_t volume)
497 * \brief sets the source volume
499 * \fn genError_t AudioManagerCore::setSourceMute (source_t source)
500 * \brief mutes a source
502 * \fn genError_t AudioManagerCore::setSourceUnMute (source_t source)
503 * \brief unmutes a source
505 * \fn genError_t AudioManagerCore::getRoute(const bool onlyfree, const source_t source, const sink_t sink, QList<genRoute_t>* ReturnList)
506 * \brief returns a route
508 * \fn connection_t AudioManagerCore::returnConnectionIDforSinkSource (sink_t sink, source_t source)
509 * \brief returns the connection ID for a sink source combination
511 * \fn source_t AudioManagerCore::returnSourceIDfromName(const QString name)
512 * \brief returns the source ID for a name
514 * \fn sink_t AudioManagerCore::returnSinkIDfromName(const QString name)
515 * \brief returns the sink ID for a given name
517 * \fn QList<ConnectionType> AudioManagerCore::getListConnections()
518 * \brief returns the list of connections
520 * \fn QList<SinkType> AudioManagerCore::getListSinks()
521 * \brief returns a list of all sinks
523 * \fn QList<SourceType> AudioManagerCore::getListSources()
524 * \brief returns a list of all sources
526 * \fn void AudioManagerCore::emitSignalConnect()
527 * \brief emits the signal connect
529 * \fn Router* AudioManagerCore::returnRouter()
530 * \brief returns the pointer to the router
532 * \fn DataBaseHandler* AudioManagerCore::returnDatabaseHandler()
533 * \brief returns the pointer to the database handler
535 * \fn RoutingReceiver* AudioManagerCore::returnReceiver()
536 * \brief returns the pointer to the receiver
538 * \fn DBusCommandInterface* AudioManagerCore::returnCommandInterface()
539 * \brief returns the pointer to the command interface
541 * \fn void AudioManagerCore::registerDatabasehandler(DataBaseHandler * handler)
542 * \brief registers the database handler @ the core
544 * \fn void AudioManagerCore::registerRouter(Router* router)
545 * \brief registers the router @ the core
547 * \fn void AudioManagerCore::registerBushandler(Bushandler* handler)
548 * \brief registers the bushandler @ the core
550 * \fn void AudioManagerCore::registerHookEngine(HookHandler* handler)
551 * \brief registers the hook engine @ the core
553 * \fn void AudioManagerCore::registerReceiver(RoutingReceiver* receiver)
554 * \brief registers the receiver @ the core
556 * \fn void AudioManagerCore::registerCommandInterface(DBusCommandInterface* command)
557 * \brief registers the command interface @ the core
559 * \fn void AudioManagerCore::addQueue(Queue* queue)
560 * \brief adds a queue
562 * \fn genError_t AudioManagerCore::removeQueue(Queue* queue)
563 * \brief removes a queue
567 class AudioManagerCore :public QObject {
571 virtual ~AudioManagerCore();
573 genError_t UserConnect(source_t source, sink_t sink);
574 genError_t UserDisconnect(connection_t connID);
575 genError_t UserSetVolume(sink_t sink, volume_t volume);
576 genError_t connect(source_t source, sink_t sink, genHandle_t* handle = NULL);
577 genError_t disconnect(connection_t ID);
578 genError_t setVolume(sink_t sink, volume_t volume);
579 genError_t interruptRequest(source_t interruptSource, sink_t sink, genInt_t* interruptID);
580 genError_t setSourceVolume (source_t source, volume_t volume);
581 genError_t setSourceMute (source_t source);
582 genError_t setSourceUnMute (source_t source);
584 genError_t getRoute(const bool onlyfree, const source_t source, const sink_t sink, QList<genRoute_t>* ReturnList);
585 connection_t returnConnectionIDforSinkSource (sink_t sink, source_t source);
586 source_t returnSourceIDfromName(const QString name);
587 sink_t returnSinkIDfromName(const QString name);
589 QList<ConnectionType> getListConnections();
590 QList<SinkType> getListSinks();
591 QList<SourceType> getListSources();
593 void emitSignalConnect();
595 Router* returnRouter();
596 DataBaseHandler* returnDatabaseHandler();
597 RoutingReceiver* returnReceiver();
598 DBusCommandInterface* returnCommandInterface();
600 void registerDatabasehandler(DataBaseHandler * handler);
601 void registerRouter(Router* router);
602 void registerBushandler(Bushandler* handler);
603 void registerHookEngine(HookHandler* handler);
604 void registerReceiver(RoutingReceiver* receiver);
605 void registerCommandInterface(DBusCommandInterface* command);
607 void addQueue(Queue* queue);
608 genError_t removeQueue(Queue* queue);
611 void signal_connectionChanged();
612 void signal_numberOfSinksChanged();
613 void signal_numberOfSourcesChanged();
616 DataBaseHandler* m_databaseHandler; //!< pointer to the DataBasehandler Class
617 Router* m_router; //!< pointer to the Router Class
618 Bushandler* m_busHandler; //!< pointer to the Bushandler Class
619 HookHandler* m_hookHandler; //!< pointer to the HookHandler CLass
620 RoutingReceiver* m_receiver; //!< pointer to the Routing receiver Class
621 DBusCommandInterface* m_command; //!< pointer to the command Interface Class
623 QList<Queue*> m_queueList; //!< List of pointers to all running queues
626 #endif /* AUDIOMANAGERCORE_H_ */