1 /* 2 * Copyright (c) 2025 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 MC_COMMAND_FACTORY_H 17 #define MC_COMMAND_FACTORY_H 18 19 #include <memory> 20 #include <vector> 21 #include "mc_command_base.h" 22 #include "mc_data_buffer.h" 23 #include "mc_get_mech_camera_tracking_layout_cmd.h" 24 #include "mc_get_mech_capability_info_cmd.h" 25 #include "mc_register_mech_camera_key_event_cmd.h" 26 #include "mc_register_mech_control_result_cmd.h" 27 #include "mc_register_mech_position_info_cmd.h" 28 #include "mc_register_mech_state_info_cmd.h" 29 #include "mc_register_mech_tracking_enable_cmd.h" 30 #include "mc_register_mech_wheel_data_cmd.h" 31 #include "mc_set_mech_camera_info_cmd.h" 32 #include "mc_set_mech_camera_tracking_enable_cmd.h" 33 #include "mc_set_mech_camera_tracking_frame_cmd.h" 34 #include "mc_set_mech_camera_tracking_layout_cmd.h" 35 #include "mc_set_mech_config_cmd.h" 36 #include "mc_set_mech_hid_preemptive_cmd.h" 37 #include "mc_set_mech_rotation_by_speed_cmd.h" 38 #include "mc_set_mech_rotation_cmd.h" 39 #include "mc_set_mech_rotation_trace_cmd.h" 40 #include "mc_set_mech_stop_cmd.h" 41 42 namespace OHOS { 43 namespace MechBodyController { 44 45 class CommandFactory { 46 public: 47 std::shared_ptr<GetMechCameraTrackingLayoutCmd> CreateGetMechCameraTrackingLayoutCmd(); 48 std::shared_ptr<GetMechCapabilityInfoCmd> CreateGetMechCapabilityInfoCmd(); 49 std::shared_ptr<SetMechCameraInfoCmd> CreateSetMechCameraInfoCmd( 50 const CameraInfoParams& params); 51 std::shared_ptr<SetMechCameraTrackingEnableCmd> CreateSetMechCameraTrackingEnableCmd( 52 MechTrackingStatus status); 53 std::shared_ptr<SetMechCameraTrackingFrameCmd> CreateSetMechCameraTrackingFrameCmd( 54 const TrackingFrameParams& params); 55 std::shared_ptr<SetMechCameraTrackingLayoutCmd> CreateSetMechCameraTrackingLayoutCmd( 56 const LayoutParams& params); 57 std::shared_ptr<SetMechConfigCmd> CreateSetMechConfigCmd( 58 uint8_t configVersion); 59 std::shared_ptr<SetMechHidPreemptiveCmd> CreateSetMechHidPreemptiveCmd(bool isPreemptive); 60 std::shared_ptr<SetMechRotationBySpeedCmd> CreateSetMechRotationBySpeedCmd( 61 const RotateBySpeedParam& params); 62 std::shared_ptr<SetMechRotationCmd> CreateSetMechRotationCmd( 63 const RotateParam& params); 64 std::shared_ptr<SetMechRotationTraceCmd> CreateSetMechRotationTraceCmd( 65 const std::vector<RotateParam>& params); 66 std::shared_ptr<SetMechStopCmd> CreateSetMechStopCmd(); 67 std::shared_ptr<RegisterMechCameraKeyEventCmd> CreateRegisterMechCameraKeyEventCmd(); 68 std::shared_ptr<RegisterMechControlResultCmd> CreateRegisterMechControlResultCmd(); 69 std::shared_ptr<RegisterMechPositionInfoCmd> CreateRegisterMechPositionInfoCmd(); 70 std::shared_ptr<RegisterMechStateInfoCmd> CreateRegisterMechStateInfoCmd(); 71 std::shared_ptr<RegisterMechWheelDataCmd> CreateRegisterMechWheelDataCmd(); 72 std::shared_ptr<RegisterMechTrackingEnableCmd> CreateRegisterMechTrackingEnableCmd(); 73 74 std::shared_ptr<CommandBase> CreateFromData(std::shared_ptr<MechDataBuffer> data); 75 private: 76 template<typename CmdT> CreateAndUnmarshal(std::shared_ptr<MechDataBuffer> data)77 std::shared_ptr<CommandBase> CreateAndUnmarshal(std::shared_ptr<MechDataBuffer> data) 78 { 79 auto cmd = std::make_shared<CmdT>(); 80 if (!cmd->Unmarshal(data)) { 81 return nullptr; 82 } 83 return cmd; 84 } 85 }; 86 87 } // namespace MechBodyController 88 } // namespace OHOS 89 90 #endif // MC_COMMAND_FACTORY_H 91