|
| 1 | +/******************************************************************************/ |
| 2 | +// File: SourceInterface.cpp |
| 3 | +/******************************************************************************/ |
| 4 | + |
| 5 | +#include "SourceInterface.h" |
| 6 | + |
| 7 | +/******************************************************************************/ |
| 8 | +// Function: SourceInterface |
| 9 | +/******************************************************************************/ |
| 10 | +SourceInterface::SourceInterface() |
| 11 | +{ |
| 12 | +} |
| 13 | + |
| 14 | +/******************************************************************************/ |
| 15 | +// Function: ~SourceInterface |
| 16 | +/******************************************************************************/ |
| 17 | +SourceInterface::~SourceInterface() |
| 18 | +{ |
| 19 | +} |
| 20 | + |
| 21 | +/******************************************************************************/ |
| 22 | +// Function: Init |
| 23 | +/******************************************************************************/ |
| 24 | +void SourceInterface::Init() |
| 25 | +{ |
| 26 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "SourceInterface::Init - For ControlsInst"); |
| 27 | + std::string domain1 = "local"; |
| 28 | + std::string connection1 = "dbusconnection"; |
| 29 | + std::string instance1 = "AudioPresCtrl.controlsInst"; //For Settings use - AudioPresCtrl.settingsInst |
| 30 | + |
| 31 | + audioControlsAvailable = false; |
| 32 | + #ifdef CONNECT_SERVICES |
| 33 | + audioControlsProxy = ResourceMaster::getInstance()->getRuntime()->buildProxy<audioPresCtrlControlsProxy>(domain1, instance1, connection1); |
| 34 | + #else |
| 35 | + audioControlsProxy = nullptr; |
| 36 | + #endif |
| 37 | + |
| 38 | + if (audioControlsProxy != nullptr) |
| 39 | + { |
| 40 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "SourceInterface::Init: AudioControlProxy is Found"); |
| 41 | + audioControlsProxy->getProxyStatusEvent().subscribe(std::bind(&SourceInterface::statusEventListenerAudioControl, this, _1)); |
| 42 | + audioControlsProxy->getEntSourceListAttribute().getChangedEvent().subscribe(std::bind(&SourceInterface::ReceiveEntSourceList, this, _1)); |
| 43 | + audioControlsProxy->getActiveAudioSourceAttribute().getChangedEvent().subscribe(std::bind(&SourceInterface::ReceiveActiveAudioSource, this, _1)); |
| 44 | + } |
| 45 | + |
| 46 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "SourceInterface::Init - For SettingsInst"); |
| 47 | + |
| 48 | + std::string domain2 = "local"; |
| 49 | + std::string connection2 = "dbusconnection"; |
| 50 | + std::string instance2 = "AudioPresCtrl.settingsInst"; |
| 51 | + settingsProxyAvailable = false; |
| 52 | + |
| 53 | + #ifdef CONNECT_SERVICES |
| 54 | + audioSettingsProxy = ResourceMaster::getInstance()->getRuntime()->buildProxy<v1_0::com::harman::audio::audioPresCtrl::audioPresCtrlSettingsProxy>(domain2,instance2,connection2); |
| 55 | + #else |
| 56 | + audioSettingsProxy = nullptr; |
| 57 | + #endif |
| 58 | + |
| 59 | + if (audioSettingsProxy != nullptr) |
| 60 | + { |
| 61 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "AudioResourceImpl::AudioResourceImpl: Audio Settings proxy Found"); |
| 62 | + audioSettingsProxy->getProxyStatusEvent().subscribe(std::bind(&SourceInterface::statusEventListenerAudioSettings,this,_1)); |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +void SourceInterface::statusEventListenerAudioControl(CommonAPI::AvailabilityStatus status) |
| 67 | +{ |
| 68 | + if(status == CommonAPI::AvailabilityStatus::AVAILABLE ) |
| 69 | + { |
| 70 | + audioControlsAvailable = true; |
| 71 | + if(audioControlsProxy != nullptr) |
| 72 | + { |
| 73 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "SourceInterface::statusEventListenerAudioControl: AudioControlProxy attach successful"); |
| 74 | + } |
| 75 | + } |
| 76 | + else |
| 77 | + { |
| 78 | + audioControlsAvailable = false; |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +/******************************************************************************/ |
| 83 | +// Function: SendRequestInformationSource |
| 84 | +/******************************************************************************/ |
| 85 | +void SourceInterface::SendRequestInformationSource() |
| 86 | +{ |
| 87 | + //TODO: Request for Active Ent Source |
| 88 | + if (audioControlsProxy != nullptr) |
| 89 | + audioControlsProxy->getActiveEntSrcAttribute().getValueAsync(std::bind(&SourceInterface::getActiveEntSrcValueAsyncCb, this, _1, _2)); |
| 90 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "SourceInterface::SendRequestInformationSource"); |
| 91 | + if (audioControlsProxy != nullptr) |
| 92 | + audioControlsProxy->SetEntertainmentSrcAsync(audioPresCtrlTypes::eEntertainmentSrcs::SRC_USB1, std::bind(&SourceInterface::SetEntertainmentSrcAsyncCb, this, _1 , _2)); |
| 93 | +} |
| 94 | + |
| 95 | +void SourceInterface::SetEntertainmentSrcAsyncCb(const CommonAPI::CallStatus& status, const audioPresCtrlTypes::eAudioPresErrors& error) |
| 96 | +{ |
| 97 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "SourceInterface::SetEntertainmentSrcAsyncCb - Status: %d, Error: %d", status, error); |
| 98 | +} |
| 99 | + |
| 100 | +void SourceInterface::getActiveEntSrcValueAsyncCb(const CommonAPI::CallStatus& status, uint64_t value) |
| 101 | +{ |
| 102 | + //audioPresCtrlTypes::eEntertainmentSrcs entSrc = (audioPresCtrlTypes::eEntertainmentSrcs::Literal)value; |
| 103 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "SourceInterface::getActiveEntSrcValueAsyncCb - Status: %d, ActiveEntSrcValue: %d", status, value); |
| 104 | +} |
| 105 | + |
| 106 | +/******************************************************************************/ |
| 107 | +// Function: SendReleaseInformationSource |
| 108 | +/******************************************************************************/ |
| 109 | +void SourceInterface::SendReleaseInformationSource() |
| 110 | +{ |
| 111 | +} |
| 112 | + |
| 113 | +/******************************************************************************/ |
| 114 | +// Function: SendSetEntertainmentSource |
| 115 | +/******************************************************************************/ |
| 116 | +void SourceInterface::SendSetEntertainmentSource() |
| 117 | +{ |
| 118 | + if (audioControlsProxy != nullptr) |
| 119 | + audioControlsProxy->SetEntertainmentSrcAsync(audioPresCtrlTypes::eEntertainmentSrcs::SRC_AUDIO_AUX, std::bind(&SourceInterface::SetEntertainmentSrcAsyncCb, this, _1 , _2)); |
| 120 | +} |
| 121 | + |
| 122 | +/******************************************************************************/ |
| 123 | +// Function: ReceiveActiveAudioSource |
| 124 | +/******************************************************************************/ |
| 125 | +void SourceInterface::ReceiveActiveAudioSource(audioPresCtrlTypes::SourceId sourceId) |
| 126 | +{ |
| 127 | + QVariantMap data; |
| 128 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "SourceInterface::ReceiveActiveAudioSource - sourceId: %d", sourceId); |
| 129 | + ResourceUpdate("STR_ACTIVEAUDIOSOURCE", QVariant(data)); |
| 130 | + return; |
| 131 | +} |
| 132 | + |
| 133 | +/******************************************************************************/ |
| 134 | +// Function: ReceiveEntSourceList |
| 135 | +/******************************************************************************/ |
| 136 | +void SourceInterface::ReceiveEntSourceList(audioPresCtrlTypes::EntSourceList sourceList) |
| 137 | +{ |
| 138 | + QVariantMap data; |
| 139 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "SourceInterface::ReceiveEntSourceList - sourceList Size: %d", sourceList.size()); |
| 140 | + |
| 141 | + //for (auto it=sourceList.begin(); it != sourceList.end(); it++) |
| 142 | + for (std::unordered_map<audioPresCtrlTypes::eEntertainmentSrcs, audioPresCtrlTypes::eSourceAvailablity>::const_iterator it = sourceList.begin(); it != sourceList.end(); ++it) |
| 143 | + { |
| 144 | + data[QString::number(it->first)] = QVariant(it->second); |
| 145 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "SourceInterface::ReceiveEntSourceList - SourceID: %d, Availability: %d", it->first, it->second); |
| 146 | + } |
| 147 | + |
| 148 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "SourceInterface::ReceiveEntSourceList - Send ResourceUpdate"); |
| 149 | + |
| 150 | + ResourceUpdate("STR_ENTSOURCELIST", QVariant(data)); |
| 151 | + |
| 152 | + return; |
| 153 | +} |
| 154 | + |
| 155 | +/******************************************************************************/ |
| 156 | +// Function: SendSetBass |
| 157 | +/******************************************************************************/ |
| 158 | +void SourceInterface::SendSetBass(QVariant data) |
| 159 | +{ |
| 160 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "SendSetBass :: %d",data.toInt()); |
| 161 | + if( audioSettingsProxy != nullptr) |
| 162 | + { |
| 163 | + audioSettingsProxy->getBassAttribute().setValueAsync(data.toInt(),std::bind(&SourceInterface::setResponse,this,_1,_2)); |
| 164 | + } |
| 165 | +} |
| 166 | + |
| 167 | +/******************************************************************************/ |
| 168 | +// Function: SendSetMidRange |
| 169 | +/******************************************************************************/ |
| 170 | +void SourceInterface::SendSetMidRange(QVariant data) |
| 171 | +{ |
| 172 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "SendSetMidRange :: %d",data.toInt()); |
| 173 | + if( audioSettingsProxy != nullptr) |
| 174 | + { |
| 175 | + audioSettingsProxy->getMidAttribute().setValueAsync(data.toInt(),std::bind(&SourceInterface::setResponse,this,_1,_2)); |
| 176 | + } |
| 177 | +} |
| 178 | + |
| 179 | +/******************************************************************************/ |
| 180 | +// Function: SendSetTreble |
| 181 | +/******************************************************************************/ |
| 182 | +void SourceInterface::SendSetTreble(QVariant data) |
| 183 | +{ |
| 184 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "SendSetTreble :: %d",data.toInt()); |
| 185 | + if( audioSettingsProxy != nullptr) |
| 186 | + { |
| 187 | + audioSettingsProxy->getTrebleAttribute().setValueAsync(data.toInt(),std::bind(&SourceInterface::setResponse,this,_1,_2)); |
| 188 | + } |
| 189 | +} |
| 190 | + |
| 191 | +/******************************************************************************/ |
| 192 | +// Function: SendSetBalance |
| 193 | +/******************************************************************************/ |
| 194 | +void SourceInterface::SendSetBalance(QVariant data) |
| 195 | +{ |
| 196 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "SendSetBalance :: %d",data.toInt()); |
| 197 | + |
| 198 | + if( audioSettingsProxy != nullptr) |
| 199 | + { |
| 200 | + audioSettingsProxy->getBalanceAttribute().setValueAsync(data.toInt(),std::bind(&SourceInterface::setResponse,this,_1,_2)); |
| 201 | + } |
| 202 | +} |
| 203 | + |
| 204 | +/******************************************************************************/ |
| 205 | +// Function: SendSetFade |
| 206 | +/******************************************************************************/ |
| 207 | +void SourceInterface::SendSetFade(QVariant data) |
| 208 | +{ |
| 209 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "SendSetFade :: %d",data.toInt()); |
| 210 | + |
| 211 | + if( audioSettingsProxy != nullptr) |
| 212 | + { |
| 213 | + audioSettingsProxy->getFadeAttribute().setValueAsync(data.toInt(),std::bind(&SourceInterface::setResponse,this,_1,_2)); |
| 214 | + } |
| 215 | +} |
| 216 | + |
| 217 | +/******************************************************************************/ |
| 218 | +// Function: SendsetSCV |
| 219 | +/******************************************************************************/ |
| 220 | +void SourceInterface::SendsetSCV(QVariant data) |
| 221 | +{ |
| 222 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "SendsetSCV :: %d",data.toInt()); |
| 223 | + |
| 224 | + if( audioSettingsProxy != nullptr) |
| 225 | + { |
| 226 | + audioSettingsProxy->getAVCModeAttribute().setValueAsync(data.toInt(),std::bind(&SourceInterface::setResponse,this,_1,_2)); |
| 227 | + } |
| 228 | +} |
| 229 | + |
| 230 | +/******************************************************************************/ |
| 231 | +// Function: ReceiveTREBLE |
| 232 | +/******************************************************************************/ |
| 233 | +void SourceInterface::ReceiveTREBLE(int16_t data) |
| 234 | +{ |
| 235 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "ReceiveTREBLE :: %d",QVariant(data).toInt()); |
| 236 | + ResourceUpdate("STR_TREBLE", QVariant(data)); |
| 237 | + return; |
| 238 | +} |
| 239 | + |
| 240 | +/******************************************************************************/ |
| 241 | +// Function: ReceiveMIDRANGE |
| 242 | +/******************************************************************************/ |
| 243 | +void SourceInterface::ReceiveMIDRANGE(int16_t data) |
| 244 | +{ |
| 245 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "ReceiveMIDRANGE :: %d",QVariant(data).toInt()); |
| 246 | + ResourceUpdate("STR_MIDRANGE", QVariant(data)); |
| 247 | + return; |
| 248 | +} |
| 249 | + |
| 250 | +/******************************************************************************/ |
| 251 | +// Function: ReceiveBASS |
| 252 | +/******************************************************************************/ |
| 253 | +void SourceInterface::ReceiveBASS(int16_t data) |
| 254 | +{ |
| 255 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "ReceiveBASS :: %d",QVariant(data).toInt()); |
| 256 | + ResourceUpdate("STR_BASS", QVariant(data)); |
| 257 | + return; |
| 258 | +} |
| 259 | + |
| 260 | +/******************************************************************************/ |
| 261 | +// Function: ReceiveBALANCE |
| 262 | +/******************************************************************************/ |
| 263 | +void SourceInterface::ReceiveBALANCE(int16_t data) |
| 264 | +{ |
| 265 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "ReceiveBALANCE :: %d",QVariant(data).toInt()); |
| 266 | + ResourceUpdate("STR_BALANCE", QVariant(data)); |
| 267 | + |
| 268 | + return; |
| 269 | +} |
| 270 | + |
| 271 | +/******************************************************************************/ |
| 272 | +// Function: ReceiveFADE |
| 273 | +/******************************************************************************/ |
| 274 | +void SourceInterface::ReceiveFADE(int16_t data) |
| 275 | +{ |
| 276 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "ReceiveFADE :: %d",QVariant(data).toInt()); |
| 277 | + ResourceUpdate("STR_FADE", QVariant(data)); |
| 278 | + |
| 279 | + return; |
| 280 | +} |
| 281 | + |
| 282 | +/******************************************************************************/ |
| 283 | +// Function: ReceiveSCV |
| 284 | +/******************************************************************************/ |
| 285 | +void SourceInterface::ReceiveSCV(uint16_t data) |
| 286 | +{ |
| 287 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "ReceiveSCV :: %d",QVariant(data).toInt()); |
| 288 | + ResourceUpdate("STR_SCV", QVariant(data)); |
| 289 | + |
| 290 | + return; |
| 291 | +} |
| 292 | +void SourceInterface::statusEventListenerAudioSettings(CommonAPI::AvailabilityStatus status) |
| 293 | +{ |
| 294 | + if(status == CommonAPI::AvailabilityStatus::AVAILABLE ) |
| 295 | + { |
| 296 | + settingsProxyAvailable = true; |
| 297 | + if( audioSettingsProxy != nullptr) |
| 298 | + { |
| 299 | + audioSettingsProxy->getTrebleAttribute().getChangedEvent().subscribe(std::bind(&SourceInterface::ReceiveTREBLE,this,_1)); |
| 300 | + audioSettingsProxy->getMidAttribute().getChangedEvent().subscribe(std::bind(&SourceInterface::ReceiveMIDRANGE,this,_1)); |
| 301 | + audioSettingsProxy->getBassAttribute().getChangedEvent().subscribe(std::bind(&SourceInterface::ReceiveBASS,this,_1)); |
| 302 | + audioSettingsProxy->getBalanceAttribute().getChangedEvent().subscribe(std::bind(&SourceInterface::ReceiveBALANCE,this,_1)); |
| 303 | + audioSettingsProxy->getFadeAttribute().getChangedEvent().subscribe(std::bind(&SourceInterface::ReceiveFADE,this,_1)); |
| 304 | + audioSettingsProxy->getAVCModeAttribute().getChangedEvent().subscribe(std::bind(&SourceInterface::ReceiveSCV,this,_1)); |
| 305 | + } |
| 306 | + } |
| 307 | + else |
| 308 | + { |
| 309 | + settingsProxyAvailable = false; |
| 310 | + } |
| 311 | +} |
| 312 | + |
| 313 | +void SourceInterface::setResponse(CommonAPI::CallStatus status, int value) |
| 314 | +{ |
| 315 | + if ( status == CommonAPI::CallStatus::SUCCESS) |
| 316 | + { |
| 317 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "SourceInterface::setResponse SUCCESS %d ",value ); |
| 318 | + } |
| 319 | + else |
| 320 | + { |
| 321 | + LOG_INFO(Log::e_LOG_CONTEXT_AUDIO, "SourceInterface::setResponse FAIL %d", value); |
| 322 | + } |
| 323 | +} |
0 commit comments