1 /* 2 * Copyright (c) 2021-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_DISTRIBUTED_HARDWARE_VERSION_MANAGER_H 17 #define OHOS_DISTRIBUTED_HARDWARE_VERSION_MANAGER_H 18 19 #include <mutex> 20 #include <vector> 21 #include <string> 22 23 #include "single_instance.h" 24 #include "distributed_hardware_errno.h" 25 #include "device_type.h" 26 #include "utils/impl_utils.h" 27 28 namespace OHOS { 29 namespace DistributedHardware { 30 const std::string DH_LOCAL_VERSION = "1.0"; 31 class VersionManager { 32 DECLARE_SINGLE_INSTANCE_BASE(VersionManager); 33 34 public: VersionManager()35 VersionManager() {} ~VersionManager()36 ~VersionManager() {} 37 int32_t Init(); 38 void UnInit(); 39 int32_t AddDHVersion(const std::string &uuid, const DHVersion &dhVersion); 40 int32_t RemoveDHVersion(const std::string &uuid); 41 int32_t GetDHVersion(const std::string &uuid, DHVersion &dhVersion); 42 int32_t GetCompVersion(const std::string &uuid, const DHType dhType, CompVersion &compVersion); 43 int32_t SyncDHVersionFromDB(const std::string &uuid, DHVersion &dhVersion); 44 std::string GetLocalDeviceVersion(); 45 void ShowLocalVersion(const DHVersion &dhVersion) const; 46 47 private: 48 std::unordered_map<std::string, DHVersion> dhVersions_; 49 std::mutex versionMutex_; 50 }; 51 } // namespace DistributedHardware 52 } // namespace OHOS 53 #endif 54