/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_DISTRIBUTED_HARDWARE_META_INFO_MANAGER_H #define OHOS_DISTRIBUTED_HARDWARE_META_INFO_MANAGER_H #include #include #include "kvstore_observer.h" #include "db_adapter.h" #include "event_handler.h" #include "meta_capability_info.h" class DBAdapter; namespace OHOS { namespace DistributedHardware { class MetaInfoManager : public std::enable_shared_from_this, public DistributedKv::KvStoreObserver { public: MetaInfoManager(const MetaInfoManager &) = delete; MetaInfoManager &operator = (const MetaInfoManager &) = delete; MetaInfoManager(MetaInfoManager &&) = delete; MetaInfoManager &operator = (MetaInfoManager &&) = delete; static std::shared_ptr GetInstance(); MetaInfoManager(); virtual ~MetaInfoManager(); int32_t Init(); int32_t UnInit(); int32_t AddMetaCapInfos(const std::vector> &meatCapInfos); int32_t SyncMetaInfoFromDB(const std::string &udidHash); int32_t SyncRemoteMetaInfos(); int32_t GetDataByKeyPrefix(const std::string &keyPrefix, MetaCapInfoMap &metaCapMap); int32_t RemoveMetaInfoByKey(const std::string &key); int32_t GetMetaCapInfo(const std::string &udidHash, const std::string &dhId, std::shared_ptr &metaCapPtr); void GetMetaCapInfosByUdidHash(const std::string &udidHash, std::vector> &metaCapInfos); int32_t GetMetaDataByDHType(const DHType dhType, MetaCapInfoMap &metaInfoMap); int32_t SyncDataByNetworkId(const std::string &networkId); /* Database data changes callback */ virtual void OnChange(const DistributedKv::ChangeNotification &changeNotification) override; /* Cloud data changes callback */ void OnChange(const DistributedKv::DataOrigin &origin, Keys &&keys) override; class MetaInfoManagerEventHandler : public AppExecFwk::EventHandler { public: MetaInfoManagerEventHandler(const std::shared_ptr runner, std::shared_ptr metaInfoMgrPtr); ~MetaInfoManagerEventHandler() override = default; void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; private: std::weak_ptr metaInfoMgrWPtr_; }; std::shared_ptr GetEventHandler(); private: int32_t GetMetaCapByValue(const std::string &value, std::shared_ptr &metaCapPtr); void HandleMetaCapabilityAddChange(const std::vector &insertRecords); void HandleMetaCapabilityUpdateChange(const std::vector &updateRecords); void HandleMetaCapabilityDeleteChange(const std::vector &deleteRecords); std::vector GetEntriesByKeys(const std::vector &keys); private: mutable std::mutex metaInfoMgrMutex_; std::shared_ptr dbAdapterPtr_; MetaCapInfoMap globalMetaInfoMap_; std::shared_ptr eventHandler_; }; } // namespace DistributedHardware } // namespace OHOS #endif