1 /* 2 * Copyright (C) 2022 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 OHOS_WIFI_HID2D_SERVICE_UTILS_H 17 #define OHOS_WIFI_HID2D_SERVICE_UTILS_H 18 19 #include <string> 20 #include <list> 21 #include <map> 22 #include <atomic> 23 24 namespace OHOS { 25 namespace Wifi { 26 class IpPool { 27 public: 28 static bool InitIpPool(const std::string& serverIp); 29 static std::string GetIp(const std::string& gcMac); 30 static void ReleaseIp(const std::string& gcMac); 31 static void ReleaseIpPool(); 32 33 private: 34 static bool IsValidIp(const std::string& ip); 35 36 static std::list<std::string> ipList; 37 static std::map<std::string, std::string> mapGcMacToAllocIp; 38 static constexpr int HID2D_IPPOOL_START = 3; 39 static constexpr int HID2D_IPPOOL_END = 75; 40 }; 41 42 class SharedLinkManager { 43 public: 44 static void SetGroupUid(int callingUid); 45 static void GetGroupUid(int &callingUid); 46 static void IncreaseSharedLink(); 47 static void IncreaseSharedLink(int callingUid); 48 static void DecreaseSharedLink(int callingUid); 49 static void ClearSharedLinkCount(); 50 static int GetSharedLinkCount(); 51 52 private: 53 static std::map<int, int> sharedLinkCountMap; 54 static int firstGroupUid; 55 }; 56 } // namespace Wifi 57 } // namespace OHOS 58 #endif