update on dbus
[profile/ivi/audiomanager.git] / AudioManagerDaemon / AudioManagerCore.h
1 /**
2  * Copyright (C) 2011, BMW AG
3  *
4  * AudioManangerDeamon
5  *
6  * \file AudioManagerCore.h
7  *
8  * \date 20.05.2011
9  * \author Christian Müller (christian.ei.mueller@bmw.de)
10  *
11  * \section License
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
14  *
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.
22  *
23  *
24  */
25
26 #ifndef AUDIOMANAGERCORE_H_
27 #define AUDIOMANAGERCORE_H_
28
29
30 #include "audioManagerIncludes.h"
31
32 /**CONSTANT for the Connection timeout when using asynchronous connect. In mseconds.
33  *
34  */
35 #define CONNECT_TIMEOUT 3000
36
37 class HookHandler;
38 class AudioManagerCore;
39 class Queue;
40 class Router;
41 class Bushandler;
42 class CommandInterface;
43
44 /**
45  * \class Task
46  * \brief Base Class for all Tasks
47  * \details a Base Class for a basic operation together with a set of parameters
48  * Every Task that can be created by the Hook Plugins is derived from this class
49  * Be sure to implement executeTask() because this will be called when the task is executed
50  * Whenever the task is finished, you need to emit the signal signal_nextTask() that will call the next
51  * Task in the queue.
52  * \fn virtual void Task::executeTask(Queue* queue)=0
53  * \brief This needs to be overwritten in implementation of the class
54  * The queue calls this function to start the execution of the task
55  * \param queue pointer to the queue
56  * \fn void Task::signal_nextTask()
57  * \brief by emitting this signal, the next task in the queue is triggered
58  */
59 class Task {
60 public:
61         Task();
62         Task(AudioManagerCore* core);
63         virtual ~Task();
64         virtual void executeTask(Queue* queue)=0;
65
66         void signal_nextTask();
67 protected:
68         AudioManagerCore* m_core; //!< pointer to the core
69 };
70
71 /**
72  * \class TaskAsyncConnect
73  * \brief This task is used to connect a source and a sink asynchronous
74  *
75  * \fn TaskAsyncConnect::TaskAsyncConnect(AudioManagerCore* core, sink_t sink, source_t source)
76  * \brief Constructor
77  * \param core pointer to the core
78  * \param sink  the sink to be connected
79  * \param source the source to be connected
80  *
81  * \fn void TaskAsyncConnect::setSink(sink_t sink)
82  * \brief Sets the Sink that should be connected to
83  * \param sink the sink
84  *
85  * \fn void TaskAsyncConnect::setSource(source_t source)
86  * \brief sets the source
87  * \param source the source
88  *
89  * \fn sink_t TaskAsyncConnect::getSink()
90  * \brief returns the sink
91  *
92  * \fn source_t TaskAsyncConnect::getSource()
93  * \brief returns the source
94  *
95  * \fn void TaskAsyncConnect::slot_connect_finished(genHandle_t handle, genError_t error)
96  * \brief is used to receive the asynchronous answer.
97  *
98  * \fn void TaskAsyncConnect::slot_timeout()
99  * \brief used to handle the timeout
100  */
101 class TaskAsyncConnect: public Task {
102
103 public:
104         TaskAsyncConnect(AudioManagerCore* core, sink_t sink, source_t source);
105         virtual ~TaskAsyncConnect();
106         void setSink(sink_t sink);
107         void setSource(source_t source);
108         sink_t getSink();
109         source_t getSource();
110         void executeTask(Queue* queue);
111
112         void slot_connect_finished(genHandle_t handle, genError_t error);
113         void slot_timeout();
114 private:
115         sink_t m_ParamSink; //!< the sink to be connected
116         source_t m_ParamSource; //!< the source to be connected
117         genHandle_t m_handle; //!< the handle (ConnectionID)
118         //QTimer* m_timer; //!< pointer to a timer used for timeout tracking
119         /**
120          * \todo implement non QT Timer
121          */
122 };
123
124 /**
125  * \class TaskConnect
126  * \brief This task is used to connect a source and a sink synchronous
127  *
128  * \fn TaskConnect::TaskConnect(AudioManagerCore* core, sink_t sink, source_t source)
129  * \brief constructor
130  * \param core pointer to the core
131  * \param sink  the sink to be connected
132  * \param source the source to be connected
133  *
134  */
135 class TaskConnect: public Task {
136
137 public:
138         TaskConnect(AudioManagerCore* core, sink_t sink, source_t source);
139         virtual ~TaskConnect();
140         void executeTask(Queue* queue);
141
142 private:
143         sink_t m_ParamSink; //!< the sink to be connected
144         source_t m_ParamSource; //!< the source to be connected
145 };
146
147 /**
148  * \class TaskDisconnect
149  * \brief This task is used to connect a source and a sink synchronous
150  *
151  * \fn TaskDisconnect::TaskDisconnect(AudioManagerCore* core, connection_t ID)
152  * \brief constructor
153  * \param core pointer to the core
154  * \param ID the connection ID to be disconnected
155  *
156  */
157 class TaskDisconnect: public Task {
158
159 public:
160         TaskDisconnect(AudioManagerCore* core, connection_t ID);
161         virtual ~TaskDisconnect();
162         void executeTask(Queue* queue);
163 private:
164         connection_t m_ParamConnectionID; //!< the connection to disconnect
165 };
166
167 /**
168  * \class TaskInterruptWait
169  * \brief this class waits for an interrupt to be resumed
170  *
171  * \fn TaskInterruptWait::TaskInterruptWait(AudioManagerCore* core, genInt_t connectionID)
172  * \brief Constructor
173  * \param core link to AudioManagercore
174  * \param connectionID the connection ID to be waited for
175  *
176  * \fn void TaskInterruptWait::slot_interrupt_ready(genInt_t ID)
177  * \brief slot that is called when the interrupt resumes
178  * \param ID the interrupt ID of the interrupt that resumed
179  */
180 class TaskInterruptWait: public Task {
181
182 public:
183         TaskInterruptWait(AudioManagerCore* core, genInt_t connectionID);
184         virtual ~TaskInterruptWait();
185         void executeTask(Queue* queue);
186
187         void slot_interrupt_ready(genInt_t ID);
188 private:
189         genInt_t m_interruptID; //!< the interrupt ID that should be waited for
190 };
191
192 /**
193  * \class TaskSetVolume
194  * \brief a task that sets the volume for a sink
195  *
196  * \fn TaskSetVolume::TaskSetVolume(AudioManagerCore* core, volume_t newVolume=0, sink_t sink=0)
197  * \brief constructor
198  * \param core the pointer to the AudioManagerCore
199  * \param newVolume the volume to be set
200  * \param sink the sink that the volume shall be applied to
201  *
202  * \fn void TaskSetVolume::setVolume(volume_t newVolume)
203  * \brief sets the volume
204  *
205  * \fn void TaskSetVolume::setSink(sink_t sink)
206  * \brief sets the sink
207  *
208  * \fn volume_t  TaskSetVolume::getVolume()
209  * \brief returns the volume
210  *
211  * \fn sink_t TaskSetVolume::getSink()
212  * \brief returns the volume
213  */
214 class TaskSetVolume: public Task {
215
216 public:
217         TaskSetVolume(AudioManagerCore* core, volume_t newVolume=0, sink_t sink=0);
218         virtual ~TaskSetVolume();
219
220         void setVolume(volume_t newVolume);
221         void setSink(sink_t sink);
222
223         volume_t getVolume();
224         sink_t getSink();
225
226         void executeTask(Queue* queue);
227 private:
228         volume_t m_volume; //!< the volume
229         sink_t m_sink; //!< the sink
230 };
231
232 /**
233  * \class TaskSetSourceVolume
234  * \brief sets the volume of a source
235  *
236  * \fn TaskSetSourceVolume::TaskSetSourceVolume(AudioManagerCore* core, volume_t newVolume=0, source_t source=0)
237  * \brief constructor
238  * \param core the pointer to the AudioManagerCore
239  * \param newVolume the volumesink_t  to be set
240  * \param source the source that the volume shall be applied to
241  *
242  *  * \fn void TaskSetSourceVolume::setVolume(volume_t newVolume)
243  * \brief sets the volume
244  *
245  * \fn void TaskSetSourceVolume::setSource (source_t source)
246  * \brief sets the sink
247  *
248  * \fn volume_t TaskSetSourceVolume::getVolume()
249  * \brief returns the volume
250  */
251 class TaskSetSourceVolume: public Task {
252
253 public:
254         TaskSetSourceVolume(AudioManagerCore* core, volume_t newVolume=0, source_t source=0);
255         virtual ~TaskSetSourceVolume();
256
257         void setVolume(volume_t newVolume);
258         void setSource(source_t source);
259
260         volume_t getVolume();
261         source_t getSource();
262
263         void executeTask(Queue* queue);
264 private:
265         volume_t m_volume; //!< the volume
266         source_t m_source; //!< the source
267 };
268
269 /**
270  * \class TaskWait
271  * \brief implements a wait in msecons
272  *
273  * \fn TaskWait::TaskWait(AudioManagerCore* core, int mseconds)
274  * \brief constructor
275  * \param core the pointer to the AudioManagerCore
276  * \param mseconds delay in milliseconds
277  *
278  * \fn void TaskWait::setTime(int mseconds)
279  * \brief sets the time
280  *
281  * \fn int TaskWait::getTime()
282  * \brief returns the time
283  *
284  * \fn  void TaskWait::slot_timeIsup()
285  * \brief slot called when the time is up
286  */
287 class TaskWait: public Task {
288
289 public:
290         TaskWait(AudioManagerCore* core, int mseconds);
291         virtual ~TaskWait();
292         void setTime(int mseconds);
293         int getTime();
294         void executeTask(Queue* queue);
295         void slot_timeIsup();
296 private:
297         int m_ParamMSeconds;//!< time to be delayed in milli seconds
298 //      QTimer* m_timer; //!< pointer to timer
299         /**
300          *\todo replace Qtimer
301          */
302 };
303
304 /**
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
308  *
309  * \fn TaskEnterUserConnect::TaskEnterUserConnect(AudioManagerCore* core, genRoute_t route, connection_t connID=0)
310  * \brief enters a user connect into the database
311  */
312 class TaskEnterUserConnect: public Task {
313
314 public:
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);
320 private:
321         genRoute_t m_route;             //!< the route to be entered
322         connection_t m_connectionID; //!< the connection ID
323 };
324
325 /**
326  * \class TaskRemoveUserConnect
327  * \brief removes a user Connect
328  *
329  * \fn TaskRemoveUserConnect::TaskRemoveUserConnect(AudioManagerCore* core, connection_t connID)
330  * \brief constructor
331  */
332 class TaskRemoveUserConnect : public Task {
333
334 public:
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);
340 private:
341         connection_t m_connectionID; //!< the connection ID
342 };
343
344 /**
345  * \class TaskEnterInterrupt
346  * \brief enters an interrupt into the database
347  */
348 class TaskEnterInterrupt: public Task {
349
350 public:
351         TaskEnterInterrupt(AudioManagerCore* core, genInt_t ID,bool mixed, connection_t connID, std::list<source_t> listInterruptedSources);
352         virtual ~TaskEnterInterrupt();
353         void executeTask(Queue* queue);
354 private:
355         genInt_t m_intID; //!< the interrupt ID
356         bool m_mixed; //!< true if mixed
357         connection_t m_connectionID; //!< the connection ID
358         std::list<source_t> m_interruptedSourcesList; //!< the list of interrupted sources
359 };
360
361 /**
362  * \class TaskRemoveInterrupt
363  * \brief removes an interrupt
364  */
365 class TaskRemoveInterrupt: public Task {
366
367 public:
368         TaskRemoveInterrupt(AudioManagerCore* core, genInt_t ID);
369         virtual ~TaskRemoveInterrupt();
370         void executeTask(Queue* queue);
371 private:
372         genInt_t m_intID; //!< the interrupt ID
373 };
374
375 /**
376  * \class TaskSetSourceMute
377  * \brief mutes a source
378  */
379 class TaskSetSourceMute: public Task {
380
381 public:
382         TaskSetSourceMute(AudioManagerCore* core, source_t source);
383         virtual ~TaskSetSourceMute();
384         void executeTask(Queue* queue);
385 private:
386         source_t m_source; //!< the source to be muted
387 };
388
389 /**
390  * \class TaskSetSourceUnmute
391  * \brief unmutes a source
392  */
393 class TaskSetSourceUnmute: public Task {
394
395 public:
396         TaskSetSourceUnmute(AudioManagerCore* core, source_t source);
397         virtual ~TaskSetSourceUnmute();
398         void executeTask(Queue* queue);
399 private:
400         source_t m_source; //!< the source to be unmuted
401 };
402
403 /**
404  * \class TaskEmitSignalConnect
405  * \brief emits the signal connect
406  */
407 class TaskEmitSignalConnect: public Task {
408 public:
409         TaskEmitSignalConnect(AudioManagerCore* core);
410         virtual ~TaskEmitSignalConnect();
411         void executeTask(Queue* queue);
412 };
413
414 /**
415  * \class Queue
416  * \brief With the help of this class, all events that need to be processed are organized and queued
417  * \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.
418  * \todo error handling
419  * \todo sorting of tasks
420  * \todo add some function to attach parameters to the Queue so that organizing and handling is possible
421  *
422  * \fn Queue::Queue(AudioManagerCore* core,std::string name="")
423  * \brief constructor
424  * \param name give the queue a name
425  * \param core pointer to AudioManagerCore
426  *
427  * \fn void Queue::run()
428  * \brief starts the queue
429  *
430  * \fn void Queue::addTask(Task* task)
431  * \brief add a task to the queue
432  * \param task pointer to the task
433  *
434  * \fn genError_t Queue::removeTask(Task* task)
435  * \brief removes a task
436  * \param task pointer to the task
437  * \return GEN_OK on success
438  *
439  * \fn  std::list<Task*> Queue::getTaskList()
440  * \brief returns the actual task list
441  * \return list with pointers to the tasks
442  *
443  * \fn std::string Queue::returnName()
444  * \brief returns the name of the Queue
445  * \return the name in std::string format
446  *
447  * \fn void Queue::slot_nextTask()
448  * \brief is called when a task is finished and the next task can be called
449  */
450 class Queue{
451
452 public:
453         Queue(AudioManagerCore* core,std::string name="");
454         virtual ~Queue();
455         void run();
456         void addTask(Task* task);
457         genError_t removeTask(Task* task);
458         std::list<Task*> getTaskList();
459         std::string returnName();
460
461         void slot_nextTask();
462 private:
463         AudioManagerCore* m_core; //!< pointer to AudioManagerCore
464         std::list<Task*>::iterator m_currentIndex; //!< the index of the list wich is currently worked on
465         std::string m_name; //!< name of the Queue
466         std::list<Task*> m_taskList; //!< the list with pointers to the tasks
467 };
468
469 /**:3: error: ISO C++ forbids declaration of ‘type name’ with no type
470  *
471  * \class AudioManagerCore
472  * \brief The central Managing Class of the AudioManager
473  *
474  * \fn genError_t AudioManagerCore::UserConnect(source_t source, sink_t sink)
475  * \brief does a user connect
476  *
477  * \fn genError_t AudioManagerCore::UserDisconnect(connection_t connID)
478  * \brief does a user disconnect
479  *
480  * \fn genError_t AudioManagerCore::UserSetVolume(sink_t sink, volume_t volume)
481  * \brief set the user volume (on sink level)
482  *
483  * \fn genError_t AudioManagerCore::connect(source_t source, sink_t sink, genHandle_t* handle = NULL)
484  * \brief connects sources and sinks
485  *
486  * \fn genError_t AudioManagerCore::disconnect(connection_t ID)
487  * \brief disconnects sources and sinks
488  *
489  * \fn genError_t AudioManagerCore::setVolume(sink_t sink, volume_t volume)
490  * \brief sets the volume to a sink
491  *
492  * \fn genError_t AudioManagerCore::interruptRequest(source_t interruptSource, sink_t sink, genInt_t* interruptID)
493  * \brief via this call, an interrupt is requested
494  *
495  * \fn genError_t AudioManagerCore::setSourceVolume (source_t source, volume_t volume)
496  * \brief sets the source volume
497  *
498  * \fn genError_t AudioManagerCore::setSourceMute (source_t source)
499  * \brief mutes a source
500  *
501  * \fn genError_t AudioManagerCore::setSourceUnMute (source_t source)
502  * \brief unmutes a source
503  *
504  * \fn genError_t AudioManagerCore::getRoute(const bool onlyfree, const source_t source, const sink_t sink, std::list<genRoute_t>* ReturnList)
505  * \brief returns a route
506  *
507  * \fn connection_t AudioManagerCore::returnConnectionIDforSinkSource (sink_t sink, source_t source)
508  * \brief returns the connection ID for a sink source combination
509  *
510  * \fn source_t AudioManagerCore::returnSourceIDfromName(const std::string name)
511  * \brief returns the source ID for a name
512  *
513  * \fn sink_t AudioManagerCore::returnSinkIDfromName(const std::string name)
514  * \brief returns the sink ID for a given name
515  *
516  * \fn std::list<ConnectionType> AudioManagerCore::getListConnections()
517  * \brief returns the list of connections
518  *
519  * \fn std::list<SinkType> AudioManagerCore::getListSinks()
520  * \brief returns a list of all sinks
521  *
522  * \fn std::list<SourceType> AudioManagerCore::getListSources()
523  * \brief returns a list of all sources
524  *
525  * \fn void AudioManagerCore::emitSignalConnect()
526  * \brief emits the signal connect
527  *
528  * \fn Router* AudioManagerCore::returnRouter()
529  * \brief returns the pointer to the router
530  *
531  * \fn DataBaseHandler* AudioManagerCore::returnDatabaseHandler()
532  * \brief returns the pointer to the database handler
533  *
534  * \fn RoutingReceiver* AudioManagerCore::returnReceiver()
535  * \brief returns the pointer to the receiver
536  *
537  * \fn DBusCommandInterface* AudioManagerCore::returnCommandInterface()
538  * \brief returns the pointer to the command interface
539  *
540  * \fn void AudioManagerCore::registerDatabasehandler(DataBaseHandler * handler)
541  * \brief registers the database handler @ the core
542  *
543  * \fn void AudioManagerCore::registerRouter(Router* router)
544  * \brief registers the router @ the core
545  *
546  * \fn void AudioManagerCore::registerBushandler(Bushandler* handler)
547  * \brief registers the bushandler @ the core
548  *
549  * \fn void AudioManagerCore::registerHookEngine(HookHandler* handler)
550  * \brief registers the hook engine @ the core
551  *
552  * \fn void AudioManagerCore::registerReceiver(RoutingReceiver* receiver)
553  * \brief registers the receiver @ the core
554  *
555  * \fn void AudioManagerCore::registerCommandInterface(DBusCommandInterface* command)
556  * \brief registers the command interface @ the core
557  *
558  * \fn void AudioManagerCore::addQueue(Queue* queue)
559  * \brief adds a queue
560  *
561  * \fn genError_t AudioManagerCore::removeQueue(Queue* queue)
562  * \brief removes a queue
563  *
564  *
565  */
566 class AudioManagerCore {
567
568 public:
569         AudioManagerCore();
570         virtual ~AudioManagerCore();
571
572         genError_t UserConnect(source_t source, sink_t sink);
573         genError_t UserDisconnect(connection_t connID);
574         genError_t UserSetVolume(sink_t sink, volume_t volume);
575         genError_t connect(source_t source, sink_t sink, genHandle_t* handle = NULL);
576         genError_t disconnect(connection_t ID);
577         genError_t setVolume(sink_t sink, volume_t volume);
578         genError_t interruptRequest(source_t interruptSource, sink_t sink, genInt_t* interruptID);
579         genError_t setSourceVolume (source_t source, volume_t volume);
580         genError_t setSourceMute (source_t source);
581         genError_t setSourceUnMute (source_t source);
582
583         genError_t getRoute(const bool onlyfree, const source_t source, const sink_t sink, std::list<genRoute_t>* ReturnList);
584         connection_t returnConnectionIDforSinkSource (sink_t sink, source_t source);
585         source_t returnSourceIDfromName(const std::string name);
586         sink_t returnSinkIDfromName(const std::string name);
587
588         std::list<ConnectionType> getListConnections();
589         std::list<SinkType> getListSinks();
590         std::list<SourceType> getListSources();
591
592         void emitSignalConnect();
593
594         Router* returnRouter();
595         DataBaseHandler* returnDatabaseHandler();
596         RoutingReceiver* returnReceiver();
597         CommandInterface* returnCommandInterface();
598         dbusRoothandler* returnDbusHandler();
599
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(CommandInterface* command);
606         void registerDbusRootHandler(dbusRoothandler* handler);
607
608         void addQueue(Queue* queue);
609         genError_t removeQueue(Queue* queue);
610
611         void signal_connectionChanged();
612         void signal_numberOfSinksChanged();
613         void signal_numberOfSourcesChanged();
614
615         std::list<std::string> getSharedLibrariesFromDirectory(std::string dirName);
616         template<class T>T* getCreateFunction(std::string libname);
617
618 private:
619         DataBaseHandler* m_databaseHandler; //!< pointer to the DataBasehandler Class
620         Router* m_router; //!< pointer to the Router Class
621         Bushandler* m_busHandler; //!< pointer to the Bushandler Class
622         HookHandler* m_hookHandler; //!< pointer to the HookHandler CLass
623         RoutingReceiver* m_receiver; //!< pointer to the Routing receiver Class
624         dbusRoothandler* m_dbusHandler;
625         CommandInterface* m_command; //!< pointer to the command Interface Class
626
627         std::list<Queue*> m_queueList; //!< List of pointers to all running queues
628 };
629
630 #endif /* AUDIOMANAGERCORE_H_ */