1 /* 2 * Copyright (c) 2024 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_DP_STATIC_CAPABILITY_LOADER_H 17 #define OHOS_DP_STATIC_CAPABILITY_LOADER_H 18 19 #include "cJSON.h" 20 #include <unordered_map> 21 22 #include "characteristic_profile.h" 23 #include "distributed_device_profile_log.h" 24 #include "single_instance.h" 25 26 namespace OHOS { 27 namespace DistributedDeviceProfile { 28 class StaticCapabilityLoader { 29 DECLARE_SINGLE_INSTANCE(StaticCapabilityLoader) 30 31 public: 32 int32_t Init(); 33 int32_t UnInit(); 34 int32_t LoadStaticCapability(std::string& staticCapability); 35 int32_t LoadStaticInfo(const std::string& staticCapability, std::string& staticVersion, 36 std::unordered_map<std::string, CharacteristicProfile>& charProfiles); 37 int32_t LoadStaticProfiles(const std::string& deviceId, const std::string& staticCapability, 38 const std::string& staticVersion, std::unordered_map<std::string, CharacteristicProfile>& charProfiles); 39 40 private: 41 int32_t LoadJsonFile(const std::string& filePath, std::string& fileContent); 42 int32_t GetStaticCapability(const cJSON* const staticCapabilityJson, std::string& staticCapability); 43 int32_t GetStaticInfo(const cJSON* const staticInfoJson, const std::string& staticCapability, 44 std::string& staticVersion, std::unordered_map<std::string, CharacteristicProfile>& charProfiles); 45 int32_t GetStaticInfoByVersion(const std::string& deviceId, const std::string& staticCapability, 46 const cJSON* const staticInfoJson, const std::string& staticVersion, 47 std::unordered_map<std::string, CharacteristicProfile>& charProfiles); 48 cJSON* GetLatestStaticInfoJson(const cJSON* const staticInfoJson); 49 cJSON* GetStaticInfoJsonByVersion(const cJSON* const staticInfoJson, const std::string& staticVersion); 50 int32_t GetStaticVersion(const cJSON* const staticInfoJson, std::string& staticVersion); 51 int32_t GenerateStaticProfiles(const std::string& deviceId, const std::string& staticCapability, 52 const cJSON* const staticInfoJson, std::unordered_map<std::string, CharacteristicProfile>& charProfiles); 53 void InitStaticCapability(int32_t size, std::string& staticCapability); 54 void SetStaticCapability(const cJSON* const staticCapabilities, std::string& staticCapability); 55 void SetStaticCapabilityFlag(const std::string& handlerName, const std::string& handlerLoc, 56 std::string& staticCapability); 57 bool GetStaticCapabilityValue(const std::string& handlerLoc); 58 bool HasStaticCapability(const std::string& serviceId, const std::string& staticCapability); 59 bool StaticVersionCheck(const std::string& peerVersion, const std::string& localVersion); 60 bool IsValidVersion(const std::string& version); 61 }; 62 } 63 } 64 #endif // OHOS_DP_STATIC_CAPABILITY_LOADER_H 65