1 /* 2 * Copyright (c) 2021-2024 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}u", static_cast<uint32_t>(profileEvent)); 41 switch (static_cast<uint32_t>(profileEvent)) { 42 case ProfileEvent::EVENT_SYNC_COMPLETED: 43 return ProfileEventHandlerFactory::GetProfileSyncHandlerInner(); 44 case ProfileEvent::EVENT_PROFILE_CHANGED: 45 return ProfileEventHandlerFactory::GetProfileChangeHandlerInner(); 46 default: 47 HILOGW("unknown request code, please check, code = %{public}u", static_cast<uint32_t>(profileEvent)); 48 return nullptr; 49 } 50 } 51 GetProfileChangeHandlerInner()52std::shared_ptr<ProfileEventHandler> ProfileEventHandlerFactory::GetProfileChangeHandlerInner() 53 { 54 return std::make_shared<ProfileChangeHandler>("profileChange"); 55 } 56 GetProfileSyncHandlerInner()57std::shared_ptr<ProfileEventHandler> ProfileEventHandlerFactory::GetProfileSyncHandlerInner() 58 { 59 return std::make_shared<ProfileSyncHandler>("profileSync"); 60 } 61 } // namespace DeviceProfile 62 } // namespace OHOS 63