1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ST_AUDIO_ZONE_CLIENT_MANAGER_H 17 #define ST_AUDIO_ZONE_CLIENT_MANAGER_H 18 19 #include "istandard_audio_zone_client.h" 20 #include "i_audio_zone_event_dispatcher.h" 21 #include "audio_policy_server_handler.h" 22 23 namespace OHOS { 24 namespace AudioStandard { 25 class AudioZoneClientManager : public IAudioZoneEventDispatcher { 26 public: 27 explicit AudioZoneClientManager(std::shared_ptr<AudioPolicyServerHandler> handler); 28 virtual ~AudioZoneClientManager() = default; 29 30 static AudioZoneClientManager &GetInstance(); 31 int32_t RegisterAudioZoneClient(pid_t clientPid, sptr<IStandardAudioZoneClient> client); 32 void UnRegisterAudioZoneClient(pid_t clientPid); 33 bool IsRegisterAudioZoneClient(pid_t clientPid); 34 35 void DispatchEvent(std::shared_ptr<AudioZoneEvent> event) override; 36 37 void SendZoneAddEvent(pid_t clientPid, std::shared_ptr<AudioZoneDescriptor> descriptor); 38 void SendZoneRemoveEvent(pid_t clientPid, int32_t zoneId); 39 void SendZoneChangeEvent(pid_t clientPid, std::shared_ptr<AudioZoneDescriptor> descriptor, 40 AudioZoneChangeReason reason); 41 void SendZoneInterruptEvent(pid_t clientPid, int32_t zoneId, const std::string &deviceTag, 42 std::list<std::pair<AudioInterrupt, AudioFocuState>> interrupts, 43 AudioZoneInterruptReason reason); 44 45 int32_t SetSystemVolumeLevel(const pid_t clientPid, const int32_t zoneId, 46 const AudioVolumeType volumeType, const int32_t volumeLevel, const int32_t volumeFlag = 0); 47 int32_t GetSystemVolumeLevel(const pid_t clientPid, const int32_t zoneId, AudioVolumeType volumeType); 48 49 private: 50 std::unordered_map<pid_t, sptr<IStandardAudioZoneClient>> clients_; 51 std::mutex clientMutex_; 52 std::shared_ptr<AudioPolicyServerHandler> handler_; 53 }; 54 } // namespace AudioStandard 55 } // namespace OHOS 56 #endif // ST_AUDIO_ZONE_CLIENT_MANAGER_H