AudioOutputManager.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. *
  3. * Copyright (c) 2021 Project CHIP Authors
  4. * All rights reserved.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #include "AudioOutputManager.h"
  19. using namespace std;
  20. using namespace chip::app;
  21. using namespace chip::app::Clusters::AudioOutput;
  22. AudioOutputManager::AudioOutputManager()
  23. {
  24. mCurrentOutput = 1;
  25. for (int i = 1; i < 4; ++i)
  26. {
  27. OutputInfoType outputInfo;
  28. outputInfo.outputType = chip::app::Clusters::AudioOutput::OutputTypeEnum::kHdmi;
  29. // note: safe only because of use of string literal
  30. outputInfo.name = chip::CharSpan::fromCharString("HDMI");
  31. outputInfo.index = static_cast<uint8_t>(i);
  32. mOutputs.push_back(outputInfo);
  33. }
  34. }
  35. uint8_t AudioOutputManager::HandleGetCurrentOutput()
  36. {
  37. return mCurrentOutput;
  38. }
  39. CHIP_ERROR AudioOutputManager::HandleGetOutputList(AttributeValueEncoder & aEncoder)
  40. {
  41. // TODO: Insert code here
  42. return aEncoder.EncodeList([this](const auto & encoder) -> CHIP_ERROR {
  43. for (auto const & outputInfo : this->mOutputs)
  44. {
  45. ReturnErrorOnFailure(encoder.Encode(outputInfo));
  46. }
  47. return CHIP_NO_ERROR;
  48. });
  49. }
  50. bool AudioOutputManager::HandleRenameOutput(const uint8_t & index, const chip::CharSpan & name)
  51. {
  52. // TODO: Insert code here
  53. bool audioOutputRenamed = false;
  54. for (OutputInfoType & output : mOutputs)
  55. {
  56. if (output.index == index)
  57. {
  58. audioOutputRenamed = true;
  59. memcpy(this->Data(index), name.data(), name.size());
  60. output.name = chip::CharSpan(this->Data(index), name.size());
  61. }
  62. }
  63. return audioOutputRenamed;
  64. }
  65. bool AudioOutputManager::HandleSelectOutput(const uint8_t & index)
  66. {
  67. // TODO: Insert code here
  68. bool audioOutputSelected = false;
  69. for (OutputInfoType & output : mOutputs)
  70. {
  71. if (output.index == index)
  72. {
  73. audioOutputSelected = true;
  74. mCurrentOutput = index;
  75. }
  76. }
  77. return audioOutputSelected;
  78. }