update on dbus
[profile/ivi/audiomanager.git] / AudioManagerDaemon / Router.h
1 /**
2  * Copyright (C) 2011, BMW AG
3  *
4  * AudioManangerDeamon
5  *
6  * \file Router.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 ROUTER_H_
27 #define ROUTER_H_
28
29 #include "audioManagerIncludes.h"
30
31 class DataBaseHandler;
32 class RoutingReceiver;
33 class AudioManagerCore;
34
35 /**calculates routes from sinks to sources
36  *  navigation for audio
37  */
38 class Router {
39 public:
40         Router();
41         virtual ~Router();
42
43         /**Registers the database handler
44          *
45          * @param db_handler pointer to dabase handler
46          */
47         void registerDatabasehandler(DataBaseHandler* db_handler);
48
49         /**the routing algorithm. Returns a list of routes
50          *
51          * @param onlyfree true if only free gateways shall be used
52          * @param Source_ID the source ID from wich the route should start
53          * @param Sink_ID the sink ID where the route should end
54          * @param ReturnList buffer for the answer.
55          * @return returns true on success
56          */
57         bool get_Route_from_Source_ID_to_Sink_ID(const bool onlyfree,
58                         const source_t Source_ID, const sink_t Sink_ID,
59                         std::list<genRoute_t>* ReturnList);
60
61 private:
62         DataBaseHandler* m_dbHandler;
63 };
64
65 /**This represents one Item in the RoutingTree
66  *
67  */
68 class RoutingTreeItem {
69 public:
70         RoutingTreeItem();
71         virtual ~RoutingTreeItem();
72
73         /**overloaded Constructor
74          *
75          * @param Domain_Id the domain ID where the gateway ends
76          * @param Gateway_Id the gateway ID that connects the domains
77          * @param parent pointer to the parent item in the tree
78          */
79         RoutingTreeItem(const domain_t Domain_Id, const gateway_t Gateway_Id = 0,
80                         RoutingTreeItem *parent = 0);
81
82         /**appends a child from the same type to the tree
83          *
84          * @param child
85          */
86         void appendChild(RoutingTreeItem *child);
87
88         /**returns a list of all child items
89          *
90          * @param ChildItems buffer for the child items
91          */
92         void returnChildItems(std::list<RoutingTreeItem*> ChildItems);
93
94         /**returns the domain ID
95          *
96          * @return the domain ID
97          */
98         domain_t returnDomainID();
99
100         /**returns the gateway ID
101          *
102          * @return gateway ID
103          */
104         gateway_t returnGatewayID(void);
105
106         /** is used to retrieve the parent item
107          *
108          * @return pointer to parent RoutingTreeItem
109          */
110         RoutingTreeItem* return_Parent();
111
112 private:
113         std::list<RoutingTreeItem*> childItems; //!< List of all child items
114         domain_t m_domainID; //!< the domain ID of the item
115         gateway_t m_gatewayID; //!< the gateway Id
116         RoutingTreeItem *parentItem; //!< pointer to the parent item
117 };
118
119 /**The routing tree iself
120  *
121  */
122 class RoutingTree {
123 public:
124
125         /**constructor must always be called with the root domain ID
126          *
127          * @param Root_Domain_ID
128          */
129         RoutingTree(const domain_t Root_Domain_ID);
130         ~RoutingTree();
131
132         /**Insert an item in the Tree with the parent parentItem
133          *
134          * @param Domain_ID the domain Id
135          * @param Gateway_ID the gateway ID
136          * @param parentItem pointer to the parent Item
137          * @return returns a pointer to the new item
138          */
139         RoutingTreeItem* insertItem(const domain_t Domain_ID,
140                         const gateway_t Gateway_ID, RoutingTreeItem* parentItem);
141
142         /**reverses the tree to get a route to the TargetItem
143          *
144          * @param TargetItem pointer to the Item from which should be reversed
145          * @param route pointer to a list of gateway IDs that need to be connected
146          * @return the length of the route.
147          */
148         int getRoute(RoutingTreeItem* TargetItem, std::list<gateway_t>* route);
149
150         /**returns the DomainId of the rootItem
151          *
152          * @return domain ID of the root Item
153          */
154         domain_t returnRootDomainID(void);
155
156         /**returns a pointer to the rootitem
157          *
158          * @return pointer to the rootitem
159          */
160         RoutingTreeItem* returnRootItem(void);
161
162 private:
163         RoutingTreeItem m_rootItem; //!< pointer to root item
164         std::list<RoutingTreeItem*> m_allChildList; //!< list of all childs
165 };
166
167 /**This class is responsible for loading the RoutingInterface Plugins
168  * In order to let a plugin be loaded by the BusManager, just add it in main.cpp  like this
169  * @code Q_IMPORT_PLUGIN(RoutingPlugin) @code
170  */
171 class Bushandler {
172
173 public:
174         Bushandler() {};
175         virtual ~Bushandler() {};
176
177         /**by calling this, all bus plugins are loaded
178          *
179          */
180         void load_Bus_plugins();
181
182         /**needed to register the m_receiver Instance
183          * via this function the receiver instance is given to the plugins so that they can call methods to talk to the audiomanager
184          * @param m_receiver pointer to the receiver
185          */
186         void registerReceiver(RoutingReceiver* Receiver);
187
188         void registerCore (AudioManagerCore* core);
189
190         /**By calling this function the plugins are called to startup.
191          * Init functions etc are done by the plugins in this phase
192          */
193         void StartupInterfaces();
194
195         /**This function returns the pointer to the actual interface for a Bus
196          *
197          * @param bus the name of the bus
198          * @return pointer to the interface
199          */
200         RoutingSendInterface* getInterfaceforBus(std::string bus);
201
202         /**This signal informs the plugins that the AudioManager is ready to register Domains Sinks and Sources
203          *
204          */
205         void signal_system_ready(void);
206
207 private:
208         /**Struct to save Name and Interface together
209          *
210          */
211         struct Bus {
212                 RoutingSendInterface* sendInterface;
213                 std::string Name;
214         };
215
216         std::list<Bus> Busses; //!< list of all busses
217         RoutingReceiver* m_receiver; //!< pointer to the routing receiver
218         AudioManagerCore* m_core;
219 };
220
221 #endif /* ROUTER_H_ */