1 /* 2 * Copyright (c) 2023 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_PROFILE_UTILS_H 17 #define OHOS_DP_PROFILE_UTILS_H 18 19 #include <list> 20 #include <string> 21 #include <vector> 22 #include <map> 23 #include "trust_device_profile.h" 24 #include "access_control_profile.h" 25 #include "device_profile.h" 26 #include "service_profile.h" 27 #include "characteristic_profile.h" 28 #include "distributed_device_profile_constants.h" 29 #include "distributed_device_profile_errors.h" 30 #include "distributed_device_profile_enums.h" 31 #include "values_bucket.h" 32 33 namespace OHOS { 34 namespace DistributedDeviceProfile { 35 using namespace OHOS::NativeRdb; 36 37 class ProfileUtils { 38 public: 39 static std::string GetAnonyString(const std::string& value); 40 static std::vector<std::string> GetOnlineDevices(); 41 static std::string GetLocalUdidFromDM(); 42 static std::vector<std::string> FilterOnlineDevices(const std::vector<std::string>& deviceList); 43 static ProfileType GetProfileType(const std::string& key); 44 static bool StartsWith(const std::string& str, const std::string prefix); 45 static bool IsKeyValid(const std::string& key); 46 static std::string GenerateDeviceProfileKey(const std::string& deviceId); 47 static std::string GenerateServiceProfileKey(const std::string& deviceId, const std::string& serviceName); 48 static std::string GenerateCharProfileKey(const std::string& deviceId, const std::string& serviceName, 49 const std::string& charKey); 50 static int32_t TrustDeviceProfileToEntries(const TrustDeviceProfile& profile, ValuesBucket& values); 51 static int32_t AccessControlProfileToEntries(const AccessControlProfile& profile, ValuesBucket& values); 52 static int32_t AccesserToEntries(const AccessControlProfile& aclProfile, ValuesBucket& values); 53 static int32_t AccesseeToEntries(const AccessControlProfile& aclProfile, ValuesBucket& values); 54 static int32_t DeviceProfileToEntries(const DeviceProfile& profile, std::map<std::string, std::string>& values); 55 static int32_t ServiceProfileToEntries(const ServiceProfile& profile, std::map<std::string, std::string>& values); 56 static int32_t CharacteristicProfileToEntries(const CharacteristicProfile& profile, 57 std::map<std::string, std::string>& values); 58 static int32_t EntriesToTrustDeviceProfile(const ValuesBucket& values, TrustDeviceProfile& profile); 59 static int32_t EntriesToAccessControlProfile(const ValuesBucket& values, AccessControlProfile& profile); 60 static int32_t EntriesToAccesser(const ValuesBucket& values, Accesser& accesser); 61 static int32_t EntriesToAccessee(const ValuesBucket& values, Accessee& accessee); 62 static int32_t EntriesToDeviceProfile(std::map<std::string, std::string> values, DeviceProfile& profile); 63 static int32_t EntriesToServiceProfile(std::map<std::string, std::string> values, ServiceProfile& profile); 64 static int32_t EntriesToCharProfile(std::map<std::string, std::string> values, CharacteristicProfile& profile); 65 static std::string GenerateDBKey(const std::string& profileKey, const std::string& profileProperty); 66 static std::string GetProfileKey(const std::string& dbKey); 67 static std::string GetDeviceIdByDBKey(const std::string& dbKey); 68 static std::string GetServiceNameByDBKey(const std::string& dbKey); 69 static std::string GetCharKeyByDBKey(const std::string& dbKey); 70 static int32_t SplitString(const std::string& str, const std::string& splits, std::vector<std::string>& res); 71 static std::string GetProfileProperty(const std::string& dbKey); 72 static std::map<std::string, std::string> GetProfilePropertiesMap(std::map<std::string, std::string> dbEntries); 73 static std::string toString(const std::u16string& str16); 74 static bool IsPropertyValid(const std::map<std::string, std::string>& propertyMap, const std::string& property, 75 int32_t maxValue); 76 static bool IsPropertyValid(const std::map<std::string, std::string>& propertyMap, const std::string& property, 77 int32_t minValue, int32_t maxValue); 78 static bool IsPropertyValid(const std::map<std::string, std::string>& propertyMap, const std::string& property, 79 uint32_t minValue, uint32_t maxValue); 80 static bool IsPropertyValid(const std::map<std::string, std::string>& propertyMap, const std::string& property, 81 int64_t minValue, int64_t maxValue); 82 static bool GetIntValue(const ValuesBucket& values, const std::string& property, int32_t& value); 83 static bool GetStringValue(const ValuesBucket& values, const std::string& property, std::string& value); 84 static bool GetLongValue(const ValuesBucket& values, const std::string& property, int64_t& value); 85 }; 86 } // namespace DistributedDeviceProfile 87 } // namespace OHOS 88 #endif // OHOS_DP_PROFILE_UTILS_H 89