1 2 /* 3 * Copyright (c) 2021-2025 Huawei Device Co., Ltd. 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ST_AUDIO_ROUTER_MAP_H 18 #define ST_AUDIO_ROUTER_MAP_H 19 20 #include <bitset> 21 #include <list> 22 #include <string> 23 #include <unordered_map> 24 #include <unordered_set> 25 #include <mutex> 26 #include "audio_device_info.h" 27 28 namespace OHOS { 29 namespace AudioStandard { 30 class AudioRouteMap { 31 public: GetInstance()32 static AudioRouteMap& GetInstance() 33 { 34 static AudioRouteMap instance; 35 return instance; 36 } 37 std::string GetDeviceInfoByUidAndPid(int32_t uid, int32_t pid); 38 bool DelRouteMapInfoByKey(int32_t uid); 39 void AddRouteMapInfo(int32_t uid, std::string device, int32_t pid); 40 int32_t AddFastRouteMapInfo(int32_t uid, std::string device, DeviceRole role); 41 void RemoveDeviceInRouterMap(std::string networkId); 42 void RemoveDeviceInFastRouterMap(std::string networkId); 43 void GetNetworkIDInFastRouterMap(int32_t uid, DeviceRole role, std::string& newworkId); 44 private: AudioRouteMap()45 AudioRouteMap() {} ~AudioRouteMap()46 ~AudioRouteMap() {} 47 private: 48 std::mutex fastRouterMapMutex_; // unordered_map is not concurrently-secure 49 std::mutex routerMapMutex_; // unordered_map is not concurrently-secure 50 std::unordered_map<int32_t, std::pair<std::string, int32_t>> routerMap_; 51 std::unordered_map<int32_t, std::pair<std::string, DeviceRole>> fastRouterMap_; // key:uid value:<netWorkId, Role> 52 }; 53 } 54 } 55 #endif