1 /* 2 * Copyright (c) 2021 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_DEVICE_PROFILE_PROFILE_CHANGE_HANDLER_H 17 #define OHOS_DISTRIBUTED_DEVICE_PROFILE_PROFILE_CHANGE_HANDLER_H 18 19 #include <vector> 20 21 #include "profile_change_notification.h" 22 #include "profile_event_handler.h" 23 24 #include "kvstore_observer.h" 25 26 namespace OHOS { 27 namespace DeviceProfile { 28 class ProfileChangeHandler : public std::enable_shared_from_this<ProfileChangeHandler>, 29 public ProfileEventHandler, 30 public DistributedKv::KvStoreObserver { 31 public: ProfileChangeHandler(const std::string & handlerName)32 explicit ProfileChangeHandler(const std::string& handlerName) 33 : ProfileEventHandler(handlerName) {} 34 ~ProfileChangeHandler() = default; 35 OnChange(const DistributedKv::ChangeNotification & changeNotification,std::shared_ptr<DistributedKv::KvStoreSnapshot> snapshot)36 void OnChange(const DistributedKv::ChangeNotification& changeNotification, 37 std::shared_ptr<DistributedKv::KvStoreSnapshot> snapshot) override {}; 38 void OnChange(const DistributedKv::ChangeNotification& changeNotification) override; 39 40 private: 41 int32_t Register() override; 42 int32_t Unregister() override; 43 int32_t Subscribe(const SubscribeInfo& subscribeInfo, 44 const sptr<IRemoteObject>& profileEventNotifier) override; 45 46 void ConvertEntry(const std::vector<DistributedKv::Entry>& entries, ProfileChangeType changeType, 47 std::vector<ProfileEntry>& profileEntries, Service2Index& service2Index); 48 49 void NotifyProfileChanged(const ProfileChangeNotification& changeNotification, 50 const Service2Index& service2Index); 51 void FilterChangedProfileLocked(const SubscribeInfo& subscribeInfo, 52 const ProfileChangeNotification& changeNotification, 53 const Service2Index& service2Index, FilterInfo& filterInfo); 54 void NotifyProfileChangedLocked(const ProfileChangeNotification& changeNotification, 55 const FilterInfo& filterInfo, 56 const sptr<IProfileEventNotifier>& profileEventNotifier); 57 }; 58 } // namespace DeviceProfile 59 } // namespace OHOS 60 #endif // OHOS_DISTRIBUTED_DEVICE_PROFILE_PROFILE_CHANGE_HANDLER_H 61