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 36 void OnChange(const DistributedKv::ChangeNotification& changeNotification) override; 37 38 private: 39 int32_t Register() override; 40 int32_t Unregister() override; 41 int32_t Subscribe(const SubscribeInfo& subscribeInfo, 42 const sptr<IRemoteObject>& profileEventNotifier) override; 43 44 void ConvertEntry(const std::vector<DistributedKv::Entry>& entries, ProfileChangeType changeType, 45 std::vector<ProfileEntry>& profileEntries, Service2Index& service2Index); 46 47 void NotifyProfileChanged(const ProfileChangeNotification& changeNotification, 48 const Service2Index& service2Index); 49 void FilterChangedProfileLocked(const SubscribeInfo& subscribeInfo, 50 const ProfileChangeNotification& changeNotification, 51 const Service2Index& service2Index, FilterInfo& filterInfo); 52 void NotifyProfileChangedLocked(const ProfileChangeNotification& changeNotification, 53 const FilterInfo& filterInfo, 54 const sptr<IProfileEventNotifier>& profileEventNotifier); 55 }; 56 } // namespace DeviceProfile 57 } // namespace OHOS 58 #endif // OHOS_DISTRIBUTED_DEVICE_PROFILE_PROFILE_CHANGE_HANDLER_H 59