update changelog
[profile/ivi/genivi/genivi-audio-manager.git] / AudioManagerDaemon / include / CAmRouter.h
1 /**
2  * Copyright (C) 2012, BMW AG
3  *
4  * This file is part of GENIVI Project AudioManager.
5  *
6  * Contributions are licensed to the GENIVI Alliance under one or more
7  * Contribution License Agreements.
8  *
9  * \copyright
10  * This Source Code Form is subject to the terms of the
11  * Mozilla Public License, v. 2.0. If a  copy of the MPL was not distributed with
12  * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
13  *
14  *
15  * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
16  *
17  * \file CAmRouter.h
18  * For further information see http://www.genivi.org/.
19  *
20  */
21
22 #ifndef ROUTER_H_
23 #define ROUTER_H_
24
25 #include "audiomanagertypes.h"
26
27 namespace am
28 {
29
30 class IAmDatabaseHandler;
31 class CAmControlSender;
32
33 /**
34  * Implements an autorouting algorithm for connecting sinks and sources via different audio domains.
35  */
36 class CAmRouter
37 {
38 public:
39     CAmRouter(IAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iSender);
40     ~CAmRouter();
41     am_Error_e getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector<am_Route_s>& returnList);
42
43 private:
44     am_Error_e findBestWay(am_sinkID_t sinkID, am_sourceID_t sourceID, std::vector<am_RoutingElement_s>& listRoute, std::vector<am_RoutingElement_s>::iterator routeIterator, std::vector<am_gatewayID_t>::iterator gatewayIterator);
45     void listPossibleConnectionFormats(const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector<am_CustomConnectionFormat_t>& listFormats) const;
46     void listRestrictedOutputFormatsGateways(const am_gatewayID_t gatewayID, const am_CustomConnectionFormat_t sinkConnectionFormat, std::vector<am_CustomConnectionFormat_t>& listFormats) const;
47     IAmDatabaseHandler* mpDatabaseHandler; //!< pointer to database handler
48     CAmControlSender* mpControlSender; //!< pointer the controlsender - is used to retrieve information for the optimal route
49 };
50
51 /**
52  * an item in the routing tree
53  */
54 class CAmRoutingTreeItem
55 {
56 public:
57     CAmRoutingTreeItem(const am_domainID_t domainID, const am_gatewayID_t gatewayID = 0, CAmRoutingTreeItem *parent = 0);
58     ~CAmRoutingTreeItem();
59     void appendChild(CAmRoutingTreeItem *newChild); //!< appends a new child
60     void returnChildItems(std::vector<CAmRoutingTreeItem*> listChildItems); //!< returns the list of childs
61     am_domainID_t returnDomainID() const; //!< returns the domainID of the tree
62     am_gatewayID_t returnGatewayID() const; //!< returns the gatewayID of the tree
63     CAmRoutingTreeItem* returnParent() const; //!< returns the parent item of the tree
64 private:
65     std::vector<CAmRoutingTreeItem*> mListChildItems; //!< List of all child items
66     am_domainID_t mDomainID; //!< the domain ID of the item
67     am_gatewayID_t mGatewayID; //!< the gateway Id
68     CAmRoutingTreeItem *mpParentItem; //!< pointer to the parent item
69 };
70
71 /**
72  * a routing tree
73  */
74 class CAmRoutingTree
75 {
76 public:
77     CAmRoutingTree(const am_domainID_t rootDomainID);
78     ~CAmRoutingTree();
79     CAmRoutingTreeItem* insertItem(const am_domainID_t domainID, const am_gatewayID_t gatewayID, CAmRoutingTreeItem *parent);
80     void getRoute(CAmRoutingTreeItem* targetItem, std::vector<am_gatewayID_t>& listGateways);
81     am_domainID_t returnRootDomainID() const;
82     CAmRoutingTreeItem* returnRootItem();
83 private:
84     CAmRoutingTreeItem mRootItem; //!< pointer to root item
85     std::vector<CAmRoutingTreeItem*> mListChild; //!< list of all childs
86 };
87
88 } /* namespace am */
89 #endif /* ROUTER_H_ */
90