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 "dcamera_source_state_factory.h" 17 18 #include "dcamera_source_capture_state.h" 19 #include "dcamera_source_config_stream_state.h" 20 #include "dcamera_source_init_state.h" 21 #include "dcamera_source_opened_state.h" 22 #include "dcamera_source_regist_state.h" 23 24 #include "distributed_camera_errno.h" 25 #include "distributed_hardware_log.h" 26 27 namespace OHOS { 28 namespace DistributedHardware { 29 IMPLEMENT_SINGLE_INSTANCE(DCameraSourceStateFactory); 30 CreateState(DCameraStateType stateType,std::shared_ptr<DCameraSourceStateMachine> & stateMachine)31std::shared_ptr<DCameraSourceState> DCameraSourceStateFactory::CreateState(DCameraStateType stateType, 32 std::shared_ptr<DCameraSourceStateMachine>& stateMachine) 33 { 34 std::shared_ptr<DCameraSourceState> state = nullptr; 35 switch (stateType) { 36 case DCAMERA_STATE_INIT: { 37 state = std::make_shared<DCameraSourceInitState>(stateMachine); 38 break; 39 } 40 case DCAMERA_STATE_REGIST: { 41 state = std::make_shared<DCameraSourceRegistState>(stateMachine); 42 break; 43 } 44 case DCAMERA_STATE_OPENED: { 45 state = std::make_shared<DCameraSourceOpenedState>(stateMachine); 46 break; 47 } 48 case DCAMERA_STATE_CONFIG_STREAM: { 49 state = std::make_shared<DCameraSourceConfigStreamState>(stateMachine); 50 break; 51 } 52 case DCAMERA_STATE_CAPTURE: { 53 state = std::make_shared<DCameraSourceCaptureState>(stateMachine); 54 break; 55 } 56 default: { 57 DHLOGE("DCameraSourceStateFactory create state failed, wrong type %{public}d", stateType); 58 return nullptr; 59 } 60 } 61 62 return state; 63 } 64 } // namespace DistributedHardware 65 } // namespace OHOS 66