* add setSinkVolume to telnetserver
[profile/ivi/audiomanager.git] / AudioManagerDaemon / src / CAmCommandReceiver.cpp
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 CAmCommandReceiver.cpp
18  * For further information see http://www.genivi.org/.
19  *
20  */
21
22 #include "CAmCommandReceiver.h"
23 #include <cassert>
24 #include <algorithm>
25 #include "CAmDatabaseHandler.h"
26 #include "CAmControlSender.h"
27 #include "shared/CAmDltWrapper.h"
28 #include "shared/CAmSocketHandler.h"
29
30 namespace am
31 {
32
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), //
40         mWaitRundown(false)
41
42 {
43     assert(mDatabaseHandler!=NULL);
44     assert(mSocketHandler!=NULL);
45     assert(mControlSender!=NULL);
46 }
47
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), //
56         mWaitRundown(false)
57 {
58     assert(mDatabaseHandler!=NULL);
59     assert(mSocketHandler!=NULL);
60     assert(mControlSender!=NULL);
61     assert(mDBusWrapper!=NULL);
62 }
63
64 CAmCommandReceiver::~CAmCommandReceiver()
65 {
66 }
67
68 am_Error_e CAmCommandReceiver::connect(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t & mainConnectionID)
69 {
70     logInfo("CommandReceiver::connect got called, sourceID=", sourceID, "sinkID=", sinkID);
71     return (mControlSender->hookUserConnectionRequest(sourceID, sinkID, mainConnectionID));
72 }
73
74 am_Error_e CAmCommandReceiver::disconnect(const am_mainConnectionID_t mainConnectionID)
75 {
76     logInfo("CommandReceiver::disconnect got called, mainConnectionID=", mainConnectionID);
77     return (mControlSender->hookUserDisconnectionRequest(mainConnectionID));
78 }
79
80 am_Error_e CAmCommandReceiver::setVolume(const am_sinkID_t sinkID, const am_mainVolume_t volume)
81 {
82     logInfo("CommandReceiver::setVolume got called, sinkID=", sinkID, "volume=", volume);
83     return (mControlSender->hookUserVolumeChange(sinkID, volume));
84 }
85
86 am_Error_e CAmCommandReceiver::volumeStep(const am_sinkID_t sinkID, const int16_t volumeStep)
87 {
88     logInfo("CommandReceiver::volumeStep got called, sinkID=", sinkID, "volumeStep=", volumeStep);
89     return (mControlSender->hookUserVolumeStep(sinkID, volumeStep));
90 }
91
92 am_Error_e CAmCommandReceiver::setSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState)
93 {
94     logInfo("CommandReceiver::setSinkMuteState got called, sinkID=", sinkID, "muteState=", muteState);
95     return (mControlSender->hookUserSetSinkMuteState(sinkID, muteState));
96 }
97
98 am_Error_e CAmCommandReceiver::setMainSinkSoundProperty(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID)
99 {
100     logInfo("CommandReceiver::setMainSinkSoundProperty got called, sinkID=", sinkID, "soundPropertyType=", soundProperty.type, "soundPropertyValue=", soundProperty.value);
101     return (mControlSender->hookUserSetMainSinkSoundProperty(sinkID, soundProperty));
102 }
103
104 am_Error_e CAmCommandReceiver::setMainSourceSoundProperty(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID)
105 {
106     logInfo("CommandReceiver::setMainSourceSoundProperty got called, sourceID=", sourceID, "soundPropertyType=", soundProperty.type, "soundPropertyValue=", soundProperty.value);
107     return (mControlSender->hookUserSetMainSourceSoundProperty(sourceID, soundProperty));
108 }
109
110 am_Error_e CAmCommandReceiver::setSystemProperty(const am_SystemProperty_s & property)
111 {
112     logInfo("CommandReceiver::setSystemProperty got called", "type=", property.type, "soundPropertyValue=", property.value);
113     return (mControlSender->hookUserSetSystemProperty(property));
114 }
115
116 am_Error_e CAmCommandReceiver::getListMainConnections(std::vector<am_MainConnectionType_s> & listConnections) const
117 {
118     return (mDatabaseHandler->getListVisibleMainConnections(listConnections));
119
120 }
121
122 am_Error_e CAmCommandReceiver::getListMainSinks(std::vector<am_SinkType_s>& listMainSinks) const
123 {
124     return (mDatabaseHandler->getListMainSinks(listMainSinks));
125 }
126
127 am_Error_e CAmCommandReceiver::getListMainSources(std::vector<am_SourceType_s>& listMainSources) const
128 {
129     return (mDatabaseHandler->getListMainSources(listMainSources));
130 }
131
132 am_Error_e CAmCommandReceiver::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_MainSoundProperty_s> & listSoundProperties) const
133 {
134     return (mDatabaseHandler->getListMainSinkSoundProperties(sinkID, listSoundProperties));
135 }
136
137 am_Error_e CAmCommandReceiver::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_MainSoundProperty_s> & listSourceProperties) const
138 {
139     return (mDatabaseHandler->getListMainSourceSoundProperties(sourceID, listSourceProperties));
140 }
141
142 am_Error_e CAmCommandReceiver::getListSourceClasses(std::vector<am_SourceClass_s> & listSourceClasses) const
143 {
144     return (mDatabaseHandler->getListSourceClasses(listSourceClasses));
145 }
146
147 am_Error_e CAmCommandReceiver::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
148 {
149     return (mDatabaseHandler->getListSinkClasses(listSinkClasses));
150 }
151
152 am_Error_e CAmCommandReceiver::getListSystemProperties(std::vector<am_SystemProperty_s> & listSystemProperties) const
153 {
154     return (mDatabaseHandler->getListSystemProperties(listSystemProperties));
155 }
156
157 am_Error_e CAmCommandReceiver::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const
158 {
159     return (mDatabaseHandler->getTimingInformation(mainConnectionID, delay));
160 }
161
162 am_Error_e CAmCommandReceiver::getDBusConnectionWrapper(CAmDbusWrapper*& dbusConnectionWrapper) const
163 {
164 #ifdef WITH_DBUS_WRAPPER
165     dbusConnectionWrapper = mDBusWrapper;
166     return (E_OK);
167 #else
168     return (E_UNKNOWN);
169 #endif /*WITH_DBUS_WRAPPER*/
170 }
171
172 am_Error_e CAmCommandReceiver::getSocketHandler(CAmSocketHandler *& socketHandler) const
173 {
174     socketHandler = mSocketHandler;
175     return (E_OK);
176 }
177
178 void CAmCommandReceiver::getInterfaceVersion(std::string & version) const
179 {
180     version = CommandReceiveVersion;
181 }
182
183 void CAmCommandReceiver::confirmCommandReady(const uint16_t handle)
184 {
185     mListStartupHandles.erase(std::remove(mListStartupHandles.begin(), mListStartupHandles.end(), handle), mListStartupHandles.end());
186     if (mWaitStartup && mListStartupHandles.empty())
187         mControlSender->confirmCommandReady();
188 }
189
190 void CAmCommandReceiver::confirmCommandRundown(const uint16_t handle)
191 {
192     mListRundownHandles.erase(std::remove(mListRundownHandles.begin(), mListRundownHandles.end(), handle), mListRundownHandles.end());
193     if (mWaitRundown && mListRundownHandles.empty())
194         mControlSender->confirmCommandRundown();
195 }
196
197 uint16_t CAmCommandReceiver::getStartupHandle()
198 {
199     uint16_t handle = ++handleCount; //todo: handle overflow
200     mListStartupHandles.push_back(handle);
201     return (handle);
202 }
203
204 uint16_t CAmCommandReceiver::getRundownHandle()
205 {
206     uint16_t handle = ++handleCount; //todo: handle overflow
207     mListRundownHandles.push_back(handle);
208     return (handle);
209 }
210
211 void CAmCommandReceiver::waitOnStartup(bool startup)
212 {
213     mWaitStartup = startup;
214 }
215
216 void CAmCommandReceiver::waitOnRundown(bool rundown)
217 {
218     mWaitRundown = rundown;
219 }
220
221 }