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 #include "profile_event_handler_factory.h" 17 18 #include "device_profile_log.h" 19 #include "profile_change_handler.h" 20 #include "profile_sync_handler.h" 21 22 namespace OHOS { 23 namespace DeviceProfile { 24 namespace { 25 const std::string TAG = "ProfileEventHandlerFactory"; 26 } 27 28 IMPLEMENT_SINGLE_INSTANCE(ProfileEventHandlerFactory); 29 ProfileEventHandlerFactory()30ProfileEventHandlerFactory::ProfileEventHandlerFactory() 31 { 32 handlersMap_[ProfileEvent::EVENT_SYNC_COMPLETED] = 33 &ProfileEventHandlerFactory::GetProfileSyncHandlerInner; 34 handlersMap_[ProfileEvent::EVENT_PROFILE_CHANGED] = 35 &ProfileEventHandlerFactory::GetProfileChangeHandlerInner; 36 } 37 GetHandler(ProfileEvent profileEvent)38std::shared_ptr<ProfileEventHandler> ProfileEventHandlerFactory::GetHandler(ProfileEvent profileEvent) 39 { 40 HILOGI("get handler for event = %{public}d", profileEvent); 41 auto iter = handlersMap_.find(profileEvent); 42 if (iter != handlersMap_.end()) { 43 auto handler = iter->second; 44 if (handler != nullptr) { 45 return (this->*handler)(); 46 } 47 } 48 return nullptr; 49 } 50 GetProfileChangeHandlerInner()51std::shared_ptr<ProfileEventHandler> ProfileEventHandlerFactory::GetProfileChangeHandlerInner() 52 { 53 return std::make_shared<ProfileChangeHandler>("profileChange"); 54 } 55 GetProfileSyncHandlerInner()56std::shared_ptr<ProfileEventHandler> ProfileEventHandlerFactory::GetProfileSyncHandlerInner() 57 { 58 return std::make_shared<ProfileSyncHandler>("profileSync"); 59 } 60 } // namespace DeviceProfile 61 } // namespace OHOS