2 * Copyright (C) 2012, BMW AG
4 * This file is part of GENIVI Project AudioManager.
6 * Contributions are licensed to the GENIVI Alliance under one or more
7 * Contribution License Agreements.
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/.
15 * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
17 * \file CAmCommandReceiver.cpp
18 * For further information see http://www.genivi.org/.
22 #include "CAmCommandReceiver.h"
25 #include "CAmDatabaseHandler.h"
26 #include "CAmControlSender.h"
27 #include "shared/CAmDltWrapper.h"
28 #include "shared/CAmSocketHandler.h"
33 CAmCommandReceiver::CAmCommandReceiver(CAmDatabaseHandler *iDatabaseHandler, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler) :
34 mDatabaseHandler(iDatabaseHandler), //
35 mControlSender(iControlSender), //
36 mSocketHandler(iSocketHandler), //
37 mListStartupHandles(), //
38 mListRundownHandles(), //
39 mWaitStartup(false), //
43 assert(mDatabaseHandler!=NULL);
44 assert(mSocketHandler!=NULL);
45 assert(mControlSender!=NULL);
48 CAmCommandReceiver::CAmCommandReceiver(CAmDatabaseHandler *iDatabaseHandler, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler, CAmDbusWrapper *iDBusWrapper) :
49 mDatabaseHandler(iDatabaseHandler), //
50 mControlSender(iControlSender), //
51 mDBusWrapper(iDBusWrapper), //
52 mSocketHandler(iSocketHandler), //
53 mListStartupHandles(), //
54 mListRundownHandles(), //
55 mWaitStartup(false), //
58 assert(mDatabaseHandler!=NULL);
59 assert(mSocketHandler!=NULL);
60 assert(mControlSender!=NULL);
61 assert(mDBusWrapper!=NULL);
64 CAmCommandReceiver::~CAmCommandReceiver()
68 am_Error_e CAmCommandReceiver::connect(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t & mainConnectionID)
70 logInfo("CommandReceiver::connect got called, sourceID=", sourceID, "sinkID=", sinkID);
71 return (mControlSender->hookUserConnectionRequest(sourceID, sinkID, mainConnectionID));
74 am_Error_e CAmCommandReceiver::disconnect(const am_mainConnectionID_t mainConnectionID)
76 logInfo("CommandReceiver::disconnect got called, mainConnectionID=", mainConnectionID);
77 return (mControlSender->hookUserDisconnectionRequest(mainConnectionID));
80 am_Error_e CAmCommandReceiver::setVolume(const am_sinkID_t sinkID, const am_mainVolume_t volume)
82 logInfo("CommandReceiver::setVolume got called, sinkID=", sinkID, "volume=", volume);
83 return (mControlSender->hookUserVolumeChange(sinkID, volume));
86 am_Error_e CAmCommandReceiver::volumeStep(const am_sinkID_t sinkID, const int16_t volumeStep)
88 logInfo("CommandReceiver::volumeStep got called, sinkID=", sinkID, "volumeStep=", volumeStep);
89 return (mControlSender->hookUserVolumeStep(sinkID, volumeStep));
92 am_Error_e CAmCommandReceiver::setSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState)
94 logInfo("CommandReceiver::setSinkMuteState got called, sinkID=", sinkID, "muteState=", muteState);
95 return (mControlSender->hookUserSetSinkMuteState(sinkID, muteState));
98 am_Error_e CAmCommandReceiver::setMainSinkSoundProperty(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID)
100 logInfo("CommandReceiver::setMainSinkSoundProperty got called, sinkID=", sinkID, "soundPropertyType=", soundProperty.type, "soundPropertyValue=", soundProperty.value);
101 return (mControlSender->hookUserSetMainSinkSoundProperty(sinkID, soundProperty));
104 am_Error_e CAmCommandReceiver::setMainSourceSoundProperty(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID)
106 logInfo("CommandReceiver::setMainSourceSoundProperty got called, sourceID=", sourceID, "soundPropertyType=", soundProperty.type, "soundPropertyValue=", soundProperty.value);
107 return (mControlSender->hookUserSetMainSourceSoundProperty(sourceID, soundProperty));
110 am_Error_e CAmCommandReceiver::setSystemProperty(const am_SystemProperty_s & property)
112 logInfo("CommandReceiver::setSystemProperty got called", "type=", property.type, "soundPropertyValue=", property.value);
113 return (mControlSender->hookUserSetSystemProperty(property));
116 am_Error_e CAmCommandReceiver::getListMainConnections(std::vector<am_MainConnectionType_s> & listConnections) const
118 return (mDatabaseHandler->getListVisibleMainConnections(listConnections));
122 am_Error_e CAmCommandReceiver::getListMainSinks(std::vector<am_SinkType_s>& listMainSinks) const
124 return (mDatabaseHandler->getListMainSinks(listMainSinks));
127 am_Error_e CAmCommandReceiver::getListMainSources(std::vector<am_SourceType_s>& listMainSources) const
129 return (mDatabaseHandler->getListMainSources(listMainSources));
132 am_Error_e CAmCommandReceiver::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_MainSoundProperty_s> & listSoundProperties) const
134 return (mDatabaseHandler->getListMainSinkSoundProperties(sinkID, listSoundProperties));
137 am_Error_e CAmCommandReceiver::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_MainSoundProperty_s> & listSourceProperties) const
139 return (mDatabaseHandler->getListMainSourceSoundProperties(sourceID, listSourceProperties));
142 am_Error_e CAmCommandReceiver::getListSourceClasses(std::vector<am_SourceClass_s> & listSourceClasses) const
144 return (mDatabaseHandler->getListSourceClasses(listSourceClasses));
147 am_Error_e CAmCommandReceiver::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
149 return (mDatabaseHandler->getListSinkClasses(listSinkClasses));
152 am_Error_e CAmCommandReceiver::getListSystemProperties(std::vector<am_SystemProperty_s> & listSystemProperties) const
154 return (mDatabaseHandler->getListSystemProperties(listSystemProperties));
157 am_Error_e CAmCommandReceiver::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const
159 return (mDatabaseHandler->getTimingInformation(mainConnectionID, delay));
162 am_Error_e CAmCommandReceiver::getDBusConnectionWrapper(CAmDbusWrapper*& dbusConnectionWrapper) const
164 #ifdef WITH_DBUS_WRAPPER
165 dbusConnectionWrapper = mDBusWrapper;
169 #endif /*WITH_DBUS_WRAPPER*/
172 am_Error_e CAmCommandReceiver::getSocketHandler(CAmSocketHandler *& socketHandler) const
174 socketHandler = mSocketHandler;
178 void CAmCommandReceiver::getInterfaceVersion(std::string & version) const
180 version = CommandReceiveVersion;
183 void CAmCommandReceiver::confirmCommandReady(const uint16_t handle)
185 mListStartupHandles.erase(std::remove(mListStartupHandles.begin(), mListStartupHandles.end(), handle), mListStartupHandles.end());
186 if (mWaitStartup && mListStartupHandles.empty())
187 mControlSender->confirmCommandReady();
190 void CAmCommandReceiver::confirmCommandRundown(const uint16_t handle)
192 mListRundownHandles.erase(std::remove(mListRundownHandles.begin(), mListRundownHandles.end(), handle), mListRundownHandles.end());
193 if (mWaitRundown && mListRundownHandles.empty())
194 mControlSender->confirmCommandRundown();
197 uint16_t CAmCommandReceiver::getStartupHandle()
199 uint16_t handle = ++handleCount; //todo: handle overflow
200 mListStartupHandles.push_back(handle);
204 uint16_t CAmCommandReceiver::getRundownHandle()
206 uint16_t handle = ++handleCount; //todo: handle overflow
207 mListRundownHandles.push_back(handle);
211 void CAmCommandReceiver::waitOnStartup(bool startup)
213 mWaitStartup = startup;
216 void CAmCommandReceiver::waitOnRundown(bool rundown)
218 mWaitRundown = rundown;