From d918e2afe2214c689666516643da1c21a120b4f8 Mon Sep 17 00:00:00 2001 From: wangyikai Date: Fri, 15 Nov 2024 10:54:30 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E3=80=90idl=E3=80=91=E5=A2=9E=E5=8A=A0hd?= =?UTF-8?q?i=20stub=E5=AF=B9=E8=B1=A1=E6=9E=90=E6=9E=84=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyikai --- .../HDI/cpp/cpp_service_stub_code_emitter.cpp | 1 + .../activity_changed_callback_stub.cpp.txt | 1 + .../v1_0/activity_interface_stub.cpp.txt | 1 + .../effect/v1_0/effect_control_proxy.c.txt | 26 +- .../effect/v1_0/effect_control_service.c.txt | 26 +- .../effect/v1_0/effect_control_stub.c.txt | 26 +- .../effect/v1_0/effect_model_driver.c.txt | 26 +- .../effect/v1_0/effect_model_proxy.c.txt | 26 +- .../effect/v1_0/effect_model_service.c.txt | 26 +- .../audio/effect/v1_0/effect_model_stub.c.txt | 26 +- .../audio/effect/v1_0/effect_types.c.txt | 26 +- .../v1_0/battery_callback_stub.cpp.txt | 1 + .../v1_0/battery_interface_stub.cpp.txt | 1 + .../v1_1/battery_callback_stub.cpp.txt | 1 + .../v1_1/battery_interface_stub.cpp.txt | 1 + .../v1_2/battery_callback_stub.cpp.txt | 1 + .../v1_2/battery_interface_stub.cpp.txt | 1 + .../v2_0/battery_callback_stub.cpp.txt | 1 + .../v2_0/battery_interface_stub.cpp.txt | 1 + .../bluetooth_audio_callback_stub.cpp.txt | 1 + .../v1_0/bluetooth_audio_session_stub.cpp.txt | 1 + .../hci/v1_0/hci_callback_stub.cpp.txt | 1 + .../hci/v1_0/hci_interface_stub.cpp.txt | 1 + .../v1_0/camera_device_callback_stub.cpp.txt | 1 + .../camera/v1_0/camera_device_stub.cpp.txt | 1 + .../v1_0/camera_host_callback_stub.cpp.txt | 1 + .../camera/v1_0/camera_host_stub.cpp.txt | 1 + .../v1_0/offline_stream_operator_stub.cpp.txt | 1 + .../stream_operator_callback_stub.cpp.txt | 1 + .../camera/v1_0/stream_operator_stub.cpp.txt | 1 + .../camera/v1_1/camera_device_stub.cpp.txt | 1 + .../camera/v1_1/camera_host_stub.cpp.txt | 1 + .../camera/v1_1/stream_operator_stub.cpp.txt | 1 + .../camera/v1_2/camera_device_stub.cpp.txt | 1 + .../v1_2/camera_host_callback_stub.cpp.txt | 1 + .../camera/v1_2/camera_host_stub.cpp.txt | 1 + .../v1_2/image_process_callback_stub.cpp.txt | 1 + .../v1_2/image_process_service_stub.cpp.txt | 1 + .../v1_2/image_process_session_stub.cpp.txt | 1 + .../stream_operator_callback_stub.cpp.txt | 1 + .../camera/v1_2/stream_operator_stub.cpp.txt | 1 + .../cpp_target/camera/v1_2/types.cpp.txt | 26 +- .../image/v1_0/codec_image_driver.cpp.txt | 26 +- .../image/v1_0/codec_image_proxy.cpp.txt | 806 +++++----- .../codec/image/v1_0/codec_image_proxy.h.txt | 228 +-- .../codec/image/v1_0/codec_image_stub.cpp.txt | 27 +- .../codec/image/v1_0/codec_image_type.cpp.txt | 26 +- .../codec/v1_0/codec_callback_stub.cpp.txt | 1 + .../v1_0/codec_component_manager_stub.cpp.txt | 1 + .../codec/v1_0/codec_component_stub.cpp.txt | 1 + .../codec/v2_0/codec_callback_stub.cpp.txt | 1 + .../v2_0/codec_component_manager_stub.cpp.txt | 1 + .../codec/v2_0/codec_component_stub.cpp.txt | 1 + .../v1_0/connected_nfc_tag_stub.cpp.txt | 1 + .../buffer/v1_0/allocator_stub.cpp.txt | 1 + .../display/buffer/v1_0/mapper_stub.cpp.txt | 1 + .../display/buffer/v1_1/metadata_stub.cpp.txt | 1 + .../v1_0/display_composer_stub.cpp.txt | 1 + .../v1_0/hot_plug_callback_stub.cpp.txt | 1 + .../v1_0/refresh_callback_stub.cpp.txt | 1 + .../v1_0/vblank_callback_stub.cpp.txt | 1 + .../v1_1/display_composer_stub.cpp.txt | 1 + .../composer/v1_1/mode_callback_stub.cpp.txt | 1 + .../seamless_change_callback_stub.cpp.txt | 1 + .../v1_0/buffer_handle_meta_key_type.cpp.txt | 26 +- .../common/v1_0/cm_color_space.cpp.txt | 26 +- .../common/v1_0/hdr_static_metadata.cpp.txt | 26 +- .../audio/v1_0/audio_adapter_stub.cpp.txt | 1 + .../audio/v1_0/audio_callback_stub.cpp.txt | 1 + .../audio/v1_0/audio_capture_stub.cpp.txt | 1 + .../audio/v1_0/audio_manager_stub.cpp.txt | 1 + .../audio/v1_0/audio_render_stub.cpp.txt | 1 + .../v1_0/daudio_callback_stub.cpp.txt | 1 + .../audioext/v1_0/daudio_manager_stub.cpp.txt | 1 + .../dcamera_provider_callback_stub.cpp.txt | 1 + .../v1_0/dcamera_provider_stub.cpp.txt | 1 + .../v1_0/media_decrypt_module_stub.cpp.txt | 1 + .../media_key_session_callback_stub.cpp.txt | 1 + .../drm/v1_0/media_key_session_stub.cpp.txt | 1 + .../media_key_system_callback_stub.cpp.txt | 1 + .../media_key_system_factory_stub.cpp.txt | 1 + .../drm/v1_0/media_key_system_stub.cpp.txt | 1 + .../drm/v1_0/oem_certificate_proxy.cpp.txt | 26 +- .../drm/v1_0/oem_certificate_stub.cpp.txt | 27 +- .../cpp_target/foo/v1_0/foo_driver.cpp.txt | 26 +- .../cpp_target/foo/v1_0/foo_proxy.cpp.txt | 552 +++---- .../cpp_target/foo/v1_0/foo_proxy.h.txt | 190 +-- .../cpp_target/foo/v1_0/foo_stub.cpp.txt | 27 +- .../cpp_target/foo/v1_0/foo_driver.cpp.txt | 26 +- .../cpp_target/foo/v1_0/foo_proxy.cpp.txt | 552 +++---- .../cpp_target/foo/v1_0/foo_proxy.h.txt | 190 +-- .../cpp_target/foo/v1_0/foo_stub.cpp.txt | 27 +- .../cpp_target/foo/v1_1/foo_driver.cpp.txt | 26 +- .../cpp_target/foo/v1_1/foo_proxy.cpp.txt | 532 +++---- .../cpp_target/foo/v1_1/foo_proxy.h.txt | 190 +-- .../cpp_target/foo/v1_1/foo_stub.cpp.txt | 27 +- .../cpp_target/foo/v1_0/foo_driver.cpp.txt | 26 +- .../cpp_target/foo/v1_0/foo_proxy.cpp.txt | 554 +++---- .../cpp_target/foo/v1_0/foo_proxy.h.txt | 192 +-- .../cpp_target/foo/v1_0/foo_stub.cpp.txt | 27 +- .../v1_0/executor_callback_stub.cpp.txt | 1 + .../face_auth/v1_0/executor_stub.cpp.txt | 1 + .../v1_0/face_auth_interface_stub.cpp.txt | 1 + .../face_auth/v1_1/executor_stub.cpp.txt | 1 + .../v1_1/face_auth_interface_stub.cpp.txt | 1 + .../v1_1/sa_command_callback_stub.cpp.txt | 1 + .../v1_0/executor_callback_stub.cpp.txt | 1 + .../v1_0/executor_stub.cpp.txt | 1 + .../fingerprint_auth_interface_stub.cpp.txt | 1 + .../v1_1/executor_stub.cpp.txt | 1 + .../fingerprint_auth_interface_stub.cpp.txt | 1 + .../v1_1/sa_command_callback_stub.cpp.txt | 1 + .../cpp_target/foo/v1_0/foo_proxy.cpp.txt | 26 +- .../foo/v1_0/foo_callback_service.c.txt | 26 +- .../c_target/foo/v1_0/foo_driver.c.txt | 26 +- .../c_target/foo/v1_0/foo_service.c.txt | 26 +- .../c_target/foo/v1_0/foo_driver.c.txt | 26 +- .../c_target/foo/v1_0/foo_proxy.c.txt | 26 +- .../c_target/foo/v1_0/foo_service.c.txt | 26 +- .../c_target/foo/v1_0/foo_stub.c.txt | 26 +- .../c_target/foo/v1_0/types.c.txt | 26 +- .../foo/v1_0/foo_callback_service.c.txt | 26 +- .../c_target/foo/v1_0/foo_service.c.txt | 26 +- .../cpp_target/foo/v1_0/foo_proxy.cpp.txt | 26 +- .../foo/v1_0/foo_callback_service.c.txt | 26 +- .../c_target/foo/v1_0/foo_service.c.txt | 26 +- .../cpp_target/foo/v1_0/foo_proxy.cpp.txt | 26 +- .../c_target/foo/v1_0/foo_driver.c.txt | 26 +- .../c_target/foo/v1_0/foo_proxy.c.txt | 26 +- .../c_target/foo/v1_0/foo_service.c.txt | 26 +- .../c_target/foo/v1_0/foo_stub.c.txt | 26 +- .../c_target/foo/v1_0/types.c.txt | 26 +- .../foo/v1_0/foo_callback_proxy.c.txt | 26 +- .../foo/v1_0/foo_callback_service.c.txt | 26 +- .../c_target/foo/v1_0/foo_callback_stub.c.txt | 26 +- .../c_target/foo/v1_0/foo_driver.c.txt | 26 +- .../c_target/foo/v1_0/foo_proxy.c.txt | 26 +- .../c_target/foo/v1_0/foo_service.c.txt | 26 +- .../c_target/foo/v1_0/foo_stub.c.txt | 26 +- .../c_target/foo/v1_0/types.c.txt | 26 +- .../foo/v1_0/foo_callback_proxy.cpp.txt | 26 +- .../foo/v1_0/foo_callback_stub.cpp.txt | 27 +- .../cpp_target/foo/v1_0/foo_driver.cpp.txt | 26 +- .../cpp_target/foo/v1_0/foo_ext_stub.cpp.txt | 1 + .../cpp_target/foo/v1_0/foo_proxy.cpp.txt | 1324 ++++++++--------- .../cpp_target/foo/v1_0/foo_proxy.h.txt | 262 ++-- .../cpp_target/foo/v1_0/foo_stub.cpp.txt | 27 +- .../cpp_target/foo/v1_0/types.cpp.txt | 26 +- .../cpp_target/foo/v1_0/foo_proxy.cpp.txt | 26 +- .../c_target/foo/v1_0/types.c.txt | 26 +- .../c_target/foo/v1_0/types.c.txt | 26 +- .../c_target/foo/v1_0/types.c.txt | 26 +- .../cpp_target/foo/v1_0/types.cpp.txt | 26 +- .../cpp_target/foo/v1_0/foo_driver.cpp.txt | 26 +- .../cpp_target/foo/v1_0/foo_proxy.cpp.txt | 552 +++---- .../cpp_target/foo/v1_0/foo_proxy.h.txt | 190 +-- .../cpp_target/foo/v1_0/foo_stub.cpp.txt | 27 +- .../foo/v1_0/foo_callback_proxy.cpp.txt | 26 +- .../foo/v1_0/foo_callback_stub.cpp.txt | 27 +- .../cpp_target/foo/v1_0/foo_driver.cpp.txt | 26 +- .../cpp_target/foo/v1_0/foo_proxy.cpp.txt | 552 +++---- .../cpp_target/foo/v1_0/foo_proxy.h.txt | 190 +-- .../cpp_target/foo/v1_0/foo_stub.cpp.txt | 27 +- .../cpp_target/foo/v1_0/types.cpp.txt | 26 +- .../foo/v1_0/foo_callback_proxy.cpp.txt | 26 +- .../foo/v1_0/foo_callback_stub.cpp.txt | 27 +- .../cpp_target/foo/v1_0/foo_driver.cpp.txt | 26 +- .../cpp_target/foo/v1_0/foo_proxy.cpp.txt | 552 +++---- .../cpp_target/foo/v1_0/foo_proxy.h.txt | 190 +-- .../cpp_target/foo/v1_0/foo_stub.cpp.txt | 27 +- .../cpp_target/foo/v1_0/types.cpp.txt | 26 +- .../c_target/huks/v1_0/huks_service.c.txt | 26 +- .../input/ddk/v1_0/hid_ddk_stub.cpp.txt | 1 + .../intell_voice_engine_adapter_stub.cpp.txt | 1 + .../intell_voice_engine_callback_stub.cpp.txt | 1 + .../intell_voice_engine_manager_stub.cpp.txt | 1 + ...ntell_voice_data_opr_callback_stub.cpp.txt | 1 + .../intell_voice_engine_manager_stub.cpp.txt | 1 + .../intell_voice_trigger_adapter_stub.cpp.txt | 1 + ...intell_voice_trigger_callback_stub.cpp.txt | 1 + .../intell_voice_trigger_manager_stub.cpp.txt | 1 + .../intell_voice_trigger_adapter_stub.cpp.txt | 1 + .../intell_voice_trigger_manager_stub.cpp.txt | 1 + .../light/v1_0/light_interface_stub.cpp.txt | 1 + .../agnss/v1_0/agnss_callback_stub.cpp.txt | 1 + .../agnss/v1_0/agnss_interface_stub.cpp.txt | 1 + .../v1_0/geofence_callback_stub.cpp.txt | 1 + .../v1_0/geofence_interface_stub.cpp.txt | 1 + .../gnss/v1_0/gnss_callback_stub.cpp.txt | 1 + .../gnss/v1_0/gnss_interface_stub.cpp.txt | 1 + .../v1_0/cellbatching_callback_stub.cpp.txt | 1 + .../v1_0/cellbatching_interface_stub.cpp.txt | 1 + .../v1_0/cellfence_callback_stub.cpp.txt | 1 + .../v1_0/cellfence_interface_stub.cpp.txt | 1 + .../v1_0/geofence_callback_stub.cpp.txt | 1 + .../geofence/v1_0/geofence_intf_stub.cpp.txt | 1 + .../v1_0/wififence_callback_stub.cpp.txt | 1 + .../v1_0/wififence_interface_stub.cpp.txt | 1 + .../memory_tracker_interface_stub.cpp.txt | 1 + .../motion/v1_0/motion_callback_stub.cpp.txt | 1 + .../motion/v1_0/motion_interface_stub.cpp.txt | 1 + .../v1_1/motion_interface_driver.cpp.txt | 26 +- .../v1_1/motion_interface_proxy.cpp.txt | 484 +++--- .../motion/v1_1/motion_interface_proxy.h.txt | 188 +-- .../motion/v1_1/motion_interface_stub.cpp.txt | 27 +- .../motion/v1_1/motion_types.cpp.txt | 26 +- .../nfc/v1_0/nfc_callback_stub.cpp.txt | 1 + .../nfc/v1_0/nfc_interface_stub.cpp.txt | 1 + .../nfc/v1_1/nfc_interface_stub.cpp.txt | 1 + .../nnrt/v1_0/nnrt_device_stub.cpp.txt | 1 + .../nnrt/v1_0/prepared_model_stub.cpp.txt | 1 + .../nnrt/v2_0/nnrt_device_stub.cpp.txt | 1 + .../nnrt/v2_0/prepared_model_stub.cpp.txt | 1 + .../cpp_target/foo/v1_1/foo_driver.cpp.txt | 26 +- .../cpp_target/foo/v1_1/foo_proxy.cpp.txt | 556 +++---- .../cpp_target/foo/v1_1/foo_proxy.h.txt | 192 +-- .../cpp_target/foo/v1_1/foo_stub.cpp.txt | 27 +- .../v1_0/partition_slot_stub.cpp.txt | 1 + .../v1_0/executor_callback_stub.cpp.txt | 1 + .../pin_auth/v1_0/executor_stub.cpp.txt | 1 + .../v1_0/pin_auth_interface_stub.cpp.txt | 1 + .../v1_1/executor_callback_stub.cpp.txt | 1 + .../pin_auth/v1_1/executor_stub.cpp.txt | 1 + .../v1_1/pin_auth_interface_stub.cpp.txt | 1 + .../v1_0/power_hdi_callback_stub.cpp.txt | 1 + .../power/v1_0/power_interface_stub.cpp.txt | 1 + .../v1_1/power_hdi_callback_stub.cpp.txt | 1 + .../power/v1_1/power_interface_stub.cpp.txt | 1 + .../power_running_lock_callback_stub.cpp.txt | 1 + .../ril/v1_0/ril_callback_stub.cpp.txt | 1 + .../cpp_target/ril/v1_0/ril_stub.cpp.txt | 1 + .../ril/v1_1/ril_callback_stub.cpp.txt | 1 + .../cpp_target/ril/v1_1/ril_stub.cpp.txt | 1 + .../ril/v1_2/ril_callback_stub.cpp.txt | 1 + .../cpp_target/ril/v1_2/ril_stub.cpp.txt | 1 + .../v1_0/secure_element_callback_stub.cpp.txt | 1 + .../secure_element_interface_stub.cpp.txt | 1 + .../sensor/v1_0/sensor_callback_stub.cpp.txt | 1 + .../sensor/v1_0/sensor_interface_stub.cpp.txt | 1 + .../sensor/v1_1/sensor_callback_stub.cpp.txt | 1 + .../sensor/v1_1/sensor_interface_stub.cpp.txt | 1 + .../sensor/v2_0/sensor_callback_stub.cpp.txt | 1 + .../sensor/v2_0/sensor_interface_stub.cpp.txt | 1 + .../foo/v1_0/foo_callback_proxy.cpp.txt | 26 +- .../foo/v1_0/foo_callback_stub.cpp.txt | 27 +- .../cpp_target/foo/v1_0/foo_driver.cpp.txt | 26 +- .../cpp_target/foo/v1_0/foo_proxy.cpp.txt | 562 +++---- .../cpp_target/foo/v1_0/foo_proxy.h.txt | 188 +-- .../cpp_target/foo/v1_0/foo_stub.cpp.txt | 27 +- .../cpp_target/foo/v1_0/foo_driver.cpp.txt | 26 +- .../cpp_target/foo/v1_0/foo_proxy.cpp.txt | 562 +++---- .../cpp_target/foo/v1_0/foo_proxy.h.txt | 188 +-- .../cpp_target/foo/v1_0/foo_stub.cpp.txt | 27 +- .../v1_0/thermal_callback_stub.cpp.txt | 1 + .../v1_0/thermal_interface_stub.cpp.txt | 1 + .../thermal/v1_1/fan_callback_stub.cpp.txt | 1 + .../v1_1/thermal_callback_stub.cpp.txt | 1 + .../v1_1/thermal_interface_stub.cpp.txt | 1 + .../cpp_target/foo/v1_0/foo_driver.cpp.txt | 26 +- .../cpp_target/foo/v1_0/foo_proxy.cpp.txt | 552 +++---- .../cpp_target/foo/v1_0/foo_proxy.h.txt | 190 +-- .../cpp_target/foo/v1_0/foo_stub.cpp.txt | 27 +- .../usb/ddk/v1_0/usb_ddk_stub.cpp.txt | 1 + .../mtp/v1_0/usbfn_mtp_interface_stub.cpp.txt | 1 + .../usb/v1_0/usb_interface_stub.cpp.txt | 1 + .../usb/v1_0/usbd_bulk_callback_stub.cpp.txt | 1 + .../usb/v1_0/usbd_subscriber_stub.cpp.txt | 1 + .../v1_0/user_auth_interface_stub.cpp.txt | 1 + .../v1_1/user_auth_interface_stub.cpp.txt | 1 + .../v1_2/user_auth_interface_stub.cpp.txt | 1 + .../v1_0/vibrator_interface_stub.cpp.txt | 1 + .../v1_1/vibrator_interface_stub.cpp.txt | 1 + .../v1_2/vibrator_interface_driver.cpp.txt | 26 +- .../v1_2/vibrator_interface_proxy.cpp.txt | 698 ++++----- .../v1_2/vibrator_interface_proxy.h.txt | 230 +-- .../v1_2/vibrator_interface_stub.cpp.txt | 27 +- .../vibrator/v1_2/vibrator_types.cpp.txt | 26 +- .../wlan/wpa/v1_0/wpa_callback_proxy.c.txt | 26 +- .../wlan/wpa/v1_0/wpa_callback_service.c.txt | 26 +- .../wlan/wpa/v1_0/wpa_callback_stub.c.txt | 26 +- .../wlan/wpa/v1_0/wpa_interface_driver.c.txt | 26 +- .../wlan/wpa/v1_0/wpa_interface_proxy.c.txt | 26 +- .../wlan/wpa/v1_0/wpa_interface_service.c.txt | 26 +- .../wlan/wpa/v1_0/wpa_interface_stub.c.txt | 26 +- .../c_target/wlan/wpa/v1_0/wpa_types.c.txt | 26 +- 285 files changed, 7669 insertions(+), 7494 deletions(-) diff --git a/idl_tool_2/codegen/HDI/cpp/cpp_service_stub_code_emitter.cpp b/idl_tool_2/codegen/HDI/cpp/cpp_service_stub_code_emitter.cpp index bbd5fca..77b5878 100644 --- a/idl_tool_2/codegen/HDI/cpp/cpp_service_stub_code_emitter.cpp +++ b/idl_tool_2/codegen/HDI/cpp/cpp_service_stub_code_emitter.cpp @@ -335,6 +335,7 @@ void CppServiceStubCodeEmitter::EmitStubConstructorImpl(StringBuilder &sb, const sb.Append(prefix).AppendFormat( "%s::~%s()\n", EmitDefinitionByInterface(interface_, stubName_).c_str(), stubName_.c_str()); sb.Append(prefix).Append("{\n"); + sb.Append(prefix + TAB).Append("HDF_LOGI(\"%{public}s enter\", __func__);\n"); sb.Append(prefix + TAB).Append("ObjectCollector::GetInstance().RemoveObject(impl_);\n"); sb.Append(prefix).Append("}\n"); } diff --git a/test/hdi_unittest/a_recognition_v1_0/cpp_target/a_recognition/v1_0/activity_changed_callback_stub.cpp.txt b/test/hdi_unittest/a_recognition_v1_0/cpp_target/a_recognition/v1_0/activity_changed_callback_stub.cpp.txt index 924fd18..4ab4e0c 100644 --- a/test/hdi_unittest/a_recognition_v1_0/cpp_target/a_recognition/v1_0/activity_changed_callback_stub.cpp.txt +++ b/test/hdi_unittest/a_recognition_v1_0/cpp_target/a_recognition/v1_0/activity_changed_callback_stub.cpp.txt @@ -57,6 +57,7 @@ OHOS::HDI::ARecognition::V1_0::ActivityChangedCallbackStub::ActivityChangedCallb OHOS::HDI::ARecognition::V1_0::ActivityChangedCallbackStub::~ActivityChangedCallbackStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/a_recognition_v1_0/cpp_target/a_recognition/v1_0/activity_interface_stub.cpp.txt b/test/hdi_unittest/a_recognition_v1_0/cpp_target/a_recognition/v1_0/activity_interface_stub.cpp.txt index db72cf4..0052be2 100644 --- a/test/hdi_unittest/a_recognition_v1_0/cpp_target/a_recognition/v1_0/activity_interface_stub.cpp.txt +++ b/test/hdi_unittest/a_recognition_v1_0/cpp_target/a_recognition/v1_0/activity_interface_stub.cpp.txt @@ -76,6 +76,7 @@ OHOS::HDI::ARecognition::V1_0::ActivityInterfaceStub::ActivityInterfaceStub(cons OHOS::HDI::ARecognition::V1_0::ActivityInterfaceStub::~ActivityInterfaceStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_control_proxy.c.txt b/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_control_proxy.c.txt index 259d131..7b5aa70 100644 --- a/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_control_proxy.c.txt +++ b/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_control_proxy.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_control_service.c.txt b/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_control_service.c.txt index e25106d..228a2b2 100644 --- a/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_control_service.c.txt +++ b/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_control_service.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/effect_control_service.h" diff --git a/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_control_stub.c.txt b/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_control_stub.c.txt index 238fc4b..1ea0238 100644 --- a/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_control_stub.c.txt +++ b/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_control_stub.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/effect_control_stub.h" diff --git a/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_model_driver.c.txt b/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_model_driver.c.txt index 55741e3..00bcddc 100644 --- a/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_model_driver.c.txt +++ b/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_model_driver.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_model_proxy.c.txt b/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_model_proxy.c.txt index c3fa730..7ed2a25 100644 --- a/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_model_proxy.c.txt +++ b/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_model_proxy.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_model_service.c.txt b/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_model_service.c.txt index 8cb04b1..90420f3 100644 --- a/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_model_service.c.txt +++ b/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_model_service.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_model_stub.c.txt b/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_model_stub.c.txt index a68b39e..cb13904 100644 --- a/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_model_stub.c.txt +++ b/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_model_stub.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/effect_model_stub.h" diff --git a/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_types.c.txt b/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_types.c.txt index 2ae328d..7f463ea 100644 --- a/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_types.c.txt +++ b/test/hdi_unittest/audio_effect_v1_0/c_target/audio/effect/v1_0/effect_types.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/effect_types.h" diff --git a/test/hdi_unittest/battery_v1_0/cpp_target/battery/v1_0/battery_callback_stub.cpp.txt b/test/hdi_unittest/battery_v1_0/cpp_target/battery/v1_0/battery_callback_stub.cpp.txt index 2071f1d..05b8ba3 100644 --- a/test/hdi_unittest/battery_v1_0/cpp_target/battery/v1_0/battery_callback_stub.cpp.txt +++ b/test/hdi_unittest/battery_v1_0/cpp_target/battery/v1_0/battery_callback_stub.cpp.txt @@ -33,6 +33,7 @@ OHOS::HDI::Battery::V1_0::BatteryCallbackStub::BatteryCallbackStub(const sptr diff --git a/test/hdi_unittest/codec_image_v1_0/cpp_target/codec/image/v1_0/codec_image_proxy.cpp.txt b/test/hdi_unittest/codec_image_v1_0/cpp_target/codec/image/v1_0/codec_image_proxy.cpp.txt index a7e2582..14ab1ca 100644 --- a/test/hdi_unittest/codec_image_v1_0/cpp_target/codec/image/v1_0/codec_image_proxy.cpp.txt +++ b/test/hdi_unittest/codec_image_v1_0/cpp_target/codec/image/v1_0/codec_image_proxy.cpp.txt @@ -11,406 +11,406 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#include "v1_0/codec_image_proxy.h" -#include -#include -#include -#include -#include -#include -#include - -#define HDF_LOG_TAG codec_image_proxy - -namespace OHOS { -namespace HDI { -namespace Codec { -namespace Image { -namespace V1_0 { - - -sptr OHOS::HDI::Codec::Image::V1_0::ICodecImage::Get(bool isStub) -{ - return ICodecImage::Get("codec_image_service", isStub); -} - -sptr OHOS::HDI::Codec::Image::V1_0::ICodecImage::Get(const std::string& serviceName, bool isStub) -{ - if (isStub) { - std::string desc = Str16ToStr8(OHOS::HDI::Codec::Image::V1_0::ICodecImage::GetDescriptor()); - void *impl = LoadHdiImpl(desc.c_str(), serviceName == "codec_image_service" ? "service" : serviceName.c_str()); - if (impl == nullptr) { - HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); - return nullptr; - } - return reinterpret_cast(impl); - } - - using namespace OHOS::HDI::ServiceManager::V1_0; - auto servMgr = IServiceManager::Get(); - if (servMgr == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return nullptr; - } - - sptr remote = servMgr->GetService(serviceName.c_str()); - if (remote == nullptr) { - HDF_LOGE("%{public}s:get remote object failed!", __func__); - return nullptr; - } - - sptr proxy = new OHOS::HDI::Codec::Image::V1_0::CodecImageProxy(remote); - if (proxy == nullptr) { - HDF_LOGE("%{public}s:iface_cast failed!", __func__); - return nullptr; - } - - proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); - proxy->deathRecipient_ = new OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::IServiceManagerDeathRecipient(proxy); - proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); - proxy->isReconnected_ = false; - proxy->serviceName_ = serviceName; - uint32_t serMajorVer = 0; - uint32_t serMinorVer = 0; - int32_t codecImageRet = proxy->GetVersion(serMajorVer, serMinorVer); - if (codecImageRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s:get version failed!", __func__); - return nullptr; - } - - if (serMajorVer != 1) { - HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); - return nullptr; - } - - return proxy; -} - -int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::Reconnect( - sptr proxy) -{ - if (proxy == nullptr) { - HDF_LOGW("Reconnect failed : input proxy is null"); - return HDF_FAILURE; - } - using namespace OHOS::HDI::ServiceManager::V1_0; - proxy->isReconnected_ = false; - auto iServMgr = IServiceManager::Get(); - if (iServMgr == nullptr) { - HDF_LOGW("Reconnect failed : iServMgr is null"); - return HDF_FAILURE; - }; - proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); - if (proxy->reconnectRemote_ == nullptr) { - HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); - return HDF_FAILURE; - } - proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); - if (proxy->servMgr_ == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return HDF_FAILURE; - } - proxy->servMgr_->AddDeathRecipient( - new OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::IServiceManagerDeathRecipient(proxy)); - proxy->isReconnected_ = true; - return HDF_SUCCESS; -} - -int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::GetImageCapability(std::vector& capList) -{ - return OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::GetImageCapability_(capList, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::Init(OHOS::HDI::Codec::Image::V1_0::CodecImageRole role) -{ - return OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::Init_(role, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::DeInit(OHOS::HDI::Codec::Image::V1_0::CodecImageRole role) -{ - return OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::DeInit_(role, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::DoJpegDecode(const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& outBuffer, const OHOS::HDI::Codec::Image::V1_0::CodecJpegDecInfo& decInfo) -{ - return OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::DoJpegDecode_(inBuffer, outBuffer, decInfo, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::AllocateInBuffer(OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, uint32_t size, OHOS::HDI::Codec::Image::V1_0::CodecImageRole role) -{ - return OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::AllocateInBuffer_(inBuffer, size, role, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::FreeInBuffer(const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer) -{ - return OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::FreeInBuffer_(inBuffer, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) -{ - return OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::GetImageCapability_(std::vector& capList, const sptr remote) -{ - MessageParcel codecImageData; - MessageParcel codecImageReply; - MessageOption codecImageOption(MessageOption::TF_SYNC); - - if (!codecImageData.WriteInterfaceToken(OHOS::HDI::Codec::Image::V1_0::ICodecImage::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!codecImageData.WriteBool(false)) { - HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t codecImageRet = remote->SendRequest(CMD_CODEC_IMAGE_GET_IMAGE_CAPABILITY, codecImageData, codecImageReply, codecImageOption); - if (codecImageRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, codecImageRet); - return codecImageRet; - } - - uint32_t capListSize = 0; - if (!codecImageReply.ReadUint32(capListSize)) { - HDF_LOGE("%{public}s: failed to read size", __func__); - return HDF_ERR_INVALID_PARAM; - } - - HDI_CHECK_VALUE_RETURN(capListSize, >, HDI_BUFF_MAX_SIZE / sizeof(OHOS::HDI::Codec::Image::V1_0::CodecImageCapability), HDF_ERR_INVALID_PARAM); - capList.clear(); - capList.reserve(capListSize); - for (uint32_t i0 = 0; i0 < capListSize; ++i0) { - OHOS::HDI::Codec::Image::V1_0::CodecImageCapability value0; - if (!CodecImageCapabilityBlockUnmarshalling(codecImageReply, value0)) { - HDF_LOGE("%{public}s: read value0 failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - capList.push_back(value0); - } - - return codecImageRet; -} - -int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::Init_(OHOS::HDI::Codec::Image::V1_0::CodecImageRole role, - const sptr remote) -{ - MessageParcel codecImageData; - MessageParcel codecImageReply; - MessageOption codecImageOption(MessageOption::TF_SYNC); - - if (!codecImageData.WriteInterfaceToken(OHOS::HDI::Codec::Image::V1_0::ICodecImage::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!codecImageData.WriteUint64(static_cast(role))) { - HDF_LOGE("%{public}s: write role failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t codecImageRet = remote->SendRequest(CMD_CODEC_IMAGE_INIT, codecImageData, codecImageReply, codecImageOption); - if (codecImageRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, codecImageRet); - return codecImageRet; - } - - return codecImageRet; -} - -int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::DeInit_(OHOS::HDI::Codec::Image::V1_0::CodecImageRole role, - const sptr remote) -{ - MessageParcel codecImageData; - MessageParcel codecImageReply; - MessageOption codecImageOption(MessageOption::TF_SYNC); - - if (!codecImageData.WriteInterfaceToken(OHOS::HDI::Codec::Image::V1_0::ICodecImage::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!codecImageData.WriteUint64(static_cast(role))) { - HDF_LOGE("%{public}s: write role failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t codecImageRet = remote->SendRequest(CMD_CODEC_IMAGE_DE_INIT, codecImageData, codecImageReply, codecImageOption); - if (codecImageRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, codecImageRet); - return codecImageRet; - } - - return codecImageRet; -} - -int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::DoJpegDecode_(const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& outBuffer, const OHOS::HDI::Codec::Image::V1_0::CodecJpegDecInfo& decInfo, const sptr remote) -{ - MessageParcel codecImageData; - MessageParcel codecImageReply; - MessageOption codecImageOption(MessageOption::TF_SYNC); - - if (!codecImageData.WriteInterfaceToken(OHOS::HDI::Codec::Image::V1_0::ICodecImage::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!OHOS::HDI::Codec::Image::V1_0::CodecImageBufferBlockMarshalling(codecImageData, inBuffer)) { - HDF_LOGE("%{public}s: write inBuffer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!OHOS::HDI::Codec::Image::V1_0::CodecImageBufferBlockMarshalling(codecImageData, outBuffer)) { - HDF_LOGE("%{public}s: write outBuffer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!OHOS::HDI::Codec::Image::V1_0::CodecJpegDecInfoBlockMarshalling(codecImageData, decInfo)) { - HDF_LOGE("%{public}s: write decInfo failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t codecImageRet = remote->SendRequest(CMD_CODEC_IMAGE_DO_JPEG_DECODE, codecImageData, codecImageReply, codecImageOption); - if (codecImageRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, codecImageRet); - return codecImageRet; - } - - return codecImageRet; -} - -int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::AllocateInBuffer_(OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, uint32_t size, OHOS::HDI::Codec::Image::V1_0::CodecImageRole role, const sptr remote) -{ - MessageParcel codecImageData; - MessageParcel codecImageReply; - MessageOption codecImageOption(MessageOption::TF_SYNC); - - if (!codecImageData.WriteInterfaceToken(OHOS::HDI::Codec::Image::V1_0::ICodecImage::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!codecImageData.WriteUint32(size)) { - HDF_LOGE("%{public}s: write size failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!codecImageData.WriteUint64(static_cast(role))) { - HDF_LOGE("%{public}s: write role failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t codecImageRet = remote->SendRequest(CMD_CODEC_IMAGE_ALLOCATE_IN_BUFFER, codecImageData, codecImageReply, codecImageOption); - if (codecImageRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, codecImageRet); - return codecImageRet; - } - - if (!CodecImageBufferBlockUnmarshalling(codecImageReply, inBuffer)) { - HDF_LOGE("%{public}s: read inBuffer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return codecImageRet; -} - -int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::FreeInBuffer_(const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, const sptr remote) -{ - MessageParcel codecImageData; - MessageParcel codecImageReply; - MessageOption codecImageOption(MessageOption::TF_SYNC); - - if (!codecImageData.WriteInterfaceToken(OHOS::HDI::Codec::Image::V1_0::ICodecImage::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!OHOS::HDI::Codec::Image::V1_0::CodecImageBufferBlockMarshalling(codecImageData, inBuffer)) { - HDF_LOGE("%{public}s: write inBuffer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t codecImageRet = remote->SendRequest(CMD_CODEC_IMAGE_FREE_IN_BUFFER, codecImageData, codecImageReply, codecImageOption); - if (codecImageRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, codecImageRet); - return codecImageRet; - } - - return codecImageRet; -} - -int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, - const sptr remote) -{ - MessageParcel codecImageData; - MessageParcel codecImageReply; - MessageOption codecImageOption(MessageOption::TF_SYNC); - - if (!codecImageData.WriteInterfaceToken(OHOS::HDI::Codec::Image::V1_0::ICodecImage::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t codecImageRet = remote->SendRequest(CMD_CODEC_IMAGE_GET_VERSION, codecImageData, codecImageReply, codecImageOption); - if (codecImageRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, codecImageRet); - return codecImageRet; - } - - if (!codecImageReply.ReadUint32(majorVer)) { - HDF_LOGE("%{public}s: read majorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!codecImageReply.ReadUint32(minorVer)) { - HDF_LOGE("%{public}s: read minorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return codecImageRet; -} - -} // V1_0 -} // Image -} // Codec -} // HDI -} // OHOS + */ + +#include "v1_0/codec_image_proxy.h" +#include +#include +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG codec_image_proxy + +namespace OHOS { +namespace HDI { +namespace Codec { +namespace Image { +namespace V1_0 { + + +sptr OHOS::HDI::Codec::Image::V1_0::ICodecImage::Get(bool isStub) +{ + return ICodecImage::Get("codec_image_service", isStub); +} + +sptr OHOS::HDI::Codec::Image::V1_0::ICodecImage::Get(const std::string& serviceName, bool isStub) +{ + if (isStub) { + std::string desc = Str16ToStr8(OHOS::HDI::Codec::Image::V1_0::ICodecImage::GetDescriptor()); + void *impl = LoadHdiImpl(desc.c_str(), serviceName == "codec_image_service" ? "service" : serviceName.c_str()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + return reinterpret_cast(impl); + } + + using namespace OHOS::HDI::ServiceManager::V1_0; + auto servMgr = IServiceManager::Get(); + if (servMgr == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return nullptr; + } + + sptr remote = servMgr->GetService(serviceName.c_str()); + if (remote == nullptr) { + HDF_LOGE("%{public}s:get remote object failed!", __func__); + return nullptr; + } + + sptr proxy = new OHOS::HDI::Codec::Image::V1_0::CodecImageProxy(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:iface_cast failed!", __func__); + return nullptr; + } + + proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); + proxy->deathRecipient_ = new OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::IServiceManagerDeathRecipient(proxy); + proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); + proxy->isReconnected_ = false; + proxy->serviceName_ = serviceName; + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t codecImageRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (codecImageRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::Reconnect( + sptr proxy) +{ + if (proxy == nullptr) { + HDF_LOGW("Reconnect failed : input proxy is null"); + return HDF_FAILURE; + } + using namespace OHOS::HDI::ServiceManager::V1_0; + proxy->isReconnected_ = false; + auto iServMgr = IServiceManager::Get(); + if (iServMgr == nullptr) { + HDF_LOGW("Reconnect failed : iServMgr is null"); + return HDF_FAILURE; + }; + proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); + if (proxy->reconnectRemote_ == nullptr) { + HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); + return HDF_FAILURE; + } + proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); + if (proxy->servMgr_ == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return HDF_FAILURE; + } + proxy->servMgr_->AddDeathRecipient( + new OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::IServiceManagerDeathRecipient(proxy)); + proxy->isReconnected_ = true; + return HDF_SUCCESS; +} + +int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::GetImageCapability(std::vector& capList) +{ + return OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::GetImageCapability_(capList, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::Init(OHOS::HDI::Codec::Image::V1_0::CodecImageRole role) +{ + return OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::Init_(role, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::DeInit(OHOS::HDI::Codec::Image::V1_0::CodecImageRole role) +{ + return OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::DeInit_(role, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::DoJpegDecode(const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& outBuffer, const OHOS::HDI::Codec::Image::V1_0::CodecJpegDecInfo& decInfo) +{ + return OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::DoJpegDecode_(inBuffer, outBuffer, decInfo, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::AllocateInBuffer(OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, uint32_t size, OHOS::HDI::Codec::Image::V1_0::CodecImageRole role) +{ + return OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::AllocateInBuffer_(inBuffer, size, role, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::FreeInBuffer(const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer) +{ + return OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::FreeInBuffer_(inBuffer, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) +{ + return OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::GetImageCapability_(std::vector& capList, const sptr remote) +{ + MessageParcel codecImageData; + MessageParcel codecImageReply; + MessageOption codecImageOption(MessageOption::TF_SYNC); + + if (!codecImageData.WriteInterfaceToken(OHOS::HDI::Codec::Image::V1_0::ICodecImage::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!codecImageData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t codecImageRet = remote->SendRequest(CMD_CODEC_IMAGE_GET_IMAGE_CAPABILITY, codecImageData, codecImageReply, codecImageOption); + if (codecImageRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, codecImageRet); + return codecImageRet; + } + + uint32_t capListSize = 0; + if (!codecImageReply.ReadUint32(capListSize)) { + HDF_LOGE("%{public}s: failed to read size", __func__); + return HDF_ERR_INVALID_PARAM; + } + + HDI_CHECK_VALUE_RETURN(capListSize, >, HDI_BUFF_MAX_SIZE / sizeof(OHOS::HDI::Codec::Image::V1_0::CodecImageCapability), HDF_ERR_INVALID_PARAM); + capList.clear(); + capList.reserve(capListSize); + for (uint32_t i0 = 0; i0 < capListSize; ++i0) { + OHOS::HDI::Codec::Image::V1_0::CodecImageCapability value0; + if (!CodecImageCapabilityBlockUnmarshalling(codecImageReply, value0)) { + HDF_LOGE("%{public}s: read value0 failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + capList.push_back(value0); + } + + return codecImageRet; +} + +int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::Init_(OHOS::HDI::Codec::Image::V1_0::CodecImageRole role, + const sptr remote) +{ + MessageParcel codecImageData; + MessageParcel codecImageReply; + MessageOption codecImageOption(MessageOption::TF_SYNC); + + if (!codecImageData.WriteInterfaceToken(OHOS::HDI::Codec::Image::V1_0::ICodecImage::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!codecImageData.WriteUint64(static_cast(role))) { + HDF_LOGE("%{public}s: write role failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t codecImageRet = remote->SendRequest(CMD_CODEC_IMAGE_INIT, codecImageData, codecImageReply, codecImageOption); + if (codecImageRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, codecImageRet); + return codecImageRet; + } + + return codecImageRet; +} + +int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::DeInit_(OHOS::HDI::Codec::Image::V1_0::CodecImageRole role, + const sptr remote) +{ + MessageParcel codecImageData; + MessageParcel codecImageReply; + MessageOption codecImageOption(MessageOption::TF_SYNC); + + if (!codecImageData.WriteInterfaceToken(OHOS::HDI::Codec::Image::V1_0::ICodecImage::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!codecImageData.WriteUint64(static_cast(role))) { + HDF_LOGE("%{public}s: write role failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t codecImageRet = remote->SendRequest(CMD_CODEC_IMAGE_DE_INIT, codecImageData, codecImageReply, codecImageOption); + if (codecImageRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, codecImageRet); + return codecImageRet; + } + + return codecImageRet; +} + +int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::DoJpegDecode_(const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& outBuffer, const OHOS::HDI::Codec::Image::V1_0::CodecJpegDecInfo& decInfo, const sptr remote) +{ + MessageParcel codecImageData; + MessageParcel codecImageReply; + MessageOption codecImageOption(MessageOption::TF_SYNC); + + if (!codecImageData.WriteInterfaceToken(OHOS::HDI::Codec::Image::V1_0::ICodecImage::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!OHOS::HDI::Codec::Image::V1_0::CodecImageBufferBlockMarshalling(codecImageData, inBuffer)) { + HDF_LOGE("%{public}s: write inBuffer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!OHOS::HDI::Codec::Image::V1_0::CodecImageBufferBlockMarshalling(codecImageData, outBuffer)) { + HDF_LOGE("%{public}s: write outBuffer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!OHOS::HDI::Codec::Image::V1_0::CodecJpegDecInfoBlockMarshalling(codecImageData, decInfo)) { + HDF_LOGE("%{public}s: write decInfo failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t codecImageRet = remote->SendRequest(CMD_CODEC_IMAGE_DO_JPEG_DECODE, codecImageData, codecImageReply, codecImageOption); + if (codecImageRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, codecImageRet); + return codecImageRet; + } + + return codecImageRet; +} + +int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::AllocateInBuffer_(OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, uint32_t size, OHOS::HDI::Codec::Image::V1_0::CodecImageRole role, const sptr remote) +{ + MessageParcel codecImageData; + MessageParcel codecImageReply; + MessageOption codecImageOption(MessageOption::TF_SYNC); + + if (!codecImageData.WriteInterfaceToken(OHOS::HDI::Codec::Image::V1_0::ICodecImage::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!codecImageData.WriteUint32(size)) { + HDF_LOGE("%{public}s: write size failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!codecImageData.WriteUint64(static_cast(role))) { + HDF_LOGE("%{public}s: write role failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t codecImageRet = remote->SendRequest(CMD_CODEC_IMAGE_ALLOCATE_IN_BUFFER, codecImageData, codecImageReply, codecImageOption); + if (codecImageRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, codecImageRet); + return codecImageRet; + } + + if (!CodecImageBufferBlockUnmarshalling(codecImageReply, inBuffer)) { + HDF_LOGE("%{public}s: read inBuffer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return codecImageRet; +} + +int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::FreeInBuffer_(const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, const sptr remote) +{ + MessageParcel codecImageData; + MessageParcel codecImageReply; + MessageOption codecImageOption(MessageOption::TF_SYNC); + + if (!codecImageData.WriteInterfaceToken(OHOS::HDI::Codec::Image::V1_0::ICodecImage::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!OHOS::HDI::Codec::Image::V1_0::CodecImageBufferBlockMarshalling(codecImageData, inBuffer)) { + HDF_LOGE("%{public}s: write inBuffer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t codecImageRet = remote->SendRequest(CMD_CODEC_IMAGE_FREE_IN_BUFFER, codecImageData, codecImageReply, codecImageOption); + if (codecImageRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, codecImageRet); + return codecImageRet; + } + + return codecImageRet; +} + +int32_t OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, + const sptr remote) +{ + MessageParcel codecImageData; + MessageParcel codecImageReply; + MessageOption codecImageOption(MessageOption::TF_SYNC); + + if (!codecImageData.WriteInterfaceToken(OHOS::HDI::Codec::Image::V1_0::ICodecImage::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t codecImageRet = remote->SendRequest(CMD_CODEC_IMAGE_GET_VERSION, codecImageData, codecImageReply, codecImageOption); + if (codecImageRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, codecImageRet); + return codecImageRet; + } + + if (!codecImageReply.ReadUint32(majorVer)) { + HDF_LOGE("%{public}s: read majorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!codecImageReply.ReadUint32(minorVer)) { + HDF_LOGE("%{public}s: read minorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return codecImageRet; +} + +} // V1_0 +} // Image +} // Codec +} // HDI +} // OHOS diff --git a/test/hdi_unittest/codec_image_v1_0/cpp_target/codec/image/v1_0/codec_image_proxy.h.txt b/test/hdi_unittest/codec_image_v1_0/cpp_target/codec/image/v1_0/codec_image_proxy.h.txt index 4160d06..a84e288 100644 --- a/test/hdi_unittest/codec_image_v1_0/cpp_target/codec/image/v1_0/codec_image_proxy.h.txt +++ b/test/hdi_unittest/codec_image_v1_0/cpp_target/codec/image/v1_0/codec_image_proxy.h.txt @@ -11,117 +11,117 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#ifndef OHOS_HDI_CODEC_IMAGE_V1_0_CODECIMAGEPROXY_H -#define OHOS_HDI_CODEC_IMAGE_V1_0_CODECIMAGEPROXY_H - -#include "v1_0/icodec_image.h" -#include -#include - -namespace OHOS { -namespace HDI { -namespace Codec { -namespace Image { -namespace V1_0 { - -class CodecImageProxy : public IProxyBroker { -public: - class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { - public: - IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} - ~IServiceManagerDeathRecipient() override = default; - void OnRemoteDied(const wptr &remote) override - { - int32_t result = HDF_FAILURE; - const int sleepInterval = 500000; - const int waitTimes = 10; - int currentTime = waitTimes; - do { - usleep(sleepInterval); - auto proxy = proxy_.promote(); - if (proxy != nullptr) { - result = OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::Reconnect(proxy); - } - --currentTime; - } while (result != HDF_SUCCESS && currentTime >0); - } - private: - wptr proxy_; - }; - - explicit CodecImageProxy(const sptr& remote) : IProxyBroker(remote) { - reconnectRemote_ = nullptr; - servMgr_ = nullptr; - deathRecipient_ = nullptr; - isReconnected_ = false; - } - virtual ~CodecImageProxy() { - if (servMgr_ != nullptr && deathRecipient_ != nullptr) { - servMgr_->RemoveDeathRecipient(deathRecipient_); - } - } - - inline bool IsProxy() override - { - return true; - } - - int32_t GetImageCapability(std::vector& capList) override; - - int32_t Init(OHOS::HDI::Codec::Image::V1_0::CodecImageRole role) override; - - int32_t DeInit(OHOS::HDI::Codec::Image::V1_0::CodecImageRole role) override; - - int32_t DoJpegDecode(const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, - const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& outBuffer, const OHOS::HDI::Codec::Image::V1_0::CodecJpegDecInfo& decInfo) override; - - int32_t AllocateInBuffer(OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, uint32_t size, - OHOS::HDI::Codec::Image::V1_0::CodecImageRole role) override; - - int32_t FreeInBuffer(const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer) override; - - int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; - - static int32_t GetImageCapability_(std::vector& capList, - const sptr remote); - - static int32_t Init_(OHOS::HDI::Codec::Image::V1_0::CodecImageRole role, const sptr remote); - - static int32_t DeInit_(OHOS::HDI::Codec::Image::V1_0::CodecImageRole role, const sptr remote); - - static int32_t DoJpegDecode_(const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, - const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& outBuffer, const OHOS::HDI::Codec::Image::V1_0::CodecJpegDecInfo& decInfo, const sptr remote); - - static int32_t AllocateInBuffer_(OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, uint32_t size, - OHOS::HDI::Codec::Image::V1_0::CodecImageRole role, const sptr remote); - - static int32_t FreeInBuffer_(const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, - const sptr remote); - - static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); - - static int32_t Reconnect(sptr proxy); - - sptr GetCurrentRemote() { - return isReconnected_ ? reconnectRemote_ : Remote(); - } - - bool isReconnected_; - std::string serviceName_; - sptr servMgr_; - sptr deathRecipient_; - sptr reconnectRemote_; -private: - static inline BrokerDelegator delegator_; -}; - -} // V1_0 -} // Image -} // Codec -} // HDI -} // OHOS - -#endif // OHOS_HDI_CODEC_IMAGE_V1_0_CODECIMAGEPROXY_H - + */ + +#ifndef OHOS_HDI_CODEC_IMAGE_V1_0_CODECIMAGEPROXY_H +#define OHOS_HDI_CODEC_IMAGE_V1_0_CODECIMAGEPROXY_H + +#include "v1_0/icodec_image.h" +#include +#include + +namespace OHOS { +namespace HDI { +namespace Codec { +namespace Image { +namespace V1_0 { + +class CodecImageProxy : public IProxyBroker { +public: + class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { + public: + IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} + ~IServiceManagerDeathRecipient() override = default; + void OnRemoteDied(const wptr &remote) override + { + int32_t result = HDF_FAILURE; + const int sleepInterval = 500000; + const int waitTimes = 10; + int currentTime = waitTimes; + do { + usleep(sleepInterval); + auto proxy = proxy_.promote(); + if (proxy != nullptr) { + result = OHOS::HDI::Codec::Image::V1_0::CodecImageProxy::Reconnect(proxy); + } + --currentTime; + } while (result != HDF_SUCCESS && currentTime >0); + } + private: + wptr proxy_; + }; + + explicit CodecImageProxy(const sptr& remote) : IProxyBroker(remote) { + reconnectRemote_ = nullptr; + servMgr_ = nullptr; + deathRecipient_ = nullptr; + isReconnected_ = false; + } + virtual ~CodecImageProxy() { + if (servMgr_ != nullptr && deathRecipient_ != nullptr) { + servMgr_->RemoveDeathRecipient(deathRecipient_); + } + } + + inline bool IsProxy() override + { + return true; + } + + int32_t GetImageCapability(std::vector& capList) override; + + int32_t Init(OHOS::HDI::Codec::Image::V1_0::CodecImageRole role) override; + + int32_t DeInit(OHOS::HDI::Codec::Image::V1_0::CodecImageRole role) override; + + int32_t DoJpegDecode(const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, + const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& outBuffer, const OHOS::HDI::Codec::Image::V1_0::CodecJpegDecInfo& decInfo) override; + + int32_t AllocateInBuffer(OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, uint32_t size, + OHOS::HDI::Codec::Image::V1_0::CodecImageRole role) override; + + int32_t FreeInBuffer(const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer) override; + + int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; + + static int32_t GetImageCapability_(std::vector& capList, + const sptr remote); + + static int32_t Init_(OHOS::HDI::Codec::Image::V1_0::CodecImageRole role, const sptr remote); + + static int32_t DeInit_(OHOS::HDI::Codec::Image::V1_0::CodecImageRole role, const sptr remote); + + static int32_t DoJpegDecode_(const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, + const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& outBuffer, const OHOS::HDI::Codec::Image::V1_0::CodecJpegDecInfo& decInfo, const sptr remote); + + static int32_t AllocateInBuffer_(OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, uint32_t size, + OHOS::HDI::Codec::Image::V1_0::CodecImageRole role, const sptr remote); + + static int32_t FreeInBuffer_(const OHOS::HDI::Codec::Image::V1_0::CodecImageBuffer& inBuffer, + const sptr remote); + + static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); + + static int32_t Reconnect(sptr proxy); + + sptr GetCurrentRemote() { + return isReconnected_ ? reconnectRemote_ : Remote(); + } + + bool isReconnected_; + std::string serviceName_; + sptr servMgr_; + sptr deathRecipient_; + sptr reconnectRemote_; +private: + static inline BrokerDelegator delegator_; +}; + +} // V1_0 +} // Image +} // Codec +} // HDI +} // OHOS + +#endif // OHOS_HDI_CODEC_IMAGE_V1_0_CODECIMAGEPROXY_H + diff --git a/test/hdi_unittest/codec_image_v1_0/cpp_target/codec/image/v1_0/codec_image_stub.cpp.txt b/test/hdi_unittest/codec_image_v1_0/cpp_target/codec/image/v1_0/codec_image_stub.cpp.txt index 0be8e93..efdc30e 100644 --- a/test/hdi_unittest/codec_image_v1_0/cpp_target/codec/image/v1_0/codec_image_stub.cpp.txt +++ b/test/hdi_unittest/codec_image_v1_0/cpp_target/codec/image/v1_0/codec_image_stub.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/codec_image_stub.h" @@ -56,6 +56,7 @@ OHOS::HDI::Codec::Image::V1_0::CodecImageStub::CodecImageStub(const sptr diff --git a/test/hdi_unittest/enum_nesting_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt b/test/hdi_unittest/enum_nesting_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt index 2c0f9ff..b98f302 100644 --- a/test/hdi_unittest/enum_nesting_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt +++ b/test/hdi_unittest/enum_nesting_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt @@ -11,279 +11,279 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#include "v1_0/foo_proxy.h" -#include -#include -#include -#include -#include -#include -#include - -#define HDF_LOG_TAG foo_proxy - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) -{ - return IFoo::Get("foo_service", isStub); -} - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) -{ - if (isStub) { - std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); - void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); - if (impl == nullptr) { - HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); - return nullptr; - } - return reinterpret_cast(impl); - } - - using namespace OHOS::HDI::ServiceManager::V1_0; - auto servMgr = IServiceManager::Get(); - if (servMgr == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return nullptr; - } - - sptr remote = servMgr->GetService(serviceName.c_str()); - if (remote == nullptr) { - HDF_LOGE("%{public}s:get remote object failed!", __func__); - return nullptr; - } - - sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); - if (proxy == nullptr) { - HDF_LOGE("%{public}s:iface_cast failed!", __func__); - return nullptr; - } - - proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); - proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); - proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); - proxy->isReconnected_ = false; - proxy->serviceName_ = serviceName; - uint32_t serMajorVer = 0; - uint32_t serMinorVer = 0; - int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s:get version failed!", __func__); - return nullptr; - } - - if (serMajorVer != 1) { - HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); - return nullptr; - } - - return proxy; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( - sptr proxy) -{ - if (proxy == nullptr) { - HDF_LOGW("Reconnect failed : input proxy is null"); - return HDF_FAILURE; - } - using namespace OHOS::HDI::ServiceManager::V1_0; - proxy->isReconnected_ = false; - auto iServMgr = IServiceManager::Get(); - if (iServMgr == nullptr) { - HDF_LOGW("Reconnect failed : iServMgr is null"); - return HDF_FAILURE; - }; - proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); - if (proxy->reconnectRemote_ == nullptr) { - HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); - return HDF_FAILURE; - } - proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); - if (proxy->servMgr_ == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return HDF_FAILURE; - } - proxy->servMgr_->AddDeathRecipient( - new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); - proxy->isReconnected_ = true; - return HDF_SUCCESS; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, - OHOS::HDI::Foo::V1_0::FooInfo& outParam) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(inParam, outParam, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteBool(false)) { - HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteCString(sendMsg.c_str())) { - HDF_LOGE("%{public}s: write sendMsg failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - const char* recvMsgCp = fooReply.ReadCString(); - if (recvMsgCp == nullptr) { - HDF_LOGE("%{public}s: read recvMsg failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - recvMsg = recvMsgCp; - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!FooInfoBlockUnmarshalling(fooReply, info)) { - HDF_LOGE("%{public}s: read info failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, - OHOS::HDI::Foo::V1_0::FooInfo& outParam, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!OHOS::HDI::Foo::V1_0::FooInfoBlockMarshalling(fooData, inParam)) { - HDF_LOGE("%{public}s: write inParam failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_INFO_TEST, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!FooInfoBlockUnmarshalling(fooReply, outParam)) { - HDF_LOGE("%{public}s: read outParam failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!fooReply.ReadUint32(majorVer)) { - HDF_LOGE("%{public}s: read majorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooReply.ReadUint32(minorVer)) { - HDF_LOGE("%{public}s: read minorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -} // V1_0 -} // Foo -} // HDI -} // OHOS + */ + +#include "v1_0/foo_proxy.h" +#include +#include +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG foo_proxy + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) +{ + return IFoo::Get("foo_service", isStub); +} + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) +{ + if (isStub) { + std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); + void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + return reinterpret_cast(impl); + } + + using namespace OHOS::HDI::ServiceManager::V1_0; + auto servMgr = IServiceManager::Get(); + if (servMgr == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return nullptr; + } + + sptr remote = servMgr->GetService(serviceName.c_str()); + if (remote == nullptr) { + HDF_LOGE("%{public}s:get remote object failed!", __func__); + return nullptr; + } + + sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:iface_cast failed!", __func__); + return nullptr; + } + + proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); + proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); + proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); + proxy->isReconnected_ = false; + proxy->serviceName_ = serviceName; + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( + sptr proxy) +{ + if (proxy == nullptr) { + HDF_LOGW("Reconnect failed : input proxy is null"); + return HDF_FAILURE; + } + using namespace OHOS::HDI::ServiceManager::V1_0; + proxy->isReconnected_ = false; + auto iServMgr = IServiceManager::Get(); + if (iServMgr == nullptr) { + HDF_LOGW("Reconnect failed : iServMgr is null"); + return HDF_FAILURE; + }; + proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); + if (proxy->reconnectRemote_ == nullptr) { + HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); + return HDF_FAILURE; + } + proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); + if (proxy->servMgr_ == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return HDF_FAILURE; + } + proxy->servMgr_->AddDeathRecipient( + new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); + proxy->isReconnected_ = true; + return HDF_SUCCESS; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, + OHOS::HDI::Foo::V1_0::FooInfo& outParam) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(inParam, outParam, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteCString(sendMsg.c_str())) { + HDF_LOGE("%{public}s: write sendMsg failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + const char* recvMsgCp = fooReply.ReadCString(); + if (recvMsgCp == nullptr) { + HDF_LOGE("%{public}s: read recvMsg failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + recvMsg = recvMsgCp; + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!FooInfoBlockUnmarshalling(fooReply, info)) { + HDF_LOGE("%{public}s: read info failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, + OHOS::HDI::Foo::V1_0::FooInfo& outParam, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!OHOS::HDI::Foo::V1_0::FooInfoBlockMarshalling(fooData, inParam)) { + HDF_LOGE("%{public}s: write inParam failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_INFO_TEST, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!FooInfoBlockUnmarshalling(fooReply, outParam)) { + HDF_LOGE("%{public}s: read outParam failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.ReadUint32(majorVer)) { + HDF_LOGE("%{public}s: read majorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooReply.ReadUint32(minorVer)) { + HDF_LOGE("%{public}s: read minorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +} // V1_0 +} // Foo +} // HDI +} // OHOS diff --git a/test/hdi_unittest/enum_nesting_idl/cpp_target/foo/v1_0/foo_proxy.h.txt b/test/hdi_unittest/enum_nesting_idl/cpp_target/foo/v1_0/foo_proxy.h.txt index c07f210..e707378 100644 --- a/test/hdi_unittest/enum_nesting_idl/cpp_target/foo/v1_0/foo_proxy.h.txt +++ b/test/hdi_unittest/enum_nesting_idl/cpp_target/foo/v1_0/foo_proxy.h.txt @@ -11,98 +11,98 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H -#define OHOS_HDI_FOO_V1_0_FOOPROXY_H - -#include "v1_0/ifoo.h" -#include -#include - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - -class FooProxy : public IProxyBroker { -public: - class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { - public: - IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} - ~IServiceManagerDeathRecipient() override = default; - void OnRemoteDied(const wptr &remote) override - { - int32_t result = HDF_FAILURE; - const int sleepInterval = 500000; - const int waitTimes = 10; - int currentTime = waitTimes; - do { - usleep(sleepInterval); - auto proxy = proxy_.promote(); - if (proxy != nullptr) { - result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); - } - --currentTime; - } while (result != HDF_SUCCESS && currentTime >0); - } - private: - wptr proxy_; - }; - - explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { - reconnectRemote_ = nullptr; - servMgr_ = nullptr; - deathRecipient_ = nullptr; - isReconnected_ = false; - } - virtual ~FooProxy() { - if (servMgr_ != nullptr && deathRecipient_ != nullptr) { - servMgr_->RemoveDeathRecipient(deathRecipient_); - } - } - - inline bool IsProxy() override - { - return true; - } - - int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; - - int32_t GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) override; - - int32_t InfoTest(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, OHOS::HDI::Foo::V1_0::FooInfo& outParam) override; - - int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; - - static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); - - static int32_t GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote); - - static int32_t InfoTest_(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, OHOS::HDI::Foo::V1_0::FooInfo& outParam, - const sptr remote); - - static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); - - static int32_t Reconnect(sptr proxy); - - sptr GetCurrentRemote() { - return isReconnected_ ? reconnectRemote_ : Remote(); - } - - bool isReconnected_; - std::string serviceName_; - sptr servMgr_; - sptr deathRecipient_; - sptr reconnectRemote_; -private: - static inline BrokerDelegator delegator_; -}; - -} // V1_0 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H - + */ + +#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H +#define OHOS_HDI_FOO_V1_0_FOOPROXY_H + +#include "v1_0/ifoo.h" +#include +#include + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + +class FooProxy : public IProxyBroker { +public: + class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { + public: + IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} + ~IServiceManagerDeathRecipient() override = default; + void OnRemoteDied(const wptr &remote) override + { + int32_t result = HDF_FAILURE; + const int sleepInterval = 500000; + const int waitTimes = 10; + int currentTime = waitTimes; + do { + usleep(sleepInterval); + auto proxy = proxy_.promote(); + if (proxy != nullptr) { + result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); + } + --currentTime; + } while (result != HDF_SUCCESS && currentTime >0); + } + private: + wptr proxy_; + }; + + explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { + reconnectRemote_ = nullptr; + servMgr_ = nullptr; + deathRecipient_ = nullptr; + isReconnected_ = false; + } + virtual ~FooProxy() { + if (servMgr_ != nullptr && deathRecipient_ != nullptr) { + servMgr_->RemoveDeathRecipient(deathRecipient_); + } + } + + inline bool IsProxy() override + { + return true; + } + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) override; + + int32_t InfoTest(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, OHOS::HDI::Foo::V1_0::FooInfo& outParam) override; + + int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; + + static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); + + static int32_t GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote); + + static int32_t InfoTest_(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, OHOS::HDI::Foo::V1_0::FooInfo& outParam, + const sptr remote); + + static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); + + static int32_t Reconnect(sptr proxy); + + sptr GetCurrentRemote() { + return isReconnected_ ? reconnectRemote_ : Remote(); + } + + bool isReconnected_; + std::string serviceName_; + sptr servMgr_; + sptr deathRecipient_; + sptr reconnectRemote_; +private: + static inline BrokerDelegator delegator_; +}; + +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H + diff --git a/test/hdi_unittest/enum_nesting_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt b/test/hdi_unittest/enum_nesting_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt index 7682a3a..4c36b9f 100644 --- a/test/hdi_unittest/enum_nesting_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt +++ b/test/hdi_unittest/enum_nesting_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_stub.h" @@ -55,6 +55,7 @@ OHOS::HDI::Foo::V1_0::FooStub::FooStub(const sptr &i OHOS::HDI::Foo::V1_0::FooStub::~FooStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/extended_enum_idl/cpp_target/foo/v1_0/foo_driver.cpp.txt b/test/hdi_unittest/extended_enum_idl/cpp_target/foo/v1_0/foo_driver.cpp.txt index 625a670..a238792 100644 --- a/test/hdi_unittest/extended_enum_idl/cpp_target/foo/v1_0/foo_driver.cpp.txt +++ b/test/hdi_unittest/extended_enum_idl/cpp_target/foo/v1_0/foo_driver.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/extended_enum_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt b/test/hdi_unittest/extended_enum_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt index 2c0f9ff..b98f302 100644 --- a/test/hdi_unittest/extended_enum_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt +++ b/test/hdi_unittest/extended_enum_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt @@ -11,279 +11,279 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#include "v1_0/foo_proxy.h" -#include -#include -#include -#include -#include -#include -#include - -#define HDF_LOG_TAG foo_proxy - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) -{ - return IFoo::Get("foo_service", isStub); -} - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) -{ - if (isStub) { - std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); - void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); - if (impl == nullptr) { - HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); - return nullptr; - } - return reinterpret_cast(impl); - } - - using namespace OHOS::HDI::ServiceManager::V1_0; - auto servMgr = IServiceManager::Get(); - if (servMgr == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return nullptr; - } - - sptr remote = servMgr->GetService(serviceName.c_str()); - if (remote == nullptr) { - HDF_LOGE("%{public}s:get remote object failed!", __func__); - return nullptr; - } - - sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); - if (proxy == nullptr) { - HDF_LOGE("%{public}s:iface_cast failed!", __func__); - return nullptr; - } - - proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); - proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); - proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); - proxy->isReconnected_ = false; - proxy->serviceName_ = serviceName; - uint32_t serMajorVer = 0; - uint32_t serMinorVer = 0; - int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s:get version failed!", __func__); - return nullptr; - } - - if (serMajorVer != 1) { - HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); - return nullptr; - } - - return proxy; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( - sptr proxy) -{ - if (proxy == nullptr) { - HDF_LOGW("Reconnect failed : input proxy is null"); - return HDF_FAILURE; - } - using namespace OHOS::HDI::ServiceManager::V1_0; - proxy->isReconnected_ = false; - auto iServMgr = IServiceManager::Get(); - if (iServMgr == nullptr) { - HDF_LOGW("Reconnect failed : iServMgr is null"); - return HDF_FAILURE; - }; - proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); - if (proxy->reconnectRemote_ == nullptr) { - HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); - return HDF_FAILURE; - } - proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); - if (proxy->servMgr_ == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return HDF_FAILURE; - } - proxy->servMgr_->AddDeathRecipient( - new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); - proxy->isReconnected_ = true; - return HDF_SUCCESS; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, - OHOS::HDI::Foo::V1_0::FooInfo& outParam) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(inParam, outParam, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteBool(false)) { - HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteCString(sendMsg.c_str())) { - HDF_LOGE("%{public}s: write sendMsg failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - const char* recvMsgCp = fooReply.ReadCString(); - if (recvMsgCp == nullptr) { - HDF_LOGE("%{public}s: read recvMsg failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - recvMsg = recvMsgCp; - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!FooInfoBlockUnmarshalling(fooReply, info)) { - HDF_LOGE("%{public}s: read info failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, - OHOS::HDI::Foo::V1_0::FooInfo& outParam, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!OHOS::HDI::Foo::V1_0::FooInfoBlockMarshalling(fooData, inParam)) { - HDF_LOGE("%{public}s: write inParam failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_INFO_TEST, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!FooInfoBlockUnmarshalling(fooReply, outParam)) { - HDF_LOGE("%{public}s: read outParam failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!fooReply.ReadUint32(majorVer)) { - HDF_LOGE("%{public}s: read majorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooReply.ReadUint32(minorVer)) { - HDF_LOGE("%{public}s: read minorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -} // V1_0 -} // Foo -} // HDI -} // OHOS + */ + +#include "v1_0/foo_proxy.h" +#include +#include +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG foo_proxy + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) +{ + return IFoo::Get("foo_service", isStub); +} + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) +{ + if (isStub) { + std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); + void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + return reinterpret_cast(impl); + } + + using namespace OHOS::HDI::ServiceManager::V1_0; + auto servMgr = IServiceManager::Get(); + if (servMgr == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return nullptr; + } + + sptr remote = servMgr->GetService(serviceName.c_str()); + if (remote == nullptr) { + HDF_LOGE("%{public}s:get remote object failed!", __func__); + return nullptr; + } + + sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:iface_cast failed!", __func__); + return nullptr; + } + + proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); + proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); + proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); + proxy->isReconnected_ = false; + proxy->serviceName_ = serviceName; + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( + sptr proxy) +{ + if (proxy == nullptr) { + HDF_LOGW("Reconnect failed : input proxy is null"); + return HDF_FAILURE; + } + using namespace OHOS::HDI::ServiceManager::V1_0; + proxy->isReconnected_ = false; + auto iServMgr = IServiceManager::Get(); + if (iServMgr == nullptr) { + HDF_LOGW("Reconnect failed : iServMgr is null"); + return HDF_FAILURE; + }; + proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); + if (proxy->reconnectRemote_ == nullptr) { + HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); + return HDF_FAILURE; + } + proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); + if (proxy->servMgr_ == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return HDF_FAILURE; + } + proxy->servMgr_->AddDeathRecipient( + new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); + proxy->isReconnected_ = true; + return HDF_SUCCESS; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, + OHOS::HDI::Foo::V1_0::FooInfo& outParam) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(inParam, outParam, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteCString(sendMsg.c_str())) { + HDF_LOGE("%{public}s: write sendMsg failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + const char* recvMsgCp = fooReply.ReadCString(); + if (recvMsgCp == nullptr) { + HDF_LOGE("%{public}s: read recvMsg failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + recvMsg = recvMsgCp; + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!FooInfoBlockUnmarshalling(fooReply, info)) { + HDF_LOGE("%{public}s: read info failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, + OHOS::HDI::Foo::V1_0::FooInfo& outParam, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!OHOS::HDI::Foo::V1_0::FooInfoBlockMarshalling(fooData, inParam)) { + HDF_LOGE("%{public}s: write inParam failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_INFO_TEST, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!FooInfoBlockUnmarshalling(fooReply, outParam)) { + HDF_LOGE("%{public}s: read outParam failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.ReadUint32(majorVer)) { + HDF_LOGE("%{public}s: read majorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooReply.ReadUint32(minorVer)) { + HDF_LOGE("%{public}s: read minorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +} // V1_0 +} // Foo +} // HDI +} // OHOS diff --git a/test/hdi_unittest/extended_enum_idl/cpp_target/foo/v1_0/foo_proxy.h.txt b/test/hdi_unittest/extended_enum_idl/cpp_target/foo/v1_0/foo_proxy.h.txt index c07f210..e707378 100644 --- a/test/hdi_unittest/extended_enum_idl/cpp_target/foo/v1_0/foo_proxy.h.txt +++ b/test/hdi_unittest/extended_enum_idl/cpp_target/foo/v1_0/foo_proxy.h.txt @@ -11,98 +11,98 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H -#define OHOS_HDI_FOO_V1_0_FOOPROXY_H - -#include "v1_0/ifoo.h" -#include -#include - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - -class FooProxy : public IProxyBroker { -public: - class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { - public: - IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} - ~IServiceManagerDeathRecipient() override = default; - void OnRemoteDied(const wptr &remote) override - { - int32_t result = HDF_FAILURE; - const int sleepInterval = 500000; - const int waitTimes = 10; - int currentTime = waitTimes; - do { - usleep(sleepInterval); - auto proxy = proxy_.promote(); - if (proxy != nullptr) { - result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); - } - --currentTime; - } while (result != HDF_SUCCESS && currentTime >0); - } - private: - wptr proxy_; - }; - - explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { - reconnectRemote_ = nullptr; - servMgr_ = nullptr; - deathRecipient_ = nullptr; - isReconnected_ = false; - } - virtual ~FooProxy() { - if (servMgr_ != nullptr && deathRecipient_ != nullptr) { - servMgr_->RemoveDeathRecipient(deathRecipient_); - } - } - - inline bool IsProxy() override - { - return true; - } - - int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; - - int32_t GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) override; - - int32_t InfoTest(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, OHOS::HDI::Foo::V1_0::FooInfo& outParam) override; - - int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; - - static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); - - static int32_t GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote); - - static int32_t InfoTest_(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, OHOS::HDI::Foo::V1_0::FooInfo& outParam, - const sptr remote); - - static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); - - static int32_t Reconnect(sptr proxy); - - sptr GetCurrentRemote() { - return isReconnected_ ? reconnectRemote_ : Remote(); - } - - bool isReconnected_; - std::string serviceName_; - sptr servMgr_; - sptr deathRecipient_; - sptr reconnectRemote_; -private: - static inline BrokerDelegator delegator_; -}; - -} // V1_0 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H - + */ + +#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H +#define OHOS_HDI_FOO_V1_0_FOOPROXY_H + +#include "v1_0/ifoo.h" +#include +#include + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + +class FooProxy : public IProxyBroker { +public: + class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { + public: + IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} + ~IServiceManagerDeathRecipient() override = default; + void OnRemoteDied(const wptr &remote) override + { + int32_t result = HDF_FAILURE; + const int sleepInterval = 500000; + const int waitTimes = 10; + int currentTime = waitTimes; + do { + usleep(sleepInterval); + auto proxy = proxy_.promote(); + if (proxy != nullptr) { + result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); + } + --currentTime; + } while (result != HDF_SUCCESS && currentTime >0); + } + private: + wptr proxy_; + }; + + explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { + reconnectRemote_ = nullptr; + servMgr_ = nullptr; + deathRecipient_ = nullptr; + isReconnected_ = false; + } + virtual ~FooProxy() { + if (servMgr_ != nullptr && deathRecipient_ != nullptr) { + servMgr_->RemoveDeathRecipient(deathRecipient_); + } + } + + inline bool IsProxy() override + { + return true; + } + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) override; + + int32_t InfoTest(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, OHOS::HDI::Foo::V1_0::FooInfo& outParam) override; + + int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; + + static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); + + static int32_t GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote); + + static int32_t InfoTest_(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, OHOS::HDI::Foo::V1_0::FooInfo& outParam, + const sptr remote); + + static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); + + static int32_t Reconnect(sptr proxy); + + sptr GetCurrentRemote() { + return isReconnected_ ? reconnectRemote_ : Remote(); + } + + bool isReconnected_; + std::string serviceName_; + sptr servMgr_; + sptr deathRecipient_; + sptr reconnectRemote_; +private: + static inline BrokerDelegator delegator_; +}; + +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H + diff --git a/test/hdi_unittest/extended_enum_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt b/test/hdi_unittest/extended_enum_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt index 7682a3a..4c36b9f 100644 --- a/test/hdi_unittest/extended_enum_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt +++ b/test/hdi_unittest/extended_enum_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_stub.h" @@ -55,6 +55,7 @@ OHOS::HDI::Foo::V1_0::FooStub::FooStub(const sptr &i OHOS::HDI::Foo::V1_0::FooStub::~FooStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/extended_interface_idl/cpp_target/foo/v1_1/foo_driver.cpp.txt b/test/hdi_unittest/extended_interface_idl/cpp_target/foo/v1_1/foo_driver.cpp.txt index 3a758d3..cb7475f 100644 --- a/test/hdi_unittest/extended_interface_idl/cpp_target/foo/v1_1/foo_driver.cpp.txt +++ b/test/hdi_unittest/extended_interface_idl/cpp_target/foo/v1_1/foo_driver.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/extended_interface_idl/cpp_target/foo/v1_1/foo_proxy.cpp.txt b/test/hdi_unittest/extended_interface_idl/cpp_target/foo/v1_1/foo_proxy.cpp.txt index ed422dc..f937266 100644 --- a/test/hdi_unittest/extended_interface_idl/cpp_target/foo/v1_1/foo_proxy.cpp.txt +++ b/test/hdi_unittest/extended_interface_idl/cpp_target/foo/v1_1/foo_proxy.cpp.txt @@ -11,269 +11,269 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#include "v1_1/foo_proxy.h" -#include -#include -#include -#include -#include -#include -#include - -#define HDF_LOG_TAG foo_proxy - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_1 { - - -template -static sptr CastFromTemplate(const sptr &parent) -{ - if (parent == nullptr) { - HDF_LOGE("%{public}s:parent is nullptr!", __func__); - return nullptr; - } - - if (!parent->IsProxy()) { - HDF_LOGE("%{public}s:not proxy, not support castfrom!", __func__); - return nullptr; - } - - sptr remote = OHOS::HDI::hdi_objcast(parent); - if (remote == nullptr) { - HDF_LOGE("%{public}s:hdi_objcast failed!", __func__); - return nullptr; - } - - sptr proxy = OHOS::HDI::hdi_facecast(remote); - if (proxy == nullptr) { - HDF_LOGE("%{public}s:hdi_facecast failed!", __func__); - return nullptr; - } - - uint32_t serMajorVer = 0; - uint32_t serMinorVer = 0; - int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s:get version failed!", __func__); - return nullptr; - } - - if (serMajorVer != 1) { - HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.1", __func__, serMajorVer, serMinorVer); - return nullptr; - } - - return proxy; -} - -sptr OHOS::HDI::Foo::V1_1::IFoo::Get(bool isStub) -{ - return IFoo::Get("foo_service", isStub); -} - -sptr OHOS::HDI::Foo::V1_1::IFoo::Get(const std::string& serviceName, bool isStub) -{ - if (isStub) { - std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_1::IFoo::GetDescriptor()); - void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); - if (impl == nullptr) { - HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); - return nullptr; - } - return reinterpret_cast(impl); - } - - using namespace OHOS::HDI::ServiceManager::V1_0; - auto servMgr = IServiceManager::Get(); - if (servMgr == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return nullptr; - } - - sptr remote = servMgr->GetService(serviceName.c_str()); - if (remote == nullptr) { - HDF_LOGE("%{public}s:get remote object failed!", __func__); - return nullptr; - } - - sptr proxy = new OHOS::HDI::Foo::V1_1::FooProxy(remote); - if (proxy == nullptr) { - HDF_LOGE("%{public}s:iface_cast failed!", __func__); - return nullptr; - } - - proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); - proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_1::FooProxy::IServiceManagerDeathRecipient(proxy); - proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); - proxy->isReconnected_ = false; - proxy->serviceName_ = serviceName; - uint32_t serMajorVer = 0; - uint32_t serMinorVer = 0; - int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s:get version failed!", __func__); - return nullptr; - } - - if (serMajorVer != 1) { - HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.1", __func__, serMajorVer, serMinorVer); - return nullptr; - } - - return proxy; -} - -int32_t OHOS::HDI::Foo::V1_1::FooProxy::Reconnect( - sptr proxy) -{ - if (proxy == nullptr) { - HDF_LOGW("Reconnect failed : input proxy is null"); - return HDF_FAILURE; - } - using namespace OHOS::HDI::ServiceManager::V1_0; - proxy->isReconnected_ = false; - auto iServMgr = IServiceManager::Get(); - if (iServMgr == nullptr) { - HDF_LOGW("Reconnect failed : iServMgr is null"); - return HDF_FAILURE; - }; - proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); - if (proxy->reconnectRemote_ == nullptr) { - HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); - return HDF_FAILURE; - } - proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); - if (proxy->servMgr_ == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return HDF_FAILURE; - } - proxy->servMgr_->AddDeathRecipient( - new OHOS::HDI::Foo::V1_1::FooProxy::IServiceManagerDeathRecipient(proxy)); - proxy->isReconnected_ = true; - return HDF_SUCCESS; -} - -sptr OHOS::HDI::Foo::V1_1::IFoo::CastFrom(const sptr &parent) -{ - return CastFromTemplate(parent); -} - -int32_t OHOS::HDI::Foo::V1_1::FooProxy::TestPingV1_1(const std::string& sendMsg, std::string& recvMsg) -{ - return OHOS::HDI::Foo::V1_1::FooProxy::TestPingV1_1_(sendMsg, recvMsg, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_1::FooProxy::TestGetData(std::string& info) -{ - return OHOS::HDI::Foo::V1_1::FooProxy::TestGetData_(info, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_1::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_1::FooProxy::GetData(std::string& info) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_1::FooProxy::InfoTest(int32_t inParam, double& outParam) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(inParam, outParam, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_1::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_1::FooProxy::TestPingV1_1_(const std::string& sendMsg, std::string& recvMsg, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_1::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteBool(false)) { - HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteCString(sendMsg.c_str())) { - HDF_LOGE("%{public}s: write sendMsg failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_PING_V1_1, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - const char* recvMsgCp = fooReply.ReadCString(); - if (recvMsgCp == nullptr) { - HDF_LOGE("%{public}s: read recvMsg failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - recvMsg = recvMsgCp; - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_1::FooProxy::TestGetData_(std::string& info, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_1::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteBool(false)) { - HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_GET_DATA, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - const char* infoCp = fooReply.ReadCString(); - if (infoCp == nullptr) { - HDF_LOGE("%{public}s: read info failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - info = infoCp; - - return fooRet; -} - -} // V1_1 -} // Foo -} // HDI -} // OHOS + */ + +#include "v1_1/foo_proxy.h" +#include +#include +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG foo_proxy + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_1 { + + +template +static sptr CastFromTemplate(const sptr &parent) +{ + if (parent == nullptr) { + HDF_LOGE("%{public}s:parent is nullptr!", __func__); + return nullptr; + } + + if (!parent->IsProxy()) { + HDF_LOGE("%{public}s:not proxy, not support castfrom!", __func__); + return nullptr; + } + + sptr remote = OHOS::HDI::hdi_objcast(parent); + if (remote == nullptr) { + HDF_LOGE("%{public}s:hdi_objcast failed!", __func__); + return nullptr; + } + + sptr proxy = OHOS::HDI::hdi_facecast(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:hdi_facecast failed!", __func__); + return nullptr; + } + + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.1", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +sptr OHOS::HDI::Foo::V1_1::IFoo::Get(bool isStub) +{ + return IFoo::Get("foo_service", isStub); +} + +sptr OHOS::HDI::Foo::V1_1::IFoo::Get(const std::string& serviceName, bool isStub) +{ + if (isStub) { + std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_1::IFoo::GetDescriptor()); + void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + return reinterpret_cast(impl); + } + + using namespace OHOS::HDI::ServiceManager::V1_0; + auto servMgr = IServiceManager::Get(); + if (servMgr == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return nullptr; + } + + sptr remote = servMgr->GetService(serviceName.c_str()); + if (remote == nullptr) { + HDF_LOGE("%{public}s:get remote object failed!", __func__); + return nullptr; + } + + sptr proxy = new OHOS::HDI::Foo::V1_1::FooProxy(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:iface_cast failed!", __func__); + return nullptr; + } + + proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); + proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_1::FooProxy::IServiceManagerDeathRecipient(proxy); + proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); + proxy->isReconnected_ = false; + proxy->serviceName_ = serviceName; + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.1", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::Reconnect( + sptr proxy) +{ + if (proxy == nullptr) { + HDF_LOGW("Reconnect failed : input proxy is null"); + return HDF_FAILURE; + } + using namespace OHOS::HDI::ServiceManager::V1_0; + proxy->isReconnected_ = false; + auto iServMgr = IServiceManager::Get(); + if (iServMgr == nullptr) { + HDF_LOGW("Reconnect failed : iServMgr is null"); + return HDF_FAILURE; + }; + proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); + if (proxy->reconnectRemote_ == nullptr) { + HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); + return HDF_FAILURE; + } + proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); + if (proxy->servMgr_ == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return HDF_FAILURE; + } + proxy->servMgr_->AddDeathRecipient( + new OHOS::HDI::Foo::V1_1::FooProxy::IServiceManagerDeathRecipient(proxy)); + proxy->isReconnected_ = true; + return HDF_SUCCESS; +} + +sptr OHOS::HDI::Foo::V1_1::IFoo::CastFrom(const sptr &parent) +{ + return CastFromTemplate(parent); +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::TestPingV1_1(const std::string& sendMsg, std::string& recvMsg) +{ + return OHOS::HDI::Foo::V1_1::FooProxy::TestPingV1_1_(sendMsg, recvMsg, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::TestGetData(std::string& info) +{ + return OHOS::HDI::Foo::V1_1::FooProxy::TestGetData_(info, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::GetData(std::string& info) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::InfoTest(int32_t inParam, double& outParam) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(inParam, outParam, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::TestPingV1_1_(const std::string& sendMsg, std::string& recvMsg, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_1::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteCString(sendMsg.c_str())) { + HDF_LOGE("%{public}s: write sendMsg failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_PING_V1_1, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + const char* recvMsgCp = fooReply.ReadCString(); + if (recvMsgCp == nullptr) { + HDF_LOGE("%{public}s: read recvMsg failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + recvMsg = recvMsgCp; + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::TestGetData_(std::string& info, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_1::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_GET_DATA, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + const char* infoCp = fooReply.ReadCString(); + if (infoCp == nullptr) { + HDF_LOGE("%{public}s: read info failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + info = infoCp; + + return fooRet; +} + +} // V1_1 +} // Foo +} // HDI +} // OHOS diff --git a/test/hdi_unittest/extended_interface_idl/cpp_target/foo/v1_1/foo_proxy.h.txt b/test/hdi_unittest/extended_interface_idl/cpp_target/foo/v1_1/foo_proxy.h.txt index 660ee38..16a930c 100644 --- a/test/hdi_unittest/extended_interface_idl/cpp_target/foo/v1_1/foo_proxy.h.txt +++ b/test/hdi_unittest/extended_interface_idl/cpp_target/foo/v1_1/foo_proxy.h.txt @@ -11,98 +11,98 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_1_FOOPROXY_H -#define OHOS_HDI_FOO_V1_1_FOOPROXY_H - -#include "v1_0/foo_proxy.h" -#include "v1_1/ifoo.h" -#include -#include - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_1 { - -class FooProxy : public IProxyBroker { -public: - class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { - public: - IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} - ~IServiceManagerDeathRecipient() override = default; - void OnRemoteDied(const wptr &remote) override - { - int32_t result = HDF_FAILURE; - const int sleepInterval = 500000; - const int waitTimes = 10; - int currentTime = waitTimes; - do { - usleep(sleepInterval); - auto proxy = proxy_.promote(); - if (proxy != nullptr) { - result = OHOS::HDI::Foo::V1_1::FooProxy::Reconnect(proxy); - } - --currentTime; - } while (result != HDF_SUCCESS && currentTime >0); - } - private: - wptr proxy_; - }; - - explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { - reconnectRemote_ = nullptr; - servMgr_ = nullptr; - deathRecipient_ = nullptr; - isReconnected_ = false; - } - virtual ~FooProxy() { - if (servMgr_ != nullptr && deathRecipient_ != nullptr) { - servMgr_->RemoveDeathRecipient(deathRecipient_); - } - } - - inline bool IsProxy() override - { - return true; - } - - int32_t TestPingV1_1(const std::string& sendMsg, std::string& recvMsg) override; - - int32_t TestGetData(std::string& info) override; - - int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; - - int32_t GetData(std::string& info) override; - - int32_t InfoTest(int32_t inParam, double& outParam) override; - - int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; - - static int32_t TestPingV1_1_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); - - static int32_t TestGetData_(std::string& info, const sptr remote); - - static int32_t Reconnect(sptr proxy); - - sptr GetCurrentRemote() { - return isReconnected_ ? reconnectRemote_ : Remote(); - } - - bool isReconnected_; - std::string serviceName_; - sptr servMgr_; - sptr deathRecipient_; - sptr reconnectRemote_; -private: - static inline BrokerDelegator delegator_; -}; - -} // V1_1 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_1_FOOPROXY_H - + */ + +#ifndef OHOS_HDI_FOO_V1_1_FOOPROXY_H +#define OHOS_HDI_FOO_V1_1_FOOPROXY_H + +#include "v1_0/foo_proxy.h" +#include "v1_1/ifoo.h" +#include +#include + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_1 { + +class FooProxy : public IProxyBroker { +public: + class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { + public: + IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} + ~IServiceManagerDeathRecipient() override = default; + void OnRemoteDied(const wptr &remote) override + { + int32_t result = HDF_FAILURE; + const int sleepInterval = 500000; + const int waitTimes = 10; + int currentTime = waitTimes; + do { + usleep(sleepInterval); + auto proxy = proxy_.promote(); + if (proxy != nullptr) { + result = OHOS::HDI::Foo::V1_1::FooProxy::Reconnect(proxy); + } + --currentTime; + } while (result != HDF_SUCCESS && currentTime >0); + } + private: + wptr proxy_; + }; + + explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { + reconnectRemote_ = nullptr; + servMgr_ = nullptr; + deathRecipient_ = nullptr; + isReconnected_ = false; + } + virtual ~FooProxy() { + if (servMgr_ != nullptr && deathRecipient_ != nullptr) { + servMgr_->RemoveDeathRecipient(deathRecipient_); + } + } + + inline bool IsProxy() override + { + return true; + } + + int32_t TestPingV1_1(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t TestGetData(std::string& info) override; + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t GetData(std::string& info) override; + + int32_t InfoTest(int32_t inParam, double& outParam) override; + + int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; + + static int32_t TestPingV1_1_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); + + static int32_t TestGetData_(std::string& info, const sptr remote); + + static int32_t Reconnect(sptr proxy); + + sptr GetCurrentRemote() { + return isReconnected_ ? reconnectRemote_ : Remote(); + } + + bool isReconnected_; + std::string serviceName_; + sptr servMgr_; + sptr deathRecipient_; + sptr reconnectRemote_; +private: + static inline BrokerDelegator delegator_; +}; + +} // V1_1 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_1_FOOPROXY_H + diff --git a/test/hdi_unittest/extended_interface_idl/cpp_target/foo/v1_1/foo_stub.cpp.txt b/test/hdi_unittest/extended_interface_idl/cpp_target/foo/v1_1/foo_stub.cpp.txt index 83403b7..ec3d9d1 100644 --- a/test/hdi_unittest/extended_interface_idl/cpp_target/foo/v1_1/foo_stub.cpp.txt +++ b/test/hdi_unittest/extended_interface_idl/cpp_target/foo/v1_1/foo_stub.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_1/foo_stub.h" @@ -55,6 +55,7 @@ OHOS::HDI::Foo::V1_1::FooStub::FooStub(const sptr &i OHOS::HDI::Foo::V1_1::FooStub::~FooStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/extended_struct_idl/cpp_target/foo/v1_0/foo_driver.cpp.txt b/test/hdi_unittest/extended_struct_idl/cpp_target/foo/v1_0/foo_driver.cpp.txt index 625a670..a238792 100644 --- a/test/hdi_unittest/extended_struct_idl/cpp_target/foo/v1_0/foo_driver.cpp.txt +++ b/test/hdi_unittest/extended_struct_idl/cpp_target/foo/v1_0/foo_driver.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/extended_struct_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt b/test/hdi_unittest/extended_struct_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt index dbd9104..4d12ff9 100644 --- a/test/hdi_unittest/extended_struct_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt +++ b/test/hdi_unittest/extended_struct_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt @@ -11,280 +11,280 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#include "v1_0/foo_proxy.h" -#include -#include -#include -#include -#include -#include -#include - -#define HDF_LOG_TAG foo_proxy - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) -{ - return IFoo::Get("foo_service", isStub); -} - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) -{ - if (isStub) { - std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); - void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); - if (impl == nullptr) { - HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); - return nullptr; - } - return reinterpret_cast(impl); - } - - using namespace OHOS::HDI::ServiceManager::V1_0; - auto servMgr = IServiceManager::Get(); - if (servMgr == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return nullptr; - } - - sptr remote = servMgr->GetService(serviceName.c_str()); - if (remote == nullptr) { - HDF_LOGE("%{public}s:get remote object failed!", __func__); - return nullptr; - } - - sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); - if (proxy == nullptr) { - HDF_LOGE("%{public}s:iface_cast failed!", __func__); - return nullptr; - } - - proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); - proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); - proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); - proxy->isReconnected_ = false; - proxy->serviceName_ = serviceName; - uint32_t serMajorVer = 0; - uint32_t serMinorVer = 0; - int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s:get version failed!", __func__); - return nullptr; - } - - if (serMajorVer != 1) { - HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); - return nullptr; - } - - return proxy; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( - sptr proxy) -{ - if (proxy == nullptr) { - HDF_LOGW("Reconnect failed : input proxy is null"); - return HDF_FAILURE; - } - using namespace OHOS::HDI::ServiceManager::V1_0; - proxy->isReconnected_ = false; - auto iServMgr = IServiceManager::Get(); - if (iServMgr == nullptr) { - HDF_LOGW("Reconnect failed : iServMgr is null"); - return HDF_FAILURE; - }; - proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); - if (proxy->reconnectRemote_ == nullptr) { - HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); - return HDF_FAILURE; - } - proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); - if (proxy->servMgr_ == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return HDF_FAILURE; - } - proxy->servMgr_->AddDeathRecipient( - new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); - proxy->isReconnected_ = true; - return HDF_SUCCESS; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(OHOS::HDI::Foo::V1_0::ExtendedFooInfo& info) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest(const OHOS::HDI::Foo::V1_0::ExtendedFooInfo& inParam, - OHOS::HDI::Foo::V1_0::ExtendedFooInfo& outParam) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(inParam, outParam, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteBool(false)) { - HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteCString(sendMsg.c_str())) { - HDF_LOGE("%{public}s: write sendMsg failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - const char* recvMsgCp = fooReply.ReadCString(); - if (recvMsgCp == nullptr) { - HDF_LOGE("%{public}s: read recvMsg failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - recvMsg = recvMsgCp; - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(OHOS::HDI::Foo::V1_0::ExtendedFooInfo& info, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!ExtendedFooInfoBlockUnmarshalling(fooReply, info)) { - HDF_LOGE("%{public}s: read info failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(const OHOS::HDI::Foo::V1_0::ExtendedFooInfo& inParam, - OHOS::HDI::Foo::V1_0::ExtendedFooInfo& outParam, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!OHOS::HDI::Foo::V1_0::ExtendedFooInfoBlockMarshalling(fooData, inParam)) { - HDF_LOGE("%{public}s: write inParam failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_INFO_TEST, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!ExtendedFooInfoBlockUnmarshalling(fooReply, outParam)) { - HDF_LOGE("%{public}s: read outParam failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!fooReply.ReadUint32(majorVer)) { - HDF_LOGE("%{public}s: read majorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooReply.ReadUint32(minorVer)) { - HDF_LOGE("%{public}s: read minorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -} // V1_0 -} // Foo -} // HDI -} // OHOS + */ + +#include "v1_0/foo_proxy.h" +#include +#include +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG foo_proxy + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) +{ + return IFoo::Get("foo_service", isStub); +} + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) +{ + if (isStub) { + std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); + void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + return reinterpret_cast(impl); + } + + using namespace OHOS::HDI::ServiceManager::V1_0; + auto servMgr = IServiceManager::Get(); + if (servMgr == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return nullptr; + } + + sptr remote = servMgr->GetService(serviceName.c_str()); + if (remote == nullptr) { + HDF_LOGE("%{public}s:get remote object failed!", __func__); + return nullptr; + } + + sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:iface_cast failed!", __func__); + return nullptr; + } + + proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); + proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); + proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); + proxy->isReconnected_ = false; + proxy->serviceName_ = serviceName; + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( + sptr proxy) +{ + if (proxy == nullptr) { + HDF_LOGW("Reconnect failed : input proxy is null"); + return HDF_FAILURE; + } + using namespace OHOS::HDI::ServiceManager::V1_0; + proxy->isReconnected_ = false; + auto iServMgr = IServiceManager::Get(); + if (iServMgr == nullptr) { + HDF_LOGW("Reconnect failed : iServMgr is null"); + return HDF_FAILURE; + }; + proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); + if (proxy->reconnectRemote_ == nullptr) { + HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); + return HDF_FAILURE; + } + proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); + if (proxy->servMgr_ == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return HDF_FAILURE; + } + proxy->servMgr_->AddDeathRecipient( + new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); + proxy->isReconnected_ = true; + return HDF_SUCCESS; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(OHOS::HDI::Foo::V1_0::ExtendedFooInfo& info) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest(const OHOS::HDI::Foo::V1_0::ExtendedFooInfo& inParam, + OHOS::HDI::Foo::V1_0::ExtendedFooInfo& outParam) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(inParam, outParam, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteCString(sendMsg.c_str())) { + HDF_LOGE("%{public}s: write sendMsg failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + const char* recvMsgCp = fooReply.ReadCString(); + if (recvMsgCp == nullptr) { + HDF_LOGE("%{public}s: read recvMsg failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + recvMsg = recvMsgCp; + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(OHOS::HDI::Foo::V1_0::ExtendedFooInfo& info, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!ExtendedFooInfoBlockUnmarshalling(fooReply, info)) { + HDF_LOGE("%{public}s: read info failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(const OHOS::HDI::Foo::V1_0::ExtendedFooInfo& inParam, + OHOS::HDI::Foo::V1_0::ExtendedFooInfo& outParam, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!OHOS::HDI::Foo::V1_0::ExtendedFooInfoBlockMarshalling(fooData, inParam)) { + HDF_LOGE("%{public}s: write inParam failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_INFO_TEST, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!ExtendedFooInfoBlockUnmarshalling(fooReply, outParam)) { + HDF_LOGE("%{public}s: read outParam failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.ReadUint32(majorVer)) { + HDF_LOGE("%{public}s: read majorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooReply.ReadUint32(minorVer)) { + HDF_LOGE("%{public}s: read minorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +} // V1_0 +} // Foo +} // HDI +} // OHOS diff --git a/test/hdi_unittest/extended_struct_idl/cpp_target/foo/v1_0/foo_proxy.h.txt b/test/hdi_unittest/extended_struct_idl/cpp_target/foo/v1_0/foo_proxy.h.txt index b6360d1..2969d91 100644 --- a/test/hdi_unittest/extended_struct_idl/cpp_target/foo/v1_0/foo_proxy.h.txt +++ b/test/hdi_unittest/extended_struct_idl/cpp_target/foo/v1_0/foo_proxy.h.txt @@ -11,99 +11,99 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H -#define OHOS_HDI_FOO_V1_0_FOOPROXY_H - -#include "v1_0/ifoo.h" -#include -#include - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - -class FooProxy : public IProxyBroker { -public: - class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { - public: - IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} - ~IServiceManagerDeathRecipient() override = default; - void OnRemoteDied(const wptr &remote) override - { - int32_t result = HDF_FAILURE; - const int sleepInterval = 500000; - const int waitTimes = 10; - int currentTime = waitTimes; - do { - usleep(sleepInterval); - auto proxy = proxy_.promote(); - if (proxy != nullptr) { - result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); - } - --currentTime; - } while (result != HDF_SUCCESS && currentTime >0); - } - private: - wptr proxy_; - }; - - explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { - reconnectRemote_ = nullptr; - servMgr_ = nullptr; - deathRecipient_ = nullptr; - isReconnected_ = false; - } - virtual ~FooProxy() { - if (servMgr_ != nullptr && deathRecipient_ != nullptr) { - servMgr_->RemoveDeathRecipient(deathRecipient_); - } - } - - inline bool IsProxy() override - { - return true; - } - - int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; - - int32_t GetData(OHOS::HDI::Foo::V1_0::ExtendedFooInfo& info) override; - - int32_t InfoTest(const OHOS::HDI::Foo::V1_0::ExtendedFooInfo& inParam, - OHOS::HDI::Foo::V1_0::ExtendedFooInfo& outParam) override; - - int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; - - static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); - - static int32_t GetData_(OHOS::HDI::Foo::V1_0::ExtendedFooInfo& info, const sptr remote); - - static int32_t InfoTest_(const OHOS::HDI::Foo::V1_0::ExtendedFooInfo& inParam, - OHOS::HDI::Foo::V1_0::ExtendedFooInfo& outParam, const sptr remote); - - static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); - - static int32_t Reconnect(sptr proxy); - - sptr GetCurrentRemote() { - return isReconnected_ ? reconnectRemote_ : Remote(); - } - - bool isReconnected_; - std::string serviceName_; - sptr servMgr_; - sptr deathRecipient_; - sptr reconnectRemote_; -private: - static inline BrokerDelegator delegator_; -}; - -} // V1_0 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H - + */ + +#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H +#define OHOS_HDI_FOO_V1_0_FOOPROXY_H + +#include "v1_0/ifoo.h" +#include +#include + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + +class FooProxy : public IProxyBroker { +public: + class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { + public: + IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} + ~IServiceManagerDeathRecipient() override = default; + void OnRemoteDied(const wptr &remote) override + { + int32_t result = HDF_FAILURE; + const int sleepInterval = 500000; + const int waitTimes = 10; + int currentTime = waitTimes; + do { + usleep(sleepInterval); + auto proxy = proxy_.promote(); + if (proxy != nullptr) { + result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); + } + --currentTime; + } while (result != HDF_SUCCESS && currentTime >0); + } + private: + wptr proxy_; + }; + + explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { + reconnectRemote_ = nullptr; + servMgr_ = nullptr; + deathRecipient_ = nullptr; + isReconnected_ = false; + } + virtual ~FooProxy() { + if (servMgr_ != nullptr && deathRecipient_ != nullptr) { + servMgr_->RemoveDeathRecipient(deathRecipient_); + } + } + + inline bool IsProxy() override + { + return true; + } + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t GetData(OHOS::HDI::Foo::V1_0::ExtendedFooInfo& info) override; + + int32_t InfoTest(const OHOS::HDI::Foo::V1_0::ExtendedFooInfo& inParam, + OHOS::HDI::Foo::V1_0::ExtendedFooInfo& outParam) override; + + int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; + + static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); + + static int32_t GetData_(OHOS::HDI::Foo::V1_0::ExtendedFooInfo& info, const sptr remote); + + static int32_t InfoTest_(const OHOS::HDI::Foo::V1_0::ExtendedFooInfo& inParam, + OHOS::HDI::Foo::V1_0::ExtendedFooInfo& outParam, const sptr remote); + + static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); + + static int32_t Reconnect(sptr proxy); + + sptr GetCurrentRemote() { + return isReconnected_ ? reconnectRemote_ : Remote(); + } + + bool isReconnected_; + std::string serviceName_; + sptr servMgr_; + sptr deathRecipient_; + sptr reconnectRemote_; +private: + static inline BrokerDelegator delegator_; +}; + +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H + diff --git a/test/hdi_unittest/extended_struct_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt b/test/hdi_unittest/extended_struct_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt index 93c2443..5760614 100644 --- a/test/hdi_unittest/extended_struct_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt +++ b/test/hdi_unittest/extended_struct_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_stub.h" @@ -55,6 +55,7 @@ OHOS::HDI::Foo::V1_0::FooStub::FooStub(const sptr &i OHOS::HDI::Foo::V1_0::FooStub::~FooStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/face_auth_v1_0/cpp_target/face_auth/v1_0/executor_callback_stub.cpp.txt b/test/hdi_unittest/face_auth_v1_0/cpp_target/face_auth/v1_0/executor_callback_stub.cpp.txt index bce3109..8bb5b07 100644 --- a/test/hdi_unittest/face_auth_v1_0/cpp_target/face_auth/v1_0/executor_callback_stub.cpp.txt +++ b/test/hdi_unittest/face_auth_v1_0/cpp_target/face_auth/v1_0/executor_callback_stub.cpp.txt @@ -57,6 +57,7 @@ OHOS::HDI::FaceAuth::V1_0::ExecutorCallbackStub::ExecutorCallbackStub(const sptr OHOS::HDI::FaceAuth::V1_0::ExecutorCallbackStub::~ExecutorCallbackStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/face_auth_v1_0/cpp_target/face_auth/v1_0/executor_stub.cpp.txt b/test/hdi_unittest/face_auth_v1_0/cpp_target/face_auth/v1_0/executor_stub.cpp.txt index 8d2741a..381a94e 100644 --- a/test/hdi_unittest/face_auth_v1_0/cpp_target/face_auth/v1_0/executor_stub.cpp.txt +++ b/test/hdi_unittest/face_auth_v1_0/cpp_target/face_auth/v1_0/executor_stub.cpp.txt @@ -81,6 +81,7 @@ OHOS::HDI::FaceAuth::V1_0::ExecutorStub::ExecutorStub(const sptr diff --git a/test/hdi_unittest/hdi_all_interface_test_003/c_target/foo/v1_0/foo_proxy.c.txt b/test/hdi_unittest/hdi_all_interface_test_003/c_target/foo/v1_0/foo_proxy.c.txt index b0e0579..e67c3c3 100644 --- a/test/hdi_unittest/hdi_all_interface_test_003/c_target/foo/v1_0/foo_proxy.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_003/c_target/foo/v1_0/foo_proxy.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/hdi_all_interface_test_003/c_target/foo/v1_0/foo_service.c.txt b/test/hdi_unittest/hdi_all_interface_test_003/c_target/foo/v1_0/foo_service.c.txt index 9b70719..7bc167c 100644 --- a/test/hdi_unittest/hdi_all_interface_test_003/c_target/foo/v1_0/foo_service.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_003/c_target/foo/v1_0/foo_service.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_service.h" diff --git a/test/hdi_unittest/hdi_all_interface_test_003/c_target/foo/v1_0/foo_stub.c.txt b/test/hdi_unittest/hdi_all_interface_test_003/c_target/foo/v1_0/foo_stub.c.txt index 6502886..91b0487 100644 --- a/test/hdi_unittest/hdi_all_interface_test_003/c_target/foo/v1_0/foo_stub.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_003/c_target/foo/v1_0/foo_stub.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_stub.h" diff --git a/test/hdi_unittest/hdi_all_interface_test_003/c_target/foo/v1_0/types.c.txt b/test/hdi_unittest/hdi_all_interface_test_003/c_target/foo/v1_0/types.c.txt index 77186a4..90e2b14 100644 --- a/test/hdi_unittest/hdi_all_interface_test_003/c_target/foo/v1_0/types.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_003/c_target/foo/v1_0/types.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/types.h" diff --git a/test/hdi_unittest/hdi_all_interface_test_004/c_target/foo/v1_0/foo_callback_service.c.txt b/test/hdi_unittest/hdi_all_interface_test_004/c_target/foo/v1_0/foo_callback_service.c.txt index 7fa6638..c10a8f8 100644 --- a/test/hdi_unittest/hdi_all_interface_test_004/c_target/foo/v1_0/foo_callback_service.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_004/c_target/foo/v1_0/foo_callback_service.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_callback_service.h" diff --git a/test/hdi_unittest/hdi_all_interface_test_004/c_target/foo/v1_0/foo_service.c.txt b/test/hdi_unittest/hdi_all_interface_test_004/c_target/foo/v1_0/foo_service.c.txt index df3da30..cf0707b 100644 --- a/test/hdi_unittest/hdi_all_interface_test_004/c_target/foo/v1_0/foo_service.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_004/c_target/foo/v1_0/foo_service.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/hdi_all_interface_test_004/cpp_target/foo/v1_0/foo_proxy.cpp.txt b/test/hdi_unittest/hdi_all_interface_test_004/cpp_target/foo/v1_0/foo_proxy.cpp.txt index 236101c..daabe6b 100644 --- a/test/hdi_unittest/hdi_all_interface_test_004/cpp_target/foo/v1_0/foo_proxy.cpp.txt +++ b/test/hdi_unittest/hdi_all_interface_test_004/cpp_target/foo/v1_0/foo_proxy.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/ifoo.h" diff --git a/test/hdi_unittest/hdi_all_interface_test_005/c_target/foo/v1_0/foo_callback_service.c.txt b/test/hdi_unittest/hdi_all_interface_test_005/c_target/foo/v1_0/foo_callback_service.c.txt index 7fa6638..c10a8f8 100644 --- a/test/hdi_unittest/hdi_all_interface_test_005/c_target/foo/v1_0/foo_callback_service.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_005/c_target/foo/v1_0/foo_callback_service.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_callback_service.h" diff --git a/test/hdi_unittest/hdi_all_interface_test_005/c_target/foo/v1_0/foo_service.c.txt b/test/hdi_unittest/hdi_all_interface_test_005/c_target/foo/v1_0/foo_service.c.txt index df3da30..cf0707b 100644 --- a/test/hdi_unittest/hdi_all_interface_test_005/c_target/foo/v1_0/foo_service.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_005/c_target/foo/v1_0/foo_service.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/hdi_all_interface_test_005/cpp_target/foo/v1_0/foo_proxy.cpp.txt b/test/hdi_unittest/hdi_all_interface_test_005/cpp_target/foo/v1_0/foo_proxy.cpp.txt index 62dc88b..5ed5afc 100644 --- a/test/hdi_unittest/hdi_all_interface_test_005/cpp_target/foo/v1_0/foo_proxy.cpp.txt +++ b/test/hdi_unittest/hdi_all_interface_test_005/cpp_target/foo/v1_0/foo_proxy.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/ifoo.h" diff --git a/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/foo_driver.c.txt b/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/foo_driver.c.txt index 835fe7c..e3360a1 100644 --- a/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/foo_driver.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/foo_driver.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/foo_proxy.c.txt b/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/foo_proxy.c.txt index b0e0579..e67c3c3 100644 --- a/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/foo_proxy.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/foo_proxy.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/foo_service.c.txt b/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/foo_service.c.txt index 9b70719..7bc167c 100644 --- a/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/foo_service.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/foo_service.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_service.h" diff --git a/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/foo_stub.c.txt b/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/foo_stub.c.txt index 6502886..91b0487 100644 --- a/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/foo_stub.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/foo_stub.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_stub.h" diff --git a/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/types.c.txt b/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/types.c.txt index 77186a4..90e2b14 100644 --- a/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/types.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_006/c_target/foo/v1_0/types.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/types.h" diff --git a/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_callback_proxy.c.txt b/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_callback_proxy.c.txt index 57718f2..0f1ff09 100644 --- a/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_callback_proxy.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_callback_proxy.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_callback_service.c.txt b/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_callback_service.c.txt index 7fa6638..c10a8f8 100644 --- a/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_callback_service.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_callback_service.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_callback_service.h" diff --git a/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_callback_stub.c.txt b/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_callback_stub.c.txt index f68d082..d6ee5a1 100644 --- a/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_callback_stub.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_callback_stub.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_callback_stub.h" diff --git a/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_driver.c.txt b/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_driver.c.txt index 956e5cd..7abe17a 100644 --- a/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_driver.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_driver.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_proxy.c.txt b/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_proxy.c.txt index 72e7c86..75ffaaa 100644 --- a/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_proxy.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_proxy.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_service.c.txt b/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_service.c.txt index df3da30..cf0707b 100644 --- a/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_service.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_service.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_stub.c.txt b/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_stub.c.txt index 64923f0..3b2c5ba 100644 --- a/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_stub.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/foo_stub.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_stub.h" diff --git a/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/types.c.txt b/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/types.c.txt index bc059cf..9fd93b8 100644 --- a/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/types.c.txt +++ b/test/hdi_unittest/hdi_all_interface_test_007/c_target/foo/v1_0/types.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/types.h" diff --git a/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_callback_proxy.cpp.txt b/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_callback_proxy.cpp.txt index 83afeec..329f9d1 100644 --- a/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_callback_proxy.cpp.txt +++ b/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_callback_proxy.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_callback_proxy.h" diff --git a/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_callback_stub.cpp.txt b/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_callback_stub.cpp.txt index 0027dac..3beb693 100644 --- a/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_callback_stub.cpp.txt +++ b/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_callback_stub.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_callback_stub.h" @@ -33,6 +33,7 @@ OHOS::HDI::Foo::V1_0::FooCallbackStub::FooCallbackStub(const sptr diff --git a/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_ext_stub.cpp.txt b/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_ext_stub.cpp.txt index 8e06aa2..f257d7e 100644 --- a/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_ext_stub.cpp.txt +++ b/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_ext_stub.cpp.txt @@ -55,6 +55,7 @@ OHOS::HDI::Foo::V1_0::FooExtStub::FooExtStub(const sptr -#include -#include -#include -#include -#include -#include -#include - -#define HDF_LOG_TAG foo_proxy - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - -static bool ReadFileDescriptor(MessageParcel &data, int &fd); -static bool WriteFileDescriptor(MessageParcel &data, int fd); - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) -{ - return IFoo::Get("foo_service", isStub); -} - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) -{ - if (isStub) { - std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); - void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); - if (impl == nullptr) { - HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); - return nullptr; - } - return reinterpret_cast(impl); - } - - using namespace OHOS::HDI::ServiceManager::V1_0; - auto servMgr = IServiceManager::Get(); - if (servMgr == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return nullptr; - } - - sptr remote = servMgr->GetService(serviceName.c_str()); - if (remote == nullptr) { - HDF_LOGE("%{public}s:get remote object failed!", __func__); - return nullptr; - } - - sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); - if (proxy == nullptr) { - HDF_LOGE("%{public}s:iface_cast failed!", __func__); - return nullptr; - } - - proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); - proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); - proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); - proxy->isReconnected_ = false; - proxy->serviceName_ = serviceName; - uint32_t serMajorVer = 0; - uint32_t serMinorVer = 0; - int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s:get version failed!", __func__); - return nullptr; - } - - if (serMajorVer != 1) { - HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); - return nullptr; - } - - return proxy; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( - sptr proxy) -{ - if (proxy == nullptr) { - HDF_LOGW("Reconnect failed : input proxy is null"); - return HDF_FAILURE; - } - using namespace OHOS::HDI::ServiceManager::V1_0; - proxy->isReconnected_ = false; - auto iServMgr = IServiceManager::Get(); - if (iServMgr == nullptr) { - HDF_LOGW("Reconnect failed : iServMgr is null"); - return HDF_FAILURE; - }; - proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); - if (proxy->reconnectRemote_ == nullptr) { - HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); - return HDF_FAILURE; - } - proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); - if (proxy->servMgr_ == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return HDF_FAILURE; - } - proxy->servMgr_->AddDeathRecipient( - new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); - proxy->isReconnected_ = true; - return HDF_SUCCESS; -} - - -static bool ReadFileDescriptor(MessageParcel &data, int &fd) -{ - fd = -1; - bool fdValid = false; - if (!data.ReadBool(fdValid)) { - HDF_LOGE("%{public}s: failed to read fdValid", __func__); - return false; - } - - if (fdValid) { - fd = data.ReadFileDescriptor(); - if (fd < 0) { - HDF_LOGE("%{public}s: failed to read fd", __func__); - return false; - } - } - return true; -} - -static bool WriteFileDescriptor(MessageParcel &data, int fd) -{ - if (!data.WriteBool(fd >= 0 ? true : false)) { - HDF_LOGE("%{public}s: failed to write fd vailed", __func__); - return false; - } - if (fd < 0) { - return true; - } - if (!data.WriteFileDescriptor(fd)) { - HDF_LOGE("%{public}s: failed to write fd", __func__); - return false; - } - return true; -} -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::SetCallback(const sptr& cbObj) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::SetCallback_(cbObj, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc1(bool inData, bool& outData) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::TestFunc1_(inData, outData, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc2(int8_t inData) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::TestFunc2_(inData, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc3(int16_t inData, int16_t& outData) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::TestFunc3_(inData, outData, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc4(int32_t inData, int32_t& outData) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::TestFunc4_(inData, outData, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc5(int64_t inData, int64_t& outData) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::TestFunc5_(inData, outData, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc6(const std::string& inData) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::TestFunc6_(inData, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc7(float inData, float& outData) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::TestFunc7_(inData, outData, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc8(double inData, double& outData) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::TestFunc8_(inData, outData, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc9(int inData, int& outData) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::TestFunc9_(inData, outData, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteBool(false)) { - HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteCString(sendMsg.c_str())) { - HDF_LOGE("%{public}s: write sendMsg failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - const char* recvMsgCp = fooReply.ReadCString(); - if (recvMsgCp == nullptr) { - HDF_LOGE("%{public}s: read recvMsg failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - recvMsg = recvMsgCp; - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!FooInfoBlockUnmarshalling(fooReply, info)) { - HDF_LOGE("%{public}s: read info failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::SetCallback_(const sptr& cbObj, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (cbObj == nullptr) { - HDF_LOGE("%{public}s: parameter cbObj is nullptr!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteRemoteObject(OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(cbObj, OHOS::HDI::Foo::V1_0::IFooCallback::GetDescriptor()))) { - HDF_LOGE("%{public}s: write cbObj failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_SET_CALLBACK, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc1_(bool inData, bool& outData, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteBool(inData)) { - HDF_LOGE("%{public}s: write inData failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_FUNC1, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!fooReply.ReadBool(outData)) { - HDF_LOGE("%{public}s: read outData failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc2_(int8_t inData, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_ASYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteInt8(inData)) { - HDF_LOGE("%{public}s: write inData failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_FUNC2, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc3_(int16_t inData, int16_t& outData, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteInt16(inData)) { - HDF_LOGE("%{public}s: write inData failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_FUNC3, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!fooReply.ReadInt16(outData)) { - HDF_LOGE("%{public}s: read outData failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc4_(int32_t inData, int32_t& outData, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteInt32(inData)) { - HDF_LOGE("%{public}s: write inData failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_FUNC4, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!fooReply.ReadInt32(outData)) { - HDF_LOGE("%{public}s: read outData failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc5_(int64_t inData, int64_t& outData, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteInt64(inData)) { - HDF_LOGE("%{public}s: write inData failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_FUNC5, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!fooReply.ReadInt64(outData)) { - HDF_LOGE("%{public}s: read outData failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc6_(const std::string& inData, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_ASYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteCString(inData.c_str())) { - HDF_LOGE("%{public}s: write inData failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_FUNC6, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc7_(float inData, float& outData, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteFloat(inData)) { - HDF_LOGE("%{public}s: write inData failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_FUNC7, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!fooReply.ReadFloat(outData)) { - HDF_LOGE("%{public}s: read outData failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc8_(double inData, double& outData, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteDouble(inData)) { - HDF_LOGE("%{public}s: write inData failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_FUNC8, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!fooReply.ReadDouble(outData)) { - HDF_LOGE("%{public}s: read outData failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc9_(int inData, int& outData, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!WriteFileDescriptor(fooData, inData)) { - HDF_LOGE("%{public}s: write inData failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_FUNC9, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - outData = -1; - if (!ReadFileDescriptor(fooReply, outData)) { - HDF_LOGE("%{public}s: read outData failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!fooReply.ReadUint32(majorVer)) { - HDF_LOGE("%{public}s: read majorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooReply.ReadUint32(minorVer)) { - HDF_LOGE("%{public}s: read minorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -} // V1_0 -} // Foo -} // HDI -} // OHOS + */ + +#include "v1_0/foo_proxy.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG foo_proxy + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + +static bool ReadFileDescriptor(MessageParcel &data, int &fd); +static bool WriteFileDescriptor(MessageParcel &data, int fd); + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) +{ + return IFoo::Get("foo_service", isStub); +} + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) +{ + if (isStub) { + std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); + void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + return reinterpret_cast(impl); + } + + using namespace OHOS::HDI::ServiceManager::V1_0; + auto servMgr = IServiceManager::Get(); + if (servMgr == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return nullptr; + } + + sptr remote = servMgr->GetService(serviceName.c_str()); + if (remote == nullptr) { + HDF_LOGE("%{public}s:get remote object failed!", __func__); + return nullptr; + } + + sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:iface_cast failed!", __func__); + return nullptr; + } + + proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); + proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); + proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); + proxy->isReconnected_ = false; + proxy->serviceName_ = serviceName; + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( + sptr proxy) +{ + if (proxy == nullptr) { + HDF_LOGW("Reconnect failed : input proxy is null"); + return HDF_FAILURE; + } + using namespace OHOS::HDI::ServiceManager::V1_0; + proxy->isReconnected_ = false; + auto iServMgr = IServiceManager::Get(); + if (iServMgr == nullptr) { + HDF_LOGW("Reconnect failed : iServMgr is null"); + return HDF_FAILURE; + }; + proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); + if (proxy->reconnectRemote_ == nullptr) { + HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); + return HDF_FAILURE; + } + proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); + if (proxy->servMgr_ == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return HDF_FAILURE; + } + proxy->servMgr_->AddDeathRecipient( + new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); + proxy->isReconnected_ = true; + return HDF_SUCCESS; +} + + +static bool ReadFileDescriptor(MessageParcel &data, int &fd) +{ + fd = -1; + bool fdValid = false; + if (!data.ReadBool(fdValid)) { + HDF_LOGE("%{public}s: failed to read fdValid", __func__); + return false; + } + + if (fdValid) { + fd = data.ReadFileDescriptor(); + if (fd < 0) { + HDF_LOGE("%{public}s: failed to read fd", __func__); + return false; + } + } + return true; +} + +static bool WriteFileDescriptor(MessageParcel &data, int fd) +{ + if (!data.WriteBool(fd >= 0 ? true : false)) { + HDF_LOGE("%{public}s: failed to write fd vailed", __func__); + return false; + } + if (fd < 0) { + return true; + } + if (!data.WriteFileDescriptor(fd)) { + HDF_LOGE("%{public}s: failed to write fd", __func__); + return false; + } + return true; +} +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::SetCallback(const sptr& cbObj) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::SetCallback_(cbObj, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc1(bool inData, bool& outData) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::TestFunc1_(inData, outData, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc2(int8_t inData) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::TestFunc2_(inData, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc3(int16_t inData, int16_t& outData) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::TestFunc3_(inData, outData, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc4(int32_t inData, int32_t& outData) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::TestFunc4_(inData, outData, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc5(int64_t inData, int64_t& outData) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::TestFunc5_(inData, outData, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc6(const std::string& inData) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::TestFunc6_(inData, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc7(float inData, float& outData) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::TestFunc7_(inData, outData, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc8(double inData, double& outData) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::TestFunc8_(inData, outData, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc9(int inData, int& outData) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::TestFunc9_(inData, outData, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteCString(sendMsg.c_str())) { + HDF_LOGE("%{public}s: write sendMsg failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + const char* recvMsgCp = fooReply.ReadCString(); + if (recvMsgCp == nullptr) { + HDF_LOGE("%{public}s: read recvMsg failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + recvMsg = recvMsgCp; + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!FooInfoBlockUnmarshalling(fooReply, info)) { + HDF_LOGE("%{public}s: read info failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::SetCallback_(const sptr& cbObj, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (cbObj == nullptr) { + HDF_LOGE("%{public}s: parameter cbObj is nullptr!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteRemoteObject(OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(cbObj, OHOS::HDI::Foo::V1_0::IFooCallback::GetDescriptor()))) { + HDF_LOGE("%{public}s: write cbObj failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_SET_CALLBACK, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc1_(bool inData, bool& outData, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(inData)) { + HDF_LOGE("%{public}s: write inData failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_FUNC1, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.ReadBool(outData)) { + HDF_LOGE("%{public}s: read outData failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc2_(int8_t inData, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_ASYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteInt8(inData)) { + HDF_LOGE("%{public}s: write inData failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_FUNC2, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc3_(int16_t inData, int16_t& outData, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteInt16(inData)) { + HDF_LOGE("%{public}s: write inData failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_FUNC3, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.ReadInt16(outData)) { + HDF_LOGE("%{public}s: read outData failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc4_(int32_t inData, int32_t& outData, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteInt32(inData)) { + HDF_LOGE("%{public}s: write inData failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_FUNC4, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.ReadInt32(outData)) { + HDF_LOGE("%{public}s: read outData failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc5_(int64_t inData, int64_t& outData, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteInt64(inData)) { + HDF_LOGE("%{public}s: write inData failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_FUNC5, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.ReadInt64(outData)) { + HDF_LOGE("%{public}s: read outData failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc6_(const std::string& inData, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_ASYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteCString(inData.c_str())) { + HDF_LOGE("%{public}s: write inData failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_FUNC6, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc7_(float inData, float& outData, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteFloat(inData)) { + HDF_LOGE("%{public}s: write inData failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_FUNC7, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.ReadFloat(outData)) { + HDF_LOGE("%{public}s: read outData failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc8_(double inData, double& outData, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteDouble(inData)) { + HDF_LOGE("%{public}s: write inData failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_FUNC8, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.ReadDouble(outData)) { + HDF_LOGE("%{public}s: read outData failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::TestFunc9_(int inData, int& outData, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!WriteFileDescriptor(fooData, inData)) { + HDF_LOGE("%{public}s: write inData failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_FUNC9, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + outData = -1; + if (!ReadFileDescriptor(fooReply, outData)) { + HDF_LOGE("%{public}s: read outData failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.ReadUint32(majorVer)) { + HDF_LOGE("%{public}s: read majorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooReply.ReadUint32(minorVer)) { + HDF_LOGE("%{public}s: read minorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +} // V1_0 +} // Foo +} // HDI +} // OHOS diff --git a/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_proxy.h.txt b/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_proxy.h.txt index f8b7316..f700393 100644 --- a/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_proxy.h.txt +++ b/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_proxy.h.txt @@ -11,134 +11,134 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H -#define OHOS_HDI_FOO_V1_0_FOOPROXY_H - -#include "v1_0/ifoo.h" -#include -#include - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - -class FooProxy : public IProxyBroker { -public: - class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { - public: - IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} - ~IServiceManagerDeathRecipient() override = default; - void OnRemoteDied(const wptr &remote) override - { - int32_t result = HDF_FAILURE; - const int sleepInterval = 500000; - const int waitTimes = 10; - int currentTime = waitTimes; - do { - usleep(sleepInterval); - auto proxy = proxy_.promote(); - if (proxy != nullptr) { - result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); - } - --currentTime; - } while (result != HDF_SUCCESS && currentTime >0); - } - private: - wptr proxy_; - }; - - explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { - reconnectRemote_ = nullptr; - servMgr_ = nullptr; - deathRecipient_ = nullptr; - isReconnected_ = false; - } - virtual ~FooProxy() { - if (servMgr_ != nullptr && deathRecipient_ != nullptr) { - servMgr_->RemoveDeathRecipient(deathRecipient_); - } - } - - inline bool IsProxy() override - { - return true; - } - - int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; - - int32_t GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) override; - - int32_t SetCallback(const sptr& cbObj) override; - - int32_t TestFunc1(bool inData, bool& outData) override; - - int32_t TestFunc2(int8_t inData) override; - - int32_t TestFunc3(int16_t inData, int16_t& outData) override; - - int32_t TestFunc4(int32_t inData, int32_t& outData) override; - - int32_t TestFunc5(int64_t inData, int64_t& outData) override; - - int32_t TestFunc6(const std::string& inData) override; - - int32_t TestFunc7(float inData, float& outData) override; - - int32_t TestFunc8(double inData, double& outData) override; - - int32_t TestFunc9(int inData, int& outData) override; - - int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; - - static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); - - static int32_t GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote); - - static int32_t SetCallback_(const sptr& cbObj, - const sptr remote); - - static int32_t TestFunc1_(bool inData, bool& outData, const sptr remote); - - static int32_t TestFunc2_(int8_t inData, const sptr remote); - - static int32_t TestFunc3_(int16_t inData, int16_t& outData, const sptr remote); - - static int32_t TestFunc4_(int32_t inData, int32_t& outData, const sptr remote); - - static int32_t TestFunc5_(int64_t inData, int64_t& outData, const sptr remote); - - static int32_t TestFunc6_(const std::string& inData, const sptr remote); - - static int32_t TestFunc7_(float inData, float& outData, const sptr remote); - - static int32_t TestFunc8_(double inData, double& outData, const sptr remote); - - static int32_t TestFunc9_(int inData, int& outData, const sptr remote); - - static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); - - static int32_t Reconnect(sptr proxy); - - sptr GetCurrentRemote() { - return isReconnected_ ? reconnectRemote_ : Remote(); - } - - bool isReconnected_; - std::string serviceName_; - sptr servMgr_; - sptr deathRecipient_; - sptr reconnectRemote_; -private: - static inline BrokerDelegator delegator_; -}; - -} // V1_0 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H - + */ + +#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H +#define OHOS_HDI_FOO_V1_0_FOOPROXY_H + +#include "v1_0/ifoo.h" +#include +#include + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + +class FooProxy : public IProxyBroker { +public: + class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { + public: + IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} + ~IServiceManagerDeathRecipient() override = default; + void OnRemoteDied(const wptr &remote) override + { + int32_t result = HDF_FAILURE; + const int sleepInterval = 500000; + const int waitTimes = 10; + int currentTime = waitTimes; + do { + usleep(sleepInterval); + auto proxy = proxy_.promote(); + if (proxy != nullptr) { + result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); + } + --currentTime; + } while (result != HDF_SUCCESS && currentTime >0); + } + private: + wptr proxy_; + }; + + explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { + reconnectRemote_ = nullptr; + servMgr_ = nullptr; + deathRecipient_ = nullptr; + isReconnected_ = false; + } + virtual ~FooProxy() { + if (servMgr_ != nullptr && deathRecipient_ != nullptr) { + servMgr_->RemoveDeathRecipient(deathRecipient_); + } + } + + inline bool IsProxy() override + { + return true; + } + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) override; + + int32_t SetCallback(const sptr& cbObj) override; + + int32_t TestFunc1(bool inData, bool& outData) override; + + int32_t TestFunc2(int8_t inData) override; + + int32_t TestFunc3(int16_t inData, int16_t& outData) override; + + int32_t TestFunc4(int32_t inData, int32_t& outData) override; + + int32_t TestFunc5(int64_t inData, int64_t& outData) override; + + int32_t TestFunc6(const std::string& inData) override; + + int32_t TestFunc7(float inData, float& outData) override; + + int32_t TestFunc8(double inData, double& outData) override; + + int32_t TestFunc9(int inData, int& outData) override; + + int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; + + static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); + + static int32_t GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote); + + static int32_t SetCallback_(const sptr& cbObj, + const sptr remote); + + static int32_t TestFunc1_(bool inData, bool& outData, const sptr remote); + + static int32_t TestFunc2_(int8_t inData, const sptr remote); + + static int32_t TestFunc3_(int16_t inData, int16_t& outData, const sptr remote); + + static int32_t TestFunc4_(int32_t inData, int32_t& outData, const sptr remote); + + static int32_t TestFunc5_(int64_t inData, int64_t& outData, const sptr remote); + + static int32_t TestFunc6_(const std::string& inData, const sptr remote); + + static int32_t TestFunc7_(float inData, float& outData, const sptr remote); + + static int32_t TestFunc8_(double inData, double& outData, const sptr remote); + + static int32_t TestFunc9_(int inData, int& outData, const sptr remote); + + static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); + + static int32_t Reconnect(sptr proxy); + + sptr GetCurrentRemote() { + return isReconnected_ ? reconnectRemote_ : Remote(); + } + + bool isReconnected_; + std::string serviceName_; + sptr servMgr_; + sptr deathRecipient_; + sptr reconnectRemote_; +private: + static inline BrokerDelegator delegator_; +}; + +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H + diff --git a/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_stub.cpp.txt b/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_stub.cpp.txt index c27bd62..e5d0e44 100644 --- a/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_stub.cpp.txt +++ b/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/foo_stub.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_stub.h" @@ -94,6 +94,7 @@ OHOS::HDI::Foo::V1_0::FooStub::FooStub(const sptr &i OHOS::HDI::Foo::V1_0::FooStub::~FooStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/types.cpp.txt b/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/types.cpp.txt index 3ecf0ec..b4969c1 100644 --- a/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/types.cpp.txt +++ b/test/hdi_unittest/hdi_all_interface_test_007/cpp_target/foo/v1_0/types.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/types.h" diff --git a/test/hdi_unittest/hdi_all_type_test_001/cpp_target/foo/v1_0/foo_proxy.cpp.txt b/test/hdi_unittest/hdi_all_type_test_001/cpp_target/foo/v1_0/foo_proxy.cpp.txt index 62dc88b..5ed5afc 100644 --- a/test/hdi_unittest/hdi_all_type_test_001/cpp_target/foo/v1_0/foo_proxy.cpp.txt +++ b/test/hdi_unittest/hdi_all_type_test_001/cpp_target/foo/v1_0/foo_proxy.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/ifoo.h" diff --git a/test/hdi_unittest/hdi_all_type_test_003/c_target/foo/v1_0/types.c.txt b/test/hdi_unittest/hdi_all_type_test_003/c_target/foo/v1_0/types.c.txt index a4eae96..07f874d 100644 --- a/test/hdi_unittest/hdi_all_type_test_003/c_target/foo/v1_0/types.c.txt +++ b/test/hdi_unittest/hdi_all_type_test_003/c_target/foo/v1_0/types.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/types.h" diff --git a/test/hdi_unittest/hdi_all_type_test_004/c_target/foo/v1_0/types.c.txt b/test/hdi_unittest/hdi_all_type_test_004/c_target/foo/v1_0/types.c.txt index a4eae96..07f874d 100644 --- a/test/hdi_unittest/hdi_all_type_test_004/c_target/foo/v1_0/types.c.txt +++ b/test/hdi_unittest/hdi_all_type_test_004/c_target/foo/v1_0/types.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/types.h" diff --git a/test/hdi_unittest/hdi_all_type_test_007/c_target/foo/v1_0/types.c.txt b/test/hdi_unittest/hdi_all_type_test_007/c_target/foo/v1_0/types.c.txt index 8d8d65c..cbbd1c7 100644 --- a/test/hdi_unittest/hdi_all_type_test_007/c_target/foo/v1_0/types.c.txt +++ b/test/hdi_unittest/hdi_all_type_test_007/c_target/foo/v1_0/types.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/types.h" diff --git a/test/hdi_unittest/hdi_all_type_test_007/cpp_target/foo/v1_0/types.cpp.txt b/test/hdi_unittest/hdi_all_type_test_007/cpp_target/foo/v1_0/types.cpp.txt index b849763..461d1e6 100644 --- a/test/hdi_unittest/hdi_all_type_test_007/cpp_target/foo/v1_0/types.cpp.txt +++ b/test/hdi_unittest/hdi_all_type_test_007/cpp_target/foo/v1_0/types.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/types.h" diff --git a/test/hdi_unittest/hdi_compile_opt_test_01/cpp_target/foo/v1_0/foo_driver.cpp.txt b/test/hdi_unittest/hdi_compile_opt_test_01/cpp_target/foo/v1_0/foo_driver.cpp.txt index 2395125..c3e6945 100644 --- a/test/hdi_unittest/hdi_compile_opt_test_01/cpp_target/foo/v1_0/foo_driver.cpp.txt +++ b/test/hdi_unittest/hdi_compile_opt_test_01/cpp_target/foo/v1_0/foo_driver.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/hdi_compile_opt_test_01/cpp_target/foo/v1_0/foo_proxy.cpp.txt b/test/hdi_unittest/hdi_compile_opt_test_01/cpp_target/foo/v1_0/foo_proxy.cpp.txt index 689cf37..a77a6f8 100644 --- a/test/hdi_unittest/hdi_compile_opt_test_01/cpp_target/foo/v1_0/foo_proxy.cpp.txt +++ b/test/hdi_unittest/hdi_compile_opt_test_01/cpp_target/foo/v1_0/foo_proxy.cpp.txt @@ -11,279 +11,279 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#include "v1_0/foo_proxy.h" -#include -#include -#include -#include -#include -#include -#include -#include - -#define HDF_LOG_TAG foo_proxy - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) -{ - return IFoo::Get("foo_service", isStub); -} - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) -{ - if (isStub) { - std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); - void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); - if (impl == nullptr) { - HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); - return nullptr; - } - return reinterpret_cast(impl); - } - - using namespace OHOS::HDI::ServiceManager::V1_0; - auto servMgr = IServiceManager::Get(); - if (servMgr == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return nullptr; - } - - sptr remote = servMgr->GetService(serviceName.c_str()); - if (remote == nullptr) { - HDF_LOGE("%{public}s:get remote object failed!", __func__); - return nullptr; - } - - sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); - if (proxy == nullptr) { - HDF_LOGE("%{public}s:iface_cast failed!", __func__); - return nullptr; - } - - proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); - proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); - proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); - proxy->isReconnected_ = false; - proxy->serviceName_ = serviceName; - uint32_t serMajorVer = 0; - uint32_t serMinorVer = 0; - int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s:get version failed!", __func__); - return nullptr; - } - - if (serMajorVer != 1) { - HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); - return nullptr; - } - - return proxy; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( - sptr proxy) -{ - if (proxy == nullptr) { - HDF_LOGW("Reconnect failed : input proxy is null"); - return HDF_FAILURE; - } - using namespace OHOS::HDI::ServiceManager::V1_0; - proxy->isReconnected_ = false; - auto iServMgr = IServiceManager::Get(); - if (iServMgr == nullptr) { - HDF_LOGW("Reconnect failed : iServMgr is null"); - return HDF_FAILURE; - }; - proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); - if (proxy->reconnectRemote_ == nullptr) { - HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); - return HDF_FAILURE; - } - proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); - if (proxy->servMgr_ == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return HDF_FAILURE; - } - proxy->servMgr_->AddDeathRecipient( - new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); - proxy->isReconnected_ = true; - return HDF_SUCCESS; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::SetCallback(const sptr& cbObj) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::SetCallback_(cbObj, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteBool(false)) { - HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteCString(sendMsg.c_str())) { - HDF_LOGE("%{public}s: write sendMsg failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - const char* recvMsgCp = fooReply.ReadCString(); - if (recvMsgCp == nullptr) { - HDF_LOGE("%{public}s: read recvMsg failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - recvMsg = recvMsgCp; - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!FooInfoBlockUnmarshalling(fooReply, info)) { - HDF_LOGE("%{public}s: read info failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::SetCallback_(const sptr& cbObj, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (cbObj == nullptr) { - HDF_LOGE("%{public}s: parameter cbObj is nullptr!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteRemoteObject(OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(cbObj, OHOS::HDI::Foo::V1_0::IFooCallback::GetDescriptor()))) { - HDF_LOGE("%{public}s: write cbObj failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_SET_CALLBACK, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!fooReply.ReadUint32(majorVer)) { - HDF_LOGE("%{public}s: read majorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooReply.ReadUint32(minorVer)) { - HDF_LOGE("%{public}s: read minorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -} // V1_0 -} // Foo -} // HDI -} // OHOS + */ + +#include "v1_0/foo_proxy.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG foo_proxy + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) +{ + return IFoo::Get("foo_service", isStub); +} + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) +{ + if (isStub) { + std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); + void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + return reinterpret_cast(impl); + } + + using namespace OHOS::HDI::ServiceManager::V1_0; + auto servMgr = IServiceManager::Get(); + if (servMgr == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return nullptr; + } + + sptr remote = servMgr->GetService(serviceName.c_str()); + if (remote == nullptr) { + HDF_LOGE("%{public}s:get remote object failed!", __func__); + return nullptr; + } + + sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:iface_cast failed!", __func__); + return nullptr; + } + + proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); + proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); + proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); + proxy->isReconnected_ = false; + proxy->serviceName_ = serviceName; + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( + sptr proxy) +{ + if (proxy == nullptr) { + HDF_LOGW("Reconnect failed : input proxy is null"); + return HDF_FAILURE; + } + using namespace OHOS::HDI::ServiceManager::V1_0; + proxy->isReconnected_ = false; + auto iServMgr = IServiceManager::Get(); + if (iServMgr == nullptr) { + HDF_LOGW("Reconnect failed : iServMgr is null"); + return HDF_FAILURE; + }; + proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); + if (proxy->reconnectRemote_ == nullptr) { + HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); + return HDF_FAILURE; + } + proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); + if (proxy->servMgr_ == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return HDF_FAILURE; + } + proxy->servMgr_->AddDeathRecipient( + new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); + proxy->isReconnected_ = true; + return HDF_SUCCESS; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::SetCallback(const sptr& cbObj) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::SetCallback_(cbObj, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteCString(sendMsg.c_str())) { + HDF_LOGE("%{public}s: write sendMsg failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + const char* recvMsgCp = fooReply.ReadCString(); + if (recvMsgCp == nullptr) { + HDF_LOGE("%{public}s: read recvMsg failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + recvMsg = recvMsgCp; + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!FooInfoBlockUnmarshalling(fooReply, info)) { + HDF_LOGE("%{public}s: read info failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::SetCallback_(const sptr& cbObj, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (cbObj == nullptr) { + HDF_LOGE("%{public}s: parameter cbObj is nullptr!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteRemoteObject(OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(cbObj, OHOS::HDI::Foo::V1_0::IFooCallback::GetDescriptor()))) { + HDF_LOGE("%{public}s: write cbObj failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_SET_CALLBACK, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.ReadUint32(majorVer)) { + HDF_LOGE("%{public}s: read majorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooReply.ReadUint32(minorVer)) { + HDF_LOGE("%{public}s: read minorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +} // V1_0 +} // Foo +} // HDI +} // OHOS diff --git a/test/hdi_unittest/hdi_compile_opt_test_01/cpp_target/foo/v1_0/foo_proxy.h.txt b/test/hdi_unittest/hdi_compile_opt_test_01/cpp_target/foo/v1_0/foo_proxy.h.txt index 4c7a31f..add4d3e 100644 --- a/test/hdi_unittest/hdi_compile_opt_test_01/cpp_target/foo/v1_0/foo_proxy.h.txt +++ b/test/hdi_unittest/hdi_compile_opt_test_01/cpp_target/foo/v1_0/foo_proxy.h.txt @@ -11,98 +11,98 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H -#define OHOS_HDI_FOO_V1_0_FOOPROXY_H - -#include "v1_0/ifoo.h" -#include -#include - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - -class FooProxy : public IProxyBroker { -public: - class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { - public: - IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} - ~IServiceManagerDeathRecipient() override = default; - void OnRemoteDied(const wptr &remote) override - { - int32_t result = HDF_FAILURE; - const int sleepInterval = 500000; - const int waitTimes = 10; - int currentTime = waitTimes; - do { - usleep(sleepInterval); - auto proxy = proxy_.promote(); - if (proxy != nullptr) { - result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); - } - --currentTime; - } while (result != HDF_SUCCESS && currentTime >0); - } - private: - wptr proxy_; - }; - - explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { - reconnectRemote_ = nullptr; - servMgr_ = nullptr; - deathRecipient_ = nullptr; - isReconnected_ = false; - } - virtual ~FooProxy() { - if (servMgr_ != nullptr && deathRecipient_ != nullptr) { - servMgr_->RemoveDeathRecipient(deathRecipient_); - } - } - - inline bool IsProxy() override - { - return true; - } - - int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; - - int32_t GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) override; - - int32_t SetCallback(const sptr& cbObj) override; - - int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; - - static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); - - static int32_t GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote); - - static int32_t SetCallback_(const sptr& cbObj, - const sptr remote); - - static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); - - static int32_t Reconnect(sptr proxy); - - sptr GetCurrentRemote() { - return isReconnected_ ? reconnectRemote_ : Remote(); - } - - bool isReconnected_; - std::string serviceName_; - sptr servMgr_; - sptr deathRecipient_; - sptr reconnectRemote_; -private: - static inline BrokerDelegator delegator_; -}; - -} // V1_0 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H - + */ + +#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H +#define OHOS_HDI_FOO_V1_0_FOOPROXY_H + +#include "v1_0/ifoo.h" +#include +#include + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + +class FooProxy : public IProxyBroker { +public: + class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { + public: + IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} + ~IServiceManagerDeathRecipient() override = default; + void OnRemoteDied(const wptr &remote) override + { + int32_t result = HDF_FAILURE; + const int sleepInterval = 500000; + const int waitTimes = 10; + int currentTime = waitTimes; + do { + usleep(sleepInterval); + auto proxy = proxy_.promote(); + if (proxy != nullptr) { + result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); + } + --currentTime; + } while (result != HDF_SUCCESS && currentTime >0); + } + private: + wptr proxy_; + }; + + explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { + reconnectRemote_ = nullptr; + servMgr_ = nullptr; + deathRecipient_ = nullptr; + isReconnected_ = false; + } + virtual ~FooProxy() { + if (servMgr_ != nullptr && deathRecipient_ != nullptr) { + servMgr_->RemoveDeathRecipient(deathRecipient_); + } + } + + inline bool IsProxy() override + { + return true; + } + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) override; + + int32_t SetCallback(const sptr& cbObj) override; + + int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; + + static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); + + static int32_t GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote); + + static int32_t SetCallback_(const sptr& cbObj, + const sptr remote); + + static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); + + static int32_t Reconnect(sptr proxy); + + sptr GetCurrentRemote() { + return isReconnected_ ? reconnectRemote_ : Remote(); + } + + bool isReconnected_; + std::string serviceName_; + sptr servMgr_; + sptr deathRecipient_; + sptr reconnectRemote_; +private: + static inline BrokerDelegator delegator_; +}; + +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H + diff --git a/test/hdi_unittest/hdi_compile_opt_test_01/cpp_target/foo/v1_0/foo_stub.cpp.txt b/test/hdi_unittest/hdi_compile_opt_test_01/cpp_target/foo/v1_0/foo_stub.cpp.txt index fb656d8..be6ca45 100644 --- a/test/hdi_unittest/hdi_compile_opt_test_01/cpp_target/foo/v1_0/foo_stub.cpp.txt +++ b/test/hdi_unittest/hdi_compile_opt_test_01/cpp_target/foo/v1_0/foo_stub.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_stub.h" @@ -57,6 +57,7 @@ OHOS::HDI::Foo::V1_0::FooStub::FooStub(const sptr &i OHOS::HDI::Foo::V1_0::FooStub::~FooStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_callback_proxy.cpp.txt b/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_callback_proxy.cpp.txt index 83afeec..329f9d1 100644 --- a/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_callback_proxy.cpp.txt +++ b/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_callback_proxy.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_callback_proxy.h" diff --git a/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_callback_stub.cpp.txt b/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_callback_stub.cpp.txt index 0027dac..3beb693 100644 --- a/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_callback_stub.cpp.txt +++ b/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_callback_stub.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_callback_stub.h" @@ -33,6 +33,7 @@ OHOS::HDI::Foo::V1_0::FooCallbackStub::FooCallbackStub(const sptr diff --git a/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_proxy.cpp.txt b/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_proxy.cpp.txt index 689cf37..a77a6f8 100644 --- a/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_proxy.cpp.txt +++ b/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_proxy.cpp.txt @@ -11,279 +11,279 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#include "v1_0/foo_proxy.h" -#include -#include -#include -#include -#include -#include -#include -#include - -#define HDF_LOG_TAG foo_proxy - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) -{ - return IFoo::Get("foo_service", isStub); -} - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) -{ - if (isStub) { - std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); - void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); - if (impl == nullptr) { - HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); - return nullptr; - } - return reinterpret_cast(impl); - } - - using namespace OHOS::HDI::ServiceManager::V1_0; - auto servMgr = IServiceManager::Get(); - if (servMgr == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return nullptr; - } - - sptr remote = servMgr->GetService(serviceName.c_str()); - if (remote == nullptr) { - HDF_LOGE("%{public}s:get remote object failed!", __func__); - return nullptr; - } - - sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); - if (proxy == nullptr) { - HDF_LOGE("%{public}s:iface_cast failed!", __func__); - return nullptr; - } - - proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); - proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); - proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); - proxy->isReconnected_ = false; - proxy->serviceName_ = serviceName; - uint32_t serMajorVer = 0; - uint32_t serMinorVer = 0; - int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s:get version failed!", __func__); - return nullptr; - } - - if (serMajorVer != 1) { - HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); - return nullptr; - } - - return proxy; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( - sptr proxy) -{ - if (proxy == nullptr) { - HDF_LOGW("Reconnect failed : input proxy is null"); - return HDF_FAILURE; - } - using namespace OHOS::HDI::ServiceManager::V1_0; - proxy->isReconnected_ = false; - auto iServMgr = IServiceManager::Get(); - if (iServMgr == nullptr) { - HDF_LOGW("Reconnect failed : iServMgr is null"); - return HDF_FAILURE; - }; - proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); - if (proxy->reconnectRemote_ == nullptr) { - HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); - return HDF_FAILURE; - } - proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); - if (proxy->servMgr_ == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return HDF_FAILURE; - } - proxy->servMgr_->AddDeathRecipient( - new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); - proxy->isReconnected_ = true; - return HDF_SUCCESS; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::SetCallback(const sptr& cbObj) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::SetCallback_(cbObj, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteBool(false)) { - HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteCString(sendMsg.c_str())) { - HDF_LOGE("%{public}s: write sendMsg failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - const char* recvMsgCp = fooReply.ReadCString(); - if (recvMsgCp == nullptr) { - HDF_LOGE("%{public}s: read recvMsg failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - recvMsg = recvMsgCp; - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!FooInfoBlockUnmarshalling(fooReply, info)) { - HDF_LOGE("%{public}s: read info failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::SetCallback_(const sptr& cbObj, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (cbObj == nullptr) { - HDF_LOGE("%{public}s: parameter cbObj is nullptr!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteRemoteObject(OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(cbObj, OHOS::HDI::Foo::V1_0::IFooCallback::GetDescriptor()))) { - HDF_LOGE("%{public}s: write cbObj failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_SET_CALLBACK, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!fooReply.ReadUint32(majorVer)) { - HDF_LOGE("%{public}s: read majorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooReply.ReadUint32(minorVer)) { - HDF_LOGE("%{public}s: read minorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -} // V1_0 -} // Foo -} // HDI -} // OHOS + */ + +#include "v1_0/foo_proxy.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG foo_proxy + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) +{ + return IFoo::Get("foo_service", isStub); +} + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) +{ + if (isStub) { + std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); + void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + return reinterpret_cast(impl); + } + + using namespace OHOS::HDI::ServiceManager::V1_0; + auto servMgr = IServiceManager::Get(); + if (servMgr == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return nullptr; + } + + sptr remote = servMgr->GetService(serviceName.c_str()); + if (remote == nullptr) { + HDF_LOGE("%{public}s:get remote object failed!", __func__); + return nullptr; + } + + sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:iface_cast failed!", __func__); + return nullptr; + } + + proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); + proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); + proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); + proxy->isReconnected_ = false; + proxy->serviceName_ = serviceName; + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( + sptr proxy) +{ + if (proxy == nullptr) { + HDF_LOGW("Reconnect failed : input proxy is null"); + return HDF_FAILURE; + } + using namespace OHOS::HDI::ServiceManager::V1_0; + proxy->isReconnected_ = false; + auto iServMgr = IServiceManager::Get(); + if (iServMgr == nullptr) { + HDF_LOGW("Reconnect failed : iServMgr is null"); + return HDF_FAILURE; + }; + proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); + if (proxy->reconnectRemote_ == nullptr) { + HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); + return HDF_FAILURE; + } + proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); + if (proxy->servMgr_ == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return HDF_FAILURE; + } + proxy->servMgr_->AddDeathRecipient( + new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); + proxy->isReconnected_ = true; + return HDF_SUCCESS; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::SetCallback(const sptr& cbObj) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::SetCallback_(cbObj, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteCString(sendMsg.c_str())) { + HDF_LOGE("%{public}s: write sendMsg failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + const char* recvMsgCp = fooReply.ReadCString(); + if (recvMsgCp == nullptr) { + HDF_LOGE("%{public}s: read recvMsg failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + recvMsg = recvMsgCp; + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!FooInfoBlockUnmarshalling(fooReply, info)) { + HDF_LOGE("%{public}s: read info failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::SetCallback_(const sptr& cbObj, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (cbObj == nullptr) { + HDF_LOGE("%{public}s: parameter cbObj is nullptr!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteRemoteObject(OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(cbObj, OHOS::HDI::Foo::V1_0::IFooCallback::GetDescriptor()))) { + HDF_LOGE("%{public}s: write cbObj failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_SET_CALLBACK, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.ReadUint32(majorVer)) { + HDF_LOGE("%{public}s: read majorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooReply.ReadUint32(minorVer)) { + HDF_LOGE("%{public}s: read minorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +} // V1_0 +} // Foo +} // HDI +} // OHOS diff --git a/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_proxy.h.txt b/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_proxy.h.txt index 4c7a31f..add4d3e 100644 --- a/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_proxy.h.txt +++ b/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_proxy.h.txt @@ -11,98 +11,98 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H -#define OHOS_HDI_FOO_V1_0_FOOPROXY_H - -#include "v1_0/ifoo.h" -#include -#include - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - -class FooProxy : public IProxyBroker { -public: - class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { - public: - IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} - ~IServiceManagerDeathRecipient() override = default; - void OnRemoteDied(const wptr &remote) override - { - int32_t result = HDF_FAILURE; - const int sleepInterval = 500000; - const int waitTimes = 10; - int currentTime = waitTimes; - do { - usleep(sleepInterval); - auto proxy = proxy_.promote(); - if (proxy != nullptr) { - result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); - } - --currentTime; - } while (result != HDF_SUCCESS && currentTime >0); - } - private: - wptr proxy_; - }; - - explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { - reconnectRemote_ = nullptr; - servMgr_ = nullptr; - deathRecipient_ = nullptr; - isReconnected_ = false; - } - virtual ~FooProxy() { - if (servMgr_ != nullptr && deathRecipient_ != nullptr) { - servMgr_->RemoveDeathRecipient(deathRecipient_); - } - } - - inline bool IsProxy() override - { - return true; - } - - int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; - - int32_t GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) override; - - int32_t SetCallback(const sptr& cbObj) override; - - int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; - - static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); - - static int32_t GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote); - - static int32_t SetCallback_(const sptr& cbObj, - const sptr remote); - - static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); - - static int32_t Reconnect(sptr proxy); - - sptr GetCurrentRemote() { - return isReconnected_ ? reconnectRemote_ : Remote(); - } - - bool isReconnected_; - std::string serviceName_; - sptr servMgr_; - sptr deathRecipient_; - sptr reconnectRemote_; -private: - static inline BrokerDelegator delegator_; -}; - -} // V1_0 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H - + */ + +#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H +#define OHOS_HDI_FOO_V1_0_FOOPROXY_H + +#include "v1_0/ifoo.h" +#include +#include + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + +class FooProxy : public IProxyBroker { +public: + class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { + public: + IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} + ~IServiceManagerDeathRecipient() override = default; + void OnRemoteDied(const wptr &remote) override + { + int32_t result = HDF_FAILURE; + const int sleepInterval = 500000; + const int waitTimes = 10; + int currentTime = waitTimes; + do { + usleep(sleepInterval); + auto proxy = proxy_.promote(); + if (proxy != nullptr) { + result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); + } + --currentTime; + } while (result != HDF_SUCCESS && currentTime >0); + } + private: + wptr proxy_; + }; + + explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { + reconnectRemote_ = nullptr; + servMgr_ = nullptr; + deathRecipient_ = nullptr; + isReconnected_ = false; + } + virtual ~FooProxy() { + if (servMgr_ != nullptr && deathRecipient_ != nullptr) { + servMgr_->RemoveDeathRecipient(deathRecipient_); + } + } + + inline bool IsProxy() override + { + return true; + } + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) override; + + int32_t SetCallback(const sptr& cbObj) override; + + int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; + + static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); + + static int32_t GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote); + + static int32_t SetCallback_(const sptr& cbObj, + const sptr remote); + + static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); + + static int32_t Reconnect(sptr proxy); + + sptr GetCurrentRemote() { + return isReconnected_ ? reconnectRemote_ : Remote(); + } + + bool isReconnected_; + std::string serviceName_; + sptr servMgr_; + sptr deathRecipient_; + sptr reconnectRemote_; +private: + static inline BrokerDelegator delegator_; +}; + +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H + diff --git a/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_stub.cpp.txt b/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_stub.cpp.txt index fb656d8..be6ca45 100644 --- a/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_stub.cpp.txt +++ b/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/foo_stub.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_stub.h" @@ -57,6 +57,7 @@ OHOS::HDI::Foo::V1_0::FooStub::FooStub(const sptr &i OHOS::HDI::Foo::V1_0::FooStub::~FooStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/types.cpp.txt b/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/types.cpp.txt index 9f33e26..bfe0801 100644 --- a/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/types.cpp.txt +++ b/test/hdi_unittest/hdi_compile_opt_test_02/cpp_target/foo/v1_0/types.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/types.h" diff --git a/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_callback_proxy.cpp.txt b/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_callback_proxy.cpp.txt index 83afeec..329f9d1 100644 --- a/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_callback_proxy.cpp.txt +++ b/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_callback_proxy.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_callback_proxy.h" diff --git a/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_callback_stub.cpp.txt b/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_callback_stub.cpp.txt index 0027dac..3beb693 100644 --- a/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_callback_stub.cpp.txt +++ b/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_callback_stub.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_callback_stub.h" @@ -33,6 +33,7 @@ OHOS::HDI::Foo::V1_0::FooCallbackStub::FooCallbackStub(const sptr diff --git a/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_proxy.cpp.txt b/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_proxy.cpp.txt index 689cf37..a77a6f8 100644 --- a/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_proxy.cpp.txt +++ b/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_proxy.cpp.txt @@ -11,279 +11,279 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#include "v1_0/foo_proxy.h" -#include -#include -#include -#include -#include -#include -#include -#include - -#define HDF_LOG_TAG foo_proxy - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) -{ - return IFoo::Get("foo_service", isStub); -} - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) -{ - if (isStub) { - std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); - void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); - if (impl == nullptr) { - HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); - return nullptr; - } - return reinterpret_cast(impl); - } - - using namespace OHOS::HDI::ServiceManager::V1_0; - auto servMgr = IServiceManager::Get(); - if (servMgr == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return nullptr; - } - - sptr remote = servMgr->GetService(serviceName.c_str()); - if (remote == nullptr) { - HDF_LOGE("%{public}s:get remote object failed!", __func__); - return nullptr; - } - - sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); - if (proxy == nullptr) { - HDF_LOGE("%{public}s:iface_cast failed!", __func__); - return nullptr; - } - - proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); - proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); - proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); - proxy->isReconnected_ = false; - proxy->serviceName_ = serviceName; - uint32_t serMajorVer = 0; - uint32_t serMinorVer = 0; - int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s:get version failed!", __func__); - return nullptr; - } - - if (serMajorVer != 1) { - HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); - return nullptr; - } - - return proxy; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( - sptr proxy) -{ - if (proxy == nullptr) { - HDF_LOGW("Reconnect failed : input proxy is null"); - return HDF_FAILURE; - } - using namespace OHOS::HDI::ServiceManager::V1_0; - proxy->isReconnected_ = false; - auto iServMgr = IServiceManager::Get(); - if (iServMgr == nullptr) { - HDF_LOGW("Reconnect failed : iServMgr is null"); - return HDF_FAILURE; - }; - proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); - if (proxy->reconnectRemote_ == nullptr) { - HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); - return HDF_FAILURE; - } - proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); - if (proxy->servMgr_ == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return HDF_FAILURE; - } - proxy->servMgr_->AddDeathRecipient( - new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); - proxy->isReconnected_ = true; - return HDF_SUCCESS; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::SetCallback(const sptr& cbObj) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::SetCallback_(cbObj, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteBool(false)) { - HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteCString(sendMsg.c_str())) { - HDF_LOGE("%{public}s: write sendMsg failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - const char* recvMsgCp = fooReply.ReadCString(); - if (recvMsgCp == nullptr) { - HDF_LOGE("%{public}s: read recvMsg failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - recvMsg = recvMsgCp; - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!FooInfoBlockUnmarshalling(fooReply, info)) { - HDF_LOGE("%{public}s: read info failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::SetCallback_(const sptr& cbObj, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (cbObj == nullptr) { - HDF_LOGE("%{public}s: parameter cbObj is nullptr!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteRemoteObject(OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(cbObj, OHOS::HDI::Foo::V1_0::IFooCallback::GetDescriptor()))) { - HDF_LOGE("%{public}s: write cbObj failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_SET_CALLBACK, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!fooReply.ReadUint32(majorVer)) { - HDF_LOGE("%{public}s: read majorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooReply.ReadUint32(minorVer)) { - HDF_LOGE("%{public}s: read minorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -} // V1_0 -} // Foo -} // HDI -} // OHOS + */ + +#include "v1_0/foo_proxy.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG foo_proxy + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) +{ + return IFoo::Get("foo_service", isStub); +} + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) +{ + if (isStub) { + std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); + void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + return reinterpret_cast(impl); + } + + using namespace OHOS::HDI::ServiceManager::V1_0; + auto servMgr = IServiceManager::Get(); + if (servMgr == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return nullptr; + } + + sptr remote = servMgr->GetService(serviceName.c_str()); + if (remote == nullptr) { + HDF_LOGE("%{public}s:get remote object failed!", __func__); + return nullptr; + } + + sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:iface_cast failed!", __func__); + return nullptr; + } + + proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); + proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); + proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); + proxy->isReconnected_ = false; + proxy->serviceName_ = serviceName; + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( + sptr proxy) +{ + if (proxy == nullptr) { + HDF_LOGW("Reconnect failed : input proxy is null"); + return HDF_FAILURE; + } + using namespace OHOS::HDI::ServiceManager::V1_0; + proxy->isReconnected_ = false; + auto iServMgr = IServiceManager::Get(); + if (iServMgr == nullptr) { + HDF_LOGW("Reconnect failed : iServMgr is null"); + return HDF_FAILURE; + }; + proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); + if (proxy->reconnectRemote_ == nullptr) { + HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); + return HDF_FAILURE; + } + proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); + if (proxy->servMgr_ == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return HDF_FAILURE; + } + proxy->servMgr_->AddDeathRecipient( + new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); + proxy->isReconnected_ = true; + return HDF_SUCCESS; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::SetCallback(const sptr& cbObj) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::SetCallback_(cbObj, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteCString(sendMsg.c_str())) { + HDF_LOGE("%{public}s: write sendMsg failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + const char* recvMsgCp = fooReply.ReadCString(); + if (recvMsgCp == nullptr) { + HDF_LOGE("%{public}s: read recvMsg failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + recvMsg = recvMsgCp; + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!FooInfoBlockUnmarshalling(fooReply, info)) { + HDF_LOGE("%{public}s: read info failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::SetCallback_(const sptr& cbObj, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (cbObj == nullptr) { + HDF_LOGE("%{public}s: parameter cbObj is nullptr!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteRemoteObject(OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(cbObj, OHOS::HDI::Foo::V1_0::IFooCallback::GetDescriptor()))) { + HDF_LOGE("%{public}s: write cbObj failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_SET_CALLBACK, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.ReadUint32(majorVer)) { + HDF_LOGE("%{public}s: read majorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooReply.ReadUint32(minorVer)) { + HDF_LOGE("%{public}s: read minorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +} // V1_0 +} // Foo +} // HDI +} // OHOS diff --git a/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_proxy.h.txt b/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_proxy.h.txt index 4c7a31f..add4d3e 100644 --- a/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_proxy.h.txt +++ b/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_proxy.h.txt @@ -11,98 +11,98 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H -#define OHOS_HDI_FOO_V1_0_FOOPROXY_H - -#include "v1_0/ifoo.h" -#include -#include - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - -class FooProxy : public IProxyBroker { -public: - class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { - public: - IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} - ~IServiceManagerDeathRecipient() override = default; - void OnRemoteDied(const wptr &remote) override - { - int32_t result = HDF_FAILURE; - const int sleepInterval = 500000; - const int waitTimes = 10; - int currentTime = waitTimes; - do { - usleep(sleepInterval); - auto proxy = proxy_.promote(); - if (proxy != nullptr) { - result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); - } - --currentTime; - } while (result != HDF_SUCCESS && currentTime >0); - } - private: - wptr proxy_; - }; - - explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { - reconnectRemote_ = nullptr; - servMgr_ = nullptr; - deathRecipient_ = nullptr; - isReconnected_ = false; - } - virtual ~FooProxy() { - if (servMgr_ != nullptr && deathRecipient_ != nullptr) { - servMgr_->RemoveDeathRecipient(deathRecipient_); - } - } - - inline bool IsProxy() override - { - return true; - } - - int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; - - int32_t GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) override; - - int32_t SetCallback(const sptr& cbObj) override; - - int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; - - static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); - - static int32_t GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote); - - static int32_t SetCallback_(const sptr& cbObj, - const sptr remote); - - static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); - - static int32_t Reconnect(sptr proxy); - - sptr GetCurrentRemote() { - return isReconnected_ ? reconnectRemote_ : Remote(); - } - - bool isReconnected_; - std::string serviceName_; - sptr servMgr_; - sptr deathRecipient_; - sptr reconnectRemote_; -private: - static inline BrokerDelegator delegator_; -}; - -} // V1_0 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H - + */ + +#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H +#define OHOS_HDI_FOO_V1_0_FOOPROXY_H + +#include "v1_0/ifoo.h" +#include +#include + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + +class FooProxy : public IProxyBroker { +public: + class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { + public: + IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} + ~IServiceManagerDeathRecipient() override = default; + void OnRemoteDied(const wptr &remote) override + { + int32_t result = HDF_FAILURE; + const int sleepInterval = 500000; + const int waitTimes = 10; + int currentTime = waitTimes; + do { + usleep(sleepInterval); + auto proxy = proxy_.promote(); + if (proxy != nullptr) { + result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); + } + --currentTime; + } while (result != HDF_SUCCESS && currentTime >0); + } + private: + wptr proxy_; + }; + + explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { + reconnectRemote_ = nullptr; + servMgr_ = nullptr; + deathRecipient_ = nullptr; + isReconnected_ = false; + } + virtual ~FooProxy() { + if (servMgr_ != nullptr && deathRecipient_ != nullptr) { + servMgr_->RemoveDeathRecipient(deathRecipient_); + } + } + + inline bool IsProxy() override + { + return true; + } + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) override; + + int32_t SetCallback(const sptr& cbObj) override; + + int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; + + static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); + + static int32_t GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote); + + static int32_t SetCallback_(const sptr& cbObj, + const sptr remote); + + static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); + + static int32_t Reconnect(sptr proxy); + + sptr GetCurrentRemote() { + return isReconnected_ ? reconnectRemote_ : Remote(); + } + + bool isReconnected_; + std::string serviceName_; + sptr servMgr_; + sptr deathRecipient_; + sptr reconnectRemote_; +private: + static inline BrokerDelegator delegator_; +}; + +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H + diff --git a/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_stub.cpp.txt b/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_stub.cpp.txt index fb656d8..be6ca45 100644 --- a/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_stub.cpp.txt +++ b/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/foo_stub.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_stub.h" @@ -57,6 +57,7 @@ OHOS::HDI::Foo::V1_0::FooStub::FooStub(const sptr &i OHOS::HDI::Foo::V1_0::FooStub::~FooStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/types.cpp.txt b/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/types.cpp.txt index 9f33e26..bfe0801 100644 --- a/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/types.cpp.txt +++ b/test/hdi_unittest/hdi_compile_opt_test_03/cpp_target/foo/v1_0/types.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/types.h" diff --git a/test/hdi_unittest/huks_v1_0/c_target/huks/v1_0/huks_service.c.txt b/test/hdi_unittest/huks_v1_0/c_target/huks/v1_0/huks_service.c.txt index 935e831..cb9566a 100644 --- a/test/hdi_unittest/huks_v1_0/c_target/huks/v1_0/huks_service.c.txt +++ b/test/hdi_unittest/huks_v1_0/c_target/huks/v1_0/huks_service.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/input_ddk_v1_0/cpp_target/input/ddk/v1_0/hid_ddk_stub.cpp.txt b/test/hdi_unittest/input_ddk_v1_0/cpp_target/input/ddk/v1_0/hid_ddk_stub.cpp.txt index be836e6..23c41f2 100644 --- a/test/hdi_unittest/input_ddk_v1_0/cpp_target/input/ddk/v1_0/hid_ddk_stub.cpp.txt +++ b/test/hdi_unittest/input_ddk_v1_0/cpp_target/input/ddk/v1_0/hid_ddk_stub.cpp.txt @@ -80,6 +80,7 @@ OHOS::HDI::Input::Ddk::V1_0::HidDdkStub::HidDdkStub(const sptr diff --git a/test/hdi_unittest/motion_v1_1/cpp_target/motion/v1_1/motion_interface_proxy.cpp.txt b/test/hdi_unittest/motion_v1_1/cpp_target/motion/v1_1/motion_interface_proxy.cpp.txt index 333f574..cb74e08 100644 --- a/test/hdi_unittest/motion_v1_1/cpp_target/motion/v1_1/motion_interface_proxy.cpp.txt +++ b/test/hdi_unittest/motion_v1_1/cpp_target/motion/v1_1/motion_interface_proxy.cpp.txt @@ -11,245 +11,245 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#include "v1_1/motion_interface_proxy.h" -#include -#include -#include -#include -#include -#include -#include - -#define HDF_LOG_TAG motion_interface_proxy - -namespace OHOS { -namespace HDI { -namespace Motion { -namespace V1_1 { - -template -static bool WritePodArray(MessageParcel &parcel, const std::vector &data); - -template -static sptr CastFromTemplate(const sptr &parent) -{ - if (parent == nullptr) { - HDF_LOGE("%{public}s:parent is nullptr!", __func__); - return nullptr; - } - - if (!parent->IsProxy()) { - HDF_LOGE("%{public}s:not proxy, not support castfrom!", __func__); - return nullptr; - } - - sptr remote = OHOS::HDI::hdi_objcast(parent); - if (remote == nullptr) { - HDF_LOGE("%{public}s:hdi_objcast failed!", __func__); - return nullptr; - } - - sptr proxy = OHOS::HDI::hdi_facecast(remote); - if (proxy == nullptr) { - HDF_LOGE("%{public}s:hdi_facecast failed!", __func__); - return nullptr; - } - - uint32_t serMajorVer = 0; - uint32_t serMinorVer = 0; - int32_t motionInterfaceRet = proxy->GetVersion(serMajorVer, serMinorVer); - if (motionInterfaceRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s:get version failed!", __func__); - return nullptr; - } - - if (serMajorVer != 1) { - HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.1", __func__, serMajorVer, serMinorVer); - return nullptr; - } - - return proxy; -} - -sptr OHOS::HDI::Motion::V1_1::IMotionInterface::Get(bool isStub) -{ - return IMotionInterface::Get("motion_interface_service", isStub); -} - -sptr OHOS::HDI::Motion::V1_1::IMotionInterface::Get(const std::string& serviceName, bool isStub) -{ - if (isStub) { - std::string desc = Str16ToStr8(OHOS::HDI::Motion::V1_1::IMotionInterface::GetDescriptor()); - void *impl = LoadHdiImpl(desc.c_str(), serviceName == "motion_interface_service" ? "service" : serviceName.c_str()); - if (impl == nullptr) { - HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); - return nullptr; - } - return reinterpret_cast(impl); - } - - using namespace OHOS::HDI::ServiceManager::V1_0; - auto servMgr = IServiceManager::Get(); - if (servMgr == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return nullptr; - } - - sptr remote = servMgr->GetService(serviceName.c_str()); - if (remote == nullptr) { - HDF_LOGE("%{public}s:get remote object failed!", __func__); - return nullptr; - } - - sptr proxy = new OHOS::HDI::Motion::V1_1::MotionInterfaceProxy(remote); - if (proxy == nullptr) { - HDF_LOGE("%{public}s:iface_cast failed!", __func__); - return nullptr; - } - - proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); - proxy->deathRecipient_ = new OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::IServiceManagerDeathRecipient(proxy); - proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); - proxy->isReconnected_ = false; - proxy->serviceName_ = serviceName; - uint32_t serMajorVer = 0; - uint32_t serMinorVer = 0; - int32_t motionInterfaceRet = proxy->GetVersion(serMajorVer, serMinorVer); - if (motionInterfaceRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s:get version failed!", __func__); - return nullptr; - } - - if (serMajorVer != 1) { - HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.1", __func__, serMajorVer, serMinorVer); - return nullptr; - } - - return proxy; -} - -int32_t OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::Reconnect( - sptr proxy) -{ - if (proxy == nullptr) { - HDF_LOGW("Reconnect failed : input proxy is null"); - return HDF_FAILURE; - } - using namespace OHOS::HDI::ServiceManager::V1_0; - proxy->isReconnected_ = false; - auto iServMgr = IServiceManager::Get(); - if (iServMgr == nullptr) { - HDF_LOGW("Reconnect failed : iServMgr is null"); - return HDF_FAILURE; - }; - proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); - if (proxy->reconnectRemote_ == nullptr) { - HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); - return HDF_FAILURE; - } - proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); - if (proxy->servMgr_ == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return HDF_FAILURE; - } - proxy->servMgr_->AddDeathRecipient( - new OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::IServiceManagerDeathRecipient(proxy)); - proxy->isReconnected_ = true; - return HDF_SUCCESS; -} - -sptr OHOS::HDI::Motion::V1_1::IMotionInterface::CastFrom(const sptr &parent) -{ - return CastFromTemplate(parent); -} - - -template -static bool WritePodArray(MessageParcel &parcel, const std::vector &data) -{ - if (!parcel.WriteUint32(data.size())) { - HDF_LOGE("%{public}s: failed to write data size", __func__); - return false; - } - if (data.empty()) { - return true; - } - if (!parcel.WriteUnpadBuffer((const void*)data.data(), sizeof(ElementType) * data.size())) { - HDF_LOGE("%{public}s: failed to write array", __func__); - return false; - } - return true; -} -int32_t OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::SetMotionConfig(int32_t motionType, - const std::vector& data) -{ - return OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::SetMotionConfig_(motionType, data, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::EnableMotion(int32_t motionType) -{ - return OHOS::HDI::Motion::V1_0::MotionInterfaceProxy::EnableMotion_(motionType, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::DisableMotion(int32_t motionType) -{ - return OHOS::HDI::Motion::V1_0::MotionInterfaceProxy::DisableMotion_(motionType, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::Register(const sptr& callbackObj) -{ - return OHOS::HDI::Motion::V1_0::MotionInterfaceProxy::Register_(callbackObj, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::Unregister(const sptr& callbackObj) -{ - return OHOS::HDI::Motion::V1_0::MotionInterfaceProxy::Unregister_(callbackObj, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) -{ - return OHOS::HDI::Motion::V1_0::MotionInterfaceProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::SetMotionConfig_(int32_t motionType, - const std::vector& data, const sptr remote) -{ - MessageParcel motionInterfaceData; - MessageParcel motionInterfaceReply; - MessageOption motionInterfaceOption(MessageOption::TF_SYNC); - - if (!motionInterfaceData.WriteInterfaceToken(OHOS::HDI::Motion::V1_1::IMotionInterface::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!motionInterfaceData.WriteInt32(motionType)) { - HDF_LOGE("%{public}s: write motionType failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!WritePodArray(motionInterfaceData, data)) { - HDF_LOGE("%{public}s: failed to write data", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t motionInterfaceRet = remote->SendRequest(CMD_MOTION_INTERFACE_SET_MOTION_CONFIG, motionInterfaceData, motionInterfaceReply, motionInterfaceOption); - if (motionInterfaceRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, motionInterfaceRet); - return motionInterfaceRet; - } - - return motionInterfaceRet; -} - -} // V1_1 -} // Motion -} // HDI -} // OHOS + */ + +#include "v1_1/motion_interface_proxy.h" +#include +#include +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG motion_interface_proxy + +namespace OHOS { +namespace HDI { +namespace Motion { +namespace V1_1 { + +template +static bool WritePodArray(MessageParcel &parcel, const std::vector &data); + +template +static sptr CastFromTemplate(const sptr &parent) +{ + if (parent == nullptr) { + HDF_LOGE("%{public}s:parent is nullptr!", __func__); + return nullptr; + } + + if (!parent->IsProxy()) { + HDF_LOGE("%{public}s:not proxy, not support castfrom!", __func__); + return nullptr; + } + + sptr remote = OHOS::HDI::hdi_objcast(parent); + if (remote == nullptr) { + HDF_LOGE("%{public}s:hdi_objcast failed!", __func__); + return nullptr; + } + + sptr proxy = OHOS::HDI::hdi_facecast(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:hdi_facecast failed!", __func__); + return nullptr; + } + + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t motionInterfaceRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (motionInterfaceRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.1", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +sptr OHOS::HDI::Motion::V1_1::IMotionInterface::Get(bool isStub) +{ + return IMotionInterface::Get("motion_interface_service", isStub); +} + +sptr OHOS::HDI::Motion::V1_1::IMotionInterface::Get(const std::string& serviceName, bool isStub) +{ + if (isStub) { + std::string desc = Str16ToStr8(OHOS::HDI::Motion::V1_1::IMotionInterface::GetDescriptor()); + void *impl = LoadHdiImpl(desc.c_str(), serviceName == "motion_interface_service" ? "service" : serviceName.c_str()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + return reinterpret_cast(impl); + } + + using namespace OHOS::HDI::ServiceManager::V1_0; + auto servMgr = IServiceManager::Get(); + if (servMgr == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return nullptr; + } + + sptr remote = servMgr->GetService(serviceName.c_str()); + if (remote == nullptr) { + HDF_LOGE("%{public}s:get remote object failed!", __func__); + return nullptr; + } + + sptr proxy = new OHOS::HDI::Motion::V1_1::MotionInterfaceProxy(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:iface_cast failed!", __func__); + return nullptr; + } + + proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); + proxy->deathRecipient_ = new OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::IServiceManagerDeathRecipient(proxy); + proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); + proxy->isReconnected_ = false; + proxy->serviceName_ = serviceName; + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t motionInterfaceRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (motionInterfaceRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.1", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +int32_t OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::Reconnect( + sptr proxy) +{ + if (proxy == nullptr) { + HDF_LOGW("Reconnect failed : input proxy is null"); + return HDF_FAILURE; + } + using namespace OHOS::HDI::ServiceManager::V1_0; + proxy->isReconnected_ = false; + auto iServMgr = IServiceManager::Get(); + if (iServMgr == nullptr) { + HDF_LOGW("Reconnect failed : iServMgr is null"); + return HDF_FAILURE; + }; + proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); + if (proxy->reconnectRemote_ == nullptr) { + HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); + return HDF_FAILURE; + } + proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); + if (proxy->servMgr_ == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return HDF_FAILURE; + } + proxy->servMgr_->AddDeathRecipient( + new OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::IServiceManagerDeathRecipient(proxy)); + proxy->isReconnected_ = true; + return HDF_SUCCESS; +} + +sptr OHOS::HDI::Motion::V1_1::IMotionInterface::CastFrom(const sptr &parent) +{ + return CastFromTemplate(parent); +} + + +template +static bool WritePodArray(MessageParcel &parcel, const std::vector &data) +{ + if (!parcel.WriteUint32(data.size())) { + HDF_LOGE("%{public}s: failed to write data size", __func__); + return false; + } + if (data.empty()) { + return true; + } + if (!parcel.WriteUnpadBuffer((const void*)data.data(), sizeof(ElementType) * data.size())) { + HDF_LOGE("%{public}s: failed to write array", __func__); + return false; + } + return true; +} +int32_t OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::SetMotionConfig(int32_t motionType, + const std::vector& data) +{ + return OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::SetMotionConfig_(motionType, data, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::EnableMotion(int32_t motionType) +{ + return OHOS::HDI::Motion::V1_0::MotionInterfaceProxy::EnableMotion_(motionType, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::DisableMotion(int32_t motionType) +{ + return OHOS::HDI::Motion::V1_0::MotionInterfaceProxy::DisableMotion_(motionType, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::Register(const sptr& callbackObj) +{ + return OHOS::HDI::Motion::V1_0::MotionInterfaceProxy::Register_(callbackObj, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::Unregister(const sptr& callbackObj) +{ + return OHOS::HDI::Motion::V1_0::MotionInterfaceProxy::Unregister_(callbackObj, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) +{ + return OHOS::HDI::Motion::V1_0::MotionInterfaceProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::SetMotionConfig_(int32_t motionType, + const std::vector& data, const sptr remote) +{ + MessageParcel motionInterfaceData; + MessageParcel motionInterfaceReply; + MessageOption motionInterfaceOption(MessageOption::TF_SYNC); + + if (!motionInterfaceData.WriteInterfaceToken(OHOS::HDI::Motion::V1_1::IMotionInterface::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!motionInterfaceData.WriteInt32(motionType)) { + HDF_LOGE("%{public}s: write motionType failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!WritePodArray(motionInterfaceData, data)) { + HDF_LOGE("%{public}s: failed to write data", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t motionInterfaceRet = remote->SendRequest(CMD_MOTION_INTERFACE_SET_MOTION_CONFIG, motionInterfaceData, motionInterfaceReply, motionInterfaceOption); + if (motionInterfaceRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, motionInterfaceRet); + return motionInterfaceRet; + } + + return motionInterfaceRet; +} + +} // V1_1 +} // Motion +} // HDI +} // OHOS diff --git a/test/hdi_unittest/motion_v1_1/cpp_target/motion/v1_1/motion_interface_proxy.h.txt b/test/hdi_unittest/motion_v1_1/cpp_target/motion/v1_1/motion_interface_proxy.h.txt index ebd8574..bddf783 100644 --- a/test/hdi_unittest/motion_v1_1/cpp_target/motion/v1_1/motion_interface_proxy.h.txt +++ b/test/hdi_unittest/motion_v1_1/cpp_target/motion/v1_1/motion_interface_proxy.h.txt @@ -11,97 +11,97 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#ifndef OHOS_HDI_MOTION_V1_1_MOTIONINTERFACEPROXY_H -#define OHOS_HDI_MOTION_V1_1_MOTIONINTERFACEPROXY_H - -#include "v1_0/motion_interface_proxy.h" -#include "v1_1/imotion_interface.h" -#include -#include - -namespace OHOS { -namespace HDI { -namespace Motion { -namespace V1_1 { - -class MotionInterfaceProxy : public IProxyBroker { -public: - class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { - public: - IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} - ~IServiceManagerDeathRecipient() override = default; - void OnRemoteDied(const wptr &remote) override - { - int32_t result = HDF_FAILURE; - const int sleepInterval = 500000; - const int waitTimes = 10; - int currentTime = waitTimes; - do { - usleep(sleepInterval); - auto proxy = proxy_.promote(); - if (proxy != nullptr) { - result = OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::Reconnect(proxy); - } - --currentTime; - } while (result != HDF_SUCCESS && currentTime >0); - } - private: - wptr proxy_; - }; - - explicit MotionInterfaceProxy(const sptr& remote) : IProxyBroker(remote) { - reconnectRemote_ = nullptr; - servMgr_ = nullptr; - deathRecipient_ = nullptr; - isReconnected_ = false; - } - virtual ~MotionInterfaceProxy() { - if (servMgr_ != nullptr && deathRecipient_ != nullptr) { - servMgr_->RemoveDeathRecipient(deathRecipient_); - } - } - - inline bool IsProxy() override - { - return true; - } - - int32_t SetMotionConfig(int32_t motionType, const std::vector& data) override; - - int32_t EnableMotion(int32_t motionType) override; - - int32_t DisableMotion(int32_t motionType) override; - - int32_t Register(const sptr& callbackObj) override; - - int32_t Unregister(const sptr& callbackObj) override; - - int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; - - static int32_t SetMotionConfig_(int32_t motionType, const std::vector& data, - const sptr remote); - - static int32_t Reconnect(sptr proxy); - - sptr GetCurrentRemote() { - return isReconnected_ ? reconnectRemote_ : Remote(); - } - - bool isReconnected_; - std::string serviceName_; - sptr servMgr_; - sptr deathRecipient_; - sptr reconnectRemote_; -private: - static inline BrokerDelegator delegator_; -}; - -} // V1_1 -} // Motion -} // HDI -} // OHOS - -#endif // OHOS_HDI_MOTION_V1_1_MOTIONINTERFACEPROXY_H - + */ + +#ifndef OHOS_HDI_MOTION_V1_1_MOTIONINTERFACEPROXY_H +#define OHOS_HDI_MOTION_V1_1_MOTIONINTERFACEPROXY_H + +#include "v1_0/motion_interface_proxy.h" +#include "v1_1/imotion_interface.h" +#include +#include + +namespace OHOS { +namespace HDI { +namespace Motion { +namespace V1_1 { + +class MotionInterfaceProxy : public IProxyBroker { +public: + class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { + public: + IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} + ~IServiceManagerDeathRecipient() override = default; + void OnRemoteDied(const wptr &remote) override + { + int32_t result = HDF_FAILURE; + const int sleepInterval = 500000; + const int waitTimes = 10; + int currentTime = waitTimes; + do { + usleep(sleepInterval); + auto proxy = proxy_.promote(); + if (proxy != nullptr) { + result = OHOS::HDI::Motion::V1_1::MotionInterfaceProxy::Reconnect(proxy); + } + --currentTime; + } while (result != HDF_SUCCESS && currentTime >0); + } + private: + wptr proxy_; + }; + + explicit MotionInterfaceProxy(const sptr& remote) : IProxyBroker(remote) { + reconnectRemote_ = nullptr; + servMgr_ = nullptr; + deathRecipient_ = nullptr; + isReconnected_ = false; + } + virtual ~MotionInterfaceProxy() { + if (servMgr_ != nullptr && deathRecipient_ != nullptr) { + servMgr_->RemoveDeathRecipient(deathRecipient_); + } + } + + inline bool IsProxy() override + { + return true; + } + + int32_t SetMotionConfig(int32_t motionType, const std::vector& data) override; + + int32_t EnableMotion(int32_t motionType) override; + + int32_t DisableMotion(int32_t motionType) override; + + int32_t Register(const sptr& callbackObj) override; + + int32_t Unregister(const sptr& callbackObj) override; + + int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; + + static int32_t SetMotionConfig_(int32_t motionType, const std::vector& data, + const sptr remote); + + static int32_t Reconnect(sptr proxy); + + sptr GetCurrentRemote() { + return isReconnected_ ? reconnectRemote_ : Remote(); + } + + bool isReconnected_; + std::string serviceName_; + sptr servMgr_; + sptr deathRecipient_; + sptr reconnectRemote_; +private: + static inline BrokerDelegator delegator_; +}; + +} // V1_1 +} // Motion +} // HDI +} // OHOS + +#endif // OHOS_HDI_MOTION_V1_1_MOTIONINTERFACEPROXY_H + diff --git a/test/hdi_unittest/motion_v1_1/cpp_target/motion/v1_1/motion_interface_stub.cpp.txt b/test/hdi_unittest/motion_v1_1/cpp_target/motion/v1_1/motion_interface_stub.cpp.txt index b2f1ca2..3fb2c8f 100644 --- a/test/hdi_unittest/motion_v1_1/cpp_target/motion/v1_1/motion_interface_stub.cpp.txt +++ b/test/hdi_unittest/motion_v1_1/cpp_target/motion/v1_1/motion_interface_stub.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_1/motion_interface_stub.h" @@ -79,6 +79,7 @@ OHOS::HDI::Motion::V1_1::MotionInterfaceStub::MotionInterfaceStub(const sptr diff --git a/test/hdi_unittest/overload_method_idl/cpp_target/foo/v1_1/foo_proxy.cpp.txt b/test/hdi_unittest/overload_method_idl/cpp_target/foo/v1_1/foo_proxy.cpp.txt index b488683..69f00de 100644 --- a/test/hdi_unittest/overload_method_idl/cpp_target/foo/v1_1/foo_proxy.cpp.txt +++ b/test/hdi_unittest/overload_method_idl/cpp_target/foo/v1_1/foo_proxy.cpp.txt @@ -11,281 +11,281 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#include "v1_1/foo_proxy.h" -#include -#include -#include -#include -#include -#include -#include - -#define HDF_LOG_TAG foo_proxy - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_1 { - - -template -static sptr CastFromTemplate(const sptr &parent) -{ - if (parent == nullptr) { - HDF_LOGE("%{public}s:parent is nullptr!", __func__); - return nullptr; - } - - if (!parent->IsProxy()) { - HDF_LOGE("%{public}s:not proxy, not support castfrom!", __func__); - return nullptr; - } - - sptr remote = OHOS::HDI::hdi_objcast(parent); - if (remote == nullptr) { - HDF_LOGE("%{public}s:hdi_objcast failed!", __func__); - return nullptr; - } - - sptr proxy = OHOS::HDI::hdi_facecast(remote); - if (proxy == nullptr) { - HDF_LOGE("%{public}s:hdi_facecast failed!", __func__); - return nullptr; - } - - uint32_t serMajorVer = 0; - uint32_t serMinorVer = 0; - int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s:get version failed!", __func__); - return nullptr; - } - - if (serMajorVer != 1) { - HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.1", __func__, serMajorVer, serMinorVer); - return nullptr; - } - - return proxy; -} - -sptr OHOS::HDI::Foo::V1_1::IFoo::Get(bool isStub) -{ - return IFoo::Get("foo_service", isStub); -} - -sptr OHOS::HDI::Foo::V1_1::IFoo::Get(const std::string& serviceName, bool isStub) -{ - if (isStub) { - std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_1::IFoo::GetDescriptor()); - void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); - if (impl == nullptr) { - HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); - return nullptr; - } - return reinterpret_cast(impl); - } - - using namespace OHOS::HDI::ServiceManager::V1_0; - auto servMgr = IServiceManager::Get(); - if (servMgr == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return nullptr; - } - - sptr remote = servMgr->GetService(serviceName.c_str()); - if (remote == nullptr) { - HDF_LOGE("%{public}s:get remote object failed!", __func__); - return nullptr; - } - - sptr proxy = new OHOS::HDI::Foo::V1_1::FooProxy(remote); - if (proxy == nullptr) { - HDF_LOGE("%{public}s:iface_cast failed!", __func__); - return nullptr; - } - - proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); - proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_1::FooProxy::IServiceManagerDeathRecipient(proxy); - proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); - proxy->isReconnected_ = false; - proxy->serviceName_ = serviceName; - uint32_t serMajorVer = 0; - uint32_t serMinorVer = 0; - int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s:get version failed!", __func__); - return nullptr; - } - - if (serMajorVer != 1) { - HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.1", __func__, serMajorVer, serMinorVer); - return nullptr; - } - - return proxy; -} - -int32_t OHOS::HDI::Foo::V1_1::FooProxy::Reconnect( - sptr proxy) -{ - if (proxy == nullptr) { - HDF_LOGW("Reconnect failed : input proxy is null"); - return HDF_FAILURE; - } - using namespace OHOS::HDI::ServiceManager::V1_0; - proxy->isReconnected_ = false; - auto iServMgr = IServiceManager::Get(); - if (iServMgr == nullptr) { - HDF_LOGW("Reconnect failed : iServMgr is null"); - return HDF_FAILURE; - }; - proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); - if (proxy->reconnectRemote_ == nullptr) { - HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); - return HDF_FAILURE; - } - proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); - if (proxy->servMgr_ == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return HDF_FAILURE; - } - proxy->servMgr_->AddDeathRecipient( - new OHOS::HDI::Foo::V1_1::FooProxy::IServiceManagerDeathRecipient(proxy)); - proxy->isReconnected_ = true; - return HDF_SUCCESS; -} - -sptr OHOS::HDI::Foo::V1_1::IFoo::CastFrom(const sptr &parent) -{ - return CastFromTemplate(parent); -} - -int32_t OHOS::HDI::Foo::V1_1::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg, int32_t code) -{ - return OHOS::HDI::Foo::V1_1::FooProxy::Ping_(sendMsg, recvMsg, code, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_1::FooProxy::GetData(std::string& info, std::string& ver) -{ - return OHOS::HDI::Foo::V1_1::FooProxy::GetData_(info, ver, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_1::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_1::FooProxy::GetData(std::string& info) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_1::FooProxy::InfoTest(int32_t inParam, double& outParam) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(inParam, outParam, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_1::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_1::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, int32_t code, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_1::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteBool(false)) { - HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteCString(sendMsg.c_str())) { - HDF_LOGE("%{public}s: write sendMsg failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteInt32(code)) { - HDF_LOGE("%{public}s: write code failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_PING_4, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - const char* recvMsgCp = fooReply.ReadCString(); - if (recvMsgCp == nullptr) { - HDF_LOGE("%{public}s: read recvMsg failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - recvMsg = recvMsgCp; - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_1::FooProxy::GetData_(std::string& info, std::string& ver, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_1::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteBool(false)) { - HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA_5, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - const char* infoCp = fooReply.ReadCString(); - if (infoCp == nullptr) { - HDF_LOGE("%{public}s: read info failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - info = infoCp; - - const char* verCp = fooReply.ReadCString(); - if (verCp == nullptr) { - HDF_LOGE("%{public}s: read ver failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - ver = verCp; - - return fooRet; -} - -} // V1_1 -} // Foo -} // HDI -} // OHOS + */ + +#include "v1_1/foo_proxy.h" +#include +#include +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG foo_proxy + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_1 { + + +template +static sptr CastFromTemplate(const sptr &parent) +{ + if (parent == nullptr) { + HDF_LOGE("%{public}s:parent is nullptr!", __func__); + return nullptr; + } + + if (!parent->IsProxy()) { + HDF_LOGE("%{public}s:not proxy, not support castfrom!", __func__); + return nullptr; + } + + sptr remote = OHOS::HDI::hdi_objcast(parent); + if (remote == nullptr) { + HDF_LOGE("%{public}s:hdi_objcast failed!", __func__); + return nullptr; + } + + sptr proxy = OHOS::HDI::hdi_facecast(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:hdi_facecast failed!", __func__); + return nullptr; + } + + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.1", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +sptr OHOS::HDI::Foo::V1_1::IFoo::Get(bool isStub) +{ + return IFoo::Get("foo_service", isStub); +} + +sptr OHOS::HDI::Foo::V1_1::IFoo::Get(const std::string& serviceName, bool isStub) +{ + if (isStub) { + std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_1::IFoo::GetDescriptor()); + void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + return reinterpret_cast(impl); + } + + using namespace OHOS::HDI::ServiceManager::V1_0; + auto servMgr = IServiceManager::Get(); + if (servMgr == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return nullptr; + } + + sptr remote = servMgr->GetService(serviceName.c_str()); + if (remote == nullptr) { + HDF_LOGE("%{public}s:get remote object failed!", __func__); + return nullptr; + } + + sptr proxy = new OHOS::HDI::Foo::V1_1::FooProxy(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:iface_cast failed!", __func__); + return nullptr; + } + + proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); + proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_1::FooProxy::IServiceManagerDeathRecipient(proxy); + proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); + proxy->isReconnected_ = false; + proxy->serviceName_ = serviceName; + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.1", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::Reconnect( + sptr proxy) +{ + if (proxy == nullptr) { + HDF_LOGW("Reconnect failed : input proxy is null"); + return HDF_FAILURE; + } + using namespace OHOS::HDI::ServiceManager::V1_0; + proxy->isReconnected_ = false; + auto iServMgr = IServiceManager::Get(); + if (iServMgr == nullptr) { + HDF_LOGW("Reconnect failed : iServMgr is null"); + return HDF_FAILURE; + }; + proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); + if (proxy->reconnectRemote_ == nullptr) { + HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); + return HDF_FAILURE; + } + proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); + if (proxy->servMgr_ == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return HDF_FAILURE; + } + proxy->servMgr_->AddDeathRecipient( + new OHOS::HDI::Foo::V1_1::FooProxy::IServiceManagerDeathRecipient(proxy)); + proxy->isReconnected_ = true; + return HDF_SUCCESS; +} + +sptr OHOS::HDI::Foo::V1_1::IFoo::CastFrom(const sptr &parent) +{ + return CastFromTemplate(parent); +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg, int32_t code) +{ + return OHOS::HDI::Foo::V1_1::FooProxy::Ping_(sendMsg, recvMsg, code, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::GetData(std::string& info, std::string& ver) +{ + return OHOS::HDI::Foo::V1_1::FooProxy::GetData_(info, ver, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::GetData(std::string& info) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::InfoTest(int32_t inParam, double& outParam) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(inParam, outParam, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, int32_t code, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_1::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteCString(sendMsg.c_str())) { + HDF_LOGE("%{public}s: write sendMsg failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteInt32(code)) { + HDF_LOGE("%{public}s: write code failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_PING_4, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + const char* recvMsgCp = fooReply.ReadCString(); + if (recvMsgCp == nullptr) { + HDF_LOGE("%{public}s: read recvMsg failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + recvMsg = recvMsgCp; + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::GetData_(std::string& info, std::string& ver, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_1::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA_5, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + const char* infoCp = fooReply.ReadCString(); + if (infoCp == nullptr) { + HDF_LOGE("%{public}s: read info failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + info = infoCp; + + const char* verCp = fooReply.ReadCString(); + if (verCp == nullptr) { + HDF_LOGE("%{public}s: read ver failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + ver = verCp; + + return fooRet; +} + +} // V1_1 +} // Foo +} // HDI +} // OHOS diff --git a/test/hdi_unittest/overload_method_idl/cpp_target/foo/v1_1/foo_proxy.h.txt b/test/hdi_unittest/overload_method_idl/cpp_target/foo/v1_1/foo_proxy.h.txt index 218d414..f3c92cc 100644 --- a/test/hdi_unittest/overload_method_idl/cpp_target/foo/v1_1/foo_proxy.h.txt +++ b/test/hdi_unittest/overload_method_idl/cpp_target/foo/v1_1/foo_proxy.h.txt @@ -11,99 +11,99 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_1_FOOPROXY_H -#define OHOS_HDI_FOO_V1_1_FOOPROXY_H - -#include "v1_0/foo_proxy.h" -#include "v1_1/ifoo.h" -#include -#include - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_1 { - -class FooProxy : public IProxyBroker { -public: - class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { - public: - IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} - ~IServiceManagerDeathRecipient() override = default; - void OnRemoteDied(const wptr &remote) override - { - int32_t result = HDF_FAILURE; - const int sleepInterval = 500000; - const int waitTimes = 10; - int currentTime = waitTimes; - do { - usleep(sleepInterval); - auto proxy = proxy_.promote(); - if (proxy != nullptr) { - result = OHOS::HDI::Foo::V1_1::FooProxy::Reconnect(proxy); - } - --currentTime; - } while (result != HDF_SUCCESS && currentTime >0); - } - private: - wptr proxy_; - }; - - explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { - reconnectRemote_ = nullptr; - servMgr_ = nullptr; - deathRecipient_ = nullptr; - isReconnected_ = false; - } - virtual ~FooProxy() { - if (servMgr_ != nullptr && deathRecipient_ != nullptr) { - servMgr_->RemoveDeathRecipient(deathRecipient_); - } - } - - inline bool IsProxy() override - { - return true; - } - - int32_t Ping(const std::string& sendMsg, std::string& recvMsg, int32_t code) override; - - int32_t GetData(std::string& info, std::string& ver) override; - - int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; - - int32_t GetData(std::string& info) override; - - int32_t InfoTest(int32_t inParam, double& outParam) override; - - int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; - - static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, int32_t code, - const sptr remote); - - static int32_t GetData_(std::string& info, std::string& ver, const sptr remote); - - static int32_t Reconnect(sptr proxy); - - sptr GetCurrentRemote() { - return isReconnected_ ? reconnectRemote_ : Remote(); - } - - bool isReconnected_; - std::string serviceName_; - sptr servMgr_; - sptr deathRecipient_; - sptr reconnectRemote_; -private: - static inline BrokerDelegator delegator_; -}; - -} // V1_1 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_1_FOOPROXY_H - + */ + +#ifndef OHOS_HDI_FOO_V1_1_FOOPROXY_H +#define OHOS_HDI_FOO_V1_1_FOOPROXY_H + +#include "v1_0/foo_proxy.h" +#include "v1_1/ifoo.h" +#include +#include + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_1 { + +class FooProxy : public IProxyBroker { +public: + class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { + public: + IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} + ~IServiceManagerDeathRecipient() override = default; + void OnRemoteDied(const wptr &remote) override + { + int32_t result = HDF_FAILURE; + const int sleepInterval = 500000; + const int waitTimes = 10; + int currentTime = waitTimes; + do { + usleep(sleepInterval); + auto proxy = proxy_.promote(); + if (proxy != nullptr) { + result = OHOS::HDI::Foo::V1_1::FooProxy::Reconnect(proxy); + } + --currentTime; + } while (result != HDF_SUCCESS && currentTime >0); + } + private: + wptr proxy_; + }; + + explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { + reconnectRemote_ = nullptr; + servMgr_ = nullptr; + deathRecipient_ = nullptr; + isReconnected_ = false; + } + virtual ~FooProxy() { + if (servMgr_ != nullptr && deathRecipient_ != nullptr) { + servMgr_->RemoveDeathRecipient(deathRecipient_); + } + } + + inline bool IsProxy() override + { + return true; + } + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg, int32_t code) override; + + int32_t GetData(std::string& info, std::string& ver) override; + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t GetData(std::string& info) override; + + int32_t InfoTest(int32_t inParam, double& outParam) override; + + int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; + + static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, int32_t code, + const sptr remote); + + static int32_t GetData_(std::string& info, std::string& ver, const sptr remote); + + static int32_t Reconnect(sptr proxy); + + sptr GetCurrentRemote() { + return isReconnected_ ? reconnectRemote_ : Remote(); + } + + bool isReconnected_; + std::string serviceName_; + sptr servMgr_; + sptr deathRecipient_; + sptr reconnectRemote_; +private: + static inline BrokerDelegator delegator_; +}; + +} // V1_1 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_1_FOOPROXY_H + diff --git a/test/hdi_unittest/overload_method_idl/cpp_target/foo/v1_1/foo_stub.cpp.txt b/test/hdi_unittest/overload_method_idl/cpp_target/foo/v1_1/foo_stub.cpp.txt index 7a2e1f9..2c1d9db 100644 --- a/test/hdi_unittest/overload_method_idl/cpp_target/foo/v1_1/foo_stub.cpp.txt +++ b/test/hdi_unittest/overload_method_idl/cpp_target/foo/v1_1/foo_stub.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_1/foo_stub.h" @@ -55,6 +55,7 @@ OHOS::HDI::Foo::V1_1::FooStub::FooStub(const sptr &i OHOS::HDI::Foo::V1_1::FooStub::~FooStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/partitionslot_v1_0/cpp_target/partitionslot/v1_0/partition_slot_stub.cpp.txt b/test/hdi_unittest/partitionslot_v1_0/cpp_target/partitionslot/v1_0/partition_slot_stub.cpp.txt index 621f380..81e4c44 100644 --- a/test/hdi_unittest/partitionslot_v1_0/cpp_target/partitionslot/v1_0/partition_slot_stub.cpp.txt +++ b/test/hdi_unittest/partitionslot_v1_0/cpp_target/partitionslot/v1_0/partition_slot_stub.cpp.txt @@ -55,6 +55,7 @@ OHOS::HDI::Partitionslot::V1_0::PartitionSlotStub::PartitionSlotStub(const sptr< OHOS::HDI::Partitionslot::V1_0::PartitionSlotStub::~PartitionSlotStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/pin_auth_v1_0/cpp_target/pin_auth/v1_0/executor_callback_stub.cpp.txt b/test/hdi_unittest/pin_auth_v1_0/cpp_target/pin_auth/v1_0/executor_callback_stub.cpp.txt index 348bd12..3dcb830 100644 --- a/test/hdi_unittest/pin_auth_v1_0/cpp_target/pin_auth/v1_0/executor_callback_stub.cpp.txt +++ b/test/hdi_unittest/pin_auth_v1_0/cpp_target/pin_auth/v1_0/executor_callback_stub.cpp.txt @@ -57,6 +57,7 @@ OHOS::HDI::PinAuth::V1_0::ExecutorCallbackStub::ExecutorCallbackStub(const sptr< OHOS::HDI::PinAuth::V1_0::ExecutorCallbackStub::~ExecutorCallbackStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/pin_auth_v1_0/cpp_target/pin_auth/v1_0/executor_stub.cpp.txt b/test/hdi_unittest/pin_auth_v1_0/cpp_target/pin_auth/v1_0/executor_stub.cpp.txt index 3173d86..b504d73 100644 --- a/test/hdi_unittest/pin_auth_v1_0/cpp_target/pin_auth/v1_0/executor_stub.cpp.txt +++ b/test/hdi_unittest/pin_auth_v1_0/cpp_target/pin_auth/v1_0/executor_stub.cpp.txt @@ -81,6 +81,7 @@ OHOS::HDI::PinAuth::V1_0::ExecutorStub::ExecutorStub(const sptr &i OHOS::HDI::Ril::V1_0::RilStub::~RilStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/ril_v1_1/cpp_target/ril/v1_1/ril_callback_stub.cpp.txt b/test/hdi_unittest/ril_v1_1/cpp_target/ril/v1_1/ril_callback_stub.cpp.txt index bda3f93..9b46260 100644 --- a/test/hdi_unittest/ril_v1_1/cpp_target/ril/v1_1/ril_callback_stub.cpp.txt +++ b/test/hdi_unittest/ril_v1_1/cpp_target/ril/v1_1/ril_callback_stub.cpp.txt @@ -33,6 +33,7 @@ OHOS::HDI::Ril::V1_1::RilCallbackStub::RilCallbackStub(const sptr &i OHOS::HDI::Ril::V1_1::RilStub::~RilStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/ril_v1_2/cpp_target/ril/v1_2/ril_callback_stub.cpp.txt b/test/hdi_unittest/ril_v1_2/cpp_target/ril/v1_2/ril_callback_stub.cpp.txt index 7fb448f..e93e5b4 100644 --- a/test/hdi_unittest/ril_v1_2/cpp_target/ril/v1_2/ril_callback_stub.cpp.txt +++ b/test/hdi_unittest/ril_v1_2/cpp_target/ril/v1_2/ril_callback_stub.cpp.txt @@ -33,6 +33,7 @@ OHOS::HDI::Ril::V1_2::RilCallbackStub::RilCallbackStub(const sptr &i OHOS::HDI::Ril::V1_2::RilStub::~RilStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/secure_element_v1_0/cpp_target/secure_element/v1_0/secure_element_callback_stub.cpp.txt b/test/hdi_unittest/secure_element_v1_0/cpp_target/secure_element/v1_0/secure_element_callback_stub.cpp.txt index 155bd24..8464bd5 100644 --- a/test/hdi_unittest/secure_element_v1_0/cpp_target/secure_element/v1_0/secure_element_callback_stub.cpp.txt +++ b/test/hdi_unittest/secure_element_v1_0/cpp_target/secure_element/v1_0/secure_element_callback_stub.cpp.txt @@ -33,6 +33,7 @@ OHOS::HDI::SecureElement::V1_0::SecureElementCallbackStub::SecureElementCallback OHOS::HDI::SecureElement::V1_0::SecureElementCallbackStub::~SecureElementCallbackStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/secure_element_v1_0/cpp_target/secure_element/v1_0/secure_element_interface_stub.cpp.txt b/test/hdi_unittest/secure_element_v1_0/cpp_target/secure_element/v1_0/secure_element_interface_stub.cpp.txt index 069840b..db0eb56 100644 --- a/test/hdi_unittest/secure_element_v1_0/cpp_target/secure_element/v1_0/secure_element_interface_stub.cpp.txt +++ b/test/hdi_unittest/secure_element_v1_0/cpp_target/secure_element/v1_0/secure_element_interface_stub.cpp.txt @@ -100,6 +100,7 @@ OHOS::HDI::SecureElement::V1_0::SecureElementInterfaceStub::SecureElementInterfa OHOS::HDI::SecureElement::V1_0::SecureElementInterfaceStub::~SecureElementInterfaceStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/sensor_v1_0/cpp_target/sensor/v1_0/sensor_callback_stub.cpp.txt b/test/hdi_unittest/sensor_v1_0/cpp_target/sensor/v1_0/sensor_callback_stub.cpp.txt index d2a1285..1179b77 100644 --- a/test/hdi_unittest/sensor_v1_0/cpp_target/sensor/v1_0/sensor_callback_stub.cpp.txt +++ b/test/hdi_unittest/sensor_v1_0/cpp_target/sensor/v1_0/sensor_callback_stub.cpp.txt @@ -33,6 +33,7 @@ OHOS::HDI::Sensor::V1_0::SensorCallbackStub::SensorCallbackStub(const sptr diff --git a/test/hdi_unittest/standard_callback_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt b/test/hdi_unittest/standard_callback_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt index 4e39e37..70a93dc 100644 --- a/test/hdi_unittest/standard_callback_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt +++ b/test/hdi_unittest/standard_callback_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt @@ -11,284 +11,284 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#include "v1_0/foo_proxy.h" -#include -#include -#include -#include -#include -#include -#include - -#define HDF_LOG_TAG foo_proxy - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) -{ - return IFoo::Get("foo_service", isStub); -} - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) -{ - if (isStub) { - std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); - void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); - if (impl == nullptr) { - HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); - return nullptr; - } - return reinterpret_cast(impl); - } - - using namespace OHOS::HDI::ServiceManager::V1_0; - auto servMgr = IServiceManager::Get(); - if (servMgr == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return nullptr; - } - - sptr remote = servMgr->GetService(serviceName.c_str()); - if (remote == nullptr) { - HDF_LOGE("%{public}s:get remote object failed!", __func__); - return nullptr; - } - - sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); - if (proxy == nullptr) { - HDF_LOGE("%{public}s:iface_cast failed!", __func__); - return nullptr; - } - - proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); - proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); - proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); - proxy->isReconnected_ = false; - proxy->serviceName_ = serviceName; - uint32_t serMajorVer = 0; - uint32_t serMinorVer = 0; - int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s:get version failed!", __func__); - return nullptr; - } - - if (serMajorVer != 1) { - HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); - return nullptr; - } - - return proxy; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( - sptr proxy) -{ - if (proxy == nullptr) { - HDF_LOGW("Reconnect failed : input proxy is null"); - return HDF_FAILURE; - } - using namespace OHOS::HDI::ServiceManager::V1_0; - proxy->isReconnected_ = false; - auto iServMgr = IServiceManager::Get(); - if (iServMgr == nullptr) { - HDF_LOGW("Reconnect failed : iServMgr is null"); - return HDF_FAILURE; - }; - proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); - if (proxy->reconnectRemote_ == nullptr) { - HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); - return HDF_FAILURE; - } - proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); - if (proxy->servMgr_ == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return HDF_FAILURE; - } - proxy->servMgr_->AddDeathRecipient( - new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); - proxy->isReconnected_ = true; - return HDF_SUCCESS; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(std::string& info) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest(int32_t inParam, double& outParam) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(inParam, outParam, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteBool(false)) { - HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteCString(sendMsg.c_str())) { - HDF_LOGE("%{public}s: write sendMsg failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - const char* recvMsgCp = fooReply.ReadCString(); - if (recvMsgCp == nullptr) { - HDF_LOGE("%{public}s: read recvMsg failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - recvMsg = recvMsgCp; - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(std::string& info, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteBool(false)) { - HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - const char* infoCp = fooReply.ReadCString(); - if (infoCp == nullptr) { - HDF_LOGE("%{public}s: read info failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - info = infoCp; - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(int32_t inParam, double& outParam, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteInt32(inParam)) { - HDF_LOGE("%{public}s: write inParam failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_INFO_TEST, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!fooReply.ReadDouble(outParam)) { - HDF_LOGE("%{public}s: read outParam failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!fooReply.ReadUint32(majorVer)) { - HDF_LOGE("%{public}s: read majorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooReply.ReadUint32(minorVer)) { - HDF_LOGE("%{public}s: read minorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -} // V1_0 -} // Foo -} // HDI -} // OHOS + */ + +#include "v1_0/foo_proxy.h" +#include +#include +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG foo_proxy + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) +{ + return IFoo::Get("foo_service", isStub); +} + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) +{ + if (isStub) { + std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); + void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + return reinterpret_cast(impl); + } + + using namespace OHOS::HDI::ServiceManager::V1_0; + auto servMgr = IServiceManager::Get(); + if (servMgr == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return nullptr; + } + + sptr remote = servMgr->GetService(serviceName.c_str()); + if (remote == nullptr) { + HDF_LOGE("%{public}s:get remote object failed!", __func__); + return nullptr; + } + + sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:iface_cast failed!", __func__); + return nullptr; + } + + proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); + proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); + proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); + proxy->isReconnected_ = false; + proxy->serviceName_ = serviceName; + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( + sptr proxy) +{ + if (proxy == nullptr) { + HDF_LOGW("Reconnect failed : input proxy is null"); + return HDF_FAILURE; + } + using namespace OHOS::HDI::ServiceManager::V1_0; + proxy->isReconnected_ = false; + auto iServMgr = IServiceManager::Get(); + if (iServMgr == nullptr) { + HDF_LOGW("Reconnect failed : iServMgr is null"); + return HDF_FAILURE; + }; + proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); + if (proxy->reconnectRemote_ == nullptr) { + HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); + return HDF_FAILURE; + } + proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); + if (proxy->servMgr_ == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return HDF_FAILURE; + } + proxy->servMgr_->AddDeathRecipient( + new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); + proxy->isReconnected_ = true; + return HDF_SUCCESS; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(std::string& info) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest(int32_t inParam, double& outParam) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(inParam, outParam, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteCString(sendMsg.c_str())) { + HDF_LOGE("%{public}s: write sendMsg failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + const char* recvMsgCp = fooReply.ReadCString(); + if (recvMsgCp == nullptr) { + HDF_LOGE("%{public}s: read recvMsg failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + recvMsg = recvMsgCp; + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(std::string& info, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + const char* infoCp = fooReply.ReadCString(); + if (infoCp == nullptr) { + HDF_LOGE("%{public}s: read info failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + info = infoCp; + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(int32_t inParam, double& outParam, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteInt32(inParam)) { + HDF_LOGE("%{public}s: write inParam failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_INFO_TEST, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.ReadDouble(outParam)) { + HDF_LOGE("%{public}s: read outParam failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.ReadUint32(majorVer)) { + HDF_LOGE("%{public}s: read majorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooReply.ReadUint32(minorVer)) { + HDF_LOGE("%{public}s: read minorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +} // V1_0 +} // Foo +} // HDI +} // OHOS diff --git a/test/hdi_unittest/standard_callback_idl/cpp_target/foo/v1_0/foo_proxy.h.txt b/test/hdi_unittest/standard_callback_idl/cpp_target/foo/v1_0/foo_proxy.h.txt index 2c7a591..42a7132 100644 --- a/test/hdi_unittest/standard_callback_idl/cpp_target/foo/v1_0/foo_proxy.h.txt +++ b/test/hdi_unittest/standard_callback_idl/cpp_target/foo/v1_0/foo_proxy.h.txt @@ -11,97 +11,97 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H -#define OHOS_HDI_FOO_V1_0_FOOPROXY_H - -#include "v1_0/ifoo.h" -#include -#include - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - -class FooProxy : public IProxyBroker { -public: - class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { - public: - IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} - ~IServiceManagerDeathRecipient() override = default; - void OnRemoteDied(const wptr &remote) override - { - int32_t result = HDF_FAILURE; - const int sleepInterval = 500000; - const int waitTimes = 10; - int currentTime = waitTimes; - do { - usleep(sleepInterval); - auto proxy = proxy_.promote(); - if (proxy != nullptr) { - result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); - } - --currentTime; - } while (result != HDF_SUCCESS && currentTime >0); - } - private: - wptr proxy_; - }; - - explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { - reconnectRemote_ = nullptr; - servMgr_ = nullptr; - deathRecipient_ = nullptr; - isReconnected_ = false; - } - virtual ~FooProxy() { - if (servMgr_ != nullptr && deathRecipient_ != nullptr) { - servMgr_->RemoveDeathRecipient(deathRecipient_); - } - } - - inline bool IsProxy() override - { - return true; - } - - int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; - - int32_t GetData(std::string& info) override; - - int32_t InfoTest(int32_t inParam, double& outParam) override; - - int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; - - static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); - - static int32_t GetData_(std::string& info, const sptr remote); - - static int32_t InfoTest_(int32_t inParam, double& outParam, const sptr remote); - - static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); - - static int32_t Reconnect(sptr proxy); - - sptr GetCurrentRemote() { - return isReconnected_ ? reconnectRemote_ : Remote(); - } - - bool isReconnected_; - std::string serviceName_; - sptr servMgr_; - sptr deathRecipient_; - sptr reconnectRemote_; -private: - static inline BrokerDelegator delegator_; -}; - -} // V1_0 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H - + */ + +#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H +#define OHOS_HDI_FOO_V1_0_FOOPROXY_H + +#include "v1_0/ifoo.h" +#include +#include + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + +class FooProxy : public IProxyBroker { +public: + class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { + public: + IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} + ~IServiceManagerDeathRecipient() override = default; + void OnRemoteDied(const wptr &remote) override + { + int32_t result = HDF_FAILURE; + const int sleepInterval = 500000; + const int waitTimes = 10; + int currentTime = waitTimes; + do { + usleep(sleepInterval); + auto proxy = proxy_.promote(); + if (proxy != nullptr) { + result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); + } + --currentTime; + } while (result != HDF_SUCCESS && currentTime >0); + } + private: + wptr proxy_; + }; + + explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { + reconnectRemote_ = nullptr; + servMgr_ = nullptr; + deathRecipient_ = nullptr; + isReconnected_ = false; + } + virtual ~FooProxy() { + if (servMgr_ != nullptr && deathRecipient_ != nullptr) { + servMgr_->RemoveDeathRecipient(deathRecipient_); + } + } + + inline bool IsProxy() override + { + return true; + } + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t GetData(std::string& info) override; + + int32_t InfoTest(int32_t inParam, double& outParam) override; + + int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; + + static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); + + static int32_t GetData_(std::string& info, const sptr remote); + + static int32_t InfoTest_(int32_t inParam, double& outParam, const sptr remote); + + static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); + + static int32_t Reconnect(sptr proxy); + + sptr GetCurrentRemote() { + return isReconnected_ ? reconnectRemote_ : Remote(); + } + + bool isReconnected_; + std::string serviceName_; + sptr servMgr_; + sptr deathRecipient_; + sptr reconnectRemote_; +private: + static inline BrokerDelegator delegator_; +}; + +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H + diff --git a/test/hdi_unittest/standard_callback_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt b/test/hdi_unittest/standard_callback_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt index 752cc75..b86a9b5 100644 --- a/test/hdi_unittest/standard_callback_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt +++ b/test/hdi_unittest/standard_callback_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_stub.h" @@ -55,6 +55,7 @@ OHOS::HDI::Foo::V1_0::FooStub::FooStub(const sptr &i OHOS::HDI::Foo::V1_0::FooStub::~FooStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/standard_interface_idl/cpp_target/foo/v1_0/foo_driver.cpp.txt b/test/hdi_unittest/standard_interface_idl/cpp_target/foo/v1_0/foo_driver.cpp.txt index 625a670..a238792 100644 --- a/test/hdi_unittest/standard_interface_idl/cpp_target/foo/v1_0/foo_driver.cpp.txt +++ b/test/hdi_unittest/standard_interface_idl/cpp_target/foo/v1_0/foo_driver.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/standard_interface_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt b/test/hdi_unittest/standard_interface_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt index 4e39e37..70a93dc 100644 --- a/test/hdi_unittest/standard_interface_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt +++ b/test/hdi_unittest/standard_interface_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt @@ -11,284 +11,284 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#include "v1_0/foo_proxy.h" -#include -#include -#include -#include -#include -#include -#include - -#define HDF_LOG_TAG foo_proxy - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) -{ - return IFoo::Get("foo_service", isStub); -} - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) -{ - if (isStub) { - std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); - void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); - if (impl == nullptr) { - HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); - return nullptr; - } - return reinterpret_cast(impl); - } - - using namespace OHOS::HDI::ServiceManager::V1_0; - auto servMgr = IServiceManager::Get(); - if (servMgr == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return nullptr; - } - - sptr remote = servMgr->GetService(serviceName.c_str()); - if (remote == nullptr) { - HDF_LOGE("%{public}s:get remote object failed!", __func__); - return nullptr; - } - - sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); - if (proxy == nullptr) { - HDF_LOGE("%{public}s:iface_cast failed!", __func__); - return nullptr; - } - - proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); - proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); - proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); - proxy->isReconnected_ = false; - proxy->serviceName_ = serviceName; - uint32_t serMajorVer = 0; - uint32_t serMinorVer = 0; - int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s:get version failed!", __func__); - return nullptr; - } - - if (serMajorVer != 1) { - HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); - return nullptr; - } - - return proxy; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( - sptr proxy) -{ - if (proxy == nullptr) { - HDF_LOGW("Reconnect failed : input proxy is null"); - return HDF_FAILURE; - } - using namespace OHOS::HDI::ServiceManager::V1_0; - proxy->isReconnected_ = false; - auto iServMgr = IServiceManager::Get(); - if (iServMgr == nullptr) { - HDF_LOGW("Reconnect failed : iServMgr is null"); - return HDF_FAILURE; - }; - proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); - if (proxy->reconnectRemote_ == nullptr) { - HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); - return HDF_FAILURE; - } - proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); - if (proxy->servMgr_ == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return HDF_FAILURE; - } - proxy->servMgr_->AddDeathRecipient( - new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); - proxy->isReconnected_ = true; - return HDF_SUCCESS; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(std::string& info) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest(int32_t inParam, double& outParam) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(inParam, outParam, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteBool(false)) { - HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteCString(sendMsg.c_str())) { - HDF_LOGE("%{public}s: write sendMsg failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - const char* recvMsgCp = fooReply.ReadCString(); - if (recvMsgCp == nullptr) { - HDF_LOGE("%{public}s: read recvMsg failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - recvMsg = recvMsgCp; - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(std::string& info, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteBool(false)) { - HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - const char* infoCp = fooReply.ReadCString(); - if (infoCp == nullptr) { - HDF_LOGE("%{public}s: read info failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - info = infoCp; - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(int32_t inParam, double& outParam, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteInt32(inParam)) { - HDF_LOGE("%{public}s: write inParam failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_INFO_TEST, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!fooReply.ReadDouble(outParam)) { - HDF_LOGE("%{public}s: read outParam failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!fooReply.ReadUint32(majorVer)) { - HDF_LOGE("%{public}s: read majorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooReply.ReadUint32(minorVer)) { - HDF_LOGE("%{public}s: read minorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -} // V1_0 -} // Foo -} // HDI -} // OHOS + */ + +#include "v1_0/foo_proxy.h" +#include +#include +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG foo_proxy + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) +{ + return IFoo::Get("foo_service", isStub); +} + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) +{ + if (isStub) { + std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); + void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + return reinterpret_cast(impl); + } + + using namespace OHOS::HDI::ServiceManager::V1_0; + auto servMgr = IServiceManager::Get(); + if (servMgr == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return nullptr; + } + + sptr remote = servMgr->GetService(serviceName.c_str()); + if (remote == nullptr) { + HDF_LOGE("%{public}s:get remote object failed!", __func__); + return nullptr; + } + + sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:iface_cast failed!", __func__); + return nullptr; + } + + proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); + proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); + proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); + proxy->isReconnected_ = false; + proxy->serviceName_ = serviceName; + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( + sptr proxy) +{ + if (proxy == nullptr) { + HDF_LOGW("Reconnect failed : input proxy is null"); + return HDF_FAILURE; + } + using namespace OHOS::HDI::ServiceManager::V1_0; + proxy->isReconnected_ = false; + auto iServMgr = IServiceManager::Get(); + if (iServMgr == nullptr) { + HDF_LOGW("Reconnect failed : iServMgr is null"); + return HDF_FAILURE; + }; + proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); + if (proxy->reconnectRemote_ == nullptr) { + HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); + return HDF_FAILURE; + } + proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); + if (proxy->servMgr_ == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return HDF_FAILURE; + } + proxy->servMgr_->AddDeathRecipient( + new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); + proxy->isReconnected_ = true; + return HDF_SUCCESS; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(std::string& info) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest(int32_t inParam, double& outParam) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(inParam, outParam, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteCString(sendMsg.c_str())) { + HDF_LOGE("%{public}s: write sendMsg failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + const char* recvMsgCp = fooReply.ReadCString(); + if (recvMsgCp == nullptr) { + HDF_LOGE("%{public}s: read recvMsg failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + recvMsg = recvMsgCp; + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(std::string& info, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + const char* infoCp = fooReply.ReadCString(); + if (infoCp == nullptr) { + HDF_LOGE("%{public}s: read info failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + info = infoCp; + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(int32_t inParam, double& outParam, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteInt32(inParam)) { + HDF_LOGE("%{public}s: write inParam failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_INFO_TEST, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.ReadDouble(outParam)) { + HDF_LOGE("%{public}s: read outParam failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.ReadUint32(majorVer)) { + HDF_LOGE("%{public}s: read majorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooReply.ReadUint32(minorVer)) { + HDF_LOGE("%{public}s: read minorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +} // V1_0 +} // Foo +} // HDI +} // OHOS diff --git a/test/hdi_unittest/standard_interface_idl/cpp_target/foo/v1_0/foo_proxy.h.txt b/test/hdi_unittest/standard_interface_idl/cpp_target/foo/v1_0/foo_proxy.h.txt index 2c7a591..42a7132 100644 --- a/test/hdi_unittest/standard_interface_idl/cpp_target/foo/v1_0/foo_proxy.h.txt +++ b/test/hdi_unittest/standard_interface_idl/cpp_target/foo/v1_0/foo_proxy.h.txt @@ -11,97 +11,97 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H -#define OHOS_HDI_FOO_V1_0_FOOPROXY_H - -#include "v1_0/ifoo.h" -#include -#include - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - -class FooProxy : public IProxyBroker { -public: - class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { - public: - IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} - ~IServiceManagerDeathRecipient() override = default; - void OnRemoteDied(const wptr &remote) override - { - int32_t result = HDF_FAILURE; - const int sleepInterval = 500000; - const int waitTimes = 10; - int currentTime = waitTimes; - do { - usleep(sleepInterval); - auto proxy = proxy_.promote(); - if (proxy != nullptr) { - result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); - } - --currentTime; - } while (result != HDF_SUCCESS && currentTime >0); - } - private: - wptr proxy_; - }; - - explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { - reconnectRemote_ = nullptr; - servMgr_ = nullptr; - deathRecipient_ = nullptr; - isReconnected_ = false; - } - virtual ~FooProxy() { - if (servMgr_ != nullptr && deathRecipient_ != nullptr) { - servMgr_->RemoveDeathRecipient(deathRecipient_); - } - } - - inline bool IsProxy() override - { - return true; - } - - int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; - - int32_t GetData(std::string& info) override; - - int32_t InfoTest(int32_t inParam, double& outParam) override; - - int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; - - static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); - - static int32_t GetData_(std::string& info, const sptr remote); - - static int32_t InfoTest_(int32_t inParam, double& outParam, const sptr remote); - - static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); - - static int32_t Reconnect(sptr proxy); - - sptr GetCurrentRemote() { - return isReconnected_ ? reconnectRemote_ : Remote(); - } - - bool isReconnected_; - std::string serviceName_; - sptr servMgr_; - sptr deathRecipient_; - sptr reconnectRemote_; -private: - static inline BrokerDelegator delegator_; -}; - -} // V1_0 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H - + */ + +#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H +#define OHOS_HDI_FOO_V1_0_FOOPROXY_H + +#include "v1_0/ifoo.h" +#include +#include + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + +class FooProxy : public IProxyBroker { +public: + class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { + public: + IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} + ~IServiceManagerDeathRecipient() override = default; + void OnRemoteDied(const wptr &remote) override + { + int32_t result = HDF_FAILURE; + const int sleepInterval = 500000; + const int waitTimes = 10; + int currentTime = waitTimes; + do { + usleep(sleepInterval); + auto proxy = proxy_.promote(); + if (proxy != nullptr) { + result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); + } + --currentTime; + } while (result != HDF_SUCCESS && currentTime >0); + } + private: + wptr proxy_; + }; + + explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { + reconnectRemote_ = nullptr; + servMgr_ = nullptr; + deathRecipient_ = nullptr; + isReconnected_ = false; + } + virtual ~FooProxy() { + if (servMgr_ != nullptr && deathRecipient_ != nullptr) { + servMgr_->RemoveDeathRecipient(deathRecipient_); + } + } + + inline bool IsProxy() override + { + return true; + } + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t GetData(std::string& info) override; + + int32_t InfoTest(int32_t inParam, double& outParam) override; + + int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; + + static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); + + static int32_t GetData_(std::string& info, const sptr remote); + + static int32_t InfoTest_(int32_t inParam, double& outParam, const sptr remote); + + static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); + + static int32_t Reconnect(sptr proxy); + + sptr GetCurrentRemote() { + return isReconnected_ ? reconnectRemote_ : Remote(); + } + + bool isReconnected_; + std::string serviceName_; + sptr servMgr_; + sptr deathRecipient_; + sptr reconnectRemote_; +private: + static inline BrokerDelegator delegator_; +}; + +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H + diff --git a/test/hdi_unittest/standard_interface_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt b/test/hdi_unittest/standard_interface_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt index 752cc75..b86a9b5 100644 --- a/test/hdi_unittest/standard_interface_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt +++ b/test/hdi_unittest/standard_interface_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_stub.h" @@ -55,6 +55,7 @@ OHOS::HDI::Foo::V1_0::FooStub::FooStub(const sptr &i OHOS::HDI::Foo::V1_0::FooStub::~FooStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/thermal_v1_0/cpp_target/thermal/v1_0/thermal_callback_stub.cpp.txt b/test/hdi_unittest/thermal_v1_0/cpp_target/thermal/v1_0/thermal_callback_stub.cpp.txt index 6f36fdf..1ae5761 100644 --- a/test/hdi_unittest/thermal_v1_0/cpp_target/thermal/v1_0/thermal_callback_stub.cpp.txt +++ b/test/hdi_unittest/thermal_v1_0/cpp_target/thermal/v1_0/thermal_callback_stub.cpp.txt @@ -33,6 +33,7 @@ OHOS::HDI::Thermal::V1_0::ThermalCallbackStub::ThermalCallbackStub(const sptr diff --git a/test/hdi_unittest/types_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt b/test/hdi_unittest/types_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt index 2c0f9ff..b98f302 100644 --- a/test/hdi_unittest/types_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt +++ b/test/hdi_unittest/types_idl/cpp_target/foo/v1_0/foo_proxy.cpp.txt @@ -11,279 +11,279 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#include "v1_0/foo_proxy.h" -#include -#include -#include -#include -#include -#include -#include - -#define HDF_LOG_TAG foo_proxy - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) -{ - return IFoo::Get("foo_service", isStub); -} - -sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) -{ - if (isStub) { - std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); - void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); - if (impl == nullptr) { - HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); - return nullptr; - } - return reinterpret_cast(impl); - } - - using namespace OHOS::HDI::ServiceManager::V1_0; - auto servMgr = IServiceManager::Get(); - if (servMgr == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return nullptr; - } - - sptr remote = servMgr->GetService(serviceName.c_str()); - if (remote == nullptr) { - HDF_LOGE("%{public}s:get remote object failed!", __func__); - return nullptr; - } - - sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); - if (proxy == nullptr) { - HDF_LOGE("%{public}s:iface_cast failed!", __func__); - return nullptr; - } - - proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); - proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); - proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); - proxy->isReconnected_ = false; - proxy->serviceName_ = serviceName; - uint32_t serMajorVer = 0; - uint32_t serMinorVer = 0; - int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s:get version failed!", __func__); - return nullptr; - } - - if (serMajorVer != 1) { - HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); - return nullptr; - } - - return proxy; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( - sptr proxy) -{ - if (proxy == nullptr) { - HDF_LOGW("Reconnect failed : input proxy is null"); - return HDF_FAILURE; - } - using namespace OHOS::HDI::ServiceManager::V1_0; - proxy->isReconnected_ = false; - auto iServMgr = IServiceManager::Get(); - if (iServMgr == nullptr) { - HDF_LOGW("Reconnect failed : iServMgr is null"); - return HDF_FAILURE; - }; - proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); - if (proxy->reconnectRemote_ == nullptr) { - HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); - return HDF_FAILURE; - } - proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); - if (proxy->servMgr_ == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return HDF_FAILURE; - } - proxy->servMgr_->AddDeathRecipient( - new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); - proxy->isReconnected_ = true; - return HDF_SUCCESS; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, - OHOS::HDI::Foo::V1_0::FooInfo& outParam) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(inParam, outParam, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) -{ - return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteBool(false)) { - HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooData.WriteCString(sendMsg.c_str())) { - HDF_LOGE("%{public}s: write sendMsg failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - const char* recvMsgCp = fooReply.ReadCString(); - if (recvMsgCp == nullptr) { - HDF_LOGE("%{public}s: read recvMsg failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - recvMsg = recvMsgCp; - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!FooInfoBlockUnmarshalling(fooReply, info)) { - HDF_LOGE("%{public}s: read info failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, - OHOS::HDI::Foo::V1_0::FooInfo& outParam, const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!OHOS::HDI::Foo::V1_0::FooInfoBlockMarshalling(fooData, inParam)) { - HDF_LOGE("%{public}s: write inParam failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_INFO_TEST, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!FooInfoBlockUnmarshalling(fooReply, outParam)) { - HDF_LOGE("%{public}s: read outParam failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, - const sptr remote) -{ - MessageParcel fooData; - MessageParcel fooReply; - MessageOption fooOption(MessageOption::TF_SYNC); - - if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); - if (fooRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); - return fooRet; - } - - if (!fooReply.ReadUint32(majorVer)) { - HDF_LOGE("%{public}s: read majorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!fooReply.ReadUint32(minorVer)) { - HDF_LOGE("%{public}s: read minorVer failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return fooRet; -} - -} // V1_0 -} // Foo -} // HDI -} // OHOS + */ + +#include "v1_0/foo_proxy.h" +#include +#include +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG foo_proxy + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) +{ + return IFoo::Get("foo_service", isStub); +} + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) +{ + if (isStub) { + std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); + void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + return reinterpret_cast(impl); + } + + using namespace OHOS::HDI::ServiceManager::V1_0; + auto servMgr = IServiceManager::Get(); + if (servMgr == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return nullptr; + } + + sptr remote = servMgr->GetService(serviceName.c_str()); + if (remote == nullptr) { + HDF_LOGE("%{public}s:get remote object failed!", __func__); + return nullptr; + } + + sptr proxy = new OHOS::HDI::Foo::V1_0::FooProxy(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:iface_cast failed!", __func__); + return nullptr; + } + + proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); + proxy->deathRecipient_ = new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy); + proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); + proxy->isReconnected_ = false; + proxy->serviceName_ = serviceName; + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Reconnect( + sptr proxy) +{ + if (proxy == nullptr) { + HDF_LOGW("Reconnect failed : input proxy is null"); + return HDF_FAILURE; + } + using namespace OHOS::HDI::ServiceManager::V1_0; + proxy->isReconnected_ = false; + auto iServMgr = IServiceManager::Get(); + if (iServMgr == nullptr) { + HDF_LOGW("Reconnect failed : iServMgr is null"); + return HDF_FAILURE; + }; + proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); + if (proxy->reconnectRemote_ == nullptr) { + HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); + return HDF_FAILURE; + } + proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); + if (proxy->servMgr_ == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return HDF_FAILURE; + } + proxy->servMgr_->AddDeathRecipient( + new OHOS::HDI::Foo::V1_0::FooProxy::IServiceManagerDeathRecipient(proxy)); + proxy->isReconnected_ = true; + return HDF_SUCCESS; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::Ping_(sendMsg, recvMsg, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetData_(info, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, + OHOS::HDI::Foo::V1_0::FooInfo& outParam) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(inParam, outParam, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) +{ + return OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteCString(sendMsg.c_str())) { + HDF_LOGE("%{public}s: write sendMsg failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_PING, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + const char* recvMsgCp = fooReply.ReadCString(); + if (recvMsgCp == nullptr) { + HDF_LOGE("%{public}s: read recvMsg failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + recvMsg = recvMsgCp; + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_DATA, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!FooInfoBlockUnmarshalling(fooReply, info)) { + HDF_LOGE("%{public}s: read info failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, + OHOS::HDI::Foo::V1_0::FooInfo& outParam, const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!OHOS::HDI::Foo::V1_0::FooInfoBlockMarshalling(fooData, inParam)) { + HDF_LOGE("%{public}s: write inParam failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_INFO_TEST, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!FooInfoBlockUnmarshalling(fooReply, outParam)) { + HDF_LOGE("%{public}s: read outParam failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_GET_VERSION, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.ReadUint32(majorVer)) { + HDF_LOGE("%{public}s: read majorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooReply.ReadUint32(minorVer)) { + HDF_LOGE("%{public}s: read minorVer failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +} // V1_0 +} // Foo +} // HDI +} // OHOS diff --git a/test/hdi_unittest/types_idl/cpp_target/foo/v1_0/foo_proxy.h.txt b/test/hdi_unittest/types_idl/cpp_target/foo/v1_0/foo_proxy.h.txt index c07f210..e707378 100644 --- a/test/hdi_unittest/types_idl/cpp_target/foo/v1_0/foo_proxy.h.txt +++ b/test/hdi_unittest/types_idl/cpp_target/foo/v1_0/foo_proxy.h.txt @@ -11,98 +11,98 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H -#define OHOS_HDI_FOO_V1_0_FOOPROXY_H - -#include "v1_0/ifoo.h" -#include -#include - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - -class FooProxy : public IProxyBroker { -public: - class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { - public: - IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} - ~IServiceManagerDeathRecipient() override = default; - void OnRemoteDied(const wptr &remote) override - { - int32_t result = HDF_FAILURE; - const int sleepInterval = 500000; - const int waitTimes = 10; - int currentTime = waitTimes; - do { - usleep(sleepInterval); - auto proxy = proxy_.promote(); - if (proxy != nullptr) { - result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); - } - --currentTime; - } while (result != HDF_SUCCESS && currentTime >0); - } - private: - wptr proxy_; - }; - - explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { - reconnectRemote_ = nullptr; - servMgr_ = nullptr; - deathRecipient_ = nullptr; - isReconnected_ = false; - } - virtual ~FooProxy() { - if (servMgr_ != nullptr && deathRecipient_ != nullptr) { - servMgr_->RemoveDeathRecipient(deathRecipient_); - } - } - - inline bool IsProxy() override - { - return true; - } - - int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; - - int32_t GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) override; - - int32_t InfoTest(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, OHOS::HDI::Foo::V1_0::FooInfo& outParam) override; - - int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; - - static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); - - static int32_t GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote); - - static int32_t InfoTest_(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, OHOS::HDI::Foo::V1_0::FooInfo& outParam, - const sptr remote); - - static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); - - static int32_t Reconnect(sptr proxy); - - sptr GetCurrentRemote() { - return isReconnected_ ? reconnectRemote_ : Remote(); - } - - bool isReconnected_; - std::string serviceName_; - sptr servMgr_; - sptr deathRecipient_; - sptr reconnectRemote_; -private: - static inline BrokerDelegator delegator_; -}; - -} // V1_0 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H - + */ + +#ifndef OHOS_HDI_FOO_V1_0_FOOPROXY_H +#define OHOS_HDI_FOO_V1_0_FOOPROXY_H + +#include "v1_0/ifoo.h" +#include +#include + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + +class FooProxy : public IProxyBroker { +public: + class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { + public: + IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} + ~IServiceManagerDeathRecipient() override = default; + void OnRemoteDied(const wptr &remote) override + { + int32_t result = HDF_FAILURE; + const int sleepInterval = 500000; + const int waitTimes = 10; + int currentTime = waitTimes; + do { + usleep(sleepInterval); + auto proxy = proxy_.promote(); + if (proxy != nullptr) { + result = OHOS::HDI::Foo::V1_0::FooProxy::Reconnect(proxy); + } + --currentTime; + } while (result != HDF_SUCCESS && currentTime >0); + } + private: + wptr proxy_; + }; + + explicit FooProxy(const sptr& remote) : IProxyBroker(remote) { + reconnectRemote_ = nullptr; + servMgr_ = nullptr; + deathRecipient_ = nullptr; + isReconnected_ = false; + } + virtual ~FooProxy() { + if (servMgr_ != nullptr && deathRecipient_ != nullptr) { + servMgr_->RemoveDeathRecipient(deathRecipient_); + } + } + + inline bool IsProxy() override + { + return true; + } + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t GetData(OHOS::HDI::Foo::V1_0::FooInfo& info) override; + + int32_t InfoTest(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, OHOS::HDI::Foo::V1_0::FooInfo& outParam) override; + + int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; + + static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); + + static int32_t GetData_(OHOS::HDI::Foo::V1_0::FooInfo& info, const sptr remote); + + static int32_t InfoTest_(const OHOS::HDI::Foo::V1_0::FooInfo& inParam, OHOS::HDI::Foo::V1_0::FooInfo& outParam, + const sptr remote); + + static int32_t GetVersion_(uint32_t& majorVer, uint32_t& minorVer, const sptr remote); + + static int32_t Reconnect(sptr proxy); + + sptr GetCurrentRemote() { + return isReconnected_ ? reconnectRemote_ : Remote(); + } + + bool isReconnected_; + std::string serviceName_; + sptr servMgr_; + sptr deathRecipient_; + sptr reconnectRemote_; +private: + static inline BrokerDelegator delegator_; +}; + +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_FOOPROXY_H + diff --git a/test/hdi_unittest/types_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt b/test/hdi_unittest/types_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt index 7682a3a..4c36b9f 100644 --- a/test/hdi_unittest/types_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt +++ b/test/hdi_unittest/types_idl/cpp_target/foo/v1_0/foo_stub.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/foo_stub.h" @@ -55,6 +55,7 @@ OHOS::HDI::Foo::V1_0::FooStub::FooStub(const sptr &i OHOS::HDI::Foo::V1_0::FooStub::~FooStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/usb_ddk_v1_0/cpp_target/usb/ddk/v1_0/usb_ddk_stub.cpp.txt b/test/hdi_unittest/usb_ddk_v1_0/cpp_target/usb/ddk/v1_0/usb_ddk_stub.cpp.txt index b60011c..acf1c5f 100644 --- a/test/hdi_unittest/usb_ddk_v1_0/cpp_target/usb/ddk/v1_0/usb_ddk_stub.cpp.txt +++ b/test/hdi_unittest/usb_ddk_v1_0/cpp_target/usb/ddk/v1_0/usb_ddk_stub.cpp.txt @@ -116,6 +116,7 @@ OHOS::HDI::Usb::Ddk::V1_0::UsbDdkStub::UsbDdkStub(const sptr diff --git a/test/hdi_unittest/vibrator_v1_2/cpp_target/vibrator/v1_2/vibrator_interface_proxy.cpp.txt b/test/hdi_unittest/vibrator_v1_2/cpp_target/vibrator/v1_2/vibrator_interface_proxy.cpp.txt index 8089d81..8af379b 100644 --- a/test/hdi_unittest/vibrator_v1_2/cpp_target/vibrator/v1_2/vibrator_interface_proxy.cpp.txt +++ b/test/hdi_unittest/vibrator_v1_2/cpp_target/vibrator/v1_2/vibrator_interface_proxy.cpp.txt @@ -11,352 +11,352 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#include "v1_2/vibrator_interface_proxy.h" -#include -#include -#include -#include -#include -#include -#include - -#define HDF_LOG_TAG vibrator_interface_proxy - -namespace OHOS { -namespace HDI { -namespace Vibrator { -namespace V1_2 { - - -template -static sptr CastFromTemplate(const sptr &parent) -{ - if (parent == nullptr) { - HDF_LOGE("%{public}s:parent is nullptr!", __func__); - return nullptr; - } - - if (!parent->IsProxy()) { - HDF_LOGE("%{public}s:not proxy, not support castfrom!", __func__); - return nullptr; - } - - sptr remote = OHOS::HDI::hdi_objcast(parent); - if (remote == nullptr) { - HDF_LOGE("%{public}s:hdi_objcast failed!", __func__); - return nullptr; - } - - sptr proxy = OHOS::HDI::hdi_facecast(remote); - if (proxy == nullptr) { - HDF_LOGE("%{public}s:hdi_facecast failed!", __func__); - return nullptr; - } - - uint32_t serMajorVer = 0; - uint32_t serMinorVer = 0; - int32_t vibratorInterfaceRet = proxy->GetVersion(serMajorVer, serMinorVer); - if (vibratorInterfaceRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s:get version failed!", __func__); - return nullptr; - } - - if (serMajorVer != 1) { - HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.2", __func__, serMajorVer, serMinorVer); - return nullptr; - } - - return proxy; -} - -sptr OHOS::HDI::Vibrator::V1_2::IVibratorInterface::Get(bool isStub) -{ - return IVibratorInterface::Get("vibrator_interface_service", isStub); -} - -sptr OHOS::HDI::Vibrator::V1_2::IVibratorInterface::Get(const std::string& serviceName, bool isStub) -{ - if (isStub) { - std::string desc = Str16ToStr8(OHOS::HDI::Vibrator::V1_2::IVibratorInterface::GetDescriptor()); - void *impl = LoadHdiImpl(desc.c_str(), serviceName == "vibrator_interface_service" ? "service" : serviceName.c_str()); - if (impl == nullptr) { - HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); - return nullptr; - } - return reinterpret_cast(impl); - } - - using namespace OHOS::HDI::ServiceManager::V1_0; - auto servMgr = IServiceManager::Get(); - if (servMgr == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return nullptr; - } - - sptr remote = servMgr->GetService(serviceName.c_str()); - if (remote == nullptr) { - HDF_LOGE("%{public}s:get remote object failed!", __func__); - return nullptr; - } - - sptr proxy = new OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy(remote); - if (proxy == nullptr) { - HDF_LOGE("%{public}s:iface_cast failed!", __func__); - return nullptr; - } - - proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); - proxy->deathRecipient_ = new OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::IServiceManagerDeathRecipient(proxy); - proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); - proxy->isReconnected_ = false; - proxy->serviceName_ = serviceName; - uint32_t serMajorVer = 0; - uint32_t serMinorVer = 0; - int32_t vibratorInterfaceRet = proxy->GetVersion(serMajorVer, serMinorVer); - if (vibratorInterfaceRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s:get version failed!", __func__); - return nullptr; - } - - if (serMajorVer != 1) { - HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.2", __func__, serMajorVer, serMinorVer); - return nullptr; - } - - return proxy; -} - -int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::Reconnect( - sptr proxy) -{ - if (proxy == nullptr) { - HDF_LOGW("Reconnect failed : input proxy is null"); - return HDF_FAILURE; - } - using namespace OHOS::HDI::ServiceManager::V1_0; - proxy->isReconnected_ = false; - auto iServMgr = IServiceManager::Get(); - if (iServMgr == nullptr) { - HDF_LOGW("Reconnect failed : iServMgr is null"); - return HDF_FAILURE; - }; - proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); - if (proxy->reconnectRemote_ == nullptr) { - HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); - return HDF_FAILURE; - } - proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); - if (proxy->servMgr_ == nullptr) { - HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); - return HDF_FAILURE; - } - proxy->servMgr_->AddDeathRecipient( - new OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::IServiceManagerDeathRecipient(proxy)); - proxy->isReconnected_ = true; - return HDF_SUCCESS; -} - -sptr OHOS::HDI::Vibrator::V1_2::IVibratorInterface::CastFrom(const sptr &parent) -{ - return CastFromTemplate(parent); -} - -int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::PlayHapticPattern(const OHOS::HDI::Vibrator::V1_2::HapticPaket& pkg) -{ - return OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::PlayHapticPattern_(pkg, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::GetHapticCapacity(OHOS::HDI::Vibrator::V1_2::HapticCapacity& HapticCapacity) -{ - return OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::GetHapticCapacity_(HapticCapacity, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::GetHapticStartUpTime(int32_t mode, int32_t& startUpTime) -{ - return OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::GetHapticStartUpTime_(mode, startUpTime, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::StopV1_2(int32_t mode) -{ - return OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::StopV1_2_(mode, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::StartOnce(uint32_t duration) -{ - return OHOS::HDI::Vibrator::V1_1::VibratorInterfaceProxy::StartOnce_(duration, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::Start(const std::string& effectType) -{ - return OHOS::HDI::Vibrator::V1_1::VibratorInterfaceProxy::Start_(effectType, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::Stop(OHOS::HDI::Vibrator::V1_1::HdfVibratorMode mode) -{ - return OHOS::HDI::Vibrator::V1_1::VibratorInterfaceProxy::Stop_(mode, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::GetVibratorInfo(std::vector& vibratorInfo) -{ - return OHOS::HDI::Vibrator::V1_1::VibratorInterfaceProxy::GetVibratorInfo_(vibratorInfo, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::EnableVibratorModulation(uint32_t duration, - uint16_t intensity, int16_t frequency) -{ - return OHOS::HDI::Vibrator::V1_1::VibratorInterfaceProxy::EnableVibratorModulation_(duration, intensity, frequency, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::EnableCompositeEffect(const OHOS::HDI::Vibrator::V1_1::HdfCompositeEffect& effect) -{ - return OHOS::HDI::Vibrator::V1_1::VibratorInterfaceProxy::EnableCompositeEffect_(effect, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::GetEffectInfo(const std::string& effectType, - OHOS::HDI::Vibrator::V1_1::HdfEffectInfo& effectInfo) -{ - return OHOS::HDI::Vibrator::V1_1::VibratorInterfaceProxy::GetEffectInfo_(effectType, effectInfo, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::IsVibratorRunning(bool& state) -{ - return OHOS::HDI::Vibrator::V1_1::VibratorInterfaceProxy::IsVibratorRunning_(state, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) -{ - return OHOS::HDI::Vibrator::V1_1::VibratorInterfaceProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); -} - -int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::PlayHapticPattern_(const OHOS::HDI::Vibrator::V1_2::HapticPaket& pkg, const sptr remote) -{ - MessageParcel vibratorInterfaceData; - MessageParcel vibratorInterfaceReply; - MessageOption vibratorInterfaceOption(MessageOption::TF_SYNC); - - if (!vibratorInterfaceData.WriteInterfaceToken(OHOS::HDI::Vibrator::V1_2::IVibratorInterface::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!OHOS::HDI::Vibrator::V1_2::HapticPaketBlockMarshalling(vibratorInterfaceData, pkg)) { - HDF_LOGE("%{public}s: write pkg failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t vibratorInterfaceRet = remote->SendRequest(CMD_VIBRATOR_INTERFACE_PLAY_HAPTIC_PATTERN, vibratorInterfaceData, vibratorInterfaceReply, vibratorInterfaceOption); - if (vibratorInterfaceRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, vibratorInterfaceRet); - return vibratorInterfaceRet; - } - - return vibratorInterfaceRet; -} - -int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::GetHapticCapacity_(OHOS::HDI::Vibrator::V1_2::HapticCapacity& HapticCapacity, const sptr remote) -{ - MessageParcel vibratorInterfaceData; - MessageParcel vibratorInterfaceReply; - MessageOption vibratorInterfaceOption(MessageOption::TF_SYNC); - - if (!vibratorInterfaceData.WriteInterfaceToken(OHOS::HDI::Vibrator::V1_2::IVibratorInterface::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t vibratorInterfaceRet = remote->SendRequest(CMD_VIBRATOR_INTERFACE_GET_HAPTIC_CAPACITY, vibratorInterfaceData, vibratorInterfaceReply, vibratorInterfaceOption); - if (vibratorInterfaceRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, vibratorInterfaceRet); - return vibratorInterfaceRet; - } - - if (!HapticCapacityBlockUnmarshalling(vibratorInterfaceReply, HapticCapacity)) { - HDF_LOGE("%{public}s: read HapticCapacity failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return vibratorInterfaceRet; -} - -int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::GetHapticStartUpTime_(int32_t mode, int32_t& startUpTime, - const sptr remote) -{ - MessageParcel vibratorInterfaceData; - MessageParcel vibratorInterfaceReply; - MessageOption vibratorInterfaceOption(MessageOption::TF_SYNC); - - if (!vibratorInterfaceData.WriteInterfaceToken(OHOS::HDI::Vibrator::V1_2::IVibratorInterface::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!vibratorInterfaceData.WriteInt32(mode)) { - HDF_LOGE("%{public}s: write mode failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t vibratorInterfaceRet = remote->SendRequest(CMD_VIBRATOR_INTERFACE_GET_HAPTIC_START_UP_TIME, vibratorInterfaceData, vibratorInterfaceReply, vibratorInterfaceOption); - if (vibratorInterfaceRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, vibratorInterfaceRet); - return vibratorInterfaceRet; - } - - if (!vibratorInterfaceReply.ReadInt32(startUpTime)) { - HDF_LOGE("%{public}s: read startUpTime failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - return vibratorInterfaceRet; -} - -int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::StopV1_2_(int32_t mode, const sptr remote) -{ - MessageParcel vibratorInterfaceData; - MessageParcel vibratorInterfaceReply; - MessageOption vibratorInterfaceOption(MessageOption::TF_SYNC); - - if (!vibratorInterfaceData.WriteInterfaceToken(OHOS::HDI::Vibrator::V1_2::IVibratorInterface::GetDescriptor())) { - HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (!vibratorInterfaceData.WriteInt32(mode)) { - HDF_LOGE("%{public}s: write mode failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (remote == nullptr) { - HDF_LOGE("%{public}s: invalid remote object!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - int32_t vibratorInterfaceRet = remote->SendRequest(CMD_VIBRATOR_INTERFACE_STOP_V1_2, vibratorInterfaceData, vibratorInterfaceReply, vibratorInterfaceOption); - if (vibratorInterfaceRet != HDF_SUCCESS) { - HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, vibratorInterfaceRet); - return vibratorInterfaceRet; - } - - return vibratorInterfaceRet; -} - -} // V1_2 -} // Vibrator -} // HDI -} // OHOS + */ + +#include "v1_2/vibrator_interface_proxy.h" +#include +#include +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG vibrator_interface_proxy + +namespace OHOS { +namespace HDI { +namespace Vibrator { +namespace V1_2 { + + +template +static sptr CastFromTemplate(const sptr &parent) +{ + if (parent == nullptr) { + HDF_LOGE("%{public}s:parent is nullptr!", __func__); + return nullptr; + } + + if (!parent->IsProxy()) { + HDF_LOGE("%{public}s:not proxy, not support castfrom!", __func__); + return nullptr; + } + + sptr remote = OHOS::HDI::hdi_objcast(parent); + if (remote == nullptr) { + HDF_LOGE("%{public}s:hdi_objcast failed!", __func__); + return nullptr; + } + + sptr proxy = OHOS::HDI::hdi_facecast(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:hdi_facecast failed!", __func__); + return nullptr; + } + + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t vibratorInterfaceRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (vibratorInterfaceRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.2", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +sptr OHOS::HDI::Vibrator::V1_2::IVibratorInterface::Get(bool isStub) +{ + return IVibratorInterface::Get("vibrator_interface_service", isStub); +} + +sptr OHOS::HDI::Vibrator::V1_2::IVibratorInterface::Get(const std::string& serviceName, bool isStub) +{ + if (isStub) { + std::string desc = Str16ToStr8(OHOS::HDI::Vibrator::V1_2::IVibratorInterface::GetDescriptor()); + void *impl = LoadHdiImpl(desc.c_str(), serviceName == "vibrator_interface_service" ? "service" : serviceName.c_str()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + return reinterpret_cast(impl); + } + + using namespace OHOS::HDI::ServiceManager::V1_0; + auto servMgr = IServiceManager::Get(); + if (servMgr == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return nullptr; + } + + sptr remote = servMgr->GetService(serviceName.c_str()); + if (remote == nullptr) { + HDF_LOGE("%{public}s:get remote object failed!", __func__); + return nullptr; + } + + sptr proxy = new OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:iface_cast failed!", __func__); + return nullptr; + } + + proxy->servMgr_ = OHOS::HDI::hdi_objcast(servMgr); + proxy->deathRecipient_ = new OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::IServiceManagerDeathRecipient(proxy); + proxy->servMgr_->AddDeathRecipient(proxy->deathRecipient_); + proxy->isReconnected_ = false; + proxy->serviceName_ = serviceName; + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t vibratorInterfaceRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (vibratorInterfaceRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.2", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::Reconnect( + sptr proxy) +{ + if (proxy == nullptr) { + HDF_LOGW("Reconnect failed : input proxy is null"); + return HDF_FAILURE; + } + using namespace OHOS::HDI::ServiceManager::V1_0; + proxy->isReconnected_ = false; + auto iServMgr = IServiceManager::Get(); + if (iServMgr == nullptr) { + HDF_LOGW("Reconnect failed : iServMgr is null"); + return HDF_FAILURE; + }; + proxy->reconnectRemote_ = iServMgr->GetService(proxy->serviceName_.c_str()); + if (proxy->reconnectRemote_ == nullptr) { + HDF_LOGW("Reconnect failed : reconnectRemote_ is null"); + return HDF_FAILURE; + } + proxy->servMgr_ = OHOS::HDI::hdi_objcast(iServMgr); + if (proxy->servMgr_ == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return HDF_FAILURE; + } + proxy->servMgr_->AddDeathRecipient( + new OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::IServiceManagerDeathRecipient(proxy)); + proxy->isReconnected_ = true; + return HDF_SUCCESS; +} + +sptr OHOS::HDI::Vibrator::V1_2::IVibratorInterface::CastFrom(const sptr &parent) +{ + return CastFromTemplate(parent); +} + +int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::PlayHapticPattern(const OHOS::HDI::Vibrator::V1_2::HapticPaket& pkg) +{ + return OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::PlayHapticPattern_(pkg, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::GetHapticCapacity(OHOS::HDI::Vibrator::V1_2::HapticCapacity& HapticCapacity) +{ + return OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::GetHapticCapacity_(HapticCapacity, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::GetHapticStartUpTime(int32_t mode, int32_t& startUpTime) +{ + return OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::GetHapticStartUpTime_(mode, startUpTime, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::StopV1_2(int32_t mode) +{ + return OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::StopV1_2_(mode, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::StartOnce(uint32_t duration) +{ + return OHOS::HDI::Vibrator::V1_1::VibratorInterfaceProxy::StartOnce_(duration, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::Start(const std::string& effectType) +{ + return OHOS::HDI::Vibrator::V1_1::VibratorInterfaceProxy::Start_(effectType, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::Stop(OHOS::HDI::Vibrator::V1_1::HdfVibratorMode mode) +{ + return OHOS::HDI::Vibrator::V1_1::VibratorInterfaceProxy::Stop_(mode, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::GetVibratorInfo(std::vector& vibratorInfo) +{ + return OHOS::HDI::Vibrator::V1_1::VibratorInterfaceProxy::GetVibratorInfo_(vibratorInfo, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::EnableVibratorModulation(uint32_t duration, + uint16_t intensity, int16_t frequency) +{ + return OHOS::HDI::Vibrator::V1_1::VibratorInterfaceProxy::EnableVibratorModulation_(duration, intensity, frequency, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::EnableCompositeEffect(const OHOS::HDI::Vibrator::V1_1::HdfCompositeEffect& effect) +{ + return OHOS::HDI::Vibrator::V1_1::VibratorInterfaceProxy::EnableCompositeEffect_(effect, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::GetEffectInfo(const std::string& effectType, + OHOS::HDI::Vibrator::V1_1::HdfEffectInfo& effectInfo) +{ + return OHOS::HDI::Vibrator::V1_1::VibratorInterfaceProxy::GetEffectInfo_(effectType, effectInfo, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::IsVibratorRunning(bool& state) +{ + return OHOS::HDI::Vibrator::V1_1::VibratorInterfaceProxy::IsVibratorRunning_(state, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) +{ + return OHOS::HDI::Vibrator::V1_1::VibratorInterfaceProxy::GetVersion_(majorVer, minorVer, GetCurrentRemote()); +} + +int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::PlayHapticPattern_(const OHOS::HDI::Vibrator::V1_2::HapticPaket& pkg, const sptr remote) +{ + MessageParcel vibratorInterfaceData; + MessageParcel vibratorInterfaceReply; + MessageOption vibratorInterfaceOption(MessageOption::TF_SYNC); + + if (!vibratorInterfaceData.WriteInterfaceToken(OHOS::HDI::Vibrator::V1_2::IVibratorInterface::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!OHOS::HDI::Vibrator::V1_2::HapticPaketBlockMarshalling(vibratorInterfaceData, pkg)) { + HDF_LOGE("%{public}s: write pkg failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t vibratorInterfaceRet = remote->SendRequest(CMD_VIBRATOR_INTERFACE_PLAY_HAPTIC_PATTERN, vibratorInterfaceData, vibratorInterfaceReply, vibratorInterfaceOption); + if (vibratorInterfaceRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, vibratorInterfaceRet); + return vibratorInterfaceRet; + } + + return vibratorInterfaceRet; +} + +int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::GetHapticCapacity_(OHOS::HDI::Vibrator::V1_2::HapticCapacity& HapticCapacity, const sptr remote) +{ + MessageParcel vibratorInterfaceData; + MessageParcel vibratorInterfaceReply; + MessageOption vibratorInterfaceOption(MessageOption::TF_SYNC); + + if (!vibratorInterfaceData.WriteInterfaceToken(OHOS::HDI::Vibrator::V1_2::IVibratorInterface::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t vibratorInterfaceRet = remote->SendRequest(CMD_VIBRATOR_INTERFACE_GET_HAPTIC_CAPACITY, vibratorInterfaceData, vibratorInterfaceReply, vibratorInterfaceOption); + if (vibratorInterfaceRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, vibratorInterfaceRet); + return vibratorInterfaceRet; + } + + if (!HapticCapacityBlockUnmarshalling(vibratorInterfaceReply, HapticCapacity)) { + HDF_LOGE("%{public}s: read HapticCapacity failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return vibratorInterfaceRet; +} + +int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::GetHapticStartUpTime_(int32_t mode, int32_t& startUpTime, + const sptr remote) +{ + MessageParcel vibratorInterfaceData; + MessageParcel vibratorInterfaceReply; + MessageOption vibratorInterfaceOption(MessageOption::TF_SYNC); + + if (!vibratorInterfaceData.WriteInterfaceToken(OHOS::HDI::Vibrator::V1_2::IVibratorInterface::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!vibratorInterfaceData.WriteInt32(mode)) { + HDF_LOGE("%{public}s: write mode failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t vibratorInterfaceRet = remote->SendRequest(CMD_VIBRATOR_INTERFACE_GET_HAPTIC_START_UP_TIME, vibratorInterfaceData, vibratorInterfaceReply, vibratorInterfaceOption); + if (vibratorInterfaceRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, vibratorInterfaceRet); + return vibratorInterfaceRet; + } + + if (!vibratorInterfaceReply.ReadInt32(startUpTime)) { + HDF_LOGE("%{public}s: read startUpTime failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return vibratorInterfaceRet; +} + +int32_t OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::StopV1_2_(int32_t mode, const sptr remote) +{ + MessageParcel vibratorInterfaceData; + MessageParcel vibratorInterfaceReply; + MessageOption vibratorInterfaceOption(MessageOption::TF_SYNC); + + if (!vibratorInterfaceData.WriteInterfaceToken(OHOS::HDI::Vibrator::V1_2::IVibratorInterface::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!vibratorInterfaceData.WriteInt32(mode)) { + HDF_LOGE("%{public}s: write mode failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t vibratorInterfaceRet = remote->SendRequest(CMD_VIBRATOR_INTERFACE_STOP_V1_2, vibratorInterfaceData, vibratorInterfaceReply, vibratorInterfaceOption); + if (vibratorInterfaceRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, vibratorInterfaceRet); + return vibratorInterfaceRet; + } + + return vibratorInterfaceRet; +} + +} // V1_2 +} // Vibrator +} // HDI +} // OHOS diff --git a/test/hdi_unittest/vibrator_v1_2/cpp_target/vibrator/v1_2/vibrator_interface_proxy.h.txt b/test/hdi_unittest/vibrator_v1_2/cpp_target/vibrator/v1_2/vibrator_interface_proxy.h.txt index 848c40a..1d6b487 100644 --- a/test/hdi_unittest/vibrator_v1_2/cpp_target/vibrator/v1_2/vibrator_interface_proxy.h.txt +++ b/test/hdi_unittest/vibrator_v1_2/cpp_target/vibrator/v1_2/vibrator_interface_proxy.h.txt @@ -11,118 +11,118 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#ifndef OHOS_HDI_VIBRATOR_V1_2_VIBRATORINTERFACEPROXY_H -#define OHOS_HDI_VIBRATOR_V1_2_VIBRATORINTERFACEPROXY_H - -#include "v1_1/vibrator_interface_proxy.h" -#include "v1_2/ivibrator_interface.h" -#include -#include - -namespace OHOS { -namespace HDI { -namespace Vibrator { -namespace V1_2 { - -class VibratorInterfaceProxy : public IProxyBroker { -public: - class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { - public: - IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} - ~IServiceManagerDeathRecipient() override = default; - void OnRemoteDied(const wptr &remote) override - { - int32_t result = HDF_FAILURE; - const int sleepInterval = 500000; - const int waitTimes = 10; - int currentTime = waitTimes; - do { - usleep(sleepInterval); - auto proxy = proxy_.promote(); - if (proxy != nullptr) { - result = OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::Reconnect(proxy); - } - --currentTime; - } while (result != HDF_SUCCESS && currentTime >0); - } - private: - wptr proxy_; - }; - - explicit VibratorInterfaceProxy(const sptr& remote) : IProxyBroker(remote) { - reconnectRemote_ = nullptr; - servMgr_ = nullptr; - deathRecipient_ = nullptr; - isReconnected_ = false; - } - virtual ~VibratorInterfaceProxy() { - if (servMgr_ != nullptr && deathRecipient_ != nullptr) { - servMgr_->RemoveDeathRecipient(deathRecipient_); - } - } - - inline bool IsProxy() override - { - return true; - } - - int32_t PlayHapticPattern(const OHOS::HDI::Vibrator::V1_2::HapticPaket& pkg) override; - - int32_t GetHapticCapacity(OHOS::HDI::Vibrator::V1_2::HapticCapacity& HapticCapacity) override; - - int32_t GetHapticStartUpTime(int32_t mode, int32_t& startUpTime) override; - - int32_t StopV1_2(int32_t mode) override; - - int32_t StartOnce(uint32_t duration) override; - - int32_t Start(const std::string& effectType) override; - - int32_t Stop(OHOS::HDI::Vibrator::V1_1::HdfVibratorMode mode) override; - - int32_t GetVibratorInfo(std::vector& vibratorInfo) override; - - int32_t EnableVibratorModulation(uint32_t duration, uint16_t intensity, int16_t frequency) override; - - int32_t EnableCompositeEffect(const OHOS::HDI::Vibrator::V1_1::HdfCompositeEffect& effect) override; - - int32_t GetEffectInfo(const std::string& effectType, OHOS::HDI::Vibrator::V1_1::HdfEffectInfo& effectInfo) override; - - int32_t IsVibratorRunning(bool& state) override; - - int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; - - static int32_t PlayHapticPattern_(const OHOS::HDI::Vibrator::V1_2::HapticPaket& pkg, - const sptr remote); - - static int32_t GetHapticCapacity_(OHOS::HDI::Vibrator::V1_2::HapticCapacity& HapticCapacity, - const sptr remote); - - static int32_t GetHapticStartUpTime_(int32_t mode, int32_t& startUpTime, const sptr remote); - - static int32_t StopV1_2_(int32_t mode, const sptr remote); - - static int32_t Reconnect(sptr proxy); - - sptr GetCurrentRemote() { - return isReconnected_ ? reconnectRemote_ : Remote(); - } - - bool isReconnected_; - std::string serviceName_; - sptr servMgr_; - sptr deathRecipient_; - sptr reconnectRemote_; -private: - static inline BrokerDelegator delegator_; -}; - -} // V1_2 -} // Vibrator -} // HDI -} // OHOS - -#endif // OHOS_HDI_VIBRATOR_V1_2_VIBRATORINTERFACEPROXY_H - + */ + +#ifndef OHOS_HDI_VIBRATOR_V1_2_VIBRATORINTERFACEPROXY_H +#define OHOS_HDI_VIBRATOR_V1_2_VIBRATORINTERFACEPROXY_H + +#include "v1_1/vibrator_interface_proxy.h" +#include "v1_2/ivibrator_interface.h" +#include +#include + +namespace OHOS { +namespace HDI { +namespace Vibrator { +namespace V1_2 { + +class VibratorInterfaceProxy : public IProxyBroker { +public: + class IServiceManagerDeathRecipient : public IRemoteObject::DeathRecipient { + public: + IServiceManagerDeathRecipient(wptr proxy) : proxy_(proxy) {} + ~IServiceManagerDeathRecipient() override = default; + void OnRemoteDied(const wptr &remote) override + { + int32_t result = HDF_FAILURE; + const int sleepInterval = 500000; + const int waitTimes = 10; + int currentTime = waitTimes; + do { + usleep(sleepInterval); + auto proxy = proxy_.promote(); + if (proxy != nullptr) { + result = OHOS::HDI::Vibrator::V1_2::VibratorInterfaceProxy::Reconnect(proxy); + } + --currentTime; + } while (result != HDF_SUCCESS && currentTime >0); + } + private: + wptr proxy_; + }; + + explicit VibratorInterfaceProxy(const sptr& remote) : IProxyBroker(remote) { + reconnectRemote_ = nullptr; + servMgr_ = nullptr; + deathRecipient_ = nullptr; + isReconnected_ = false; + } + virtual ~VibratorInterfaceProxy() { + if (servMgr_ != nullptr && deathRecipient_ != nullptr) { + servMgr_->RemoveDeathRecipient(deathRecipient_); + } + } + + inline bool IsProxy() override + { + return true; + } + + int32_t PlayHapticPattern(const OHOS::HDI::Vibrator::V1_2::HapticPaket& pkg) override; + + int32_t GetHapticCapacity(OHOS::HDI::Vibrator::V1_2::HapticCapacity& HapticCapacity) override; + + int32_t GetHapticStartUpTime(int32_t mode, int32_t& startUpTime) override; + + int32_t StopV1_2(int32_t mode) override; + + int32_t StartOnce(uint32_t duration) override; + + int32_t Start(const std::string& effectType) override; + + int32_t Stop(OHOS::HDI::Vibrator::V1_1::HdfVibratorMode mode) override; + + int32_t GetVibratorInfo(std::vector& vibratorInfo) override; + + int32_t EnableVibratorModulation(uint32_t duration, uint16_t intensity, int16_t frequency) override; + + int32_t EnableCompositeEffect(const OHOS::HDI::Vibrator::V1_1::HdfCompositeEffect& effect) override; + + int32_t GetEffectInfo(const std::string& effectType, OHOS::HDI::Vibrator::V1_1::HdfEffectInfo& effectInfo) override; + + int32_t IsVibratorRunning(bool& state) override; + + int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; + + static int32_t PlayHapticPattern_(const OHOS::HDI::Vibrator::V1_2::HapticPaket& pkg, + const sptr remote); + + static int32_t GetHapticCapacity_(OHOS::HDI::Vibrator::V1_2::HapticCapacity& HapticCapacity, + const sptr remote); + + static int32_t GetHapticStartUpTime_(int32_t mode, int32_t& startUpTime, const sptr remote); + + static int32_t StopV1_2_(int32_t mode, const sptr remote); + + static int32_t Reconnect(sptr proxy); + + sptr GetCurrentRemote() { + return isReconnected_ ? reconnectRemote_ : Remote(); + } + + bool isReconnected_; + std::string serviceName_; + sptr servMgr_; + sptr deathRecipient_; + sptr reconnectRemote_; +private: + static inline BrokerDelegator delegator_; +}; + +} // V1_2 +} // Vibrator +} // HDI +} // OHOS + +#endif // OHOS_HDI_VIBRATOR_V1_2_VIBRATORINTERFACEPROXY_H + diff --git a/test/hdi_unittest/vibrator_v1_2/cpp_target/vibrator/v1_2/vibrator_interface_stub.cpp.txt b/test/hdi_unittest/vibrator_v1_2/cpp_target/vibrator/v1_2/vibrator_interface_stub.cpp.txt index 3b795a4..74cc276 100644 --- a/test/hdi_unittest/vibrator_v1_2/cpp_target/vibrator/v1_2/vibrator_interface_stub.cpp.txt +++ b/test/hdi_unittest/vibrator_v1_2/cpp_target/vibrator/v1_2/vibrator_interface_stub.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_2/vibrator_interface_stub.h" @@ -55,6 +55,7 @@ OHOS::HDI::Vibrator::V1_2::VibratorInterfaceStub::VibratorInterfaceStub(const sp OHOS::HDI::Vibrator::V1_2::VibratorInterfaceStub::~VibratorInterfaceStub() { + HDF_LOGI("%{public}s enter", __func__); ObjectCollector::GetInstance().RemoveObject(impl_); } diff --git a/test/hdi_unittest/vibrator_v1_2/cpp_target/vibrator/v1_2/vibrator_types.cpp.txt b/test/hdi_unittest/vibrator_v1_2/cpp_target/vibrator/v1_2/vibrator_types.cpp.txt index 190e2c5..81150f1 100644 --- a/test/hdi_unittest/vibrator_v1_2/cpp_target/vibrator/v1_2/vibrator_types.cpp.txt +++ b/test/hdi_unittest/vibrator_v1_2/cpp_target/vibrator/v1_2/vibrator_types.cpp.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_2/vibrator_types.h" diff --git a/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_callback_proxy.c.txt b/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_callback_proxy.c.txt index 26d6976..33f41cb 100644 --- a/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_callback_proxy.c.txt +++ b/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_callback_proxy.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_callback_service.c.txt b/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_callback_service.c.txt index a59547f..f5325da 100644 --- a/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_callback_service.c.txt +++ b/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_callback_service.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/wpa_callback_service.h" diff --git a/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_callback_stub.c.txt b/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_callback_stub.c.txt index 1ba6972..6a0db39 100644 --- a/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_callback_stub.c.txt +++ b/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_callback_stub.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/wpa_callback_stub.h" diff --git a/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_interface_driver.c.txt b/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_interface_driver.c.txt index bad1b36..8b674e4 100644 --- a/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_interface_driver.c.txt +++ b/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_interface_driver.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_interface_proxy.c.txt b/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_interface_proxy.c.txt index 7f96604..afaef77 100644 --- a/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_interface_proxy.c.txt +++ b/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_interface_proxy.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_interface_service.c.txt b/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_interface_service.c.txt index 11d64ca..10ac1e5 100644 --- a/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_interface_service.c.txt +++ b/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_interface_service.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_interface_stub.c.txt b/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_interface_stub.c.txt index d8b1385..52cab34 100644 --- a/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_interface_stub.c.txt +++ b/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_interface_stub.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/wpa_interface_stub.h" diff --git a/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_types.c.txt b/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_types.c.txt index 975a86f..ad2f464 100644 --- a/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_types.c.txt +++ b/test/hdi_unittest/wlan_wpa_v1_0/c_target/wlan/wpa/v1_0/wpa_types.c.txt @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "v1_0/wpa_types.h" -- Gitee From e62ed52489e1bf53fae8f4986f1aba3deb9c019f Mon Sep 17 00:00:00 2001 From: wangjingchang Date: Thu, 14 Nov 2024 16:40:10 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dresult=E5=92=8Cinfo?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E5=91=BD=E5=90=8D=E5=86=B2=E7=AA=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangjingchang --- .../cpp/sa_cpp_client_proxy_code_emitter.cpp | 2 +- .../codegen/SA/cpp/sa_cpp_code_emitter.cpp | 3 +- .../codegen/SA/type/sa_seq_type_emitter.cpp | 8 +- .../cmd_hitrace_tag/target/foo_proxy.cpp.txt | 60 +++++----- .../cmd_hitrace_tag/target/foo_proxy.h.txt | 22 ++-- .../sa_test/cmd_hitrace_tag/target/ifoo.h.txt | 22 ++-- .../target/foo_proxy.cpp.txt | 60 +++++----- .../target/foo_proxy.h.txt | 22 ++-- .../cmd_log_tag_domainid/target/ifoo.h.txt | 22 ++-- .../target/foo_proxy.cpp.txt | 60 +++++----- .../cmd_save_metadata/target/foo_proxy.h.txt | 22 ++-- .../cmd_save_metadata/target/ifoo.h.txt | 22 ++-- .../target_cpp/foo_proxy.cpp.txt | 6 +- .../target_cpp/foo_proxy.h.txt | 2 +- .../target_cpp/ifoo.h.txt | 2 +- .../target_cpp/foo_proxy.cpp.txt | 24 ++-- .../type_array/target_cpp/foo_proxy.cpp.txt | 110 +++++++++--------- .../type_array/target_cpp/foo_proxy.h.txt | 22 ++-- test/sa_test/type_array/target_cpp/ifoo.h.txt | 22 ++-- .../type_list/target_cpp/foo_proxy.cpp.txt | 110 +++++++++--------- .../type_list/target_cpp/foo_proxy.h.txt | 22 ++-- test/sa_test/type_list/target_cpp/ifoo.h.txt | 22 ++-- .../type_map/target_cpp/foo_proxy.cpp.txt | 88 +++++++------- .../type_map/target_cpp/foo_proxy.h.txt | 22 ++-- test/sa_test/type_map/target_cpp/ifoo.h.txt | 22 ++-- .../type_single/target_cpp/foo_proxy.cpp.txt | 64 +++++----- .../type_single/target_cpp/foo_proxy.h.txt | 24 ++-- .../sa_test/type_single/target_cpp/ifoo.h.txt | 24 ++-- 28 files changed, 456 insertions(+), 455 deletions(-) diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp b/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp index 2a213cd..6ac6ea1 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp @@ -366,7 +366,7 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodReply(AutoPtr returnType = method->GetReturnType(); if (returnType->GetTypeKind() != TypeKind::TYPE_VOID) { AutoPtr typeEmitter = GetTypeEmitter(returnType); - typeEmitter->EmitCppReadVar("reply.", "result", sb, prefix + TAB, false); + typeEmitter->EmitCppReadVar("reply.", "funcResult", sb, prefix + TAB, false); } } diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_code_emitter.cpp b/idl_tool_2/codegen/SA/cpp/sa_cpp_code_emitter.cpp index 576ba3c..0a773ee 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_code_emitter.cpp @@ -100,7 +100,8 @@ void SACppCodeEmitter::EmitInterfaceMethodParams(AutoPtr &method, Str } if (retTypeKind != TypeKind::TYPE_VOID) { AutoPtr typeEmitter = GetTypeEmitter(returnType); - sb.Append("\n").Append(prefix).AppendFormat("%s result", typeEmitter->EmitCppType(TypeMode::PARAM_OUT).c_str()); + sb.Append("\n").Append(prefix).AppendFormat("%s funcResult", + typeEmitter->EmitCppType(TypeMode::PARAM_OUT).c_str()); } } diff --git a/idl_tool_2/codegen/SA/type/sa_seq_type_emitter.cpp b/idl_tool_2/codegen/SA/type/sa_seq_type_emitter.cpp index 07024f7..1fd3f20 100644 --- a/idl_tool_2/codegen/SA/type/sa_seq_type_emitter.cpp +++ b/idl_tool_2/codegen/SA/type/sa_seq_type_emitter.cpp @@ -74,10 +74,10 @@ void SaSeqTypeEmitter::EmitCppReadVar(const std::string &parcelName, const std:: sb.Append(prefix).Append(TAB).Append("return ERR_INVALID_DATA;\n"); sb.Append(prefix).Append("}\n"); } else { - sb.Append(prefix).AppendFormat("std::unique_ptr<%s> info(%sReadParcelable<%s>());\n", typeName_.c_str(), - parcelName.c_str(), typeName_.c_str()); - sb.Append(prefix).Append("if (info != nullptr) {\n"); - sb.Append(prefix).Append(TAB).AppendFormat("%s = *info;\n", name.c_str()); + sb.Append(prefix).AppendFormat("std::unique_ptr<%s> %sInfo(%sReadParcelable<%s>());\n", typeName_.c_str(), + name.c_str(), parcelName.c_str(), typeName_.c_str()); + sb.Append(prefix).AppendFormat("if (%sInfo != nullptr) {\n", name.c_str()); + sb.Append(prefix).Append(TAB).AppendFormat("%s = *%sInfo;\n", name.c_str(), name.c_str()); sb.Append(prefix).Append("}\n\n"); } } diff --git a/test/sa_test/cmd_hitrace_tag/target/foo_proxy.cpp.txt b/test/sa_test/cmd_hitrace_tag/target/foo_proxy.cpp.txt index 16590a7..b44afeb 100644 --- a/test/sa_test/cmd_hitrace_tag/target/foo_proxy.cpp.txt +++ b/test/sa_test/cmd_hitrace_tag/target/foo_proxy.cpp.txt @@ -48,7 +48,7 @@ ErrCode FooProxy::bool_test_func( bool inParam, bool& outParam, bool inoutParam, - bool& result) + bool& funcResult) { MessageParcel data; MessageParcel reply; @@ -81,7 +81,7 @@ ErrCode FooProxy::bool_test_func( outParam = reply.ReadInt32() == 1 ? true : false; inoutParam = reply.ReadInt32() == 1 ? true : false; - result = reply.ReadInt32() == 1 ? true : false; + funcResult = reply.ReadInt32() == 1 ? true : false; return ERR_OK; } @@ -89,7 +89,7 @@ ErrCode FooProxy::byte_test_func( int8_t inParam, int8_t& outParam, int8_t inoutParam, - int8_t& result) + int8_t& funcResult) { MessageParcel data; MessageParcel reply; @@ -122,7 +122,7 @@ ErrCode FooProxy::byte_test_func( outParam = (int8_t)reply.ReadInt32(); inoutParam = (int8_t)reply.ReadInt32(); - result = (int8_t)reply.ReadInt32(); + funcResult = (int8_t)reply.ReadInt32(); return ERR_OK; } @@ -130,7 +130,7 @@ ErrCode FooProxy::short_test_func( short inParam, short& outParam, short inoutParam, - short& result) + short& funcResult) { MessageParcel data; MessageParcel reply; @@ -163,7 +163,7 @@ ErrCode FooProxy::short_test_func( outParam = (short)reply.ReadInt32(); inoutParam = (short)reply.ReadInt32(); - result = (short)reply.ReadInt32(); + funcResult = (short)reply.ReadInt32(); return ERR_OK; } @@ -171,7 +171,7 @@ ErrCode FooProxy::int_test_func( int32_t inParam, int32_t& outParam, int32_t inoutParam, - int32_t& result) + int32_t& funcResult) { MessageParcel data; MessageParcel reply; @@ -204,7 +204,7 @@ ErrCode FooProxy::int_test_func( outParam = reply.ReadInt32(); inoutParam = reply.ReadInt32(); - result = reply.ReadInt32(); + funcResult = reply.ReadInt32(); return ERR_OK; } @@ -212,7 +212,7 @@ ErrCode FooProxy::long_test_func( int64_t inParam, int64_t& outParam, int64_t inoutParam, - int64_t& result) + int64_t& funcResult) { MessageParcel data; MessageParcel reply; @@ -245,7 +245,7 @@ ErrCode FooProxy::long_test_func( outParam = reply.ReadInt64(); inoutParam = reply.ReadInt64(); - result = reply.ReadInt64(); + funcResult = reply.ReadInt64(); return ERR_OK; } @@ -253,7 +253,7 @@ ErrCode FooProxy::string_test_func( const std::string& inParam, std::string& outParam, const std::string& inoutParam, - std::string& result) + std::string& funcResult) { MessageParcel data; MessageParcel reply; @@ -286,7 +286,7 @@ ErrCode FooProxy::string_test_func( outParam = Str16ToStr8(reply.ReadString16()); inoutParam = Str16ToStr8(reply.ReadString16()); - result = Str16ToStr8(reply.ReadString16()); + funcResult = Str16ToStr8(reply.ReadString16()); return ERR_OK; } @@ -294,7 +294,7 @@ ErrCode FooProxy::float_test_func( float inParam, float& outParam, float inoutParam, - float& result) + float& funcResult) { MessageParcel data; MessageParcel reply; @@ -327,7 +327,7 @@ ErrCode FooProxy::float_test_func( outParam = reply.ReadFloat(); inoutParam = reply.ReadFloat(); - result = reply.ReadFloat(); + funcResult = reply.ReadFloat(); return ERR_OK; } @@ -335,7 +335,7 @@ ErrCode FooProxy::double_test_func( double inParam, double& outParam, double inoutParam, - double& result) + double& funcResult) { MessageParcel data; MessageParcel reply; @@ -368,7 +368,7 @@ ErrCode FooProxy::double_test_func( outParam = reply.ReadDouble(); inoutParam = reply.ReadDouble(); - result = reply.ReadDouble(); + funcResult = reply.ReadDouble(); return ERR_OK; } @@ -376,7 +376,7 @@ ErrCode FooProxy::char_test_func( zchar inParam, zchar& outParam, zchar inoutParam, - zchar& result) + zchar& funcResult) { MessageParcel data; MessageParcel reply; @@ -409,7 +409,7 @@ ErrCode FooProxy::char_test_func( outParam = (zchar)reply.ReadInt32(); inoutParam = (zchar)reply.ReadInt32(); - result = (zchar)reply.ReadInt32(); + funcResult = (zchar)reply.ReadInt32(); return ERR_OK; } @@ -417,7 +417,7 @@ ErrCode FooProxy::seq_test_func( const myseq& inParam, myseq& outParam, myseq* inoutParam, - myseq& result) + myseq& funcResult) { MessageParcel data; MessageParcel reply; @@ -448,19 +448,19 @@ ErrCode FooProxy::seq_test_func( return errCode; } - std::unique_ptr info(reply.ReadParcelable()); - if (info != nullptr) { - outParam = *info; + std::unique_ptr outParamInfo(reply.ReadParcelable()); + if (outParamInfo != nullptr) { + outParam = *outParamInfo; } - std::unique_ptr info(reply.ReadParcelable()); - if (info != nullptr) { - inoutParam = *info; + std::unique_ptr inoutParamInfo(reply.ReadParcelable()); + if (inoutParamInfo != nullptr) { + inoutParam = *inoutParamInfo; } - std::unique_ptr info(reply.ReadParcelable()); - if (info != nullptr) { - result = *info; + std::unique_ptr funcResultInfo(reply.ReadParcelable()); + if (funcResultInfo != nullptr) { + funcResult = *funcResultInfo; } return ERR_OK; @@ -470,7 +470,7 @@ ErrCode FooProxy::interface_test_func( const sptr& inParam, sptr& outParam, const sptr& inoutParam, - sptr& result) + sptr& funcResult) { MessageParcel data; MessageParcel reply; @@ -509,7 +509,7 @@ ErrCode FooProxy::interface_test_func( outParam = iface_cast(reply.ReadRemoteObject()); inoutParam = iface_cast(reply.ReadRemoteObject()); - result = iface_cast(reply.ReadRemoteObject()); + funcResult = iface_cast(reply.ReadRemoteObject()); return ERR_OK; } } // namespace test diff --git a/test/sa_test/cmd_hitrace_tag/target/foo_proxy.h.txt b/test/sa_test/cmd_hitrace_tag/target/foo_proxy.h.txt index c4aba07..1873b8d 100644 --- a/test/sa_test/cmd_hitrace_tag/target/foo_proxy.h.txt +++ b/test/sa_test/cmd_hitrace_tag/target/foo_proxy.h.txt @@ -36,67 +36,67 @@ public: bool inParam, bool& outParam, bool inoutParam, - bool& result) override; + bool& funcResult) override; ErrCode byte_test_func( int8_t inParam, int8_t& outParam, int8_t inoutParam, - int8_t& result) override; + int8_t& funcResult) override; ErrCode short_test_func( short inParam, short& outParam, short inoutParam, - short& result) override; + short& funcResult) override; ErrCode int_test_func( int32_t inParam, int32_t& outParam, int32_t inoutParam, - int32_t& result) override; + int32_t& funcResult) override; ErrCode long_test_func( int64_t inParam, int64_t& outParam, int64_t inoutParam, - int64_t& result) override; + int64_t& funcResult) override; ErrCode string_test_func( const std::string& inParam, std::string& outParam, const std::string& inoutParam, - std::string& result) override; + std::string& funcResult) override; ErrCode float_test_func( float inParam, float& outParam, float inoutParam, - float& result) override; + float& funcResult) override; ErrCode double_test_func( double inParam, double& outParam, double inoutParam, - double& result) override; + double& funcResult) override; ErrCode char_test_func( zchar inParam, zchar& outParam, zchar inoutParam, - zchar& result) override; + zchar& funcResult) override; ErrCode seq_test_func( const myseq& inParam, myseq& outParam, myseq* inoutParam, - myseq& result) override; + myseq& funcResult) override; ErrCode interface_test_func( const sptr& inParam, sptr& outParam, const sptr& inoutParam, - sptr& result) override; + sptr& funcResult) override; private: static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; diff --git a/test/sa_test/cmd_hitrace_tag/target/ifoo.h.txt b/test/sa_test/cmd_hitrace_tag/target/ifoo.h.txt index 120fe78..3bde861 100644 --- a/test/sa_test/cmd_hitrace_tag/target/ifoo.h.txt +++ b/test/sa_test/cmd_hitrace_tag/target/ifoo.h.txt @@ -36,67 +36,67 @@ public: bool inParam, bool& outParam, bool inoutParam, - bool& result) = 0; + bool& funcResult) = 0; virtual ErrCode byte_test_func( int8_t inParam, int8_t& outParam, int8_t inoutParam, - int8_t& result) = 0; + int8_t& funcResult) = 0; virtual ErrCode short_test_func( short inParam, short& outParam, short inoutParam, - short& result) = 0; + short& funcResult) = 0; virtual ErrCode int_test_func( int32_t inParam, int32_t& outParam, int32_t inoutParam, - int32_t& result) = 0; + int32_t& funcResult) = 0; virtual ErrCode long_test_func( int64_t inParam, int64_t& outParam, int64_t inoutParam, - int64_t& result) = 0; + int64_t& funcResult) = 0; virtual ErrCode string_test_func( const std::string& inParam, std::string& outParam, const std::string& inoutParam, - std::string& result) = 0; + std::string& funcResult) = 0; virtual ErrCode float_test_func( float inParam, float& outParam, float inoutParam, - float& result) = 0; + float& funcResult) = 0; virtual ErrCode double_test_func( double inParam, double& outParam, double inoutParam, - double& result) = 0; + double& funcResult) = 0; virtual ErrCode char_test_func( zchar inParam, zchar& outParam, zchar inoutParam, - zchar& result) = 0; + zchar& funcResult) = 0; virtual ErrCode seq_test_func( const myseq& inParam, myseq& outParam, myseq* inoutParam, - myseq& result) = 0; + myseq& funcResult) = 0; virtual ErrCode interface_test_func( const sptr& inParam, sptr& outParam, const sptr& inoutParam, - sptr& result) = 0; + sptr& funcResult) = 0; protected: const int VECTOR_MAX_SIZE = 102400; const int LIST_MAX_SIZE = 102400; diff --git a/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.cpp.txt b/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.cpp.txt index 4d5f5a8..2f46b6f 100644 --- a/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.cpp.txt +++ b/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.cpp.txt @@ -55,7 +55,7 @@ ErrCode FooProxy::bool_test_func( bool inParam, bool& outParam, bool inoutParam, - bool& result) + bool& funcResult) { MessageParcel data; MessageParcel reply; @@ -94,7 +94,7 @@ ErrCode FooProxy::bool_test_func( outParam = reply.ReadInt32() == 1 ? true : false; inoutParam = reply.ReadInt32() == 1 ? true : false; - result = reply.ReadInt32() == 1 ? true : false; + funcResult = reply.ReadInt32() == 1 ? true : false; return ERR_OK; } @@ -102,7 +102,7 @@ ErrCode FooProxy::byte_test_func( int8_t inParam, int8_t& outParam, int8_t inoutParam, - int8_t& result) + int8_t& funcResult) { MessageParcel data; MessageParcel reply; @@ -141,7 +141,7 @@ ErrCode FooProxy::byte_test_func( outParam = (int8_t)reply.ReadInt32(); inoutParam = (int8_t)reply.ReadInt32(); - result = (int8_t)reply.ReadInt32(); + funcResult = (int8_t)reply.ReadInt32(); return ERR_OK; } @@ -149,7 +149,7 @@ ErrCode FooProxy::short_test_func( short inParam, short& outParam, short inoutParam, - short& result) + short& funcResult) { MessageParcel data; MessageParcel reply; @@ -188,7 +188,7 @@ ErrCode FooProxy::short_test_func( outParam = (short)reply.ReadInt32(); inoutParam = (short)reply.ReadInt32(); - result = (short)reply.ReadInt32(); + funcResult = (short)reply.ReadInt32(); return ERR_OK; } @@ -196,7 +196,7 @@ ErrCode FooProxy::int_test_func( int32_t inParam, int32_t& outParam, int32_t inoutParam, - int32_t& result) + int32_t& funcResult) { MessageParcel data; MessageParcel reply; @@ -235,7 +235,7 @@ ErrCode FooProxy::int_test_func( outParam = reply.ReadInt32(); inoutParam = reply.ReadInt32(); - result = reply.ReadInt32(); + funcResult = reply.ReadInt32(); return ERR_OK; } @@ -243,7 +243,7 @@ ErrCode FooProxy::long_test_func( int64_t inParam, int64_t& outParam, int64_t inoutParam, - int64_t& result) + int64_t& funcResult) { MessageParcel data; MessageParcel reply; @@ -282,7 +282,7 @@ ErrCode FooProxy::long_test_func( outParam = reply.ReadInt64(); inoutParam = reply.ReadInt64(); - result = reply.ReadInt64(); + funcResult = reply.ReadInt64(); return ERR_OK; } @@ -290,7 +290,7 @@ ErrCode FooProxy::string_test_func( const std::string& inParam, std::string& outParam, const std::string& inoutParam, - std::string& result) + std::string& funcResult) { MessageParcel data; MessageParcel reply; @@ -329,7 +329,7 @@ ErrCode FooProxy::string_test_func( outParam = Str16ToStr8(reply.ReadString16()); inoutParam = Str16ToStr8(reply.ReadString16()); - result = Str16ToStr8(reply.ReadString16()); + funcResult = Str16ToStr8(reply.ReadString16()); return ERR_OK; } @@ -337,7 +337,7 @@ ErrCode FooProxy::float_test_func( float inParam, float& outParam, float inoutParam, - float& result) + float& funcResult) { MessageParcel data; MessageParcel reply; @@ -376,7 +376,7 @@ ErrCode FooProxy::float_test_func( outParam = reply.ReadFloat(); inoutParam = reply.ReadFloat(); - result = reply.ReadFloat(); + funcResult = reply.ReadFloat(); return ERR_OK; } @@ -384,7 +384,7 @@ ErrCode FooProxy::double_test_func( double inParam, double& outParam, double inoutParam, - double& result) + double& funcResult) { MessageParcel data; MessageParcel reply; @@ -423,7 +423,7 @@ ErrCode FooProxy::double_test_func( outParam = reply.ReadDouble(); inoutParam = reply.ReadDouble(); - result = reply.ReadDouble(); + funcResult = reply.ReadDouble(); return ERR_OK; } @@ -431,7 +431,7 @@ ErrCode FooProxy::char_test_func( zchar inParam, zchar& outParam, zchar inoutParam, - zchar& result) + zchar& funcResult) { MessageParcel data; MessageParcel reply; @@ -470,7 +470,7 @@ ErrCode FooProxy::char_test_func( outParam = (zchar)reply.ReadInt32(); inoutParam = (zchar)reply.ReadInt32(); - result = (zchar)reply.ReadInt32(); + funcResult = (zchar)reply.ReadInt32(); return ERR_OK; } @@ -478,7 +478,7 @@ ErrCode FooProxy::seq_test_func( const myseq& inParam, myseq& outParam, myseq* inoutParam, - myseq& result) + myseq& funcResult) { MessageParcel data; MessageParcel reply; @@ -515,19 +515,19 @@ ErrCode FooProxy::seq_test_func( return errCode; } - std::unique_ptr info(reply.ReadParcelable()); - if (info != nullptr) { - outParam = *info; + std::unique_ptr outParamInfo(reply.ReadParcelable()); + if (outParamInfo != nullptr) { + outParam = *outParamInfo; } - std::unique_ptr info(reply.ReadParcelable()); - if (info != nullptr) { - inoutParam = *info; + std::unique_ptr inoutParamInfo(reply.ReadParcelable()); + if (inoutParamInfo != nullptr) { + inoutParam = *inoutParamInfo; } - std::unique_ptr info(reply.ReadParcelable()); - if (info != nullptr) { - result = *info; + std::unique_ptr funcResultInfo(reply.ReadParcelable()); + if (funcResultInfo != nullptr) { + funcResult = *funcResultInfo; } return ERR_OK; @@ -537,7 +537,7 @@ ErrCode FooProxy::interface_test_func( const sptr& inParam, sptr& outParam, const sptr& inoutParam, - sptr& result) + sptr& funcResult) { MessageParcel data; MessageParcel reply; @@ -584,7 +584,7 @@ ErrCode FooProxy::interface_test_func( outParam = iface_cast(reply.ReadRemoteObject()); inoutParam = iface_cast(reply.ReadRemoteObject()); - result = iface_cast(reply.ReadRemoteObject()); + funcResult = iface_cast(reply.ReadRemoteObject()); return ERR_OK; } } // namespace test diff --git a/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.h.txt b/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.h.txt index c4aba07..1873b8d 100644 --- a/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.h.txt +++ b/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.h.txt @@ -36,67 +36,67 @@ public: bool inParam, bool& outParam, bool inoutParam, - bool& result) override; + bool& funcResult) override; ErrCode byte_test_func( int8_t inParam, int8_t& outParam, int8_t inoutParam, - int8_t& result) override; + int8_t& funcResult) override; ErrCode short_test_func( short inParam, short& outParam, short inoutParam, - short& result) override; + short& funcResult) override; ErrCode int_test_func( int32_t inParam, int32_t& outParam, int32_t inoutParam, - int32_t& result) override; + int32_t& funcResult) override; ErrCode long_test_func( int64_t inParam, int64_t& outParam, int64_t inoutParam, - int64_t& result) override; + int64_t& funcResult) override; ErrCode string_test_func( const std::string& inParam, std::string& outParam, const std::string& inoutParam, - std::string& result) override; + std::string& funcResult) override; ErrCode float_test_func( float inParam, float& outParam, float inoutParam, - float& result) override; + float& funcResult) override; ErrCode double_test_func( double inParam, double& outParam, double inoutParam, - double& result) override; + double& funcResult) override; ErrCode char_test_func( zchar inParam, zchar& outParam, zchar inoutParam, - zchar& result) override; + zchar& funcResult) override; ErrCode seq_test_func( const myseq& inParam, myseq& outParam, myseq* inoutParam, - myseq& result) override; + myseq& funcResult) override; ErrCode interface_test_func( const sptr& inParam, sptr& outParam, const sptr& inoutParam, - sptr& result) override; + sptr& funcResult) override; private: static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; diff --git a/test/sa_test/cmd_log_tag_domainid/target/ifoo.h.txt b/test/sa_test/cmd_log_tag_domainid/target/ifoo.h.txt index 3b364e5..ad86778 100644 --- a/test/sa_test/cmd_log_tag_domainid/target/ifoo.h.txt +++ b/test/sa_test/cmd_log_tag_domainid/target/ifoo.h.txt @@ -37,67 +37,67 @@ public: bool inParam, bool& outParam, bool inoutParam, - bool& result) = 0; + bool& funcResult) = 0; virtual ErrCode byte_test_func( int8_t inParam, int8_t& outParam, int8_t inoutParam, - int8_t& result) = 0; + int8_t& funcResult) = 0; virtual ErrCode short_test_func( short inParam, short& outParam, short inoutParam, - short& result) = 0; + short& funcResult) = 0; virtual ErrCode int_test_func( int32_t inParam, int32_t& outParam, int32_t inoutParam, - int32_t& result) = 0; + int32_t& funcResult) = 0; virtual ErrCode long_test_func( int64_t inParam, int64_t& outParam, int64_t inoutParam, - int64_t& result) = 0; + int64_t& funcResult) = 0; virtual ErrCode string_test_func( const std::string& inParam, std::string& outParam, const std::string& inoutParam, - std::string& result) = 0; + std::string& funcResult) = 0; virtual ErrCode float_test_func( float inParam, float& outParam, float inoutParam, - float& result) = 0; + float& funcResult) = 0; virtual ErrCode double_test_func( double inParam, double& outParam, double inoutParam, - double& result) = 0; + double& funcResult) = 0; virtual ErrCode char_test_func( zchar inParam, zchar& outParam, zchar inoutParam, - zchar& result) = 0; + zchar& funcResult) = 0; virtual ErrCode seq_test_func( const myseq& inParam, myseq& outParam, myseq* inoutParam, - myseq& result) = 0; + myseq& funcResult) = 0; virtual ErrCode interface_test_func( const sptr& inParam, sptr& outParam, const sptr& inoutParam, - sptr& result) = 0; + sptr& funcResult) = 0; protected: static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, new_id, "new_tag"}; const int VECTOR_MAX_SIZE = 102400; diff --git a/test/sa_test/cmd_save_metadata/target/foo_proxy.cpp.txt b/test/sa_test/cmd_save_metadata/target/foo_proxy.cpp.txt index 16590a7..b44afeb 100644 --- a/test/sa_test/cmd_save_metadata/target/foo_proxy.cpp.txt +++ b/test/sa_test/cmd_save_metadata/target/foo_proxy.cpp.txt @@ -48,7 +48,7 @@ ErrCode FooProxy::bool_test_func( bool inParam, bool& outParam, bool inoutParam, - bool& result) + bool& funcResult) { MessageParcel data; MessageParcel reply; @@ -81,7 +81,7 @@ ErrCode FooProxy::bool_test_func( outParam = reply.ReadInt32() == 1 ? true : false; inoutParam = reply.ReadInt32() == 1 ? true : false; - result = reply.ReadInt32() == 1 ? true : false; + funcResult = reply.ReadInt32() == 1 ? true : false; return ERR_OK; } @@ -89,7 +89,7 @@ ErrCode FooProxy::byte_test_func( int8_t inParam, int8_t& outParam, int8_t inoutParam, - int8_t& result) + int8_t& funcResult) { MessageParcel data; MessageParcel reply; @@ -122,7 +122,7 @@ ErrCode FooProxy::byte_test_func( outParam = (int8_t)reply.ReadInt32(); inoutParam = (int8_t)reply.ReadInt32(); - result = (int8_t)reply.ReadInt32(); + funcResult = (int8_t)reply.ReadInt32(); return ERR_OK; } @@ -130,7 +130,7 @@ ErrCode FooProxy::short_test_func( short inParam, short& outParam, short inoutParam, - short& result) + short& funcResult) { MessageParcel data; MessageParcel reply; @@ -163,7 +163,7 @@ ErrCode FooProxy::short_test_func( outParam = (short)reply.ReadInt32(); inoutParam = (short)reply.ReadInt32(); - result = (short)reply.ReadInt32(); + funcResult = (short)reply.ReadInt32(); return ERR_OK; } @@ -171,7 +171,7 @@ ErrCode FooProxy::int_test_func( int32_t inParam, int32_t& outParam, int32_t inoutParam, - int32_t& result) + int32_t& funcResult) { MessageParcel data; MessageParcel reply; @@ -204,7 +204,7 @@ ErrCode FooProxy::int_test_func( outParam = reply.ReadInt32(); inoutParam = reply.ReadInt32(); - result = reply.ReadInt32(); + funcResult = reply.ReadInt32(); return ERR_OK; } @@ -212,7 +212,7 @@ ErrCode FooProxy::long_test_func( int64_t inParam, int64_t& outParam, int64_t inoutParam, - int64_t& result) + int64_t& funcResult) { MessageParcel data; MessageParcel reply; @@ -245,7 +245,7 @@ ErrCode FooProxy::long_test_func( outParam = reply.ReadInt64(); inoutParam = reply.ReadInt64(); - result = reply.ReadInt64(); + funcResult = reply.ReadInt64(); return ERR_OK; } @@ -253,7 +253,7 @@ ErrCode FooProxy::string_test_func( const std::string& inParam, std::string& outParam, const std::string& inoutParam, - std::string& result) + std::string& funcResult) { MessageParcel data; MessageParcel reply; @@ -286,7 +286,7 @@ ErrCode FooProxy::string_test_func( outParam = Str16ToStr8(reply.ReadString16()); inoutParam = Str16ToStr8(reply.ReadString16()); - result = Str16ToStr8(reply.ReadString16()); + funcResult = Str16ToStr8(reply.ReadString16()); return ERR_OK; } @@ -294,7 +294,7 @@ ErrCode FooProxy::float_test_func( float inParam, float& outParam, float inoutParam, - float& result) + float& funcResult) { MessageParcel data; MessageParcel reply; @@ -327,7 +327,7 @@ ErrCode FooProxy::float_test_func( outParam = reply.ReadFloat(); inoutParam = reply.ReadFloat(); - result = reply.ReadFloat(); + funcResult = reply.ReadFloat(); return ERR_OK; } @@ -335,7 +335,7 @@ ErrCode FooProxy::double_test_func( double inParam, double& outParam, double inoutParam, - double& result) + double& funcResult) { MessageParcel data; MessageParcel reply; @@ -368,7 +368,7 @@ ErrCode FooProxy::double_test_func( outParam = reply.ReadDouble(); inoutParam = reply.ReadDouble(); - result = reply.ReadDouble(); + funcResult = reply.ReadDouble(); return ERR_OK; } @@ -376,7 +376,7 @@ ErrCode FooProxy::char_test_func( zchar inParam, zchar& outParam, zchar inoutParam, - zchar& result) + zchar& funcResult) { MessageParcel data; MessageParcel reply; @@ -409,7 +409,7 @@ ErrCode FooProxy::char_test_func( outParam = (zchar)reply.ReadInt32(); inoutParam = (zchar)reply.ReadInt32(); - result = (zchar)reply.ReadInt32(); + funcResult = (zchar)reply.ReadInt32(); return ERR_OK; } @@ -417,7 +417,7 @@ ErrCode FooProxy::seq_test_func( const myseq& inParam, myseq& outParam, myseq* inoutParam, - myseq& result) + myseq& funcResult) { MessageParcel data; MessageParcel reply; @@ -448,19 +448,19 @@ ErrCode FooProxy::seq_test_func( return errCode; } - std::unique_ptr info(reply.ReadParcelable()); - if (info != nullptr) { - outParam = *info; + std::unique_ptr outParamInfo(reply.ReadParcelable()); + if (outParamInfo != nullptr) { + outParam = *outParamInfo; } - std::unique_ptr info(reply.ReadParcelable()); - if (info != nullptr) { - inoutParam = *info; + std::unique_ptr inoutParamInfo(reply.ReadParcelable()); + if (inoutParamInfo != nullptr) { + inoutParam = *inoutParamInfo; } - std::unique_ptr info(reply.ReadParcelable()); - if (info != nullptr) { - result = *info; + std::unique_ptr funcResultInfo(reply.ReadParcelable()); + if (funcResultInfo != nullptr) { + funcResult = *funcResultInfo; } return ERR_OK; @@ -470,7 +470,7 @@ ErrCode FooProxy::interface_test_func( const sptr& inParam, sptr& outParam, const sptr& inoutParam, - sptr& result) + sptr& funcResult) { MessageParcel data; MessageParcel reply; @@ -509,7 +509,7 @@ ErrCode FooProxy::interface_test_func( outParam = iface_cast(reply.ReadRemoteObject()); inoutParam = iface_cast(reply.ReadRemoteObject()); - result = iface_cast(reply.ReadRemoteObject()); + funcResult = iface_cast(reply.ReadRemoteObject()); return ERR_OK; } } // namespace test diff --git a/test/sa_test/cmd_save_metadata/target/foo_proxy.h.txt b/test/sa_test/cmd_save_metadata/target/foo_proxy.h.txt index c4aba07..1873b8d 100644 --- a/test/sa_test/cmd_save_metadata/target/foo_proxy.h.txt +++ b/test/sa_test/cmd_save_metadata/target/foo_proxy.h.txt @@ -36,67 +36,67 @@ public: bool inParam, bool& outParam, bool inoutParam, - bool& result) override; + bool& funcResult) override; ErrCode byte_test_func( int8_t inParam, int8_t& outParam, int8_t inoutParam, - int8_t& result) override; + int8_t& funcResult) override; ErrCode short_test_func( short inParam, short& outParam, short inoutParam, - short& result) override; + short& funcResult) override; ErrCode int_test_func( int32_t inParam, int32_t& outParam, int32_t inoutParam, - int32_t& result) override; + int32_t& funcResult) override; ErrCode long_test_func( int64_t inParam, int64_t& outParam, int64_t inoutParam, - int64_t& result) override; + int64_t& funcResult) override; ErrCode string_test_func( const std::string& inParam, std::string& outParam, const std::string& inoutParam, - std::string& result) override; + std::string& funcResult) override; ErrCode float_test_func( float inParam, float& outParam, float inoutParam, - float& result) override; + float& funcResult) override; ErrCode double_test_func( double inParam, double& outParam, double inoutParam, - double& result) override; + double& funcResult) override; ErrCode char_test_func( zchar inParam, zchar& outParam, zchar inoutParam, - zchar& result) override; + zchar& funcResult) override; ErrCode seq_test_func( const myseq& inParam, myseq& outParam, myseq* inoutParam, - myseq& result) override; + myseq& funcResult) override; ErrCode interface_test_func( const sptr& inParam, sptr& outParam, const sptr& inoutParam, - sptr& result) override; + sptr& funcResult) override; private: static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; diff --git a/test/sa_test/cmd_save_metadata/target/ifoo.h.txt b/test/sa_test/cmd_save_metadata/target/ifoo.h.txt index 120fe78..3bde861 100644 --- a/test/sa_test/cmd_save_metadata/target/ifoo.h.txt +++ b/test/sa_test/cmd_save_metadata/target/ifoo.h.txt @@ -36,67 +36,67 @@ public: bool inParam, bool& outParam, bool inoutParam, - bool& result) = 0; + bool& funcResult) = 0; virtual ErrCode byte_test_func( int8_t inParam, int8_t& outParam, int8_t inoutParam, - int8_t& result) = 0; + int8_t& funcResult) = 0; virtual ErrCode short_test_func( short inParam, short& outParam, short inoutParam, - short& result) = 0; + short& funcResult) = 0; virtual ErrCode int_test_func( int32_t inParam, int32_t& outParam, int32_t inoutParam, - int32_t& result) = 0; + int32_t& funcResult) = 0; virtual ErrCode long_test_func( int64_t inParam, int64_t& outParam, int64_t inoutParam, - int64_t& result) = 0; + int64_t& funcResult) = 0; virtual ErrCode string_test_func( const std::string& inParam, std::string& outParam, const std::string& inoutParam, - std::string& result) = 0; + std::string& funcResult) = 0; virtual ErrCode float_test_func( float inParam, float& outParam, float inoutParam, - float& result) = 0; + float& funcResult) = 0; virtual ErrCode double_test_func( double inParam, double& outParam, double inoutParam, - double& result) = 0; + double& funcResult) = 0; virtual ErrCode char_test_func( zchar inParam, zchar& outParam, zchar inoutParam, - zchar& result) = 0; + zchar& funcResult) = 0; virtual ErrCode seq_test_func( const myseq& inParam, myseq& outParam, myseq* inoutParam, - myseq& result) = 0; + myseq& funcResult) = 0; virtual ErrCode interface_test_func( const sptr& inParam, sptr& outParam, const sptr& inoutParam, - sptr& result) = 0; + sptr& funcResult) = 0; protected: const int VECTOR_MAX_SIZE = 102400; const int LIST_MAX_SIZE = 102400; diff --git a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.cpp.txt b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.cpp.txt index 67da394..6c9ec10 100644 --- a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.cpp.txt @@ -19,7 +19,7 @@ namespace idl { namespace OHOS { ErrCode FooProxy::test001( short param1, - int32_t& result) + int32_t& funcResult) { MessageParcel data; MessageParcel reply; @@ -39,7 +39,7 @@ ErrCode FooProxy::test001( if (FAILED(errCode)) { return errCode; } - result = reply.ReadInt32(); + funcResult = reply.ReadInt32(); return ERR_OK; } @@ -58,7 +58,7 @@ ErrCode FooProxy::test001( } ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), COMMAND_TEST001, data, reply); - result = reply.ReadInt32(); + funcResult = reply.ReadInt32(); return ERR_OK; } diff --git a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.h.txt b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.h.txt index dc0a375..3ec76dc 100644 --- a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.h.txt @@ -69,7 +69,7 @@ public: ErrCode test001( short param1, - int32_t& result) override; + int32_t& funcResult) override; ErrCode test002( int32_t param1) override; diff --git a/test/sa_test/keyword_cacheable_test_001/target_cpp/ifoo.h.txt b/test/sa_test/keyword_cacheable_test_001/target_cpp/ifoo.h.txt index 25c21d6..1cddb80 100644 --- a/test/sa_test/keyword_cacheable_test_001/target_cpp/ifoo.h.txt +++ b/test/sa_test/keyword_cacheable_test_001/target_cpp/ifoo.h.txt @@ -29,7 +29,7 @@ public: virtual ErrCode test001( short param1, - int32_t& result) = 0; + int32_t& funcResult) = 0; virtual ErrCode test002( int32_t param1) = 0; diff --git a/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.cpp.txt b/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.cpp.txt index 68a7f36..3590686 100644 --- a/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.cpp.txt @@ -50,14 +50,14 @@ ErrCode FooProxy::seq_test_func( return errCode; } - std::unique_ptr info(reply.ReadParcelable()); - if (info != nullptr) { - outParam = *info; + std::unique_ptr outParamInfo(reply.ReadParcelable()); + if (outParamInfo != nullptr) { + outParam = *outParamInfo; } - std::unique_ptr info(reply.ReadParcelable()); - if (info != nullptr) { - inoutParam = *info; + std::unique_ptr inoutParamInfo(reply.ReadParcelable()); + if (inoutParamInfo != nullptr) { + inoutParam = *inoutParamInfo; } return ERR_OK; @@ -97,14 +97,14 @@ ErrCode FooProxy::seq_test_func2( return errCode; } - std::unique_ptr info(reply.ReadParcelable()); - if (info != nullptr) { - outParam = *info; + std::unique_ptr outParamInfo(reply.ReadParcelable()); + if (outParamInfo != nullptr) { + outParam = *outParamInfo; } - std::unique_ptr info(reply.ReadParcelable()); - if (info != nullptr) { - inoutParam = *info; + std::unique_ptr inoutParamInfo(reply.ReadParcelable()); + if (inoutParamInfo != nullptr) { + inoutParam = *inoutParamInfo; } return ERR_OK; diff --git a/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt index cc59f12..858e7fb 100644 --- a/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt @@ -48,7 +48,7 @@ ErrCode FooProxy::bool_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -107,13 +107,13 @@ ErrCode FooProxy::bool_test_func( bool value2 = reply.ReadInt32() == 1 ? true : false; inoutParam.push_back(value2); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i3 = 0; i3 < resultSize; ++i3) { + for (int32_t i3 = 0; i3 < funcResultSize; ++i3) { bool value3 = reply.ReadInt32() == 1 ? true : false; - result.push_back(value3); + funcResult.push_back(value3); } return ERR_OK; } @@ -122,7 +122,7 @@ ErrCode FooProxy::byte_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -181,13 +181,13 @@ ErrCode FooProxy::byte_test_func( int8_t value5 = (int8_t)reply.ReadInt32(); inoutParam.push_back(value5); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i6 = 0; i6 < resultSize; ++i6) { + for (int32_t i6 = 0; i6 < funcResultSize; ++i6) { int8_t value6 = (int8_t)reply.ReadInt32(); - result.push_back(value6); + funcResult.push_back(value6); } return ERR_OK; } @@ -196,7 +196,7 @@ ErrCode FooProxy::short_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -255,13 +255,13 @@ ErrCode FooProxy::short_test_func( short value8 = (short)reply.ReadInt32(); inoutParam.push_back(value8); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i9 = 0; i9 < resultSize; ++i9) { + for (int32_t i9 = 0; i9 < funcResultSize; ++i9) { short value9 = (short)reply.ReadInt32(); - result.push_back(value9); + funcResult.push_back(value9); } return ERR_OK; } @@ -270,7 +270,7 @@ ErrCode FooProxy::int_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -329,13 +329,13 @@ ErrCode FooProxy::int_test_func( int32_t value11 = reply.ReadInt32(); inoutParam.push_back(value11); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i12 = 0; i12 < resultSize; ++i12) { + for (int32_t i12 = 0; i12 < funcResultSize; ++i12) { int32_t value12 = reply.ReadInt32(); - result.push_back(value12); + funcResult.push_back(value12); } return ERR_OK; } @@ -344,7 +344,7 @@ ErrCode FooProxy::long_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -403,13 +403,13 @@ ErrCode FooProxy::long_test_func( int64_t value14 = reply.ReadInt64(); inoutParam.push_back(value14); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i15 = 0; i15 < resultSize; ++i15) { + for (int32_t i15 = 0; i15 < funcResultSize; ++i15) { int64_t value15 = reply.ReadInt64(); - result.push_back(value15); + funcResult.push_back(value15); } return ERR_OK; } @@ -418,7 +418,7 @@ ErrCode FooProxy::string_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -477,13 +477,13 @@ ErrCode FooProxy::string_test_func( std::string value17 = Str16ToStr8(reply.ReadString16()); inoutParam.push_back(value17); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i18 = 0; i18 < resultSize; ++i18) { + for (int32_t i18 = 0; i18 < funcResultSize; ++i18) { std::string value18 = Str16ToStr8(reply.ReadString16()); - result.push_back(value18); + funcResult.push_back(value18); } return ERR_OK; } @@ -492,7 +492,7 @@ ErrCode FooProxy::float_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -551,13 +551,13 @@ ErrCode FooProxy::float_test_func( float value20 = reply.ReadFloat(); inoutParam.push_back(value20); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i21 = 0; i21 < resultSize; ++i21) { + for (int32_t i21 = 0; i21 < funcResultSize; ++i21) { float value21 = reply.ReadFloat(); - result.push_back(value21); + funcResult.push_back(value21); } return ERR_OK; } @@ -566,7 +566,7 @@ ErrCode FooProxy::double_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -625,13 +625,13 @@ ErrCode FooProxy::double_test_func( double value23 = reply.ReadDouble(); inoutParam.push_back(value23); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i24 = 0; i24 < resultSize; ++i24) { + for (int32_t i24 = 0; i24 < funcResultSize; ++i24) { double value24 = reply.ReadDouble(); - result.push_back(value24); + funcResult.push_back(value24); } return ERR_OK; } @@ -640,7 +640,7 @@ ErrCode FooProxy::char_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -699,13 +699,13 @@ ErrCode FooProxy::char_test_func( zchar value26 = (zchar)reply.ReadInt32(); inoutParam.push_back(value26); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i27 = 0; i27 < resultSize; ++i27) { + for (int32_t i27 = 0; i27 < funcResultSize; ++i27) { zchar value27 = (zchar)reply.ReadInt32(); - result.push_back(value27); + funcResult.push_back(value27); } return ERR_OK; } @@ -714,7 +714,7 @@ ErrCode FooProxy::seq_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -781,17 +781,17 @@ ErrCode FooProxy::seq_test_func( } inoutParam.push_back(*value29); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i30 = 0; i30 < resultSize; ++i30) { + for (int32_t i30 = 0; i30 < funcResultSize; ++i30) { std::unique_ptr value30(reply.ReadParcelable()); if (!value30) { return ERR_INVALID_DATA; } - result.push_back(*value30); + funcResult.push_back(*value30); } return ERR_OK; } @@ -800,7 +800,7 @@ ErrCode FooProxy::interface_test_func( const std::vector>& inParam, std::vector>& outParam, std::vector>& inoutParam, - std::vector>& result) + std::vector>& funcResult) { MessageParcel data; MessageParcel reply; @@ -873,17 +873,17 @@ ErrCode FooProxy::interface_test_func( inoutParam.push_back(value32); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i33 = 0; i33 < resultSize; ++i33) { + for (int32_t i33 = 0; i33 < funcResultSize; ++i33) { sptr value33 = iface_cast(reply.ReadRemoteObject()); if (value33 == nullptr) { return ERR_INVALID_DATA; } - result.push_back(value33); + funcResult.push_back(value33); } return ERR_OK; } diff --git a/test/sa_test/type_array/target_cpp/foo_proxy.h.txt b/test/sa_test/type_array/target_cpp/foo_proxy.h.txt index d0a8552..ccd71b8 100644 --- a/test/sa_test/type_array/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_array/target_cpp/foo_proxy.h.txt @@ -36,67 +36,67 @@ public: const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode byte_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode short_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode int_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode long_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode string_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode float_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode double_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode char_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode seq_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode interface_test_func( const std::vector>& inParam, std::vector>& outParam, std::vector>& inoutParam, - std::vector>& result) override; + std::vector>& funcResult) override; private: static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; diff --git a/test/sa_test/type_array/target_cpp/ifoo.h.txt b/test/sa_test/type_array/target_cpp/ifoo.h.txt index 2b3d8df..b24be16 100644 --- a/test/sa_test/type_array/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_array/target_cpp/ifoo.h.txt @@ -37,67 +37,67 @@ public: const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode byte_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode short_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode int_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode long_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode string_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode float_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode double_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode char_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode seq_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode interface_test_func( const std::vector>& inParam, std::vector>& outParam, std::vector>& inoutParam, - std::vector>& result) = 0; + std::vector>& funcResult) = 0; protected: const int VECTOR_MAX_SIZE = 102400; const int LIST_MAX_SIZE = 102400; diff --git a/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt index cca3c27..6fbd5e4 100644 --- a/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt @@ -20,7 +20,7 @@ ErrCode FooProxy::bool_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -79,13 +79,13 @@ ErrCode FooProxy::bool_test_func( bool value2 = reply.ReadInt32() == 1 ? true : false; inoutParam.push_back(value2); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i3 = 0; i3 < resultSize; ++i3) { + for (int32_t i3 = 0; i3 < funcResultSize; ++i3) { bool value3 = reply.ReadInt32() == 1 ? true : false; - result.push_back(value3); + funcResult.push_back(value3); } return ERR_OK; } @@ -94,7 +94,7 @@ ErrCode FooProxy::byte_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -153,13 +153,13 @@ ErrCode FooProxy::byte_test_func( bool value5 = reply.ReadInt32() == 1 ? true : false; inoutParam.push_back(value5); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i6 = 0; i6 < resultSize; ++i6) { + for (int32_t i6 = 0; i6 < funcResultSize; ++i6) { bool value6 = reply.ReadInt32() == 1 ? true : false; - result.push_back(value6); + funcResult.push_back(value6); } return ERR_OK; } @@ -168,7 +168,7 @@ ErrCode FooProxy::short_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -227,13 +227,13 @@ ErrCode FooProxy::short_test_func( short value8 = (short)reply.ReadInt32(); inoutParam.push_back(value8); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i9 = 0; i9 < resultSize; ++i9) { + for (int32_t i9 = 0; i9 < funcResultSize; ++i9) { short value9 = (short)reply.ReadInt32(); - result.push_back(value9); + funcResult.push_back(value9); } return ERR_OK; } @@ -242,7 +242,7 @@ ErrCode FooProxy::int_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -301,13 +301,13 @@ ErrCode FooProxy::int_test_func( int32_t value11 = reply.ReadInt32(); inoutParam.push_back(value11); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i12 = 0; i12 < resultSize; ++i12) { + for (int32_t i12 = 0; i12 < funcResultSize; ++i12) { int32_t value12 = reply.ReadInt32(); - result.push_back(value12); + funcResult.push_back(value12); } return ERR_OK; } @@ -316,7 +316,7 @@ ErrCode FooProxy::long_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -375,13 +375,13 @@ ErrCode FooProxy::long_test_func( int64_t value14 = reply.ReadInt64(); inoutParam.push_back(value14); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i15 = 0; i15 < resultSize; ++i15) { + for (int32_t i15 = 0; i15 < funcResultSize; ++i15) { int64_t value15 = reply.ReadInt64(); - result.push_back(value15); + funcResult.push_back(value15); } return ERR_OK; } @@ -390,7 +390,7 @@ ErrCode FooProxy::string_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -449,13 +449,13 @@ ErrCode FooProxy::string_test_func( std::string value17 = Str16ToStr8(reply.ReadString16()); inoutParam.push_back(value17); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i18 = 0; i18 < resultSize; ++i18) { + for (int32_t i18 = 0; i18 < funcResultSize; ++i18) { std::string value18 = Str16ToStr8(reply.ReadString16()); - result.push_back(value18); + funcResult.push_back(value18); } return ERR_OK; } @@ -464,7 +464,7 @@ ErrCode FooProxy::float_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -523,13 +523,13 @@ ErrCode FooProxy::float_test_func( float value20 = reply.ReadFloat(); inoutParam.push_back(value20); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i21 = 0; i21 < resultSize; ++i21) { + for (int32_t i21 = 0; i21 < funcResultSize; ++i21) { float value21 = reply.ReadFloat(); - result.push_back(value21); + funcResult.push_back(value21); } return ERR_OK; } @@ -538,7 +538,7 @@ ErrCode FooProxy::double_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -597,13 +597,13 @@ ErrCode FooProxy::double_test_func( double value23 = reply.ReadDouble(); inoutParam.push_back(value23); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i24 = 0; i24 < resultSize; ++i24) { + for (int32_t i24 = 0; i24 < funcResultSize; ++i24) { double value24 = reply.ReadDouble(); - result.push_back(value24); + funcResult.push_back(value24); } return ERR_OK; } @@ -612,7 +612,7 @@ ErrCode FooProxy::char_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -671,13 +671,13 @@ ErrCode FooProxy::char_test_func( zchar value26 = (zchar)reply.ReadInt32(); inoutParam.push_back(value26); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i27 = 0; i27 < resultSize; ++i27) { + for (int32_t i27 = 0; i27 < funcResultSize; ++i27) { zchar value27 = (zchar)reply.ReadInt32(); - result.push_back(value27); + funcResult.push_back(value27); } return ERR_OK; } @@ -686,7 +686,7 @@ ErrCode FooProxy::seq_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) + std::vector& funcResult) { MessageParcel data; MessageParcel reply; @@ -753,17 +753,17 @@ ErrCode FooProxy::seq_test_func( } inoutParam.push_back(*value29); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i30 = 0; i30 < resultSize; ++i30) { + for (int32_t i30 = 0; i30 < funcResultSize; ++i30) { std::unique_ptr value30(reply.ReadParcelable()); if (!value30) { return ERR_INVALID_DATA; } - result.push_back(*value30); + funcResult.push_back(*value30); } return ERR_OK; } @@ -772,7 +772,7 @@ ErrCode FooProxy::interface_test_func( const std::vector>& inParam, std::vector>& outParam, std::vector>& inoutParam, - std::vector>& result) + std::vector>& funcResult) { MessageParcel data; MessageParcel reply; @@ -845,17 +845,17 @@ ErrCode FooProxy::interface_test_func( inoutParam.push_back(value32); } - int32_t resultSize = reply.ReadInt32(); - if (resultSize > static_cast(VECTOR_MAX_SIZE)) { + int32_t funcResultSize = reply.ReadInt32(); + if (funcResultSize > static_cast(VECTOR_MAX_SIZE)) { return ERR_INVALID_DATA; } - for (int32_t i33 = 0; i33 < resultSize; ++i33) { + for (int32_t i33 = 0; i33 < funcResultSize; ++i33) { sptr value33 = iface_cast(reply.ReadRemoteObject()); if (value33 == nullptr) { return ERR_INVALID_DATA; } - result.push_back(value33); + funcResult.push_back(value33); } return ERR_OK; } diff --git a/test/sa_test/type_list/target_cpp/foo_proxy.h.txt b/test/sa_test/type_list/target_cpp/foo_proxy.h.txt index 84e7bed..2272a78 100644 --- a/test/sa_test/type_list/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_list/target_cpp/foo_proxy.h.txt @@ -34,67 +34,67 @@ public: const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode byte_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode short_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode int_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode long_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode string_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode float_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode double_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode char_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode seq_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) override; + std::vector& funcResult) override; ErrCode interface_test_func( const std::vector>& inParam, std::vector>& outParam, std::vector>& inoutParam, - std::vector>& result) override; + std::vector>& funcResult) override; private: static constexpr int32_t COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID + 0; diff --git a/test/sa_test/type_list/target_cpp/ifoo.h.txt b/test/sa_test/type_list/target_cpp/ifoo.h.txt index 1e65f75..ea7527b 100644 --- a/test/sa_test/type_list/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_list/target_cpp/ifoo.h.txt @@ -35,67 +35,67 @@ public: const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode byte_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode short_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode int_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode long_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode string_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode float_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode double_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode char_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode seq_test_func( const std::vector& inParam, std::vector& outParam, std::vector& inoutParam, - std::vector& result) = 0; + std::vector& funcResult) = 0; virtual ErrCode interface_test_func( const std::vector>& inParam, std::vector>& outParam, std::vector>& inoutParam, - std::vector>& result) = 0; + std::vector>& funcResult) = 0; protected: const int VECTOR_MAX_SIZE = 102400; const int LIST_MAX_SIZE = 102400; diff --git a/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt index e8a94b9..e868e9c 100644 --- a/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt @@ -48,7 +48,7 @@ ErrCode FooProxy::bool_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) + std::unordered_map& funcResult) { MessageParcel data; MessageParcel reply; @@ -111,11 +111,11 @@ ErrCode FooProxy::bool_test_func( bool value = reply.ReadInt32() == 1 ? true : false; inoutParam[key] = value; } - int32_t resultSize = reply.ReadInt32(); - for (int32_t i = 0; i < resultSize; ++i) { + int32_t funcResultSize = reply.ReadInt32(); + for (int32_t i = 0; i < funcResultSize; ++i) { bool key = reply.ReadInt32() == 1 ? true : false; bool value = reply.ReadInt32() == 1 ? true : false; - result[key] = value; + funcResult[key] = value; } return ERR_OK; } @@ -124,7 +124,7 @@ ErrCode FooProxy::byte_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) + std::unordered_map& funcResult) { MessageParcel data; MessageParcel reply; @@ -187,11 +187,11 @@ ErrCode FooProxy::byte_test_func( int8_t value = (int8_t)reply.ReadInt32(); inoutParam[key] = value; } - int32_t resultSize = reply.ReadInt32(); - for (int32_t i = 0; i < resultSize; ++i) { + int32_t funcResultSize = reply.ReadInt32(); + for (int32_t i = 0; i < funcResultSize; ++i) { int8_t key = (int8_t)reply.ReadInt32(); int8_t value = (int8_t)reply.ReadInt32(); - result[key] = value; + funcResult[key] = value; } return ERR_OK; } @@ -200,7 +200,7 @@ ErrCode FooProxy::short_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) + std::unordered_map& funcResult) { MessageParcel data; MessageParcel reply; @@ -263,11 +263,11 @@ ErrCode FooProxy::short_test_func( short value = (short)reply.ReadInt32(); inoutParam[key] = value; } - int32_t resultSize = reply.ReadInt32(); - for (int32_t i = 0; i < resultSize; ++i) { + int32_t funcResultSize = reply.ReadInt32(); + for (int32_t i = 0; i < funcResultSize; ++i) { short key = (short)reply.ReadInt32(); short value = (short)reply.ReadInt32(); - result[key] = value; + funcResult[key] = value; } return ERR_OK; } @@ -276,7 +276,7 @@ ErrCode FooProxy::int_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) + std::unordered_map& funcResult) { MessageParcel data; MessageParcel reply; @@ -339,11 +339,11 @@ ErrCode FooProxy::int_test_func( int32_t value = reply.ReadInt32(); inoutParam[key] = value; } - int32_t resultSize = reply.ReadInt32(); - for (int32_t i = 0; i < resultSize; ++i) { + int32_t funcResultSize = reply.ReadInt32(); + for (int32_t i = 0; i < funcResultSize; ++i) { int32_t key = reply.ReadInt32(); int32_t value = reply.ReadInt32(); - result[key] = value; + funcResult[key] = value; } return ERR_OK; } @@ -352,7 +352,7 @@ ErrCode FooProxy::long_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) + std::unordered_map& funcResult) { MessageParcel data; MessageParcel reply; @@ -415,11 +415,11 @@ ErrCode FooProxy::long_test_func( int64_t value = reply.ReadInt64(); inoutParam[key] = value; } - int32_t resultSize = reply.ReadInt32(); - for (int32_t i = 0; i < resultSize; ++i) { + int32_t funcResultSize = reply.ReadInt32(); + for (int32_t i = 0; i < funcResultSize; ++i) { int64_t key = reply.ReadInt64(); int64_t value = reply.ReadInt64(); - result[key] = value; + funcResult[key] = value; } return ERR_OK; } @@ -428,7 +428,7 @@ ErrCode FooProxy::string_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) + std::unordered_map& funcResult) { MessageParcel data; MessageParcel reply; @@ -491,11 +491,11 @@ ErrCode FooProxy::string_test_func( std::string value = Str16ToStr8(reply.ReadString16()); inoutParam[key] = value; } - int32_t resultSize = reply.ReadInt32(); - for (int32_t i = 0; i < resultSize; ++i) { + int32_t funcResultSize = reply.ReadInt32(); + for (int32_t i = 0; i < funcResultSize; ++i) { std::string key = Str16ToStr8(reply.ReadString16()); std::string value = Str16ToStr8(reply.ReadString16()); - result[key] = value; + funcResult[key] = value; } return ERR_OK; } @@ -504,7 +504,7 @@ ErrCode FooProxy::float_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) + std::unordered_map& funcResult) { MessageParcel data; MessageParcel reply; @@ -567,11 +567,11 @@ ErrCode FooProxy::float_test_func( float value = reply.ReadFloat(); inoutParam[key] = value; } - int32_t resultSize = reply.ReadInt32(); - for (int32_t i = 0; i < resultSize; ++i) { + int32_t funcResultSize = reply.ReadInt32(); + for (int32_t i = 0; i < funcResultSize; ++i) { float key = reply.ReadFloat(); float value = reply.ReadFloat(); - result[key] = value; + funcResult[key] = value; } return ERR_OK; } @@ -580,7 +580,7 @@ ErrCode FooProxy::double_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) + std::unordered_map& funcResult) { MessageParcel data; MessageParcel reply; @@ -643,11 +643,11 @@ ErrCode FooProxy::double_test_func( double value = reply.ReadDouble(); inoutParam[key] = value; } - int32_t resultSize = reply.ReadInt32(); - for (int32_t i = 0; i < resultSize; ++i) { + int32_t funcResultSize = reply.ReadInt32(); + for (int32_t i = 0; i < funcResultSize; ++i) { double key = reply.ReadDouble(); double value = reply.ReadDouble(); - result[key] = value; + funcResult[key] = value; } return ERR_OK; } @@ -656,7 +656,7 @@ ErrCode FooProxy::char_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) + std::unordered_map& funcResult) { MessageParcel data; MessageParcel reply; @@ -719,11 +719,11 @@ ErrCode FooProxy::char_test_func( zchar value = (zchar)reply.ReadInt32(); inoutParam[key] = value; } - int32_t resultSize = reply.ReadInt32(); - for (int32_t i = 0; i < resultSize; ++i) { + int32_t funcResultSize = reply.ReadInt32(); + for (int32_t i = 0; i < funcResultSize; ++i) { zchar key = (zchar)reply.ReadInt32(); zchar value = (zchar)reply.ReadInt32(); - result[key] = value; + funcResult[key] = value; } return ERR_OK; } @@ -732,7 +732,7 @@ ErrCode FooProxy::seq_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) + std::unordered_map& funcResult) { MessageParcel data; MessageParcel reply; @@ -811,8 +811,8 @@ ErrCode FooProxy::seq_test_func( } inoutParam[key] = value; } - int32_t resultSize = reply.ReadInt32(); - for (int32_t i = 0; i < resultSize; ++i) { + int32_t funcResultSize = reply.ReadInt32(); + for (int32_t i = 0; i < funcResultSize; ++i) { std::unique_ptr key(reply.ReadParcelable()); if (!key) { @@ -823,7 +823,7 @@ ErrCode FooProxy::seq_test_func( if (!value) { return ERR_INVALID_DATA; } - result[key] = value; + funcResult[key] = value; } return ERR_OK; } @@ -832,7 +832,7 @@ ErrCode FooProxy::interface_test_func( const std::unordered_map, sptr>& inParam, std::unordered_map, sptr>& outParam, std::unordered_map, sptr>& inoutParam, - std::unordered_map, sptr>& result) + std::unordered_map, sptr>& funcResult) { MessageParcel data; MessageParcel reply; @@ -923,8 +923,8 @@ ErrCode FooProxy::interface_test_func( inoutParam[key] = value; } - int32_t resultSize = reply.ReadInt32(); - for (int32_t i = 0; i < resultSize; ++i) { + int32_t funcResultSize = reply.ReadInt32(); + for (int32_t i = 0; i < funcResultSize; ++i) { sptr key = iface_cast(reply.ReadRemoteObject()); if (key == nullptr) { return ERR_INVALID_DATA; @@ -935,7 +935,7 @@ ErrCode FooProxy::interface_test_func( return ERR_INVALID_DATA; } - result[key] = value; + funcResult[key] = value; } return ERR_OK; } diff --git a/test/sa_test/type_map/target_cpp/foo_proxy.h.txt b/test/sa_test/type_map/target_cpp/foo_proxy.h.txt index 251c88b..e24ceb2 100644 --- a/test/sa_test/type_map/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_map/target_cpp/foo_proxy.h.txt @@ -36,67 +36,67 @@ public: const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) override; + std::unordered_map& funcResult) override; ErrCode byte_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) override; + std::unordered_map& funcResult) override; ErrCode short_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) override; + std::unordered_map& funcResult) override; ErrCode int_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) override; + std::unordered_map& funcResult) override; ErrCode long_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) override; + std::unordered_map& funcResult) override; ErrCode string_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) override; + std::unordered_map& funcResult) override; ErrCode float_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) override; + std::unordered_map& funcResult) override; ErrCode double_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) override; + std::unordered_map& funcResult) override; ErrCode char_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) override; + std::unordered_map& funcResult) override; ErrCode seq_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) override; + std::unordered_map& funcResult) override; ErrCode interface_test_func( const std::unordered_map, sptr>& inParam, std::unordered_map, sptr>& outParam, std::unordered_map, sptr>& inoutParam, - std::unordered_map, sptr>& result) override; + std::unordered_map, sptr>& funcResult) override; private: static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; diff --git a/test/sa_test/type_map/target_cpp/ifoo.h.txt b/test/sa_test/type_map/target_cpp/ifoo.h.txt index b3d7146..a8fcc32 100644 --- a/test/sa_test/type_map/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_map/target_cpp/ifoo.h.txt @@ -37,67 +37,67 @@ public: const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) = 0; + std::unordered_map& funcResult) = 0; virtual ErrCode byte_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) = 0; + std::unordered_map& funcResult) = 0; virtual ErrCode short_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) = 0; + std::unordered_map& funcResult) = 0; virtual ErrCode int_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) = 0; + std::unordered_map& funcResult) = 0; virtual ErrCode long_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) = 0; + std::unordered_map& funcResult) = 0; virtual ErrCode string_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) = 0; + std::unordered_map& funcResult) = 0; virtual ErrCode float_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) = 0; + std::unordered_map& funcResult) = 0; virtual ErrCode double_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) = 0; + std::unordered_map& funcResult) = 0; virtual ErrCode char_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) = 0; + std::unordered_map& funcResult) = 0; virtual ErrCode seq_test_func( const std::unordered_map& inParam, std::unordered_map& outParam, std::unordered_map& inoutParam, - std::unordered_map& result) = 0; + std::unordered_map& funcResult) = 0; virtual ErrCode interface_test_func( const std::unordered_map, sptr>& inParam, std::unordered_map, sptr>& outParam, std::unordered_map, sptr>& inoutParam, - std::unordered_map, sptr>& result) = 0; + std::unordered_map, sptr>& funcResult) = 0; protected: const int VECTOR_MAX_SIZE = 102400; const int LIST_MAX_SIZE = 102400; diff --git a/test/sa_test/type_single/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_single/target_cpp/foo_proxy.cpp.txt index d2b68ce..c629e17 100644 --- a/test/sa_test/type_single/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_single/target_cpp/foo_proxy.cpp.txt @@ -48,7 +48,7 @@ ErrCode FooProxy::bool_test_func( bool inParam, bool& outParam, bool inoutParam, - bool& result) + bool& funcResult) { MessageParcel data; MessageParcel reply; @@ -81,7 +81,7 @@ ErrCode FooProxy::bool_test_func( outParam = reply.ReadInt32() == 1 ? true : false; inoutParam = reply.ReadInt32() == 1 ? true : false; - result = reply.ReadInt32() == 1 ? true : false; + funcResult = reply.ReadInt32() == 1 ? true : false; return ERR_OK; } @@ -89,7 +89,7 @@ ErrCode FooProxy::byte_test_func( int8_t inParam, int8_t& outParam, int8_t inoutParam, - int8_t& result) + int8_t& funcResult) { MessageParcel data; MessageParcel reply; @@ -122,7 +122,7 @@ ErrCode FooProxy::byte_test_func( outParam = (int8_t)reply.ReadInt32(); inoutParam = (int8_t)reply.ReadInt32(); - result = (int8_t)reply.ReadInt32(); + funcResult = (int8_t)reply.ReadInt32(); return ERR_OK; } @@ -130,7 +130,7 @@ ErrCode FooProxy::short_test_func( short inParam, short& outParam, short inoutParam, - short& result) + short& funcResult) { MessageParcel data; MessageParcel reply; @@ -163,7 +163,7 @@ ErrCode FooProxy::short_test_func( outParam = (short)reply.ReadInt32(); inoutParam = (short)reply.ReadInt32(); - result = (short)reply.ReadInt32(); + funcResult = (short)reply.ReadInt32(); return ERR_OK; } @@ -171,7 +171,7 @@ ErrCode FooProxy::int_test_func( int32_t inParam, int32_t& outParam, int32_t inoutParam, - int32_t& result) + int32_t& funcResult) { MessageParcel data; MessageParcel reply; @@ -204,7 +204,7 @@ ErrCode FooProxy::int_test_func( outParam = reply.ReadInt32(); inoutParam = reply.ReadInt32(); - result = reply.ReadInt32(); + funcResult = reply.ReadInt32(); return ERR_OK; } @@ -212,7 +212,7 @@ ErrCode FooProxy::long_test_func( int64_t inParam, int64_t& outParam, int64_t inoutParam, - int64_t& result) + int64_t& funcResult) { MessageParcel data; MessageParcel reply; @@ -245,7 +245,7 @@ ErrCode FooProxy::long_test_func( outParam = reply.ReadInt64(); inoutParam = reply.ReadInt64(); - result = reply.ReadInt64(); + funcResult = reply.ReadInt64(); return ERR_OK; } @@ -253,7 +253,7 @@ ErrCode FooProxy::string_test_func( const std::string& inParam, std::string& outParam, const std::string& inoutParam, - std::string& result) + std::string& funcResult) { MessageParcel data; MessageParcel reply; @@ -286,7 +286,7 @@ ErrCode FooProxy::string_test_func( outParam = Str16ToStr8(reply.ReadString16()); inoutParam = Str16ToStr8(reply.ReadString16()); - result = Str16ToStr8(reply.ReadString16()); + funcResult = Str16ToStr8(reply.ReadString16()); return ERR_OK; } @@ -294,7 +294,7 @@ ErrCode FooProxy::float_test_func( float inParam, float& outParam, float inoutParam, - float& result) + float& funcResult) { MessageParcel data; MessageParcel reply; @@ -327,7 +327,7 @@ ErrCode FooProxy::float_test_func( outParam = reply.ReadFloat(); inoutParam = reply.ReadFloat(); - result = reply.ReadFloat(); + funcResult = reply.ReadFloat(); return ERR_OK; } @@ -335,7 +335,7 @@ ErrCode FooProxy::double_test_func( double inParam, double& outParam, double inoutParam, - double& result) + double& funcResult) { MessageParcel data; MessageParcel reply; @@ -368,7 +368,7 @@ ErrCode FooProxy::double_test_func( outParam = reply.ReadDouble(); inoutParam = reply.ReadDouble(); - result = reply.ReadDouble(); + funcResult = reply.ReadDouble(); return ERR_OK; } @@ -376,7 +376,7 @@ ErrCode FooProxy::char_test_func( zchar inParam, zchar& outParam, zchar inoutParam, - zchar& result) + zchar& funcResult) { MessageParcel data; MessageParcel reply; @@ -409,7 +409,7 @@ ErrCode FooProxy::char_test_func( outParam = (zchar)reply.ReadInt32(); inoutParam = (zchar)reply.ReadInt32(); - result = (zchar)reply.ReadInt32(); + funcResult = (zchar)reply.ReadInt32(); return ERR_OK; } @@ -417,7 +417,7 @@ ErrCode FooProxy::seq_test_func( const myseq& inParam, myseq& outParam, myseq* inoutParam, - myseq& result) + myseq& funcResult) { MessageParcel data; MessageParcel reply; @@ -448,19 +448,19 @@ ErrCode FooProxy::seq_test_func( return errCode; } - std::unique_ptr info(reply.ReadParcelable()); - if (info != nullptr) { - outParam = *info; + std::unique_ptr outParamInfo(reply.ReadParcelable()); + if (outParamInfo != nullptr) { + outParam = *outParamInfo; } - std::unique_ptr info(reply.ReadParcelable()); - if (info != nullptr) { - inoutParam = *info; + std::unique_ptr inoutParamInfo(reply.ReadParcelable()); + if (inoutParamInfo != nullptr) { + inoutParam = *inoutParamInfo; } - std::unique_ptr info(reply.ReadParcelable()); - if (info != nullptr) { - result = *info; + std::unique_ptr funcResultInfo(reply.ReadParcelable()); + if (funcResultInfo != nullptr) { + funcResult = *funcResultInfo; } return ERR_OK; @@ -470,7 +470,7 @@ ErrCode FooProxy::interface_test_func( const sptr& inParam, sptr& outParam, const sptr& inoutParam, - sptr& result) + sptr& funcResult) { MessageParcel data; MessageParcel reply; @@ -509,7 +509,7 @@ ErrCode FooProxy::interface_test_func( outParam = iface_cast(reply.ReadRemoteObject()); inoutParam = iface_cast(reply.ReadRemoteObject()); - result = iface_cast(reply.ReadRemoteObject()); + funcResult = iface_cast(reply.ReadRemoteObject()); return ERR_OK; } @@ -517,7 +517,7 @@ ErrCode FooProxy::interface_test_func2( const sptr& inParam, sptr& outParam, const sptr& inoutParam, - sptr& result) + sptr& funcResult) { MessageParcel data; MessageParcel reply; @@ -556,7 +556,7 @@ ErrCode FooProxy::interface_test_func2( outParam = iface_cast(reply.ReadRemoteObject()); inoutParam = iface_cast(reply.ReadRemoteObject()); - result = iface_cast(reply.ReadRemoteObject()); + funcResult = iface_cast(reply.ReadRemoteObject()); return ERR_OK; } } // namespace test diff --git a/test/sa_test/type_single/target_cpp/foo_proxy.h.txt b/test/sa_test/type_single/target_cpp/foo_proxy.h.txt index b6043c9..9c59ce3 100644 --- a/test/sa_test/type_single/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_single/target_cpp/foo_proxy.h.txt @@ -36,73 +36,73 @@ public: bool inParam, bool& outParam, bool inoutParam, - bool& result) override; + bool& funcResult) override; ErrCode byte_test_func( int8_t inParam, int8_t& outParam, int8_t inoutParam, - int8_t& result) override; + int8_t& funcResult) override; ErrCode short_test_func( short inParam, short& outParam, short inoutParam, - short& result) override; + short& funcResult) override; ErrCode int_test_func( int32_t inParam, int32_t& outParam, int32_t inoutParam, - int32_t& result) override; + int32_t& funcResult) override; ErrCode long_test_func( int64_t inParam, int64_t& outParam, int64_t inoutParam, - int64_t& result) override; + int64_t& funcResult) override; ErrCode string_test_func( const std::string& inParam, std::string& outParam, const std::string& inoutParam, - std::string& result) override; + std::string& funcResult) override; ErrCode float_test_func( float inParam, float& outParam, float inoutParam, - float& result) override; + float& funcResult) override; ErrCode double_test_func( double inParam, double& outParam, double inoutParam, - double& result) override; + double& funcResult) override; ErrCode char_test_func( zchar inParam, zchar& outParam, zchar inoutParam, - zchar& result) override; + zchar& funcResult) override; ErrCode seq_test_func( const myseq& inParam, myseq& outParam, myseq* inoutParam, - myseq& result) override; + myseq& funcResult) override; ErrCode interface_test_func( const sptr& inParam, sptr& outParam, const sptr& inoutParam, - sptr& result) override; + sptr& funcResult) override; ErrCode interface_test_func2( const sptr& inParam, sptr& outParam, const sptr& inoutParam, - sptr& result) override; + sptr& funcResult) override; private: static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; diff --git a/test/sa_test/type_single/target_cpp/ifoo.h.txt b/test/sa_test/type_single/target_cpp/ifoo.h.txt index 204d9bb..644e139 100644 --- a/test/sa_test/type_single/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_single/target_cpp/ifoo.h.txt @@ -38,73 +38,73 @@ public: bool inParam, bool& outParam, bool inoutParam, - bool& result) = 0; + bool& funcResult) = 0; virtual ErrCode byte_test_func( int8_t inParam, int8_t& outParam, int8_t inoutParam, - int8_t& result) = 0; + int8_t& funcResult) = 0; virtual ErrCode short_test_func( short inParam, short& outParam, short inoutParam, - short& result) = 0; + short& funcResult) = 0; virtual ErrCode int_test_func( int32_t inParam, int32_t& outParam, int32_t inoutParam, - int32_t& result) = 0; + int32_t& funcResult) = 0; virtual ErrCode long_test_func( int64_t inParam, int64_t& outParam, int64_t inoutParam, - int64_t& result) = 0; + int64_t& funcResult) = 0; virtual ErrCode string_test_func( const std::string& inParam, std::string& outParam, const std::string& inoutParam, - std::string& result) = 0; + std::string& funcResult) = 0; virtual ErrCode float_test_func( float inParam, float& outParam, float inoutParam, - float& result) = 0; + float& funcResult) = 0; virtual ErrCode double_test_func( double inParam, double& outParam, double inoutParam, - double& result) = 0; + double& funcResult) = 0; virtual ErrCode char_test_func( zchar inParam, zchar& outParam, zchar inoutParam, - zchar& result) = 0; + zchar& funcResult) = 0; virtual ErrCode seq_test_func( const myseq& inParam, myseq& outParam, myseq* inoutParam, - myseq& result) = 0; + myseq& funcResult) = 0; virtual ErrCode interface_test_func( const sptr& inParam, sptr& outParam, const sptr& inoutParam, - sptr& result) = 0; + sptr& funcResult) = 0; virtual ErrCode interface_test_func2( const sptr& inParam, sptr& outParam, const sptr& inoutParam, - sptr& result) = 0; + sptr& funcResult) = 0; protected: const int VECTOR_MAX_SIZE = 102400; const int LIST_MAX_SIZE = 102400; -- Gitee From 96981964c31fdb5041f1a67dfa9141653847bc57 Mon Sep 17 00:00:00 2001 From: wenyu Date: Thu, 14 Nov 2024 11:34:06 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9=20unsigned=20?= =?UTF-8?q?char/short/int/long=20=E5=92=8C=20fd=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wenyu --- BUILD.gn | 10 + .../cpp/sa_cpp_service_stub_code_emitter.cpp | 5 + idl_tool_2/codegen/SA/sa_code_emitter.cpp | 16 +- .../codegen/SA/type/sa_fd_type_emitter.cpp | 62 +++++ .../codegen/SA/type/sa_fd_type_emitter.h | 38 +++ .../codegen/SA/type/sa_uchar_type_emitter.cpp | 62 +++++ .../codegen/SA/type/sa_uchar_type_emitter.h | 38 +++ .../codegen/SA/type/sa_uint_type_emitter.cpp | 62 +++++ .../codegen/SA/type/sa_uint_type_emitter.h | 38 +++ .../codegen/SA/type/sa_ulong_type_emitter.cpp | 62 +++++ .../codegen/SA/type/sa_ulong_type_emitter.h | 38 +++ .../SA/type/sa_ushort_type_emitter.cpp | 62 +++++ .../codegen/SA/type/sa_ushort_type_emitter.h | 38 +++ idl_tool_2/parser/intf_type_check.cpp | 5 - idl_tool_2/util/string_pool.h | 1 + test/sa_test/type_single_unsigned_fd.py | 35 +++ .../type_single_unsigned_fd/foo/IFoo.idl | 22 ++ .../target_cpp/foo_proxy.cpp.txt | 223 ++++++++++++++++++ .../target_cpp/foo_proxy.h.txt | 74 ++++++ .../target_cpp/foo_stub.cpp.txt | 147 ++++++++++++ .../target_cpp/foo_stub.h.txt | 40 ++++ .../target_cpp/ifoo.h.txt | 64 +++++ 22 files changed, 1133 insertions(+), 9 deletions(-) create mode 100644 idl_tool_2/codegen/SA/type/sa_fd_type_emitter.cpp create mode 100644 idl_tool_2/codegen/SA/type/sa_fd_type_emitter.h create mode 100644 idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.cpp create mode 100644 idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.h create mode 100644 idl_tool_2/codegen/SA/type/sa_uint_type_emitter.cpp create mode 100644 idl_tool_2/codegen/SA/type/sa_uint_type_emitter.h create mode 100644 idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.cpp create mode 100644 idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.h create mode 100644 idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.cpp create mode 100644 idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.h create mode 100644 test/sa_test/type_single_unsigned_fd.py create mode 100644 test/sa_test/type_single_unsigned_fd/foo/IFoo.idl create mode 100644 test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt create mode 100644 test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt create mode 100644 test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.cpp.txt create mode 100644 test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.h.txt create mode 100644 test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt diff --git a/BUILD.gn b/BUILD.gn index c764976..a79f9f2 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -232,6 +232,8 @@ common_sources += [ "idl_tool_2/codegen/SA/type/sa_char_type_emitter.h", "idl_tool_2/codegen/SA/type/sa_double_type_emitter.cpp", "idl_tool_2/codegen/SA/type/sa_double_type_emitter.h", + "idl_tool_2/codegen/SA/type/sa_fd_type_emitter.cpp", + "idl_tool_2/codegen/SA/type/sa_fd_type_emitter.h", "idl_tool_2/codegen/SA/type/sa_float_type_emitter.cpp", "idl_tool_2/codegen/SA/type/sa_float_type_emitter.h", "idl_tool_2/codegen/SA/type/sa_int_type_emitter.cpp", @@ -248,6 +250,14 @@ common_sources += [ "idl_tool_2/codegen/SA/type/sa_short_type_emitter.h", "idl_tool_2/codegen/SA/type/sa_string_type_emitter.cpp", "idl_tool_2/codegen/SA/type/sa_string_type_emitter.h", + "idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.cpp", + "idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.h", + "idl_tool_2/codegen/SA/type/sa_uint_type_emitter.cpp", + "idl_tool_2/codegen/SA/type/sa_uint_type_emitter.h", + "idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.cpp", + "idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.h", + "idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.cpp", + "idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.h", ] common_sources += [ diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp b/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp index a40e030..e092176 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp @@ -238,6 +238,11 @@ void SaCppServiceStubCodeEmitter::EmitSaReturnParameter(const std::string &name, case TypeKind::TYPE_LIST: case TypeKind::TYPE_MAP: case TypeKind::TYPE_ARRAY: + case TypeKind::TYPE_UCHAR: + case TypeKind::TYPE_UINT: + case TypeKind::TYPE_ULONG: + case TypeKind::TYPE_USHORT: + case TypeKind::TYPE_FILEDESCRIPTOR: sb.Append(name.c_str()); break; default: diff --git a/idl_tool_2/codegen/SA/sa_code_emitter.cpp b/idl_tool_2/codegen/SA/sa_code_emitter.cpp index cc929ac..efe8423 100644 --- a/idl_tool_2/codegen/SA/sa_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/sa_code_emitter.cpp @@ -13,6 +13,8 @@ * limitations under the License. */ +#include +#include #include "sa_code_emitter.h" #include "ast/ast_map_type.h" #include "type/sa_boolean_type_emitter.h" @@ -28,10 +30,11 @@ #include "type/sa_interface_type_emitter.h" #include "type/sa_map_type_emitter.h" #include "type/sa_array_type_emitter.h" - -#include -#include -#include +#include "type/sa_uchar_type_emitter.h" +#include "type/sa_uint_type_emitter.h" +#include "type/sa_ulong_type_emitter.h" +#include "type/sa_ushort_type_emitter.h" +#include "type/sa_fd_type_emitter.h" #include "util/file.h" #include "util/options.h" #include "util/logger.h" @@ -49,6 +52,11 @@ SACodeEmitter::TypeEmitterMap SACodeEmitter::basicEmitters_ = { {TypeKind::TYPE_DOUBLE, new SaDoubleTypeEmitter() }, {TypeKind::TYPE_CHAR, new SaCharTypeEmitter() }, {TypeKind::TYPE_STRING, new SaStringTypeEmitter() }, + {TypeKind::TYPE_UCHAR, new SaUcharTypeEmitter() }, + {TypeKind::TYPE_UINT, new SaUintTypeEmitter() }, + {TypeKind::TYPE_ULONG, new SaUlongTypeEmitter() }, + {TypeKind::TYPE_USHORT, new SaUshortTypeEmitter() }, + {TypeKind::TYPE_FILEDESCRIPTOR, new SaFdTypeEmitter() }, }; bool SACodeEmitter::OutPut(const AutoPtr &ast, const std::string &targetDirectory, GenMode mode) diff --git a/idl_tool_2/codegen/SA/type/sa_fd_type_emitter.cpp b/idl_tool_2/codegen/SA/type/sa_fd_type_emitter.cpp new file mode 100644 index 0000000..aca1c02 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_fd_type_emitter.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sa_fd_type_emitter.h" + +namespace OHOS { +namespace Idl { +TypeKind SaFdTypeEmitter::GetTypeKind() +{ + return TypeKind::TYPE_FILEDESCRIPTOR; +} + +std::string SaFdTypeEmitter::EmitCppType(TypeMode mode) const +{ + switch (mode) { + case TypeMode::NO_MODE: + case TypeMode::PARAM_IN: + case TypeMode::PARAM_INOUT: + case TypeMode::LOCAL_VAR: + return "int"; + case TypeMode::PARAM_OUT: + return "int&"; + default: + return "unknown type"; + } +} + +void SaFdTypeEmitter::EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const +{ + sb.Append(prefix).AppendFormat("if (!%sWriteFileDescriptor(%s)) {\n", parcelName.c_str(), name.c_str()); + if (logOn_) { + sb.Append(prefix).Append(TAB).AppendFormat("HiLog::Error(LABEL, \"Write [%s] failed!\");\n", name.c_str()); + } + sb.Append(prefix).Append(TAB).Append("return ERR_INVALID_DATA;\n"); + sb.Append(prefix).Append("}\n"); +} + +void SaFdTypeEmitter::EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const +{ + if (emitType) { + sb.Append(prefix).AppendFormat("%s %s = %sReadFileDescriptor();\n", + EmitCppType(TypeMode::LOCAL_VAR).c_str(), name.c_str(), parcelName.c_str()); + } else { + sb.Append(prefix).AppendFormat("%s = %sReadFileDescriptor();\n", name.c_str(), parcelName.c_str()); + } +} +} // namespace Idl +} // namespace OHOS \ No newline at end of file diff --git a/idl_tool_2/codegen/SA/type/sa_fd_type_emitter.h b/idl_tool_2/codegen/SA/type/sa_fd_type_emitter.h new file mode 100644 index 0000000..cd86835 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_fd_type_emitter.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IDL_SA_FDTYPE_EMITTER_H +#define OHOS_IDL_SA_FDTYPE_EMITTER_H + +#include "codegen/SA/sa_type_emitter.h" + +namespace OHOS { +namespace Idl { +class SaFdTypeEmitter : public SaTypeEmitter { +public: + TypeKind GetTypeKind() override; + + std::string EmitCppType(TypeMode mode = TypeMode::NO_MODE) const override; + + void EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const override; + + void EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const override; +}; +} // namespace Idl +} // namespace OHOS + +#endif // OHOS_IDL_SA_FDTYPE_EMITTER_H \ No newline at end of file diff --git a/idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.cpp b/idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.cpp new file mode 100644 index 0000000..61181d0 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sa_uchar_type_emitter.h" + +namespace OHOS { +namespace Idl { +TypeKind SaUcharTypeEmitter::GetTypeKind() +{ + return TypeKind::TYPE_UCHAR; +} + +std::string SaUcharTypeEmitter::EmitCppType(TypeMode mode) const +{ + switch (mode) { + case TypeMode::NO_MODE: + case TypeMode::PARAM_IN: + case TypeMode::PARAM_INOUT: + case TypeMode::LOCAL_VAR: + return "uint8_t"; + case TypeMode::PARAM_OUT: + return "uint8_t&"; + default: + return "unknown type"; + } +} + +void SaUcharTypeEmitter::EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const +{ + sb.Append(prefix).AppendFormat("if (!%sWriteUint8(%s)) {\n", parcelName.c_str(), name.c_str()); + if (logOn_) { + sb.Append(prefix).Append(TAB).AppendFormat("HiLog::Error(LABEL, \"Write [%s] failed!\");\n", name.c_str()); + } + sb.Append(prefix).Append(TAB).Append("return ERR_INVALID_DATA;\n"); + sb.Append(prefix).Append("}\n"); +} + +void SaUcharTypeEmitter::EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const +{ + if (emitType) { + sb.Append(prefix).AppendFormat("%s %s = %sReadUint8();\n", + EmitCppType(TypeMode::LOCAL_VAR).c_str(), name.c_str(), parcelName.c_str()); + } else { + sb.Append(prefix).AppendFormat("%s = %sReadUint8();\n", name.c_str(), parcelName.c_str()); + } +} +} // namespace Idl +} // namespace OHOS \ No newline at end of file diff --git a/idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.h b/idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.h new file mode 100644 index 0000000..7711287 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IDL_SA_UCHARTYPE_EMITTER_H +#define OHOS_IDL_SA_UCHARTYPE_EMITTER_H + +#include "codegen/SA/sa_type_emitter.h" + +namespace OHOS { +namespace Idl { +class SaUcharTypeEmitter : public SaTypeEmitter { +public: + TypeKind GetTypeKind() override; + + std::string EmitCppType(TypeMode mode = TypeMode::NO_MODE) const override; + + void EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const override; + + void EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const override; +}; +} // namespace Idl +} // namespace OHOS + +#endif // OHOS_IDL_SA_UCHARTYPE_EMITTER_H \ No newline at end of file diff --git a/idl_tool_2/codegen/SA/type/sa_uint_type_emitter.cpp b/idl_tool_2/codegen/SA/type/sa_uint_type_emitter.cpp new file mode 100644 index 0000000..e0d12d0 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_uint_type_emitter.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sa_uint_type_emitter.h" + +namespace OHOS { +namespace Idl { +TypeKind SaUintTypeEmitter::GetTypeKind() +{ + return TypeKind::TYPE_UINT; +} + +std::string SaUintTypeEmitter::EmitCppType(TypeMode mode) const +{ + switch (mode) { + case TypeMode::NO_MODE: + case TypeMode::PARAM_IN: + case TypeMode::PARAM_INOUT: + case TypeMode::LOCAL_VAR: + return "uint32_t"; + case TypeMode::PARAM_OUT: + return "uint32_t&"; + default: + return "unknown type"; + } +} + +void SaUintTypeEmitter::EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const +{ + sb.Append(prefix).AppendFormat("if (!%sWriteUint32(%s)) {\n", parcelName.c_str(), name.c_str()); + if (logOn_) { + sb.Append(prefix).Append(TAB).AppendFormat("HiLog::Error(LABEL, \"Write [%s] failed!\");\n", name.c_str()); + } + sb.Append(prefix).Append(TAB).Append("return ERR_INVALID_DATA;\n"); + sb.Append(prefix).Append("}\n"); +} + +void SaUintTypeEmitter::EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const +{ + if (emitType) { + sb.Append(prefix).AppendFormat("%s %s = %sReadUint32();\n", + EmitCppType(TypeMode::LOCAL_VAR).c_str(), name.c_str(), parcelName.c_str()); + } else { + sb.Append(prefix).AppendFormat("%s = %sReadUint32();\n", name.c_str(), parcelName.c_str()); + } +} +} // namespace Idl +} // namespace OHOS \ No newline at end of file diff --git a/idl_tool_2/codegen/SA/type/sa_uint_type_emitter.h b/idl_tool_2/codegen/SA/type/sa_uint_type_emitter.h new file mode 100644 index 0000000..9f510c7 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_uint_type_emitter.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IDL_SA_UINTTYPE_EMITTER_H +#define OHOS_IDL_SA_UINTTYPE_EMITTER_H + +#include "codegen/SA/sa_type_emitter.h" + +namespace OHOS { +namespace Idl { +class SaUintTypeEmitter : public SaTypeEmitter { +public: + TypeKind GetTypeKind() override; + + std::string EmitCppType(TypeMode mode = TypeMode::NO_MODE) const override; + + void EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const override; + + void EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const override; +}; +} // namespace Idl +} // namespace OHOS + +#endif // OHOS_IDL_SA_UINTTYPE_EMITTER_H \ No newline at end of file diff --git a/idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.cpp b/idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.cpp new file mode 100644 index 0000000..98ec468 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sa_ulong_type_emitter.h" + +namespace OHOS { +namespace Idl { +TypeKind SaUlongTypeEmitter::GetTypeKind() +{ + return TypeKind::TYPE_ULONG; +} + +std::string SaUlongTypeEmitter::EmitCppType(TypeMode mode) const +{ + switch (mode) { + case TypeMode::NO_MODE: + case TypeMode::PARAM_IN: + case TypeMode::PARAM_INOUT: + case TypeMode::LOCAL_VAR: + return "uint64_t"; + case TypeMode::PARAM_OUT: + return "uint64_t&"; + default: + return "unknown type"; + } +} + +void SaUlongTypeEmitter::EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const +{ + sb.Append(prefix).AppendFormat("if (!%sWriteUint64(%s)) {\n", parcelName.c_str(), name.c_str()); + if (logOn_) { + sb.Append(prefix).Append(TAB).AppendFormat("HiLog::Error(LABEL, \"Write [%s] failed!\");\n", name.c_str()); + } + sb.Append(prefix).Append(TAB).Append("return ERR_INVALID_DATA;\n"); + sb.Append(prefix).Append("}\n"); +} + +void SaUlongTypeEmitter::EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const +{ + if (emitType) { + sb.Append(prefix).AppendFormat("%s %s = %sReadUint64();\n", + EmitCppType(TypeMode::LOCAL_VAR).c_str(), name.c_str(), parcelName.c_str()); + } else { + sb.Append(prefix).AppendFormat("%s = %sReadUint64();\n", name.c_str(), parcelName.c_str()); + } +} +} // namespace Idl +} // namespace OHOS \ No newline at end of file diff --git a/idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.h b/idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.h new file mode 100644 index 0000000..a916c22 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IDL_SA_ULONGTYPE_EMITTER_H +#define OHOS_IDL_SA_ULONGTYPE_EMITTER_H + +#include "codegen/SA/sa_type_emitter.h" + +namespace OHOS { +namespace Idl { +class SaUlongTypeEmitter : public SaTypeEmitter { +public: + TypeKind GetTypeKind() override; + + std::string EmitCppType(TypeMode mode = TypeMode::NO_MODE) const override; + + void EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const override; + + void EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const override; +}; +} // namespace Idl +} // namespace OHOS + +#endif // OHOS_IDL_SA_ULONGTYPE_EMITTER_H \ No newline at end of file diff --git a/idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.cpp b/idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.cpp new file mode 100644 index 0000000..1afca68 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sa_ushort_type_emitter.h" + +namespace OHOS { +namespace Idl { +TypeKind SaUshortTypeEmitter::GetTypeKind() +{ + return TypeKind::TYPE_USHORT; +} + +std::string SaUshortTypeEmitter::EmitCppType(TypeMode mode) const +{ + switch (mode) { + case TypeMode::NO_MODE: + case TypeMode::PARAM_IN: + case TypeMode::PARAM_INOUT: + case TypeMode::LOCAL_VAR: + return "uint16_t"; + case TypeMode::PARAM_OUT: + return "uint16_t&"; + default: + return "unknown type"; + } +} + +void SaUshortTypeEmitter::EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const +{ + sb.Append(prefix).AppendFormat("if (!%sWriteUint16(%s)) {\n", parcelName.c_str(), name.c_str()); + if (logOn_) { + sb.Append(prefix).Append(TAB).AppendFormat("HiLog::Error(LABEL, \"Write [%s] failed!\");\n", name.c_str()); + } + sb.Append(prefix).Append(TAB).Append("return ERR_INVALID_DATA;\n"); + sb.Append(prefix).Append("}\n"); +} + +void SaUshortTypeEmitter::EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const +{ + if (emitType) { + sb.Append(prefix).AppendFormat("%s %s = %sReadUint16();\n", + EmitCppType(TypeMode::LOCAL_VAR).c_str(), name.c_str(), parcelName.c_str()); + } else { + sb.Append(prefix).AppendFormat("%s = %sReadUint16();\n", name.c_str(), parcelName.c_str()); + } +} +} // namespace Idl +} // namespace OHOS \ No newline at end of file diff --git a/idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.h b/idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.h new file mode 100644 index 0000000..8296813 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IDL_SA_USHORTTYPE_EMITTER_H +#define OHOS_IDL_SA_USHORTTYPE_EMITTER_H + +#include "codegen/SA/sa_type_emitter.h" + +namespace OHOS { +namespace Idl { +class SaUshortTypeEmitter : public SaTypeEmitter { +public: + TypeKind GetTypeKind() override; + + std::string EmitCppType(TypeMode mode = TypeMode::NO_MODE) const override; + + void EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const override; + + void EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const override; +}; +} // namespace Idl +} // namespace OHOS + +#endif // OHOS_IDL_SA_USHORTTYPE_EMITTER_H \ No newline at end of file diff --git a/idl_tool_2/parser/intf_type_check.cpp b/idl_tool_2/parser/intf_type_check.cpp index 72588dc..8860f9d 100644 --- a/idl_tool_2/parser/intf_type_check.cpp +++ b/idl_tool_2/parser/intf_type_check.cpp @@ -97,7 +97,6 @@ bool IntfTypeChecker::CheckIntfSaAstTypes() for (const auto &pair : ast_->GetTypes()) { AutoPtr type = pair.second; switch (type->GetTypeKind()) { - case TypeKind::TYPE_FILEDESCRIPTOR: case TypeKind::TYPE_ASHMEM: case TypeKind::TYPE_NATIVE_BUFFER: case TypeKind::TYPE_POINTER: @@ -105,10 +104,6 @@ bool IntfTypeChecker::CheckIntfSaAstTypes() case TypeKind::TYPE_ENUM: case TypeKind::TYPE_STRUCT: case TypeKind::TYPE_UNION: - case TypeKind::TYPE_UCHAR: - case TypeKind::TYPE_USHORT: - case TypeKind::TYPE_UINT: - case TypeKind::TYPE_ULONG: Logger::E(TAG, StringHelper::Format("[%s:%d] error:intf sa: type '%s' not support", __func__, __LINE__, pair.first.c_str()).c_str()); return false; diff --git a/idl_tool_2/util/string_pool.h b/idl_tool_2/util/string_pool.h index 4261ffa..1e189ea 100644 --- a/idl_tool_2/util/string_pool.h +++ b/idl_tool_2/util/string_pool.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "util/string_helper.h" namespace OHOS { diff --git a/test/sa_test/type_single_unsigned_fd.py b/test/sa_test/type_single_unsigned_fd.py new file mode 100644 index 0000000..b01c8d4 --- /dev/null +++ b/test/sa_test/type_single_unsigned_fd.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from test_base import Test + + +class TypeSingleUnsignedFd(Test): + def get_file_name(self): + return __file__ + + def run_cpp(self): + self.set_gen_cpp_env() + return self.run_choose(True) + + def run(self): + return self.run_cpp() + + +if __name__ == "__main__": + TypeSingleUnsignedFd().test() diff --git a/test/sa_test/type_single_unsigned_fd/foo/IFoo.idl b/test/sa_test/type_single_unsigned_fd/foo/IFoo.idl new file mode 100644 index 0000000..dcc6338 --- /dev/null +++ b/test/sa_test/type_single_unsigned_fd/foo/IFoo.idl @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +interface test.IFoo { + unsigned char uchar_test_func([in] unsigned char inParam, [out] unsigned char outParam, [inout] unsigned char inoutParam); + unsigned short ushort_test_func([in] unsigned short inParam, [out] unsigned short outParam, [inout] unsigned short inoutParam); + unsigned int uint_test_func([in] unsigned int inParam, [out] unsigned int outParam, [inout] unsigned int inoutParam); + unsigned long ulong_test_func([in] unsigned long inParam, [out] unsigned long outParam, [inout] unsigned long inoutParam); + FileDescriptor fd_test_func([in] FileDescriptor inParam, [out] FileDescriptor outParam, [inout] FileDescriptor inoutParam); +} diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt new file mode 100644 index 0000000..a36e957 --- /dev/null +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt @@ -0,0 +1,223 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "foo_proxy.h" + +namespace test { +ErrCode FooProxy::uchar_test_func( + uint8_t inParam, + uint8_t& outParam, + uint8_t inoutParam, + uint8_t& funcResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteUint8(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteUint8(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_UCHAR_TEST_FUNC, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = reply.ReadUint8(); + inoutParam = reply.ReadUint8(); + funcResult = reply.ReadUint8(); + return ERR_OK; +} + +ErrCode FooProxy::ushort_test_func( + uint16_t inParam, + uint16_t& outParam, + uint16_t inoutParam, + uint16_t& funcResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteUint16(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteUint16(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_USHORT_TEST_FUNC, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = reply.ReadUint16(); + inoutParam = reply.ReadUint16(); + funcResult = reply.ReadUint16(); + return ERR_OK; +} + +ErrCode FooProxy::uint_test_func( + uint32_t inParam, + uint32_t& outParam, + uint32_t inoutParam, + uint32_t& funcResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteUint32(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteUint32(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_UINT_TEST_FUNC, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = reply.ReadUint32(); + inoutParam = reply.ReadUint32(); + funcResult = reply.ReadUint32(); + return ERR_OK; +} + +ErrCode FooProxy::ulong_test_func( + uint64_t inParam, + uint64_t& outParam, + uint64_t inoutParam, + uint64_t& funcResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteUint64(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteUint64(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_ULONG_TEST_FUNC, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = reply.ReadUint64(); + inoutParam = reply.ReadUint64(); + funcResult = reply.ReadUint64(); + return ERR_OK; +} + +ErrCode FooProxy::fd_test_func( + int inParam, + int& outParam, + int inoutParam, + int& funcResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteFileDescriptor(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteFileDescriptor(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_FD_TEST_FUNC, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = reply.ReadFileDescriptor(); + inoutParam = reply.ReadFileDescriptor(); + funcResult = reply.ReadFileDescriptor(); + return ERR_OK; +} +} // namespace test diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt new file mode 100644 index 0000000..9b36d7b --- /dev/null +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FOOPROXY_H +#define TEST_FOOPROXY_H + +#include "ifoo.h" +#include + +namespace test { +class FooProxy : public IRemoteProxy { +public: + explicit FooProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} + + virtual ~FooProxy() + {} + + ErrCode uchar_test_func( + uint8_t inParam, + uint8_t& outParam, + uint8_t inoutParam, + uint8_t& funcResult) override; + + ErrCode ushort_test_func( + uint16_t inParam, + uint16_t& outParam, + uint16_t inoutParam, + uint16_t& funcResult) override; + + ErrCode uint_test_func( + uint32_t inParam, + uint32_t& outParam, + uint32_t inoutParam, + uint32_t& funcResult) override; + + ErrCode ulong_test_func( + uint64_t inParam, + uint64_t& outParam, + uint64_t inoutParam, + uint64_t& funcResult) override; + + ErrCode fd_test_func( + int inParam, + int& outParam, + int inoutParam, + int& funcResult) override; + +private: + static constexpr int32_t COMMAND_UCHAR_TEST_FUNC = MIN_TRANSACTION_ID + 0; + static constexpr int32_t COMMAND_USHORT_TEST_FUNC = MIN_TRANSACTION_ID + 1; + static constexpr int32_t COMMAND_UINT_TEST_FUNC = MIN_TRANSACTION_ID + 2; + static constexpr int32_t COMMAND_ULONG_TEST_FUNC = MIN_TRANSACTION_ID + 3; + static constexpr int32_t COMMAND_FD_TEST_FUNC = MIN_TRANSACTION_ID + 4; + + static inline BrokerDelegator delegator_; +}; +} // namespace test +#endif // TEST_FOOPROXY_H + diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.cpp.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.cpp.txt new file mode 100644 index 0000000..6ca7a8b --- /dev/null +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.cpp.txt @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "foo_stub.h" + +namespace test { +int32_t FooStub::OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) +{ + std::u16string localDescriptor = GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (localDescriptor != remoteDescriptor) { + return ERR_TRANSACTION_FAILED; + } + switch (code) { + case COMMAND_UCHAR_TEST_FUNC: { + uint8_t inParam = data.ReadUint8(); + uint8_t outParam; + uint8_t inoutParam = data.ReadUint8(); + uint8_t result; + ErrCode errCode = uchar_test_func(inParam, outParam, inoutParam, result); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteUint8(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteUint8(inoutParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteUint8(result)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_USHORT_TEST_FUNC: { + uint16_t inParam = data.ReadUint16(); + uint16_t outParam; + uint16_t inoutParam = data.ReadUint16(); + uint16_t result; + ErrCode errCode = ushort_test_func(inParam, outParam, inoutParam, result); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteUint16(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteUint16(inoutParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteUint16(result)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_UINT_TEST_FUNC: { + uint32_t inParam = data.ReadUint32(); + uint32_t outParam; + uint32_t inoutParam = data.ReadUint32(); + uint32_t result; + ErrCode errCode = uint_test_func(inParam, outParam, inoutParam, result); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteUint32(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteUint32(inoutParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteUint32(result)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_ULONG_TEST_FUNC: { + uint64_t inParam = data.ReadUint64(); + uint64_t outParam; + uint64_t inoutParam = data.ReadUint64(); + uint64_t result; + ErrCode errCode = ulong_test_func(inParam, outParam, inoutParam, result); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteUint64(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteUint64(inoutParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteUint64(result)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_FD_TEST_FUNC: { + int inParam = data.ReadFileDescriptor(); + int outParam; + int inoutParam = data.ReadFileDescriptor(); + int result; + ErrCode errCode = fd_test_func(inParam, outParam, inoutParam, result); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteFileDescriptor(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteFileDescriptor(inoutParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteFileDescriptor(result)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + + return ERR_TRANSACTION_FAILED; +} +} // namespace test diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.h.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.h.txt new file mode 100644 index 0000000..046573a --- /dev/null +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.h.txt @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FOOSTUB_H +#define TEST_FOOSTUB_H + +#include "ifoo.h" +#include + +namespace test { +class FooStub : public IRemoteStub { +public: + int32_t OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) override; + +private: + static constexpr int32_t COMMAND_UCHAR_TEST_FUNC = MIN_TRANSACTION_ID + 0; + static constexpr int32_t COMMAND_USHORT_TEST_FUNC = MIN_TRANSACTION_ID + 1; + static constexpr int32_t COMMAND_UINT_TEST_FUNC = MIN_TRANSACTION_ID + 2; + static constexpr int32_t COMMAND_ULONG_TEST_FUNC = MIN_TRANSACTION_ID + 3; + static constexpr int32_t COMMAND_FD_TEST_FUNC = MIN_TRANSACTION_ID + 4; +}; +} // namespace test +#endif // TEST_FOOSTUB_H + diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt new file mode 100644 index 0000000..d6612c8 --- /dev/null +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_IFOO_H +#define TEST_IFOO_H + +#include +#include +#include + +namespace test { +class IFoo : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); + + virtual ErrCode uchar_test_func( + uint8_t inParam, + uint8_t& outParam, + uint8_t inoutParam, + uint8_t& funcResult) = 0; + + virtual ErrCode ushort_test_func( + uint16_t inParam, + uint16_t& outParam, + uint16_t inoutParam, + uint16_t& funcResult) = 0; + + virtual ErrCode uint_test_func( + uint32_t inParam, + uint32_t& outParam, + uint32_t inoutParam, + uint32_t& funcResult) = 0; + + virtual ErrCode ulong_test_func( + uint64_t inParam, + uint64_t& outParam, + uint64_t inoutParam, + uint64_t& funcResult) = 0; + + virtual ErrCode fd_test_func( + int inParam, + int& outParam, + int inoutParam, + int& funcResult) = 0; +protected: + const int VECTOR_MAX_SIZE = 102400; + const int LIST_MAX_SIZE = 102400; + const int MAP_MAX_SIZE = 102400; +}; +} // namespace test +#endif // TEST_IFOO_H + -- Gitee From 4c8439cf46e2668f6e7b974216c1d6114cc2eb8c Mon Sep 17 00:00:00 2001 From: wenyu Date: Mon, 18 Nov 2024 17:04:55 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9=20IRemoteObje?= =?UTF-8?q?ct=20=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B=E7=9A=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81=EF=BC=8C=E8=A1=A5=E5=85=85=E5=B7=B2=E4=B8=8A=E7=BA=BF?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=20IDL=20=E6=96=87=E4=BB=B6=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wenyu --- .../SA/cpp/sa_cpp_interface_code_emitter.cpp | 6 + .../cpp/sa_cpp_service_stub_code_emitter.cpp | 7 +- .../codegen/SA/type/sa_seq_type_emitter.cpp | 91 ++- .../cmd_hitrace_tag/target/foo_stub.cpp.txt | 4 +- .../target/foo_stub.cpp.txt | 4 +- .../cmd_save_metadata/target/foo_stub.cpp.txt | 4 +- test/sa_test/in_use_idl.py | 44 ++ .../in_use_idl/foo/IAppFwkUpdateService.idl | 18 + test/sa_test/in_use_idl/foo/IEsimService.idl | 69 ++ .../in_use_idl/foo/IIdlTestService.idl | 19 + .../in_use_idl/foo/IQuickFixManager.idl | 22 + .../in_use_idl/foo/ITestServerInterface.idl | 23 + .../app_fwk_update_service_proxy.cpp.txt | 58 ++ .../app_fwk_update_service_proxy.h.txt | 47 ++ .../app_fwk_update_service_stub.cpp.txt | 54 ++ .../app_fwk_update_service_stub.h.txt | 38 + .../target_cpp/esim_service_proxy.cpp.txt | 688 ++++++++++++++++++ .../target_cpp/esim_service_proxy.h.txt | 142 ++++ .../target_cpp/esim_service_stub.cpp.txt | 300 ++++++++ .../target_cpp/esim_service_stub.h.txt | 54 ++ .../target_cpp/iapp_fwk_update_service.h.txt | 41 ++ .../target_cpp/idl_test_service_proxy.cpp.txt | 82 +++ .../target_cpp/idl_test_service_proxy.h.txt | 47 ++ .../target_cpp/idl_test_service_stub.cpp.txt | 53 ++ .../target_cpp/idl_test_service_stub.h.txt | 37 + .../in_use_idl/target_cpp/iesim_service.h.txt | 137 ++++ .../target_cpp/iidl_test_service.h.txt | 40 + .../target_cpp/iquick_fix_manager.h.txt | 51 ++ .../target_cpp/itest_server_interface.h.txt | 51 ++ .../quick_fix_manager_proxy.cpp.txt | 132 ++++ .../target_cpp/quick_fix_manager_proxy.h.txt | 55 ++ .../target_cpp/quick_fix_manager_stub.cpp.txt | 78 ++ .../target_cpp/quick_fix_manager_stub.h.txt | 40 + .../test_server_interface_proxy.cpp.txt | 118 +++ .../test_server_interface_proxy.h.txt | 54 ++ .../test_server_interface_stub.cpp.txt | 77 ++ .../test_server_interface_stub.h.txt | 40 + .../target_cpp/foo_stub.cpp.txt | 8 +- .../type_array/target_cpp/foo_proxy.cpp.txt | 6 +- .../type_array/target_cpp/foo_stub.cpp.txt | 4 +- .../type_list/target_cpp/foo_proxy.cpp.txt | 6 +- .../type_list/target_cpp/foo_stub.cpp.txt | 4 +- .../type_map/target_cpp/foo_proxy.cpp.txt | 12 +- .../type_map/target_cpp/foo_stub.cpp.txt | 8 +- .../type_single/target_cpp/foo_stub.cpp.txt | 4 +- .../type_single_unsigned_fd/foo/IFoo.idl | 3 + .../target_cpp/foo_proxy.cpp.txt | 44 ++ .../target_cpp/foo_proxy.h.txt | 7 + .../target_cpp/foo_stub.cpp.txt | 30 + .../target_cpp/foo_stub.h.txt | 1 + .../target_cpp/ifoo.h.txt | 6 + 51 files changed, 2908 insertions(+), 60 deletions(-) create mode 100644 test/sa_test/in_use_idl.py create mode 100644 test/sa_test/in_use_idl/foo/IAppFwkUpdateService.idl create mode 100644 test/sa_test/in_use_idl/foo/IEsimService.idl create mode 100644 test/sa_test/in_use_idl/foo/IIdlTestService.idl create mode 100644 test/sa_test/in_use_idl/foo/IQuickFixManager.idl create mode 100644 test/sa_test/in_use_idl/foo/ITestServerInterface.idl create mode 100644 test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.cpp.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.h.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_stub.cpp.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_stub.h.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/esim_service_proxy.cpp.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/esim_service_proxy.h.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/esim_service_stub.cpp.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/esim_service_stub.h.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/iapp_fwk_update_service.h.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.cpp.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.h.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/idl_test_service_stub.cpp.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/idl_test_service_stub.h.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/iesim_service.h.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/iidl_test_service.h.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/iquick_fix_manager.h.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/itest_server_interface.h.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.cpp.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.h.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/quick_fix_manager_stub.cpp.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/quick_fix_manager_stub.h.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.cpp.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.h.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/test_server_interface_stub.cpp.txt create mode 100644 test/sa_test/in_use_idl/target_cpp/test_server_interface_stub.h.txt diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp b/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp index 8568249..5c0376e 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp @@ -108,6 +108,9 @@ void SaCppInterfaceCodeEmitter::EmitInterfaceSelfDefinedTypeInclusions(HeaderFil int sequenceableNumber = static_cast(ast_->GetSequenceableDefNumber()); for (int i = 0; i < sequenceableNumber; i++) { AutoPtr seqType = ast_->GetSequenceableDef(i); + if (seqType->GetName() == "IRemoteObject") { + continue; + } filePath = GetFilePathNoPoint(seqType->GetNamespace()->ToString()); fileName = filePath.empty() ? FileName(seqType->GetName()) : FileName(filePath); headerFiles.emplace(HeaderFileType::OWN_MODULE_HEADER_FILE, fileName); @@ -133,6 +136,9 @@ bool SaCppInterfaceCodeEmitter::EmitInterfaceUsings(StringBuilder &sb) const int sequenceableNumber = static_cast(ast_->GetSequenceableDefNumber()); for (int i = 0; i < sequenceableNumber; i++) { AutoPtr seqType = ast_->GetSequenceableDef(i); + if (seqType->GetName() == "IRemoteObject") { + continue; + } np = GetNamespace(seqType->GetNamespace()->ToString()); if (np.empty()) { continue; diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp b/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp index e092176..11bdadf 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp @@ -189,7 +189,12 @@ void SaCppServiceStubCodeEmitter::EmitInterfaceStubMethodCall(AutoPtr const std::string name = param->GetName(); AutoPtr type = param->GetType(); if ((type->GetTypeKind() == TypeKind::TYPE_SEQUENCEABLE) && (param->GetAttribute() & ASTParamAttr::PARAM_IN)) { - const std::string parameterName = "*" + name; + std::string parameterName = "*" + name; + if (type->GetName() == "IRemoteObject") { + parameterName = name; + } else { + parameterName = "*" + name; + } sb.Append(parameterName.c_str()); } else { sb.Append(name.c_str()); diff --git a/idl_tool_2/codegen/SA/type/sa_seq_type_emitter.cpp b/idl_tool_2/codegen/SA/type/sa_seq_type_emitter.cpp index 1fd3f20..69433f2 100644 --- a/idl_tool_2/codegen/SA/type/sa_seq_type_emitter.cpp +++ b/idl_tool_2/codegen/SA/type/sa_seq_type_emitter.cpp @@ -24,18 +24,34 @@ TypeKind SaSeqTypeEmitter::GetTypeKind() std::string SaSeqTypeEmitter::EmitCppType(TypeMode mode) const { - switch (mode) { - case TypeMode::NO_MODE: - case TypeMode::PARAM_IN: - return StringHelper::Format("const %s&", typeName_.c_str()); - case TypeMode::PARAM_INOUT: - return StringHelper::Format("%s*", typeName_.c_str()); - case TypeMode::PARAM_OUT: - return StringHelper::Format("%s&", typeName_.c_str()); - case TypeMode::LOCAL_VAR: - return StringHelper::Format("%s", typeName_.c_str()); - default: - return "unknown type"; + if (typeName_ == "IRemoteObject") { + switch (mode) { + case TypeMode::PARAM_IN: + return StringHelper::Format("const sptr<%s>&", typeName_.c_str()); + case TypeMode::PARAM_INOUT: + return StringHelper::Format("sptr<%s>&", typeName_.c_str()); + case TypeMode::PARAM_OUT: + return StringHelper::Format("sptr<%s>&", typeName_.c_str()); + case TypeMode::NO_MODE: + case TypeMode::LOCAL_VAR: + return StringHelper::Format("sptr<%s>", typeName_.c_str()); + default: + return "unknown type"; + } + } else { + switch (mode) { + case TypeMode::NO_MODE: + case TypeMode::PARAM_IN: + return StringHelper::Format("const %s&", typeName_.c_str()); + case TypeMode::PARAM_INOUT: + return StringHelper::Format("%s*", typeName_.c_str()); + case TypeMode::PARAM_OUT: + return StringHelper::Format("%s&", typeName_.c_str()); + case TypeMode::LOCAL_VAR: + return StringHelper::Format("%s", typeName_.c_str()); + default: + return "unknown type"; + } } } @@ -52,7 +68,11 @@ std::string SaSeqTypeEmitter::EmitTsType(TypeMode mode) const void SaSeqTypeEmitter::EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, const std::string &prefix) const { - sb.Append(prefix).AppendFormat("if (!%sWriteParcelable(&%s)) {\n", parcelName.c_str(), name.c_str()); + if (typeName_ == "IRemoteObject") { + sb.Append(prefix).AppendFormat("if (!%sWriteRemoteObject(%s)) {\n", parcelName.c_str(), name.c_str()); + } else { + sb.Append(prefix).AppendFormat("if (!%sWriteParcelable(&%s)) {\n", parcelName.c_str(), name.c_str()); + } if (logOn_) { sb.Append(prefix).Append(TAB).AppendFormat("HiLog::Error(LABEL, \"Write [%s] failed!\");\n", name.c_str()); } @@ -63,22 +83,39 @@ void SaSeqTypeEmitter::EmitCppWriteVar(const std::string &parcelName, const std: void SaSeqTypeEmitter::EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, const std::string &prefix, bool emitType) const { - if (emitType) { - sb.Append(prefix).AppendFormat("std::unique_ptr<%s> %s(%sReadParcelable<%s>());\n\n", - typeName_.c_str(), name.c_str(), parcelName.c_str(), typeName_.c_str()); - sb.Append(prefix).AppendFormat("if (!%s) {\n", name.c_str()); - if (logOn_) { - sb.Append(prefix).Append(TAB).AppendFormat( - "HiLog::Error(LABEL, \"Read [%s] failed!\");\n", typeName_.c_str()); + if (typeName_ == "IRemoteObject") { + if (emitType) { + sb.Append(prefix).AppendFormat("sptr<%s> %s = %sReadRemoteObject();\n", + typeName_.c_str(), name.c_str(), parcelName.c_str(), typeName_.c_str()); + sb.Append(prefix).AppendFormat("if (!%s) {\n", name.c_str()); + if (logOn_) { + sb.Append(prefix).Append(TAB).AppendFormat( + "HiLog::Error(LABEL, \"Read [%s] failed!\");\n", typeName_.c_str()); + } + sb.Append(prefix).Append(TAB).Append("return ERR_INVALID_DATA;\n"); + sb.Append(prefix).Append("}\n\n"); + } else { + sb.Append(prefix).AppendFormat("%s = %sReadRemoteObject();\n\n", + name.c_str(), parcelName.c_str()); } - sb.Append(prefix).Append(TAB).Append("return ERR_INVALID_DATA;\n"); - sb.Append(prefix).Append("}\n"); } else { - sb.Append(prefix).AppendFormat("std::unique_ptr<%s> %sInfo(%sReadParcelable<%s>());\n", typeName_.c_str(), - name.c_str(), parcelName.c_str(), typeName_.c_str()); - sb.Append(prefix).AppendFormat("if (%sInfo != nullptr) {\n", name.c_str()); - sb.Append(prefix).Append(TAB).AppendFormat("%s = *%sInfo;\n", name.c_str(), name.c_str()); - sb.Append(prefix).Append("}\n\n"); + if (emitType) { + sb.Append(prefix).AppendFormat("std::unique_ptr<%s> %s(%sReadParcelable<%s>());\n", + typeName_.c_str(), name.c_str(), parcelName.c_str(), typeName_.c_str()); + sb.Append(prefix).AppendFormat("if (!%s) {\n", name.c_str()); + if (logOn_) { + sb.Append(prefix).Append(TAB).AppendFormat( + "HiLog::Error(LABEL, \"Read [%s] failed!\");\n", typeName_.c_str()); + } + sb.Append(prefix).Append(TAB).Append("return ERR_INVALID_DATA;\n"); + sb.Append(prefix).Append("}\n\n"); + } else { + sb.Append(prefix).AppendFormat("std::unique_ptr<%s> %sInfo(%sReadParcelable<%s>());\n", + typeName_.c_str(), name.c_str(), parcelName.c_str(), typeName_.c_str()); + sb.Append(prefix).AppendFormat("if (%sInfo != nullptr) {\n", name.c_str()); + sb.Append(prefix).Append(TAB).AppendFormat("%s = *%sInfo;\n", name.c_str(), name.c_str()); + sb.Append(prefix).Append("}\n\n"); + } } } diff --git a/test/sa_test/cmd_hitrace_tag/target/foo_stub.cpp.txt b/test/sa_test/cmd_hitrace_tag/target/foo_stub.cpp.txt index 6c80989..ab46269 100644 --- a/test/sa_test/cmd_hitrace_tag/target/foo_stub.cpp.txt +++ b/test/sa_test/cmd_hitrace_tag/target/foo_stub.cpp.txt @@ -235,16 +235,16 @@ int32_t FooStub::OnRemoteRequest( } case COMMAND_SEQ_TEST_FUNC: { std::unique_ptr inParam(data.ReadParcelable()); - if (!inParam) { return ERR_INVALID_DATA; } + myseq outParam; std::unique_ptr inoutParam(data.ReadParcelable()); - if (!inoutParam) { return ERR_INVALID_DATA; } + const myseq& result = nullptr; ErrCode errCode = seq_test_func(*inParam, outParam, *inoutParam, result); if (!reply.WriteInt32(errCode)) { diff --git a/test/sa_test/cmd_log_tag_domainid/target/foo_stub.cpp.txt b/test/sa_test/cmd_log_tag_domainid/target/foo_stub.cpp.txt index 9a26ed1..adee1dd 100644 --- a/test/sa_test/cmd_log_tag_domainid/target/foo_stub.cpp.txt +++ b/test/sa_test/cmd_log_tag_domainid/target/foo_stub.cpp.txt @@ -275,18 +275,18 @@ int32_t FooStub::OnRemoteRequest( } case COMMAND_SEQ_TEST_FUNC: { std::unique_ptr inParam(data.ReadParcelable()); - if (!inParam) { HiLog::Error(LABEL, "Read [myseq] failed!"); return ERR_INVALID_DATA; } + myseq outParam; std::unique_ptr inoutParam(data.ReadParcelable()); - if (!inoutParam) { HiLog::Error(LABEL, "Read [myseq] failed!"); return ERR_INVALID_DATA; } + const myseq& result = nullptr; ErrCode errCode = seq_test_func(*inParam, outParam, *inoutParam, result); if (!reply.WriteInt32(errCode)) { diff --git a/test/sa_test/cmd_save_metadata/target/foo_stub.cpp.txt b/test/sa_test/cmd_save_metadata/target/foo_stub.cpp.txt index 6c80989..ab46269 100644 --- a/test/sa_test/cmd_save_metadata/target/foo_stub.cpp.txt +++ b/test/sa_test/cmd_save_metadata/target/foo_stub.cpp.txt @@ -235,16 +235,16 @@ int32_t FooStub::OnRemoteRequest( } case COMMAND_SEQ_TEST_FUNC: { std::unique_ptr inParam(data.ReadParcelable()); - if (!inParam) { return ERR_INVALID_DATA; } + myseq outParam; std::unique_ptr inoutParam(data.ReadParcelable()); - if (!inoutParam) { return ERR_INVALID_DATA; } + const myseq& result = nullptr; ErrCode errCode = seq_test_func(*inParam, outParam, *inoutParam, result); if (!reply.WriteInt32(errCode)) { diff --git a/test/sa_test/in_use_idl.py b/test/sa_test/in_use_idl.py new file mode 100644 index 0000000..06bcefd --- /dev/null +++ b/test/sa_test/in_use_idl.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import os + +from test_base import Test + + +class InUseIdl(Test): + def get_file_name(self): + return __file__ + + def update_command(self): + files = os.listdir(f'{self.working_dir}/foo') + idl_files = [] + for file in files: + idl_files.append(os.path.realpath(f'{self.working_dir}/foo/{file}')) + self.command = self._command_format.format(self._idl, self._gen_langauge, ' '.join(idl_files), self.output_dir) + + def run_cpp(self): + self.set_gen_cpp_env() + return self.run_choose(True) + + def run(self): + return self.run_cpp() + + +if __name__ == "__main__": + InUseIdl().test() diff --git a/test/sa_test/in_use_idl/foo/IAppFwkUpdateService.idl b/test/sa_test/in_use_idl/foo/IAppFwkUpdateService.idl new file mode 100644 index 0000000..ba8b539 --- /dev/null +++ b/test/sa_test/in_use_idl/foo/IAppFwkUpdateService.idl @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +interface OHOS.NWeb.IAppFwkUpdateService { + void VerifyPackageInstall([in] String bundleName, [in] String hapPath, [out] int success); +} diff --git a/test/sa_test/in_use_idl/foo/IEsimService.idl b/test/sa_test/in_use_idl/foo/IEsimService.idl new file mode 100644 index 0000000..cd42332 --- /dev/null +++ b/test/sa_test/in_use_idl/foo/IEsimService.idl @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +sequenceable download_profile_config_info_parcel..OHOS.Telephony.DownloadProfileConfigInfo; +sequenceable download_profile_result_parcel..OHOS.Telephony.DownloadableProfile; +sequenceable downloadable_profile_parcel..OHOS.Telephony.DownloadProfileResult; +sequenceable euicc_info_parcel..OHOS.Telephony.EuiccInfo; +sequenceable get_downloadable_profiles_result_parcel..OHOS.Telephony.GetDownloadableProfileMetadataResult; +sequenceable profile_info_list_parcel..OHOS.Telephony.GetDownloadableProfilesResult; +sequenceable profile_metadata_result_parcel..OHOS.Telephony.GetEuiccProfileInfoListResult; +sequenceable response_esim_result..OHOS.Telephony.ResponseEsimResult; + +interface OHOS.Telephony.IEsimService { + void GetEid([in] int slotId, [out] String eId); + void GetOsuStatus([in] int slotId, [out] int osuStatus); + void StartOsu([in] int slotId, [out] int startOsuResult); + void GetDownloadableProfileMetadata( + [in] int slotId, + [in] int portIndex, + [in] DownloadableProfile profile, + [in] boolean forceDisableProfile, + [out] GetDownloadableProfileMetadataResult profileMetadataResult); + void GetDownloadableProfiles( + [in] int slotId, + [in] int portIndex, + [in] boolean forceDisableProfile, + [out] GetDownloadableProfilesResult profileListResult); + void DownloadProfile( + [in] int slotId, + [in] DownloadProfileConfigInfo configInfo, + [in] DownloadableProfile profile, + [out] DownloadProfileResult downloadProfileResult); + void GetEuiccProfileInfoList([in] int slotId, [out] GetEuiccProfileInfoListResult euiccProfileInfoList); + void GetEuiccInfo([in] int slotId, [out] EuiccInfo eUiccInfo); + void DeleteProfile([in] int slotId, [in] String iccId, [out] int deleteProfileResult); + void SwitchToProfile( + [in] int slotId, + [in] int portIndex, + [in] String iccId, + [in] boolean forceDisableProfile, + [out] int switchToProfileResult); + void SetProfileNickname( + [in] int slotId, + [in] String iccId, + [in] String nickname, + [out] int setProfileNicknameResult); + void ResetMemory([in] int slotId, [in] int resetOption, [out] int resetMemoryResult); + void ReserveProfilesForFactoryRestore([in] int slotId, [out] int restoreResult); + void SetDefaultSmdpAddress( + [in] int slotId, + [in] String defaultSmdpAddress, + [out] int setDefaultSmdpAddressResult); + void GetDefaultSmdpAddress([in] int slotId, [out] String defaultSmdpAddress); + void CancelSession([in] int slotId, [in] String transactionId, [in] int cancelReason, + [out] ResponseEsimResult responseResult); + void IsEsimSupported([in] int slotId); +} \ No newline at end of file diff --git a/test/sa_test/in_use_idl/foo/IIdlTestService.idl b/test/sa_test/in_use_idl/foo/IIdlTestService.idl new file mode 100644 index 0000000..b3f00cc --- /dev/null +++ b/test/sa_test/in_use_idl/foo/IIdlTestService.idl @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +interface OHOS.IIdlTestService { + void TestIntTransaction([in] int val); + void TestStringTransaction([in] String val); +} diff --git a/test/sa_test/in_use_idl/foo/IQuickFixManager.idl b/test/sa_test/in_use_idl/foo/IQuickFixManager.idl new file mode 100644 index 0000000..0c4589a --- /dev/null +++ b/test/sa_test/in_use_idl/foo/IQuickFixManager.idl @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +sequenceable QuickFixInfo..OHOS.AAFwk.ApplicationQuickFixInfo; + +interface OHOS.AAFwk.IQuickFixManager { + void ApplyQuickFix([in] String[] quickFixFiles, [in] boolean isDebug); + void GetApplyedQuickFixInfo([in] String bundleName, [out] ApplicationQuickFixInfo quickFixInfo); + void RevokeQuickFix([in] String bundleName); +} \ No newline at end of file diff --git a/test/sa_test/in_use_idl/foo/ITestServerInterface.idl b/test/sa_test/in_use_idl/foo/ITestServerInterface.idl new file mode 100644 index 0000000..8ee3e61 --- /dev/null +++ b/test/sa_test/in_use_idl/foo/ITestServerInterface.idl @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +sequenceable SessionToken..OHOS.testserver.SessionToken; +sequenceable CommonEventData..OHOS.EventFwk.CommonEventData; + +interface OHOS.testserver.ITestServerInterface { + void CreateSession([in] SessionToken sessionToken); + void SetPasteData([in] String text); + void PublishCommonEvent([in] CommonEventData event, [out] boolean re); +} diff --git a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.cpp.txt new file mode 100644 index 0000000..a0220af --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.cpp.txt @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "app_fwk_update_service_proxy.h" + +namespace OHOS { +namespace NWeb { +ErrCode AppFwkUpdateServiceProxy::VerifyPackageInstall( + const std::string& bundleName, + const std::string& hapPath, + int32_t& success) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(bundleName))) { + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(hapPath))) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_VERIFY_PACKAGE_INSTALL, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + success = reply.ReadInt32(); + return ERR_OK; +} +} // namespace NWeb +} // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.h.txt new file mode 100644 index 0000000..33e20d5 --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.h.txt @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_NWEB_APPFWKUPDATESERVICEPROXY_H +#define OHOS_NWEB_APPFWKUPDATESERVICEPROXY_H + +#include "iapp_fwk_update_service.h" +#include + +namespace OHOS { +namespace NWeb { +class AppFwkUpdateServiceProxy : public IRemoteProxy { +public: + explicit AppFwkUpdateServiceProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} + + virtual ~AppFwkUpdateServiceProxy() + {} + + ErrCode VerifyPackageInstall( + const std::string& bundleName, + const std::string& hapPath, + int32_t& success) override; + +private: + static constexpr int32_t COMMAND_VERIFY_PACKAGE_INSTALL = MIN_TRANSACTION_ID + 0; + + static inline BrokerDelegator delegator_; +}; +} // namespace NWeb +} // namespace OHOS +#endif // OHOS_NWEB_APPFWKUPDATESERVICEPROXY_H + diff --git a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_stub.cpp.txt b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_stub.cpp.txt new file mode 100644 index 0000000..565d956 --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_stub.cpp.txt @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "app_fwk_update_service_stub.h" + +namespace OHOS { +namespace NWeb { +int32_t AppFwkUpdateServiceStub::OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) +{ + std::u16string localDescriptor = GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (localDescriptor != remoteDescriptor) { + return ERR_TRANSACTION_FAILED; + } + switch (code) { + case COMMAND_VERIFY_PACKAGE_INSTALL: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + std::string hapPath = Str16ToStr8(data.ReadString16()); + int32_t success; + ErrCode errCode = VerifyPackageInstall(bundleName, hapPath, success); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(success)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + + return ERR_TRANSACTION_FAILED; +} +} // namespace NWeb +} // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_stub.h.txt b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_stub.h.txt new file mode 100644 index 0000000..369de91 --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_stub.h.txt @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_NWEB_APPFWKUPDATESERVICESTUB_H +#define OHOS_NWEB_APPFWKUPDATESERVICESTUB_H + +#include "iapp_fwk_update_service.h" +#include + +namespace OHOS { +namespace NWeb { +class AppFwkUpdateServiceStub : public IRemoteStub { +public: + int32_t OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) override; + +private: + static constexpr int32_t COMMAND_VERIFY_PACKAGE_INSTALL = MIN_TRANSACTION_ID + 0; +}; +} // namespace NWeb +} // namespace OHOS +#endif // OHOS_NWEB_APPFWKUPDATESERVICESTUB_H + diff --git a/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.cpp.txt new file mode 100644 index 0000000..b151a61 --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.cpp.txt @@ -0,0 +1,688 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "esim_service_proxy.h" + +namespace OHOS { +namespace Telephony { +ErrCode EsimServiceProxy::GetEid( + int32_t slotId, + std::string& eId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(slotId)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_GET_EID, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + eId = Str16ToStr8(reply.ReadString16()); + return ERR_OK; +} + +ErrCode EsimServiceProxy::GetOsuStatus( + int32_t slotId, + int32_t& osuStatus) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(slotId)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_GET_OSU_STATUS, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + osuStatus = reply.ReadInt32(); + return ERR_OK; +} + +ErrCode EsimServiceProxy::StartOsu( + int32_t slotId, + int32_t& startOsuResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(slotId)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_START_OSU, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + startOsuResult = reply.ReadInt32(); + return ERR_OK; +} + +ErrCode EsimServiceProxy::GetDownloadableProfileMetadata( + int32_t slotId, + int32_t portIndex, + const DownloadableProfile& profile, + bool forceDisableProfile, + GetDownloadableProfileMetadataResult& profileMetadataResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(slotId)) { + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(portIndex)) { + return ERR_INVALID_DATA; + } + if (!data.WriteParcelable(&profile)) { + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(forceDisableProfile ? 1 : 0)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_GET_DOWNLOADABLE_PROFILE_METADATA, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + std::unique_ptr profileMetadataResultInfo(reply.ReadParcelable()); + if (profileMetadataResultInfo != nullptr) { + profileMetadataResult = *profileMetadataResultInfo; + } + + return ERR_OK; +} + +ErrCode EsimServiceProxy::GetDownloadableProfiles( + int32_t slotId, + int32_t portIndex, + bool forceDisableProfile, + GetDownloadableProfilesResult& profileListResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(slotId)) { + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(portIndex)) { + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(forceDisableProfile ? 1 : 0)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_GET_DOWNLOADABLE_PROFILES, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + std::unique_ptr profileListResultInfo(reply.ReadParcelable()); + if (profileListResultInfo != nullptr) { + profileListResult = *profileListResultInfo; + } + + return ERR_OK; +} + +ErrCode EsimServiceProxy::DownloadProfile( + int32_t slotId, + const DownloadProfileConfigInfo& configInfo, + const DownloadableProfile& profile, + DownloadProfileResult& downloadProfileResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(slotId)) { + return ERR_INVALID_DATA; + } + if (!data.WriteParcelable(&configInfo)) { + return ERR_INVALID_DATA; + } + if (!data.WriteParcelable(&profile)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_DOWNLOAD_PROFILE, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + std::unique_ptr downloadProfileResultInfo(reply.ReadParcelable()); + if (downloadProfileResultInfo != nullptr) { + downloadProfileResult = *downloadProfileResultInfo; + } + + return ERR_OK; +} + +ErrCode EsimServiceProxy::GetEuiccProfileInfoList( + int32_t slotId, + GetEuiccProfileInfoListResult& euiccProfileInfoList) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(slotId)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_GET_EUICC_PROFILE_INFO_LIST, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + std::unique_ptr euiccProfileInfoListInfo(reply.ReadParcelable()); + if (euiccProfileInfoListInfo != nullptr) { + euiccProfileInfoList = *euiccProfileInfoListInfo; + } + + return ERR_OK; +} + +ErrCode EsimServiceProxy::GetEuiccInfo( + int32_t slotId, + EuiccInfo& eUiccInfo) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(slotId)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_GET_EUICC_INFO, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + std::unique_ptr eUiccInfoInfo(reply.ReadParcelable()); + if (eUiccInfoInfo != nullptr) { + eUiccInfo = *eUiccInfoInfo; + } + + return ERR_OK; +} + +ErrCode EsimServiceProxy::DeleteProfile( + int32_t slotId, + const std::string& iccId, + int32_t& deleteProfileResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(slotId)) { + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(iccId))) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_DELETE_PROFILE, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + deleteProfileResult = reply.ReadInt32(); + return ERR_OK; +} + +ErrCode EsimServiceProxy::SwitchToProfile( + int32_t slotId, + int32_t portIndex, + const std::string& iccId, + bool forceDisableProfile, + int32_t& switchToProfileResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(slotId)) { + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(portIndex)) { + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(iccId))) { + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(forceDisableProfile ? 1 : 0)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_SWITCH_TO_PROFILE, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + switchToProfileResult = reply.ReadInt32(); + return ERR_OK; +} + +ErrCode EsimServiceProxy::SetProfileNickname( + int32_t slotId, + const std::string& iccId, + const std::string& nickname, + int32_t& setProfileNicknameResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(slotId)) { + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(iccId))) { + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(nickname))) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_SET_PROFILE_NICKNAME, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + setProfileNicknameResult = reply.ReadInt32(); + return ERR_OK; +} + +ErrCode EsimServiceProxy::ResetMemory( + int32_t slotId, + int32_t resetOption, + int32_t& resetMemoryResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(slotId)) { + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(resetOption)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_RESET_MEMORY, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + resetMemoryResult = reply.ReadInt32(); + return ERR_OK; +} + +ErrCode EsimServiceProxy::ReserveProfilesForFactoryRestore( + int32_t slotId, + int32_t& restoreResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(slotId)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_RESERVE_PROFILES_FOR_FACTORY_RESTORE, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + restoreResult = reply.ReadInt32(); + return ERR_OK; +} + +ErrCode EsimServiceProxy::SetDefaultSmdpAddress( + int32_t slotId, + const std::string& defaultSmdpAddress, + int32_t& setDefaultSmdpAddressResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(slotId)) { + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(defaultSmdpAddress))) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_SET_DEFAULT_SMDP_ADDRESS, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + setDefaultSmdpAddressResult = reply.ReadInt32(); + return ERR_OK; +} + +ErrCode EsimServiceProxy::GetDefaultSmdpAddress( + int32_t slotId, + std::string& defaultSmdpAddress) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(slotId)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_GET_DEFAULT_SMDP_ADDRESS, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + defaultSmdpAddress = Str16ToStr8(reply.ReadString16()); + return ERR_OK; +} + +ErrCode EsimServiceProxy::CancelSession( + int32_t slotId, + const std::string& transactionId, + int32_t cancelReason, + ResponseEsimResult& responseResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(slotId)) { + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(transactionId))) { + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(cancelReason)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_CANCEL_SESSION, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + std::unique_ptr responseResultInfo(reply.ReadParcelable()); + if (responseResultInfo != nullptr) { + responseResult = *responseResultInfo; + } + + return ERR_OK; +} + +ErrCode EsimServiceProxy::IsEsimSupported( + int32_t slotId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(slotId)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_IS_ESIM_SUPPORTED, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + return ERR_OK; +} +} // namespace Telephony +} // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.h.txt new file mode 100644 index 0000000..87ab698 --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.h.txt @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_TELEPHONY_ESIMSERVICEPROXY_H +#define OHOS_TELEPHONY_ESIMSERVICEPROXY_H + +#include "iesim_service.h" +#include + +namespace OHOS { +namespace Telephony { +class EsimServiceProxy : public IRemoteProxy { +public: + explicit EsimServiceProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} + + virtual ~EsimServiceProxy() + {} + + ErrCode GetEid( + int32_t slotId, + std::string& eId) override; + + ErrCode GetOsuStatus( + int32_t slotId, + int32_t& osuStatus) override; + + ErrCode StartOsu( + int32_t slotId, + int32_t& startOsuResult) override; + + ErrCode GetDownloadableProfileMetadata( + int32_t slotId, + int32_t portIndex, + const DownloadableProfile& profile, + bool forceDisableProfile, + GetDownloadableProfileMetadataResult& profileMetadataResult) override; + + ErrCode GetDownloadableProfiles( + int32_t slotId, + int32_t portIndex, + bool forceDisableProfile, + GetDownloadableProfilesResult& profileListResult) override; + + ErrCode DownloadProfile( + int32_t slotId, + const DownloadProfileConfigInfo& configInfo, + const DownloadableProfile& profile, + DownloadProfileResult& downloadProfileResult) override; + + ErrCode GetEuiccProfileInfoList( + int32_t slotId, + GetEuiccProfileInfoListResult& euiccProfileInfoList) override; + + ErrCode GetEuiccInfo( + int32_t slotId, + EuiccInfo& eUiccInfo) override; + + ErrCode DeleteProfile( + int32_t slotId, + const std::string& iccId, + int32_t& deleteProfileResult) override; + + ErrCode SwitchToProfile( + int32_t slotId, + int32_t portIndex, + const std::string& iccId, + bool forceDisableProfile, + int32_t& switchToProfileResult) override; + + ErrCode SetProfileNickname( + int32_t slotId, + const std::string& iccId, + const std::string& nickname, + int32_t& setProfileNicknameResult) override; + + ErrCode ResetMemory( + int32_t slotId, + int32_t resetOption, + int32_t& resetMemoryResult) override; + + ErrCode ReserveProfilesForFactoryRestore( + int32_t slotId, + int32_t& restoreResult) override; + + ErrCode SetDefaultSmdpAddress( + int32_t slotId, + const std::string& defaultSmdpAddress, + int32_t& setDefaultSmdpAddressResult) override; + + ErrCode GetDefaultSmdpAddress( + int32_t slotId, + std::string& defaultSmdpAddress) override; + + ErrCode CancelSession( + int32_t slotId, + const std::string& transactionId, + int32_t cancelReason, + ResponseEsimResult& responseResult) override; + + ErrCode IsEsimSupported( + int32_t slotId) override; + +private: + static constexpr int32_t COMMAND_GET_EID = MIN_TRANSACTION_ID + 0; + static constexpr int32_t COMMAND_GET_OSU_STATUS = MIN_TRANSACTION_ID + 1; + static constexpr int32_t COMMAND_START_OSU = MIN_TRANSACTION_ID + 2; + static constexpr int32_t COMMAND_GET_DOWNLOADABLE_PROFILE_METADATA = MIN_TRANSACTION_ID + 3; + static constexpr int32_t COMMAND_GET_DOWNLOADABLE_PROFILES = MIN_TRANSACTION_ID + 4; + static constexpr int32_t COMMAND_DOWNLOAD_PROFILE = MIN_TRANSACTION_ID + 5; + static constexpr int32_t COMMAND_GET_EUICC_PROFILE_INFO_LIST = MIN_TRANSACTION_ID + 6; + static constexpr int32_t COMMAND_GET_EUICC_INFO = MIN_TRANSACTION_ID + 7; + static constexpr int32_t COMMAND_DELETE_PROFILE = MIN_TRANSACTION_ID + 8; + static constexpr int32_t COMMAND_SWITCH_TO_PROFILE = MIN_TRANSACTION_ID + 9; + static constexpr int32_t COMMAND_SET_PROFILE_NICKNAME = MIN_TRANSACTION_ID + 10; + static constexpr int32_t COMMAND_RESET_MEMORY = MIN_TRANSACTION_ID + 11; + static constexpr int32_t COMMAND_RESERVE_PROFILES_FOR_FACTORY_RESTORE = MIN_TRANSACTION_ID + 12; + static constexpr int32_t COMMAND_SET_DEFAULT_SMDP_ADDRESS = MIN_TRANSACTION_ID + 13; + static constexpr int32_t COMMAND_GET_DEFAULT_SMDP_ADDRESS = MIN_TRANSACTION_ID + 14; + static constexpr int32_t COMMAND_CANCEL_SESSION = MIN_TRANSACTION_ID + 15; + static constexpr int32_t COMMAND_IS_ESIM_SUPPORTED = MIN_TRANSACTION_ID + 16; + + static inline BrokerDelegator delegator_; +}; +} // namespace Telephony +} // namespace OHOS +#endif // OHOS_TELEPHONY_ESIMSERVICEPROXY_H + diff --git a/test/sa_test/in_use_idl/target_cpp/esim_service_stub.cpp.txt b/test/sa_test/in_use_idl/target_cpp/esim_service_stub.cpp.txt new file mode 100644 index 0000000..a39c85e --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/esim_service_stub.cpp.txt @@ -0,0 +1,300 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "esim_service_stub.h" + +namespace OHOS { +namespace Telephony { +int32_t EsimServiceStub::OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) +{ + std::u16string localDescriptor = GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (localDescriptor != remoteDescriptor) { + return ERR_TRANSACTION_FAILED; + } + switch (code) { + case COMMAND_GET_EID: { + int32_t slotId = data.ReadInt32(); + std::string eId; + ErrCode errCode = GetEid(slotId, eId); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteString16(Str8ToStr16(eId))) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_GET_OSU_STATUS: { + int32_t slotId = data.ReadInt32(); + int32_t osuStatus; + ErrCode errCode = GetOsuStatus(slotId, osuStatus); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(osuStatus)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_START_OSU: { + int32_t slotId = data.ReadInt32(); + int32_t startOsuResult; + ErrCode errCode = StartOsu(slotId, startOsuResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(startOsuResult)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_GET_DOWNLOADABLE_PROFILE_METADATA: { + int32_t slotId = data.ReadInt32(); + int32_t portIndex = data.ReadInt32(); + std::unique_ptr profile(data.ReadParcelable()); + if (!profile) { + return ERR_INVALID_DATA; + } + + bool forceDisableProfile = data.ReadInt32() == 1 ? true : false; + GetDownloadableProfileMetadataResult profileMetadataResult; + ErrCode errCode = GetDownloadableProfileMetadata(slotId, portIndex, *profile, forceDisableProfile, profileMetadataResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteParcelable(&profileMetadataResult)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_GET_DOWNLOADABLE_PROFILES: { + int32_t slotId = data.ReadInt32(); + int32_t portIndex = data.ReadInt32(); + bool forceDisableProfile = data.ReadInt32() == 1 ? true : false; + GetDownloadableProfilesResult profileListResult; + ErrCode errCode = GetDownloadableProfiles(slotId, portIndex, forceDisableProfile, profileListResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteParcelable(&profileListResult)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_DOWNLOAD_PROFILE: { + int32_t slotId = data.ReadInt32(); + std::unique_ptr configInfo(data.ReadParcelable()); + if (!configInfo) { + return ERR_INVALID_DATA; + } + + std::unique_ptr profile(data.ReadParcelable()); + if (!profile) { + return ERR_INVALID_DATA; + } + + DownloadProfileResult downloadProfileResult; + ErrCode errCode = DownloadProfile(slotId, *configInfo, *profile, downloadProfileResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteParcelable(&downloadProfileResult)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_GET_EUICC_PROFILE_INFO_LIST: { + int32_t slotId = data.ReadInt32(); + GetEuiccProfileInfoListResult euiccProfileInfoList; + ErrCode errCode = GetEuiccProfileInfoList(slotId, euiccProfileInfoList); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteParcelable(&euiccProfileInfoList)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_GET_EUICC_INFO: { + int32_t slotId = data.ReadInt32(); + EuiccInfo eUiccInfo; + ErrCode errCode = GetEuiccInfo(slotId, eUiccInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteParcelable(&eUiccInfo)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_DELETE_PROFILE: { + int32_t slotId = data.ReadInt32(); + std::string iccId = Str16ToStr8(data.ReadString16()); + int32_t deleteProfileResult; + ErrCode errCode = DeleteProfile(slotId, iccId, deleteProfileResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(deleteProfileResult)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_SWITCH_TO_PROFILE: { + int32_t slotId = data.ReadInt32(); + int32_t portIndex = data.ReadInt32(); + std::string iccId = Str16ToStr8(data.ReadString16()); + bool forceDisableProfile = data.ReadInt32() == 1 ? true : false; + int32_t switchToProfileResult; + ErrCode errCode = SwitchToProfile(slotId, portIndex, iccId, forceDisableProfile, switchToProfileResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(switchToProfileResult)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_SET_PROFILE_NICKNAME: { + int32_t slotId = data.ReadInt32(); + std::string iccId = Str16ToStr8(data.ReadString16()); + std::string nickname = Str16ToStr8(data.ReadString16()); + int32_t setProfileNicknameResult; + ErrCode errCode = SetProfileNickname(slotId, iccId, nickname, setProfileNicknameResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(setProfileNicknameResult)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_RESET_MEMORY: { + int32_t slotId = data.ReadInt32(); + int32_t resetOption = data.ReadInt32(); + int32_t resetMemoryResult; + ErrCode errCode = ResetMemory(slotId, resetOption, resetMemoryResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(resetMemoryResult)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_RESERVE_PROFILES_FOR_FACTORY_RESTORE: { + int32_t slotId = data.ReadInt32(); + int32_t restoreResult; + ErrCode errCode = ReserveProfilesForFactoryRestore(slotId, restoreResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(restoreResult)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_SET_DEFAULT_SMDP_ADDRESS: { + int32_t slotId = data.ReadInt32(); + std::string defaultSmdpAddress = Str16ToStr8(data.ReadString16()); + int32_t setDefaultSmdpAddressResult; + ErrCode errCode = SetDefaultSmdpAddress(slotId, defaultSmdpAddress, setDefaultSmdpAddressResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(setDefaultSmdpAddressResult)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_GET_DEFAULT_SMDP_ADDRESS: { + int32_t slotId = data.ReadInt32(); + std::string defaultSmdpAddress; + ErrCode errCode = GetDefaultSmdpAddress(slotId, defaultSmdpAddress); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteString16(Str8ToStr16(defaultSmdpAddress))) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_CANCEL_SESSION: { + int32_t slotId = data.ReadInt32(); + std::string transactionId = Str16ToStr8(data.ReadString16()); + int32_t cancelReason = data.ReadInt32(); + ResponseEsimResult responseResult; + ErrCode errCode = CancelSession(slotId, transactionId, cancelReason, responseResult); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteParcelable(&responseResult)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_IS_ESIM_SUPPORTED: { + int32_t slotId = data.ReadInt32(); + ErrCode errCode = IsEsimSupported(slotId); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + + return ERR_TRANSACTION_FAILED; +} +} // namespace Telephony +} // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/esim_service_stub.h.txt b/test/sa_test/in_use_idl/target_cpp/esim_service_stub.h.txt new file mode 100644 index 0000000..87b1b98 --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/esim_service_stub.h.txt @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_TELEPHONY_ESIMSERVICESTUB_H +#define OHOS_TELEPHONY_ESIMSERVICESTUB_H + +#include "iesim_service.h" +#include + +namespace OHOS { +namespace Telephony { +class EsimServiceStub : public IRemoteStub { +public: + int32_t OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) override; + +private: + static constexpr int32_t COMMAND_GET_EID = MIN_TRANSACTION_ID + 0; + static constexpr int32_t COMMAND_GET_OSU_STATUS = MIN_TRANSACTION_ID + 1; + static constexpr int32_t COMMAND_START_OSU = MIN_TRANSACTION_ID + 2; + static constexpr int32_t COMMAND_GET_DOWNLOADABLE_PROFILE_METADATA = MIN_TRANSACTION_ID + 3; + static constexpr int32_t COMMAND_GET_DOWNLOADABLE_PROFILES = MIN_TRANSACTION_ID + 4; + static constexpr int32_t COMMAND_DOWNLOAD_PROFILE = MIN_TRANSACTION_ID + 5; + static constexpr int32_t COMMAND_GET_EUICC_PROFILE_INFO_LIST = MIN_TRANSACTION_ID + 6; + static constexpr int32_t COMMAND_GET_EUICC_INFO = MIN_TRANSACTION_ID + 7; + static constexpr int32_t COMMAND_DELETE_PROFILE = MIN_TRANSACTION_ID + 8; + static constexpr int32_t COMMAND_SWITCH_TO_PROFILE = MIN_TRANSACTION_ID + 9; + static constexpr int32_t COMMAND_SET_PROFILE_NICKNAME = MIN_TRANSACTION_ID + 10; + static constexpr int32_t COMMAND_RESET_MEMORY = MIN_TRANSACTION_ID + 11; + static constexpr int32_t COMMAND_RESERVE_PROFILES_FOR_FACTORY_RESTORE = MIN_TRANSACTION_ID + 12; + static constexpr int32_t COMMAND_SET_DEFAULT_SMDP_ADDRESS = MIN_TRANSACTION_ID + 13; + static constexpr int32_t COMMAND_GET_DEFAULT_SMDP_ADDRESS = MIN_TRANSACTION_ID + 14; + static constexpr int32_t COMMAND_CANCEL_SESSION = MIN_TRANSACTION_ID + 15; + static constexpr int32_t COMMAND_IS_ESIM_SUPPORTED = MIN_TRANSACTION_ID + 16; +}; +} // namespace Telephony +} // namespace OHOS +#endif // OHOS_TELEPHONY_ESIMSERVICESTUB_H + diff --git a/test/sa_test/in_use_idl/target_cpp/iapp_fwk_update_service.h.txt b/test/sa_test/in_use_idl/target_cpp/iapp_fwk_update_service.h.txt new file mode 100644 index 0000000..30ce753 --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/iapp_fwk_update_service.h.txt @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_NWEB_IAPPFWKUPDATESERVICE_H +#define OHOS_NWEB_IAPPFWKUPDATESERVICE_H + +#include +#include +#include + +namespace OHOS { +namespace NWeb { +class IAppFwkUpdateService : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.NWeb.IAppFwkUpdateService"); + + virtual ErrCode VerifyPackageInstall( + const std::string& bundleName, + const std::string& hapPath, + int32_t& success) = 0; +protected: + const int VECTOR_MAX_SIZE = 102400; + const int LIST_MAX_SIZE = 102400; + const int MAP_MAX_SIZE = 102400; +}; +} // namespace NWeb +} // namespace OHOS +#endif // OHOS_NWEB_IAPPFWKUPDATESERVICE_H + diff --git a/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.cpp.txt new file mode 100644 index 0000000..ffff89d --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.cpp.txt @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "idl_test_service_proxy.h" + +namespace OHOS { +ErrCode IdlTestServiceProxy::TestIntTransaction( + int32_t val) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(val)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_TEST_INT_TRANSACTION, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + return ERR_OK; +} + +ErrCode IdlTestServiceProxy::TestStringTransaction( + const std::string& val) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(val))) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_TEST_STRING_TRANSACTION, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + return ERR_OK; +} +} // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.h.txt new file mode 100644 index 0000000..3d8c19a --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.h.txt @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IDLTESTSERVICEPROXY_H +#define OHOS_IDLTESTSERVICEPROXY_H + +#include "iidl_test_service.h" +#include + +namespace OHOS { +class IdlTestServiceProxy : public IRemoteProxy { +public: + explicit IdlTestServiceProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} + + virtual ~IdlTestServiceProxy() + {} + + ErrCode TestIntTransaction( + int32_t val) override; + + ErrCode TestStringTransaction( + const std::string& val) override; + +private: + static constexpr int32_t COMMAND_TEST_INT_TRANSACTION = MIN_TRANSACTION_ID + 0; + static constexpr int32_t COMMAND_TEST_STRING_TRANSACTION = MIN_TRANSACTION_ID + 1; + + static inline BrokerDelegator delegator_; +}; +} // namespace OHOS +#endif // OHOS_IDLTESTSERVICEPROXY_H + diff --git a/test/sa_test/in_use_idl/target_cpp/idl_test_service_stub.cpp.txt b/test/sa_test/in_use_idl/target_cpp/idl_test_service_stub.cpp.txt new file mode 100644 index 0000000..c6993c5 --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/idl_test_service_stub.cpp.txt @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "idl_test_service_stub.h" + +namespace OHOS { +int32_t IdlTestServiceStub::OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) +{ + std::u16string localDescriptor = GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (localDescriptor != remoteDescriptor) { + return ERR_TRANSACTION_FAILED; + } + switch (code) { + case COMMAND_TEST_INT_TRANSACTION: { + int32_t val = data.ReadInt32(); + ErrCode errCode = TestIntTransaction(val); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case COMMAND_TEST_STRING_TRANSACTION: { + std::string val = Str16ToStr8(data.ReadString16()); + ErrCode errCode = TestStringTransaction(val); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + + return ERR_TRANSACTION_FAILED; +} +} // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/idl_test_service_stub.h.txt b/test/sa_test/in_use_idl/target_cpp/idl_test_service_stub.h.txt new file mode 100644 index 0000000..83ad285 --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/idl_test_service_stub.h.txt @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IDLTESTSERVICESTUB_H +#define OHOS_IDLTESTSERVICESTUB_H + +#include "iidl_test_service.h" +#include + +namespace OHOS { +class IdlTestServiceStub : public IRemoteStub { +public: + int32_t OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) override; + +private: + static constexpr int32_t COMMAND_TEST_INT_TRANSACTION = MIN_TRANSACTION_ID + 0; + static constexpr int32_t COMMAND_TEST_STRING_TRANSACTION = MIN_TRANSACTION_ID + 1; +}; +} // namespace OHOS +#endif // OHOS_IDLTESTSERVICESTUB_H + diff --git a/test/sa_test/in_use_idl/target_cpp/iesim_service.h.txt b/test/sa_test/in_use_idl/target_cpp/iesim_service.h.txt new file mode 100644 index 0000000..c032151 --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/iesim_service.h.txt @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_TELEPHONY_IESIMSERVICE_H +#define OHOS_TELEPHONY_IESIMSERVICE_H + +#include +#include +#include +#include "download_profile_config_info_parcel.h" +#include "download_profile_result_parcel.h" +#include "downloadable_profile_parcel.h" +#include "euicc_info_parcel.h" +#include "get_downloadable_profiles_result_parcel.h" +#include "profile_info_list_parcel.h" +#include "profile_metadata_result_parcel.h" +#include "response_esim_result.h" + +using OHOS::Telephony::DownloadProfileConfigInfo; +using OHOS::Telephony::DownloadableProfile; +using OHOS::Telephony::DownloadProfileResult; +using OHOS::Telephony::EuiccInfo; +using OHOS::Telephony::GetDownloadableProfileMetadataResult; +using OHOS::Telephony::GetDownloadableProfilesResult; +using OHOS::Telephony::GetEuiccProfileInfoListResult; +using OHOS::Telephony::ResponseEsimResult; + +namespace OHOS { +namespace Telephony { +class IEsimService : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Telephony.IEsimService"); + + virtual ErrCode GetEid( + int32_t slotId, + std::string& eId) = 0; + + virtual ErrCode GetOsuStatus( + int32_t slotId, + int32_t& osuStatus) = 0; + + virtual ErrCode StartOsu( + int32_t slotId, + int32_t& startOsuResult) = 0; + + virtual ErrCode GetDownloadableProfileMetadata( + int32_t slotId, + int32_t portIndex, + const DownloadableProfile& profile, + bool forceDisableProfile, + GetDownloadableProfileMetadataResult& profileMetadataResult) = 0; + + virtual ErrCode GetDownloadableProfiles( + int32_t slotId, + int32_t portIndex, + bool forceDisableProfile, + GetDownloadableProfilesResult& profileListResult) = 0; + + virtual ErrCode DownloadProfile( + int32_t slotId, + const DownloadProfileConfigInfo& configInfo, + const DownloadableProfile& profile, + DownloadProfileResult& downloadProfileResult) = 0; + + virtual ErrCode GetEuiccProfileInfoList( + int32_t slotId, + GetEuiccProfileInfoListResult& euiccProfileInfoList) = 0; + + virtual ErrCode GetEuiccInfo( + int32_t slotId, + EuiccInfo& eUiccInfo) = 0; + + virtual ErrCode DeleteProfile( + int32_t slotId, + const std::string& iccId, + int32_t& deleteProfileResult) = 0; + + virtual ErrCode SwitchToProfile( + int32_t slotId, + int32_t portIndex, + const std::string& iccId, + bool forceDisableProfile, + int32_t& switchToProfileResult) = 0; + + virtual ErrCode SetProfileNickname( + int32_t slotId, + const std::string& iccId, + const std::string& nickname, + int32_t& setProfileNicknameResult) = 0; + + virtual ErrCode ResetMemory( + int32_t slotId, + int32_t resetOption, + int32_t& resetMemoryResult) = 0; + + virtual ErrCode ReserveProfilesForFactoryRestore( + int32_t slotId, + int32_t& restoreResult) = 0; + + virtual ErrCode SetDefaultSmdpAddress( + int32_t slotId, + const std::string& defaultSmdpAddress, + int32_t& setDefaultSmdpAddressResult) = 0; + + virtual ErrCode GetDefaultSmdpAddress( + int32_t slotId, + std::string& defaultSmdpAddress) = 0; + + virtual ErrCode CancelSession( + int32_t slotId, + const std::string& transactionId, + int32_t cancelReason, + ResponseEsimResult& responseResult) = 0; + + virtual ErrCode IsEsimSupported( + int32_t slotId) = 0; +protected: + const int VECTOR_MAX_SIZE = 102400; + const int LIST_MAX_SIZE = 102400; + const int MAP_MAX_SIZE = 102400; +}; +} // namespace Telephony +} // namespace OHOS +#endif // OHOS_TELEPHONY_IESIMSERVICE_H + diff --git a/test/sa_test/in_use_idl/target_cpp/iidl_test_service.h.txt b/test/sa_test/in_use_idl/target_cpp/iidl_test_service.h.txt new file mode 100644 index 0000000..947e5f0 --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/iidl_test_service.h.txt @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IIDLTESTSERVICE_H +#define OHOS_IIDLTESTSERVICE_H + +#include +#include +#include + +namespace OHOS { +class IIdlTestService : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IIdlTestService"); + + virtual ErrCode TestIntTransaction( + int32_t val) = 0; + + virtual ErrCode TestStringTransaction( + const std::string& val) = 0; +protected: + const int VECTOR_MAX_SIZE = 102400; + const int LIST_MAX_SIZE = 102400; + const int MAP_MAX_SIZE = 102400; +}; +} // namespace OHOS +#endif // OHOS_IIDLTESTSERVICE_H + diff --git a/test/sa_test/in_use_idl/target_cpp/iquick_fix_manager.h.txt b/test/sa_test/in_use_idl/target_cpp/iquick_fix_manager.h.txt new file mode 100644 index 0000000..aed70f0 --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/iquick_fix_manager.h.txt @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_AAFWK_IQUICKFIXMANAGER_H +#define OHOS_AAFWK_IQUICKFIXMANAGER_H + +#include +#include +#include +#include +#include "quick_fix_info.h" + +using OHOS::AAFwk::ApplicationQuickFixInfo; + +namespace OHOS { +namespace AAFwk { +class IQuickFixManager : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.AAFwk.IQuickFixManager"); + + virtual ErrCode ApplyQuickFix( + const std::vector& quickFixFiles, + bool isDebug) = 0; + + virtual ErrCode GetApplyedQuickFixInfo( + const std::string& bundleName, + ApplicationQuickFixInfo& quickFixInfo) = 0; + + virtual ErrCode RevokeQuickFix( + const std::string& bundleName) = 0; +protected: + const int VECTOR_MAX_SIZE = 102400; + const int LIST_MAX_SIZE = 102400; + const int MAP_MAX_SIZE = 102400; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_AAFWK_IQUICKFIXMANAGER_H + diff --git a/test/sa_test/in_use_idl/target_cpp/itest_server_interface.h.txt b/test/sa_test/in_use_idl/target_cpp/itest_server_interface.h.txt new file mode 100644 index 0000000..80de32a --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/itest_server_interface.h.txt @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_TESTSERVER_ITESTSERVERINTERFACE_H +#define OHOS_TESTSERVER_ITESTSERVERINTERFACE_H + +#include +#include +#include +#include "common_event_data.h" +#include "session_token.h" + +using OHOS::testserver::SessionToken; +using OHOS::EventFwk::CommonEventData; + +namespace OHOS { +namespace testserver { +class ITestServerInterface : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.testserver.ITestServerInterface"); + + virtual ErrCode CreateSession( + const SessionToken& sessionToken) = 0; + + virtual ErrCode SetPasteData( + const std::string& text) = 0; + + virtual ErrCode PublishCommonEvent( + const CommonEventData& event, + bool& re) = 0; +protected: + const int VECTOR_MAX_SIZE = 102400; + const int LIST_MAX_SIZE = 102400; + const int MAP_MAX_SIZE = 102400; +}; +} // namespace testserver +} // namespace OHOS +#endif // OHOS_TESTSERVER_ITESTSERVERINTERFACE_H + diff --git a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.cpp.txt new file mode 100644 index 0000000..2051f96 --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.cpp.txt @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "quick_fix_manager_proxy.h" + +namespace OHOS { +namespace AAFwk { +ErrCode QuickFixManagerProxy::ApplyQuickFix( + const std::vector& quickFixFiles, + bool isDebug) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (quickFixFiles.size() > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + data.WriteInt32(quickFixFiles.size()); + for (auto it = quickFixFiles.begin(); it != quickFixFiles.end(); ++it) { + if (!data.WriteString16(Str8ToStr16((*it)))) { + return ERR_INVALID_DATA; + } + } + if (!data.WriteInt32(isDebug ? 1 : 0)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_APPLY_QUICK_FIX, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + return ERR_OK; +} + +ErrCode QuickFixManagerProxy::GetApplyedQuickFixInfo( + const std::string& bundleName, + ApplicationQuickFixInfo& quickFixInfo) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(bundleName))) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_GET_APPLYED_QUICK_FIX_INFO, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + std::unique_ptr quickFixInfoInfo(reply.ReadParcelable()); + if (quickFixInfoInfo != nullptr) { + quickFixInfo = *quickFixInfoInfo; + } + + return ERR_OK; +} + +ErrCode QuickFixManagerProxy::RevokeQuickFix( + const std::string& bundleName) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(bundleName))) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_REVOKE_QUICK_FIX, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + return ERR_OK; +} +} // namespace AAFwk +} // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.h.txt new file mode 100644 index 0000000..0c58c3e --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.h.txt @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_AAFWK_QUICKFIXMANAGERPROXY_H +#define OHOS_AAFWK_QUICKFIXMANAGERPROXY_H + +#include "iquick_fix_manager.h" +#include + +namespace OHOS { +namespace AAFwk { +class QuickFixManagerProxy : public IRemoteProxy { +public: + explicit QuickFixManagerProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} + + virtual ~QuickFixManagerProxy() + {} + + ErrCode ApplyQuickFix( + const std::vector& quickFixFiles, + bool isDebug) override; + + ErrCode GetApplyedQuickFixInfo( + const std::string& bundleName, + ApplicationQuickFixInfo& quickFixInfo) override; + + ErrCode RevokeQuickFix( + const std::string& bundleName) override; + +private: + static constexpr int32_t COMMAND_APPLY_QUICK_FIX = MIN_TRANSACTION_ID + 0; + static constexpr int32_t COMMAND_GET_APPLYED_QUICK_FIX_INFO = MIN_TRANSACTION_ID + 1; + static constexpr int32_t COMMAND_REVOKE_QUICK_FIX = MIN_TRANSACTION_ID + 2; + + static inline BrokerDelegator delegator_; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_AAFWK_QUICKFIXMANAGERPROXY_H + diff --git a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_stub.cpp.txt b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_stub.cpp.txt new file mode 100644 index 0000000..76bdfb2 --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_stub.cpp.txt @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "quick_fix_manager_stub.h" + +namespace OHOS { +namespace AAFwk { +int32_t QuickFixManagerStub::OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) +{ + std::u16string localDescriptor = GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (localDescriptor != remoteDescriptor) { + return ERR_TRANSACTION_FAILED; + } + switch (code) { + case COMMAND_APPLY_QUICK_FIX: { + std::vector quickFixFiles; + int32_t quickFixFilesSize = data.ReadInt32(); + if (quickFixFilesSize > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int32_t i1 = 0; i1 < quickFixFilesSize; ++i1) { + std::string value1 = Str16ToStr8(data.ReadString16()); + quickFixFiles.push_back(value1); + } + bool isDebug = data.ReadInt32() == 1 ? true : false; + ErrCode errCode = ApplyQuickFix(quickFixFiles, isDebug); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case COMMAND_GET_APPLYED_QUICK_FIX_INFO: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + ApplicationQuickFixInfo quickFixInfo; + ErrCode errCode = GetApplyedQuickFixInfo(bundleName, quickFixInfo); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteParcelable(&quickFixInfo)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_REVOKE_QUICK_FIX: { + std::string bundleName = Str16ToStr8(data.ReadString16()); + ErrCode errCode = RevokeQuickFix(bundleName); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + + return ERR_TRANSACTION_FAILED; +} +} // namespace AAFwk +} // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_stub.h.txt b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_stub.h.txt new file mode 100644 index 0000000..a3c8807 --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_stub.h.txt @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_AAFWK_QUICKFIXMANAGERSTUB_H +#define OHOS_AAFWK_QUICKFIXMANAGERSTUB_H + +#include "iquick_fix_manager.h" +#include + +namespace OHOS { +namespace AAFwk { +class QuickFixManagerStub : public IRemoteStub { +public: + int32_t OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) override; + +private: + static constexpr int32_t COMMAND_APPLY_QUICK_FIX = MIN_TRANSACTION_ID + 0; + static constexpr int32_t COMMAND_GET_APPLYED_QUICK_FIX_INFO = MIN_TRANSACTION_ID + 1; + static constexpr int32_t COMMAND_REVOKE_QUICK_FIX = MIN_TRANSACTION_ID + 2; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_AAFWK_QUICKFIXMANAGERSTUB_H + diff --git a/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.cpp.txt new file mode 100644 index 0000000..69d85b0 --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.cpp.txt @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "test_server_interface_proxy.h" + +namespace OHOS { +namespace testserver { +ErrCode TestServerInterfaceProxy::CreateSession( + const SessionToken& sessionToken) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteParcelable(&sessionToken)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_CREATE_SESSION, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + return ERR_OK; +} + +ErrCode TestServerInterfaceProxy::SetPasteData( + const std::string& text) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(text))) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_SET_PASTE_DATA, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + return ERR_OK; +} + +ErrCode TestServerInterfaceProxy::PublishCommonEvent( + const CommonEventData& event, + bool& re) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteParcelable(&event)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_PUBLISH_COMMON_EVENT, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + re = reply.ReadInt32() == 1 ? true : false; + return ERR_OK; +} +} // namespace testserver +} // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.h.txt new file mode 100644 index 0000000..ded8218 --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.h.txt @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_TESTSERVER_TESTSERVERINTERFACEPROXY_H +#define OHOS_TESTSERVER_TESTSERVERINTERFACEPROXY_H + +#include "itest_server_interface.h" +#include + +namespace OHOS { +namespace testserver { +class TestServerInterfaceProxy : public IRemoteProxy { +public: + explicit TestServerInterfaceProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} + + virtual ~TestServerInterfaceProxy() + {} + + ErrCode CreateSession( + const SessionToken& sessionToken) override; + + ErrCode SetPasteData( + const std::string& text) override; + + ErrCode PublishCommonEvent( + const CommonEventData& event, + bool& re) override; + +private: + static constexpr int32_t COMMAND_CREATE_SESSION = MIN_TRANSACTION_ID + 0; + static constexpr int32_t COMMAND_SET_PASTE_DATA = MIN_TRANSACTION_ID + 1; + static constexpr int32_t COMMAND_PUBLISH_COMMON_EVENT = MIN_TRANSACTION_ID + 2; + + static inline BrokerDelegator delegator_; +}; +} // namespace testserver +} // namespace OHOS +#endif // OHOS_TESTSERVER_TESTSERVERINTERFACEPROXY_H + diff --git a/test/sa_test/in_use_idl/target_cpp/test_server_interface_stub.cpp.txt b/test/sa_test/in_use_idl/target_cpp/test_server_interface_stub.cpp.txt new file mode 100644 index 0000000..c85a0c6 --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/test_server_interface_stub.cpp.txt @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "test_server_interface_stub.h" + +namespace OHOS { +namespace testserver { +int32_t TestServerInterfaceStub::OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) +{ + std::u16string localDescriptor = GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (localDescriptor != remoteDescriptor) { + return ERR_TRANSACTION_FAILED; + } + switch (code) { + case COMMAND_CREATE_SESSION: { + std::unique_ptr sessionToken(data.ReadParcelable()); + if (!sessionToken) { + return ERR_INVALID_DATA; + } + + ErrCode errCode = CreateSession(*sessionToken); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case COMMAND_SET_PASTE_DATA: { + std::string text = Str16ToStr8(data.ReadString16()); + ErrCode errCode = SetPasteData(text); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case COMMAND_PUBLISH_COMMON_EVENT: { + std::unique_ptr event(data.ReadParcelable()); + if (!event) { + return ERR_INVALID_DATA; + } + + bool re; + ErrCode errCode = PublishCommonEvent(*event, re); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(re ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + + return ERR_TRANSACTION_FAILED; +} +} // namespace testserver +} // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/test_server_interface_stub.h.txt b/test/sa_test/in_use_idl/target_cpp/test_server_interface_stub.h.txt new file mode 100644 index 0000000..2c7628a --- /dev/null +++ b/test/sa_test/in_use_idl/target_cpp/test_server_interface_stub.h.txt @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_TESTSERVER_TESTSERVERINTERFACESTUB_H +#define OHOS_TESTSERVER_TESTSERVERINTERFACESTUB_H + +#include "itest_server_interface.h" +#include + +namespace OHOS { +namespace testserver { +class TestServerInterfaceStub : public IRemoteStub { +public: + int32_t OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) override; + +private: + static constexpr int32_t COMMAND_CREATE_SESSION = MIN_TRANSACTION_ID + 0; + static constexpr int32_t COMMAND_SET_PASTE_DATA = MIN_TRANSACTION_ID + 1; + static constexpr int32_t COMMAND_PUBLISH_COMMON_EVENT = MIN_TRANSACTION_ID + 2; +}; +} // namespace testserver +} // namespace OHOS +#endif // OHOS_TESTSERVER_TESTSERVERINTERFACESTUB_H + diff --git a/test/sa_test/keyword_import_dir/target_cpp/foo_stub.cpp.txt b/test/sa_test/keyword_import_dir/target_cpp/foo_stub.cpp.txt index 8f55967..9db880c 100644 --- a/test/sa_test/keyword_import_dir/target_cpp/foo_stub.cpp.txt +++ b/test/sa_test/keyword_import_dir/target_cpp/foo_stub.cpp.txt @@ -30,16 +30,16 @@ int32_t FooStub::OnRemoteRequest( switch (code) { case COMMAND_SEQ_TEST_FUNC: { std::unique_ptr inParam(data.ReadParcelable()); - if (!inParam) { return ERR_INVALID_DATA; } + myseq outParam; std::unique_ptr inoutParam(data.ReadParcelable()); - if (!inoutParam) { return ERR_INVALID_DATA; } + ErrCode errCode = seq_test_func(*inParam, outParam, *inoutParam); if (!reply.WriteInt32(errCode)) { return ERR_INVALID_VALUE; @@ -56,16 +56,16 @@ int32_t FooStub::OnRemoteRequest( } case COMMAND_SEQ_TEST_FUNC2: { std::unique_ptr inParam(data.ReadParcelable()); - if (!inParam) { return ERR_INVALID_DATA; } + myseq2 outParam; std::unique_ptr inoutParam(data.ReadParcelable()); - if (!inoutParam) { return ERR_INVALID_DATA; } + ErrCode errCode = seq_test_func2(*inParam, outParam, *inoutParam); if (!reply.WriteInt32(errCode)) { return ERR_INVALID_VALUE; diff --git a/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt index 858e7fb..228f189 100644 --- a/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt @@ -763,10 +763,10 @@ ErrCode FooProxy::seq_test_func( } for (int32_t i28 = 0; i28 < outParamSize; ++i28) { std::unique_ptr value28(reply.ReadParcelable()); - if (!value28) { return ERR_INVALID_DATA; } + outParam.push_back(*value28); } int32_t inoutParamSize = reply.ReadInt32(); @@ -775,10 +775,10 @@ ErrCode FooProxy::seq_test_func( } for (int32_t i29 = 0; i29 < inoutParamSize; ++i29) { std::unique_ptr value29(reply.ReadParcelable()); - if (!value29) { return ERR_INVALID_DATA; } + inoutParam.push_back(*value29); } int32_t funcResultSize = reply.ReadInt32(); @@ -787,10 +787,10 @@ ErrCode FooProxy::seq_test_func( } for (int32_t i30 = 0; i30 < funcResultSize; ++i30) { std::unique_ptr value30(reply.ReadParcelable()); - if (!value30) { return ERR_INVALID_DATA; } + funcResult.push_back(*value30); } return ERR_OK; diff --git a/test/sa_test/type_array/target_cpp/foo_stub.cpp.txt b/test/sa_test/type_array/target_cpp/foo_stub.cpp.txt index eaecb74..c34fd1f 100644 --- a/test/sa_test/type_array/target_cpp/foo_stub.cpp.txt +++ b/test/sa_test/type_array/target_cpp/foo_stub.cpp.txt @@ -547,10 +547,10 @@ int32_t FooStub::OnRemoteRequest( } for (int32_t i52 = 0; i52 < inParamSize; ++i52) { std::unique_ptr value52(data.ReadParcelable()); - if (!value52) { return ERR_INVALID_DATA; } + inParam.push_back(*value52); } std::vector outParam; @@ -561,10 +561,10 @@ int32_t FooStub::OnRemoteRequest( } for (int32_t i53 = 0; i53 < inoutParamSize; ++i53) { std::unique_ptr value53(data.ReadParcelable()); - if (!value53) { return ERR_INVALID_DATA; } + inoutParam.push_back(*value53); } std::vector result; diff --git a/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt index 6fbd5e4..b49f076 100644 --- a/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt @@ -735,10 +735,10 @@ ErrCode FooProxy::seq_test_func( } for (int32_t i28 = 0; i28 < outParamSize; ++i28) { std::unique_ptr value28(reply.ReadParcelable()); - if (!value28) { return ERR_INVALID_DATA; } + outParam.push_back(*value28); } int32_t inoutParamSize = reply.ReadInt32(); @@ -747,10 +747,10 @@ ErrCode FooProxy::seq_test_func( } for (int32_t i29 = 0; i29 < inoutParamSize; ++i29) { std::unique_ptr value29(reply.ReadParcelable()); - if (!value29) { return ERR_INVALID_DATA; } + inoutParam.push_back(*value29); } int32_t funcResultSize = reply.ReadInt32(); @@ -759,10 +759,10 @@ ErrCode FooProxy::seq_test_func( } for (int32_t i30 = 0; i30 < funcResultSize; ++i30) { std::unique_ptr value30(reply.ReadParcelable()); - if (!value30) { return ERR_INVALID_DATA; } + funcResult.push_back(*value30); } return ERR_OK; diff --git a/test/sa_test/type_list/target_cpp/foo_stub.cpp.txt b/test/sa_test/type_list/target_cpp/foo_stub.cpp.txt index 5f57000..6af9e2b 100644 --- a/test/sa_test/type_list/target_cpp/foo_stub.cpp.txt +++ b/test/sa_test/type_list/target_cpp/foo_stub.cpp.txt @@ -540,10 +540,10 @@ int32_t FooStub::OnRemoteRequest( } for (int32_t i52 = 0; i52 < inParamSize; ++i52) { std::unique_ptr value52(data.ReadParcelable()); - if (!value52) { return ERR_INVALID_DATA; } + inParam.push_back(*value52); } std::vector outParam; @@ -554,10 +554,10 @@ int32_t FooStub::OnRemoteRequest( } for (int32_t i53 = 0; i53 < inoutParamSize; ++i53) { std::unique_ptr value53(data.ReadParcelable()); - if (!value53) { return ERR_INVALID_DATA; } + inoutParam.push_back(*value53); } std::vector result; diff --git a/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt index e868e9c..ec7ffba 100644 --- a/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt @@ -786,43 +786,43 @@ ErrCode FooProxy::seq_test_func( int32_t outParamSize = reply.ReadInt32(); for (int32_t i = 0; i < outParamSize; ++i) { std::unique_ptr key(reply.ReadParcelable()); - if (!key) { return ERR_INVALID_DATA; } - std::unique_ptr value(reply.ReadParcelable()); + std::unique_ptr value(reply.ReadParcelable()); if (!value) { return ERR_INVALID_DATA; } + outParam[key] = value; } int32_t inoutParamSize = reply.ReadInt32(); for (int32_t i = 0; i < inoutParamSize; ++i) { std::unique_ptr key(reply.ReadParcelable()); - if (!key) { return ERR_INVALID_DATA; } - std::unique_ptr value(reply.ReadParcelable()); + std::unique_ptr value(reply.ReadParcelable()); if (!value) { return ERR_INVALID_DATA; } + inoutParam[key] = value; } int32_t funcResultSize = reply.ReadInt32(); for (int32_t i = 0; i < funcResultSize; ++i) { std::unique_ptr key(reply.ReadParcelable()); - if (!key) { return ERR_INVALID_DATA; } - std::unique_ptr value(reply.ReadParcelable()); + std::unique_ptr value(reply.ReadParcelable()); if (!value) { return ERR_INVALID_DATA; } + funcResult[key] = value; } return ERR_OK; diff --git a/test/sa_test/type_map/target_cpp/foo_stub.cpp.txt b/test/sa_test/type_map/target_cpp/foo_stub.cpp.txt index aceb225..0c2c3d0 100644 --- a/test/sa_test/type_map/target_cpp/foo_stub.cpp.txt +++ b/test/sa_test/type_map/target_cpp/foo_stub.cpp.txt @@ -616,15 +616,15 @@ int32_t FooStub::OnRemoteRequest( int32_t inParamSize = data.ReadInt32(); for (int32_t i = 0; i < inParamSize; ++i) { std::unique_ptr key(data.ReadParcelable()); - if (!key) { return ERR_INVALID_DATA; } - std::unique_ptr value(data.ReadParcelable()); + std::unique_ptr value(data.ReadParcelable()); if (!value) { return ERR_INVALID_DATA; } + inParam[key] = value; } std::unordered_map outParam; @@ -632,15 +632,15 @@ int32_t FooStub::OnRemoteRequest( int32_t inoutParamSize = data.ReadInt32(); for (int32_t i = 0; i < inoutParamSize; ++i) { std::unique_ptr key(data.ReadParcelable()); - if (!key) { return ERR_INVALID_DATA; } - std::unique_ptr value(data.ReadParcelable()); + std::unique_ptr value(data.ReadParcelable()); if (!value) { return ERR_INVALID_DATA; } + inoutParam[key] = value; } std::unordered_map result; diff --git a/test/sa_test/type_single/target_cpp/foo_stub.cpp.txt b/test/sa_test/type_single/target_cpp/foo_stub.cpp.txt index 5dab597..f4f0c0e 100644 --- a/test/sa_test/type_single/target_cpp/foo_stub.cpp.txt +++ b/test/sa_test/type_single/target_cpp/foo_stub.cpp.txt @@ -235,16 +235,16 @@ int32_t FooStub::OnRemoteRequest( } case COMMAND_SEQ_TEST_FUNC: { std::unique_ptr inParam(data.ReadParcelable()); - if (!inParam) { return ERR_INVALID_DATA; } + myseq outParam; std::unique_ptr inoutParam(data.ReadParcelable()); - if (!inoutParam) { return ERR_INVALID_DATA; } + const myseq& result = nullptr; ErrCode errCode = seq_test_func(*inParam, outParam, *inoutParam, result); if (!reply.WriteInt32(errCode)) { diff --git a/test/sa_test/type_single_unsigned_fd/foo/IFoo.idl b/test/sa_test/type_single_unsigned_fd/foo/IFoo.idl index dcc6338..5f8f01f 100644 --- a/test/sa_test/type_single_unsigned_fd/foo/IFoo.idl +++ b/test/sa_test/type_single_unsigned_fd/foo/IFoo.idl @@ -13,10 +13,13 @@ * limitations under the License. */ +sequenceable OHOS.IRemoteObject; + interface test.IFoo { unsigned char uchar_test_func([in] unsigned char inParam, [out] unsigned char outParam, [inout] unsigned char inoutParam); unsigned short ushort_test_func([in] unsigned short inParam, [out] unsigned short outParam, [inout] unsigned short inoutParam); unsigned int uint_test_func([in] unsigned int inParam, [out] unsigned int outParam, [inout] unsigned int inoutParam); unsigned long ulong_test_func([in] unsigned long inParam, [out] unsigned long outParam, [inout] unsigned long inoutParam); FileDescriptor fd_test_func([in] FileDescriptor inParam, [out] FileDescriptor outParam, [inout] FileDescriptor inoutParam); + IRemoteObject remote_object_test_func([in] IRemoteObject inParam, [out] IRemoteObject outParam, [inout] IRemoteObject inoutParam); } diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt index a36e957..c38fe7a 100644 --- a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt @@ -220,4 +220,48 @@ ErrCode FooProxy::fd_test_func( funcResult = reply.ReadFileDescriptor(); return ERR_OK; } + +ErrCode FooProxy::remote_object_test_func( + const sptr& inParam, + sptr& outParam, + sptr& inoutParam, + sptr& funcResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteRemoteObject(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteRemoteObject(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_REMOTE_OBJECT_TEST_FUNC, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = reply.ReadRemoteObject(); + + inoutParam = reply.ReadRemoteObject(); + + funcResult = reply.ReadRemoteObject(); + + return ERR_OK; +} } // namespace test diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt index 9b36d7b..a05ea66 100644 --- a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt @@ -60,12 +60,19 @@ public: int inoutParam, int& funcResult) override; + ErrCode remote_object_test_func( + const sptr& inParam, + sptr& outParam, + sptr& inoutParam, + sptr& funcResult) override; + private: static constexpr int32_t COMMAND_UCHAR_TEST_FUNC = MIN_TRANSACTION_ID + 0; static constexpr int32_t COMMAND_USHORT_TEST_FUNC = MIN_TRANSACTION_ID + 1; static constexpr int32_t COMMAND_UINT_TEST_FUNC = MIN_TRANSACTION_ID + 2; static constexpr int32_t COMMAND_ULONG_TEST_FUNC = MIN_TRANSACTION_ID + 3; static constexpr int32_t COMMAND_FD_TEST_FUNC = MIN_TRANSACTION_ID + 4; + static constexpr int32_t COMMAND_REMOTE_OBJECT_TEST_FUNC = MIN_TRANSACTION_ID + 5; static inline BrokerDelegator delegator_; }; diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.cpp.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.cpp.txt index 6ca7a8b..4010aca 100644 --- a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.cpp.txt +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.cpp.txt @@ -138,6 +138,36 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } + case COMMAND_REMOTE_OBJECT_TEST_FUNC: { + sptr inParam = data.ReadRemoteObject(); + if (!inParam) { + return ERR_INVALID_DATA; + } + + sptr outParam; + sptr inoutParam = data.ReadRemoteObject(); + if (!inoutParam) { + return ERR_INVALID_DATA; + } + + sptr result = nullptr; + ErrCode errCode = remote_object_test_func(inParam, outParam, inoutParam, result); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteRemoteObject(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteRemoteObject(inoutParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteRemoteObject(result)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } default: return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.h.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.h.txt index 046573a..4cadec5 100644 --- a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.h.txt +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.h.txt @@ -34,6 +34,7 @@ private: static constexpr int32_t COMMAND_UINT_TEST_FUNC = MIN_TRANSACTION_ID + 2; static constexpr int32_t COMMAND_ULONG_TEST_FUNC = MIN_TRANSACTION_ID + 3; static constexpr int32_t COMMAND_FD_TEST_FUNC = MIN_TRANSACTION_ID + 4; + static constexpr int32_t COMMAND_REMOTE_OBJECT_TEST_FUNC = MIN_TRANSACTION_ID + 5; }; } // namespace test #endif // TEST_FOOSTUB_H diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt index d6612c8..1624874 100644 --- a/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt @@ -54,6 +54,12 @@ public: int& outParam, int inoutParam, int& funcResult) = 0; + + virtual ErrCode remote_object_test_func( + const sptr& inParam, + sptr& outParam, + sptr& inoutParam, + sptr& funcResult) = 0; protected: const int VECTOR_MAX_SIZE = 102400; const int LIST_MAX_SIZE = 102400; -- Gitee From e33ff7428b246568452a701389b051aaac4db76a Mon Sep 17 00:00:00 2001 From: zhangjidong Date: Wed, 27 Nov 2024 09:16:53 +0800 Subject: [PATCH 05/10] modify warning Signed-off-by: zhangjidong --- idl_tool_2/util/autoptr.h | 1 + 1 file changed, 1 insertion(+) diff --git a/idl_tool_2/util/autoptr.h b/idl_tool_2/util/autoptr.h index 3bb5866..0a30b7c 100644 --- a/idl_tool_2/util/autoptr.h +++ b/idl_tool_2/util/autoptr.h @@ -104,6 +104,7 @@ AutoPtr::~AutoPtr() { if (mPtr != nullptr) { mPtr->Release(); + mPtr = nullptr; } } -- Gitee From 4a6c9bce70360a11adba602c7372bc335e75ef09 Mon Sep 17 00:00:00 2001 From: zhangjidong Date: Fri, 29 Nov 2024 09:19:43 +0800 Subject: [PATCH 06/10] modify warning Signed-off-by: zhangjidong --- idl_tool_2/util/options.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/idl_tool_2/util/options.cpp b/idl_tool_2/util/options.cpp index 9bac20a..d0f2d9f 100644 --- a/idl_tool_2/util/options.cpp +++ b/idl_tool_2/util/options.cpp @@ -15,6 +15,7 @@ #include "util/options.h" +#include #include #include #include @@ -67,6 +68,11 @@ bool Options::Parse(int argc, char *argv[]) int op = 0; int optIndex = 0; + if (argc < INT_MIN || argc > INT_MAX) { + Logger::E(TAG, "argc out of range"); + return false; + } + while ((op = getopt_long_only(argc, argv, optSupportArgs, g_longOpts, &optIndex)) != -1) { if (optind > 0 && optind <= argc) { ret = ParseSingle(op, std::string(argv[optind - 1])); -- Gitee From 3c0168d8efc3a6229ac55a4d8d7ff54c34e1f4af Mon Sep 17 00:00:00 2001 From: litao Date: Sat, 23 Nov 2024 18:39:58 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89code=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: litao --- idl_tool_2/ast/ast_attribute.h | 12 + idl_tool_2/ast/ast_method.h | 17 + .../cpp/sa_cpp_client_proxy_code_emitter.cpp | 32 +- .../codegen/SA/cpp/sa_cpp_code_emitter.cpp | 13 +- .../SA/cpp/sa_cpp_interface_code_emitter.cpp | 1 + .../cpp/sa_cpp_service_stub_code_emitter.cpp | 8 +- idl_tool_2/lexer/lexer.cpp | 3 +- idl_tool_2/lexer/token.h | 1 + idl_tool_2/parser/intf_type_check.cpp | 7 +- idl_tool_2/parser/parser.cpp | 81 ++++ idl_tool_2/parser/parser.h | 8 + .../cmd_hitrace_tag/target/foo_proxy.cpp.txt | 24 +- .../cmd_hitrace_tag/target/foo_proxy.h.txt | 13 - .../cmd_hitrace_tag/target/foo_stub.cpp.txt | 26 +- .../cmd_hitrace_tag/target/foo_stub.h.txt | 14 - .../sa_test/cmd_hitrace_tag/target/ifoo.h.txt | 15 + .../target/foo_proxy.cpp.txt | 24 +- .../target/foo_proxy.h.txt | 13 - .../target/foo_stub.cpp.txt | 26 +- .../target/foo_stub.h.txt | 14 - .../cmd_log_tag_domainid/target/ifoo.h.txt | 15 + .../target/foo_proxy.cpp.txt | 24 +- .../cmd_save_metadata/target/foo_proxy.h.txt | 13 - .../cmd_save_metadata/target/foo_stub.cpp.txt | 26 +- .../cmd_save_metadata/target/foo_stub.h.txt | 14 - .../cmd_save_metadata/target/ifoo.h.txt | 15 + .../app_fwk_update_service_proxy.cpp.txt | 2 +- .../app_fwk_update_service_proxy.h.txt | 2 - .../app_fwk_update_service_stub.cpp.txt | 4 +- .../app_fwk_update_service_stub.h.txt | 3 - .../target_cpp/esim_service_proxy.cpp.txt | 34 +- .../target_cpp/esim_service_proxy.h.txt | 18 - .../target_cpp/esim_service_stub.cpp.txt | 36 +- .../target_cpp/esim_service_stub.h.txt | 19 - .../target_cpp/iapp_fwk_update_service.h.txt | 4 + .../target_cpp/idl_test_service_proxy.cpp.txt | 4 +- .../target_cpp/idl_test_service_proxy.h.txt | 3 - .../target_cpp/idl_test_service_stub.cpp.txt | 6 +- .../target_cpp/idl_test_service_stub.h.txt | 4 - .../in_use_idl/target_cpp/iesim_service.h.txt | 20 + .../target_cpp/iidl_test_service.h.txt | 5 + .../target_cpp/iquick_fix_manager.h.txt | 6 + .../target_cpp/itest_server_interface.h.txt | 6 + .../quick_fix_manager_proxy.cpp.txt | 6 +- .../target_cpp/quick_fix_manager_proxy.h.txt | 4 - .../target_cpp/quick_fix_manager_stub.cpp.txt | 8 +- .../target_cpp/quick_fix_manager_stub.h.txt | 5 - .../test_server_interface_proxy.cpp.txt | 6 +- .../test_server_interface_proxy.h.txt | 4 - .../test_server_interface_stub.cpp.txt | 8 +- .../test_server_interface_stub.h.txt | 5 - .../target_cpp/foo_proxy.cpp.txt | 30 +- .../target_cpp/foo_proxy.h.txt | 26 +- .../target_cpp/foo_stub.cpp.txt | 12 +- .../target_cpp/foo_stub.h.txt | 7 - .../target_cpp/ifoo.h.txt | 8 + .../target_cpp/foo_proxy.cpp.txt | 16 +- .../target_cpp/foo_proxy.h.txt | 13 +- .../target_cpp/foo_stub.cpp.txt | 10 +- .../target_cpp/foo_stub.h.txt | 6 - .../target_cpp/ifoo.h.txt | 7 + .../target_cpp/foo_proxy.cpp.txt | 8 +- .../target_cpp/foo_proxy.h.txt | 5 - .../target_cpp/foo_stub.cpp.txt | 10 +- .../target_cpp/foo_stub.h.txt | 6 - .../keyword_import_dir/target_cpp/ifoo.h.txt | 7 + test/sa_test/keyword_ipccode_test_001.py | 34 ++ .../keyword_ipccode_test_001/foo/IFoo.idl | 31 ++ .../target_cpp/foo_proxy.cpp.txt | 452 ++++++++++++++++++ .../target_cpp/foo_proxy.h.txt | 90 ++++ .../target_cpp/foo_stub.cpp.txt | 230 +++++++++ .../target_cpp/foo_stub.h.txt | 33 ++ .../target_cpp/ifoo.h.txt | 105 ++++ test/sa_test/keyword_ipccode_test_002.py | 34 ++ .../keyword_ipccode_test_002/foo/IFoo.idl | 50 ++ .../target_cpp/fail_output.txt | 31 ++ .../target_cpp/foo_proxy.cpp.txt.txt | 31 +- .../target_cpp/foo_proxy.h.txt.txt | 15 +- .../target_cpp/foo_stub.cpp.txt.txt | 34 +- .../target_cpp/foo_stub.h.txt.txt | 14 - .../keyword_oneway/target_cpp/ifoo.h.txt.txt | 21 +- .../type_array/target_cpp/foo_proxy.cpp.txt | 24 +- .../type_array/target_cpp/foo_proxy.h.txt | 13 - .../type_array/target_cpp/foo_stub.cpp.txt | 26 +- .../type_array/target_cpp/foo_stub.h.txt | 14 - test/sa_test/type_array/target_cpp/ifoo.h.txt | 15 + .../type_list/target_cpp/foo_proxy.cpp.txt | 22 +- .../type_list/target_cpp/foo_proxy.h.txt | 12 - .../type_list/target_cpp/foo_stub.cpp.txt | 24 +- .../type_list/target_cpp/foo_stub.h.txt | 13 - test/sa_test/type_list/target_cpp/ifoo.h.txt | 14 + .../type_map/target_cpp/foo_proxy.cpp.txt | 24 +- .../type_map/target_cpp/foo_proxy.h.txt | 13 - .../type_map/target_cpp/foo_stub.cpp.txt | 26 +- .../type_map/target_cpp/foo_stub.h.txt | 14 - test/sa_test/type_map/target_cpp/ifoo.h.txt | 15 + .../type_single/target_cpp/foo_proxy.cpp.txt | 26 +- .../type_single/target_cpp/foo_proxy.h.txt | 14 - .../type_single/target_cpp/foo_stub.cpp.txt | 28 +- .../type_single/target_cpp/foo_stub.h.txt | 15 - .../sa_test/type_single/target_cpp/ifoo.h.txt | 16 + .../target_cpp/foo_proxy.cpp.txt | 12 +- .../target_cpp/foo_proxy.h.txt | 7 - .../target_cpp/foo_stub.cpp.txt | 14 +- .../target_cpp/foo_stub.h.txt | 8 - .../target_cpp/ifoo.h.txt | 9 + 106 files changed, 1780 insertions(+), 695 deletions(-) create mode 100644 test/sa_test/keyword_ipccode_test_001.py create mode 100644 test/sa_test/keyword_ipccode_test_001/foo/IFoo.idl create mode 100644 test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.cpp.txt create mode 100644 test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.h.txt create mode 100644 test/sa_test/keyword_ipccode_test_001/target_cpp/foo_stub.cpp.txt create mode 100644 test/sa_test/keyword_ipccode_test_001/target_cpp/foo_stub.h.txt create mode 100644 test/sa_test/keyword_ipccode_test_001/target_cpp/ifoo.h.txt create mode 100644 test/sa_test/keyword_ipccode_test_002.py create mode 100644 test/sa_test/keyword_ipccode_test_002/foo/IFoo.idl create mode 100644 test/sa_test/keyword_ipccode_test_002/target_cpp/fail_output.txt diff --git a/idl_tool_2/ast/ast_attribute.h b/idl_tool_2/ast/ast_attribute.h index d1faccb..b1305bf 100644 --- a/idl_tool_2/ast/ast_attribute.h +++ b/idl_tool_2/ast/ast_attribute.h @@ -31,6 +31,7 @@ public: static constexpr Attribute CALLBACK = 0x1U << 4; static constexpr Attribute CACHEABLE = 0x1U << 5; static constexpr Attribute FREEZECONTROL = 0x1U << 6; + static constexpr Attribute IPCCODE = 0x1U << 7; explicit ASTAttr(Attribute value = ASTAttr::NONE) : value_(value) {} @@ -77,10 +78,21 @@ public: bool CacheableStrToInt(); + std::string& GetIpcCodeStr() + { + return ipcCodeStr_; + } + + void SetIpcCodeStr(const std::string &ipcCodeStr) + { + ipcCodeStr_ = ipcCodeStr; + } + private: Attribute value_; int32_t cacheableTime_ = 0; std::string cacheableTimeString_; + std::string ipcCodeStr_; }; class ASTParamAttr : public ASTNode { diff --git a/idl_tool_2/ast/ast_method.h b/idl_tool_2/ast/ast_method.h index 7275896..37e2c6e 100644 --- a/idl_tool_2/ast/ast_method.h +++ b/idl_tool_2/ast/ast_method.h @@ -151,6 +151,23 @@ public: return attr_->HasValue(ASTAttr::FREEZECONTROL); } + bool HasIpcCode() + { + return attr_->HasValue(ASTAttr::IPCCODE); + } + + std::string& GetIpcCodeStr() + { + return attr_->GetIpcCodeStr(); + } + + void SetIpcCode(const AutoPtr &attr) + { + if (attr->HasValue(ASTAttr::IPCCODE)) { + attr_->SetIpcCodeStr(attr->GetIpcCodeStr()); + } + } + private: void BuildSignature(); diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp b/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp index 6ac6ea1..307b985 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp @@ -106,12 +106,14 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyAddCacheAbleAPI(StringBuilde int32_t cacheableTime = method->GetCacheableTime(); if (cacheableTime != 0) { sb.Append(prefix + TAB).AppendFormat( - "ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), COMMAND_%s, %d000);\n", - ConstantName(method->GetName()).c_str(), cacheableTime); + "ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), " + "static_cast(%sIpcCode::COMMAND_%s), %d000);\n", + interface_->GetName().c_str(), ConstantName(method->GetName()).c_str(), cacheableTime); } else { sb.Append(prefix + TAB).AppendFormat( - "ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), COMMAND_%s, 0);\n", - ConstantName(method->GetName()).c_str()); + "ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), " + "static_cast(%sIpcCode::COMMAND_%s), 0);\n", + interface_->GetName().c_str(), ConstantName(method->GetName()).c_str()); } } sb.Append("\n"); @@ -138,8 +140,9 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyUnRegisterDeathRecipient(Str AutoPtr method = interface_->GetMethod(i); if (method->GetCacheable() && !method->IsOneWay()) { sb.Append(prefix + TAB).AppendFormat( - "ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), COMMAND_%s);\n", - ConstantName(method->GetName()).c_str()); + "ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), " + "static_cast(%sIpcCode::COMMAND_%s));\n", + interface_->GetName().c_str(), ConstantName(method->GetName()).c_str()); } } } @@ -214,8 +217,6 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyConstants(StringBuilder &sb, if (ast_->GetHasCacheableProxyMethods()) { EmitInterfaceProxyDeathRecipient(sb, prefix); } - EmitInterfaceMethodCommands(sb, prefix); - sb.Append("\n"); sb.Append(prefix).AppendFormat("static inline BrokerDelegator<%s> delegator_;\n", proxyName_.c_str()); } @@ -275,8 +276,9 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodPreSendRequest(AutoPtr if ((method->GetCacheable()) && (!method->IsOneWay())) { sb.Append("\n"); sb.Append(prefix + TAB).AppendFormat( - "bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), COMMAND_%s, data, reply);", - ConstantName(method->GetName()).c_str()); + "bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), " + "static_cast(%sIpcCode::COMMAND_%s), data, reply);", + interface_->GetName().c_str(), ConstantName(method->GetName()).c_str()); sb.Append("\n"); sb.Append(prefix + TAB).Append("if (hitCache == true) {\n"); EmitInterfaceProxyMethodErrCode(sb, prefix + TAB); @@ -290,8 +292,9 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodPostSendRequest(AutoPt const std::string &prefix) const { sb.Append(prefix + TAB).AppendFormat( - "ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), COMMAND_%s, data, reply);\n", - ConstantName(method->GetName()).c_str()); + "ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), " + "static_cast(%sIpcCode::COMMAND_%s), data, reply);\n", + interface_->GetName().c_str(), ConstantName(method->GetName()).c_str()); } void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodBody(AutoPtr &method, StringBuilder &sb, @@ -331,8 +334,9 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodBody(AutoPtrSendRequest(COMMAND_%s, data, reply, option);\n", - ConstantName(method->GetName()).c_str()); + sb.Append(prefix + TAB).AppendFormat("int32_t result = remote->SendRequest(" + "static_cast(%sIpcCode::COMMAND_%s), data, reply, option);\n", + interface_->GetName().c_str(), ConstantName(method->GetName()).c_str()); sb.Append(prefix + TAB).Append("if (FAILED(result)) {\n"); if (logOn_) { sb.Append(prefix + TAB).Append(TAB).Append("HiLog::Error(LABEL, \"Send request failed!\");\n"); diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_code_emitter.cpp b/idl_tool_2/codegen/SA/cpp/sa_cpp_code_emitter.cpp index 0a773ee..858c5d8 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_code_emitter.cpp @@ -123,11 +123,20 @@ std::string SACppCodeEmitter::EmitCppParameter(AutoPtr ¶m) con void SACppCodeEmitter::EmitInterfaceMethodCommands(StringBuilder &sb, const std::string &prefix) { int methodNumber = static_cast(interface_->GetMethodNumber()); + sb.AppendFormat("enum class %sIpcCode {\n", interface_->GetName().c_str()); for (int i = 0; i < methodNumber; i++) { AutoPtr method = interface_->GetMethod(i); - sb.Append(prefix).AppendFormat("static constexpr int32_t COMMAND_%s = MIN_TRANSACTION_ID + %d;\n", - ConstantName(method->GetName()).c_str(), i); + std::string commandCode = "COMMAND_" + ConstantName(method->GetName()); + bool hasIpcCode = method->HasIpcCode(); + if (i == 0 && !hasIpcCode) { + commandCode += " = MIN_TRANSACTION_ID"; + } else if (hasIpcCode) { + commandCode += " = " + method->GetIpcCodeStr(); + } + commandCode += ",\n"; + sb.Append(prefix).AppendFormat(commandCode.c_str()); } + sb.Append("};\n\n"); } } // namespace Idl diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp b/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp index 5c0376e..67c3878 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp @@ -167,6 +167,7 @@ bool SaCppInterfaceCodeEmitter::EmitInterfaceUsings(StringBuilder &sb) const void SaCppInterfaceCodeEmitter::EmitInterfaceDefinition(StringBuilder &sb) { EmitBeginNamespace(sb); + EmitInterfaceMethodCommands(sb, TAB); sb.AppendFormat("class %s : public IRemoteBroker {\n", interface_->GetName().c_str()); sb.Append("public:\n"); EmitInterfaceBody(sb, TAB); diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp b/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp index 11bdadf..11f8e4e 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp @@ -53,9 +53,6 @@ void SaCppServiceStubCodeEmitter::EmitInterfaceStubInHeaderFile(StringBuilder &s sb.AppendFormat("class %s : public IRemoteStub<%s> {\n", stubName_.c_str(), interfaceName_.c_str()); sb.Append("public:\n"); EmitInterfaceStubMethodDecls(sb, TAB); - sb.Append("\n"); - sb.Append("private:\n"); - EmitInterfaceMethodCommands(sb, TAB); sb.Append("};\n"); EmitEndNamespace(sb); } @@ -115,7 +112,7 @@ void SaCppServiceStubCodeEmitter::EmitInterfaceStubMethodImpls(StringBuilder &sb sb.Append(prefix + TAB).Append("if (localDescriptor != remoteDescriptor) {\n"); sb.Append(prefix + TAB).Append(TAB).Append("return ERR_TRANSACTION_FAILED;\n"); sb.Append(prefix + TAB).Append("}\n"); - sb.Append(prefix + TAB).Append("switch (code) {\n"); + sb.Append(prefix + TAB).AppendFormat("switch (static_cast<%sIpcCode>(code)) {\n", interface_->GetName().c_str()); int methodNumber = static_cast(interface_->GetMethodNumber()); for (int i = 0; i < methodNumber; i++) { AutoPtr method = interface_->GetMethod(i); @@ -133,7 +130,8 @@ void SaCppServiceStubCodeEmitter::EmitInterfaceStubMethodImpl(AutoPtr const std::string &prefix) const { bool hasOutParameter = false; - sb.Append(prefix).AppendFormat("case COMMAND_%s: {\n", ConstantName(method->GetName()).c_str()); + sb.Append(prefix).AppendFormat("case %sIpcCode::COMMAND_%s: {\n", interface_->GetName().c_str(), + ConstantName(method->GetName()).c_str()); int paramNumber = static_cast(method->GetParameterNumber()); for (int i = 0; i < paramNumber; i++) { AutoPtr param = method->GetParameter(i); diff --git a/idl_tool_2/lexer/lexer.cpp b/idl_tool_2/lexer/lexer.cpp index 5087781..cd019e0 100644 --- a/idl_tool_2/lexer/lexer.cpp +++ b/idl_tool_2/lexer/lexer.cpp @@ -57,6 +57,7 @@ Lexer::StrTokenTypeMap Lexer::keyWords_ = { {"lite", TokenType::LITE }, {"mini", TokenType::MINI }, {"cacheable", TokenType::CACHEABLE }, + {"ipccode", TokenType::IPCCODE }, {"in", TokenType::IN }, {"out", TokenType::OUT }, {"inout", TokenType::INOUT }, @@ -167,7 +168,7 @@ void Lexer::Skip(char untilChar) void Lexer::SkipToken(TokenType tokenType) { - while (curToken_.kind != tokenType) { + while (curToken_.kind != tokenType && curToken_.kind != TokenType::END_OF_FILE) { GetToken(false); } } diff --git a/idl_tool_2/lexer/token.h b/idl_tool_2/lexer/token.h index da495d0..247b531 100644 --- a/idl_tool_2/lexer/token.h +++ b/idl_tool_2/lexer/token.h @@ -62,6 +62,7 @@ enum class TokenType { LITE, // "lite" MINI, // "mini" CACHEABLE, // "cacheable" + IPCCODE, // "ipccode" IN, // "in" OUT, // "out" INOUT, // "inout" diff --git a/idl_tool_2/parser/intf_type_check.cpp b/idl_tool_2/parser/intf_type_check.cpp index 8860f9d..bb07acf 100644 --- a/idl_tool_2/parser/intf_type_check.cpp +++ b/idl_tool_2/parser/intf_type_check.cpp @@ -121,9 +121,10 @@ bool IntfTypeChecker::CheckIntfSaAstMethods() for (size_t i = 0; i < interfaceType->GetMethodNumber(); i++) { AutoPtr method = interfaceType->GetMethod(i); - if (((method->GetAttribute()->GetValue()) & (~(ASTAttr::ONEWAY | ASTAttr::CACHEABLE))) != 0) { - Logger::E(TAG, StringHelper::Format("[%s:%d] error:intf sa: method attr support oneway or cacheable", - __func__, __LINE__).c_str()); + if (((method->GetAttribute()->GetValue()) & + (~(ASTAttr::ONEWAY | ASTAttr::CACHEABLE | ASTAttr::IPCCODE))) != 0) { + Logger::E(TAG, StringHelper::Format("[%s:%d] error:intf sa: method attr support oneway or cacheable or " + "ipccode", __func__, __LINE__).c_str()); return false; } if (method->GetAttribute()->HasValue(ASTAttr::CACHEABLE) && diff --git a/idl_tool_2/parser/parser.cpp b/idl_tool_2/parser/parser.cpp index b5ae8fc..12088d1 100644 --- a/idl_tool_2/parser/parser.cpp +++ b/idl_tool_2/parser/parser.cpp @@ -16,6 +16,7 @@ #include "parser/parser.h" #include +#include #include "ast/ast_array_type.h" #include "ast/ast_enum_type.h" @@ -500,6 +501,10 @@ bool Parser::ParseAttrUnit(AttrSet &attrs) ParseAttrUnitFreezecontrol(attrs, token); return true; } + case TokenType::IPCCODE: { + ParseAttrUnitIpccode(attrs, token); + return true; + } default: LogError(__func__, __LINE__, token, StringHelper::Format("'%s' is a illegal attribute", token.value.c_str())); @@ -525,6 +530,53 @@ void Parser::ParseAttrUnitFreezecontrol(AttrSet &attrs, Token &token) lexer_.GetToken(); } +void Parser::ParseAttrUnitIpccode(AttrSet &attrs, Token &token) +{ + Options &options = Options::GetInstance(); + if (options.GetInterfaceType() != InterfaceType::SA || options.GetLanguage() != Language::CPP) { + LogError(__func__, __LINE__, token, StringHelper::Format("Not support ipccode")); + lexer_.GetToken(); + return; + } + if (attrs.find(token) != attrs.end()) { + LogError(__func__, __LINE__, token, StringHelper::Format("Duplicate declared attr ipc code")); + lexer_.GetToken(); + return; + } + + Token tokenTmp = token; + lexer_.GetToken(); + token = lexer_.PeekToken(); + if (token.value == "]" || token.value == "," || token.value.empty()) { + LogError(__func__, __LINE__, token, StringHelper::Format("Ipccode attr cannot be empty")); + return; + } + + size_t end = 0; + int ipcCodeValue = 0; + int base = 10; // 10: decimal + if (token.value.size() >= sizeof("0x") && token.value[0] == '0' && tolower(token.value[1]) == 'x') { + base = 16; // 16: hexadecimal + } + try { + ipcCodeValue = std::stoi(token.value, &end, base); + } catch (...) { + end = 0; + } + if (end != token.value.size()) { + LogError(__func__, __LINE__, token, StringHelper::Format("%s is illegal ipccode value", token.value.c_str())); + } else { + if (ipcCodeValue < MIN_TRANSACTION_ID || ipcCodeValue > MAX_TRANSACTION_ID) { + LogError(__func__, __LINE__, token, StringHelper::Format("ipccode %d is out of range [%d, %d]", + ipcCodeValue, MIN_TRANSACTION_ID, MAX_TRANSACTION_ID)); + } else { + tokenTmp.value = std::to_string(ipcCodeValue); + attrs.insert(tokenTmp); + } + } + lexer_.GetToken(); +} + void Parser::ParseInterface(const AttrSet &attrs) { AutoPtr interfaceType = new ASTInterfaceType; @@ -627,6 +679,27 @@ void Parser::CheckInterfaceAttr(const AutoPtr &interface, Toke } } +void Parser::CheckIpcCodeValue( + const AutoPtr &method, int32_t &ipcCodeValue, std::unordered_set &ipcCodeSet) +{ + Options &options = Options::GetInstance(); + if (options.GetInterfaceType() != InterfaceType::SA || options.GetLanguage() != Language::CPP) { + return; + } + if (method->HasIpcCode()) { + ipcCodeValue = std::stoi(method->GetIpcCodeStr()); + } + if (ipcCodeValue > MAX_TRANSACTION_ID) { + LogError(__func__, __LINE__, StringHelper::Format("the ipccode %d is out of range [%d, %d]", + ipcCodeValue, MIN_TRANSACTION_ID, MAX_TRANSACTION_ID)); + } else if (ipcCodeSet.find(ipcCodeValue) != ipcCodeSet.end()) { + LogError(__func__, __LINE__, StringHelper::Format("the ipccode %d is duplicated", ipcCodeValue)); + } else { + ipcCodeSet.insert(ipcCodeValue); + } + ipcCodeValue++; +} + void Parser::ParseInterfaceExternal(const AutoPtr &interface) { Token token = lexer_.PeekToken(); @@ -650,10 +723,13 @@ void Parser::ParseInterfaceBody(const AutoPtr &interface) // parse method token = lexer_.PeekToken(); + int32_t ipcCodeValue = MIN_TRANSACTION_ID; + std::unordered_set ipcCodeSet; while (token.kind != TokenType::BRACES_RIGHT && token.kind != TokenType::END_OF_FILE) { AutoPtr method = ParseMethod(interface); interface->AddMethod(method); token = lexer_.PeekToken(); + CheckIpcCodeValue(method, ipcCodeValue, ipcCodeSet); } // expect symbol "}" @@ -680,6 +756,7 @@ AutoPtr Parser::ParseMethod(const AutoPtr &interfac AutoPtr methodAttr = ParseMethodAttr(); method->SetAttribute(methodAttr); method->SetCacheable(methodAttr); + method->SetIpcCode(methodAttr); method->SetReturnType(ParseMethodReturnType()); // parser method name @@ -766,6 +843,10 @@ AutoPtr Parser::ParseMethodAttr() case TokenType::FREEZECONTROL: methodAttr->SetValue(ASTAttr::FREEZECONTROL); break; + case TokenType::IPCCODE: + methodAttr->SetValue(ASTAttr::IPCCODE); + methodAttr->SetIpcCodeStr(attr.value); + break; default: LogError(__func__, __LINE__, attr, std::string("illegal attribute of interface")); break; diff --git a/idl_tool_2/parser/parser.h b/idl_tool_2/parser/parser.h index 04de0b7..5a29180 100644 --- a/idl_tool_2/parser/parser.h +++ b/idl_tool_2/parser/parser.h @@ -57,6 +57,9 @@ public: } private: + static constexpr int MIN_TRANSACTION_ID = 0x01; + static constexpr int MAX_TRANSACTION_ID = 0x00ffffff; + class Attribute : public LightRefCountBase { public: bool isOneWay = false; @@ -98,6 +101,8 @@ private: void ParseAttrUnitFreezecontrol(AttrSet &attrs, Token &token); + void ParseAttrUnitIpccode(AttrSet &attrs, Token &token); + // parse interface type void ParseInterface(const AttrSet &attrs = {}); @@ -105,6 +110,9 @@ private: void CheckInterfaceAttr(const AutoPtr &interface, Token token); + void CheckIpcCodeValue( + const AutoPtr &method, int32_t &ipcCodeValue, std::unordered_set &ipcCodeSet); + void ParseInterfaceExternal(const AutoPtr &interface); void ParseInterfaceBody(const AutoPtr &interface); diff --git a/test/sa_test/cmd_hitrace_tag/target/foo_proxy.cpp.txt b/test/sa_test/cmd_hitrace_tag/target/foo_proxy.cpp.txt index b44afeb..92dc6d5 100644 --- a/test/sa_test/cmd_hitrace_tag/target/foo_proxy.cpp.txt +++ b/test/sa_test/cmd_hitrace_tag/target/foo_proxy.cpp.txt @@ -31,7 +31,7 @@ ErrCode FooProxy::void_test_func() if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_VOID_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -69,7 +69,7 @@ ErrCode FooProxy::bool_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_BOOL_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -110,7 +110,7 @@ ErrCode FooProxy::byte_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_BYTE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -151,7 +151,7 @@ ErrCode FooProxy::short_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SHORT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -192,7 +192,7 @@ ErrCode FooProxy::int_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_INT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -233,7 +233,7 @@ ErrCode FooProxy::long_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_LONG_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -274,7 +274,7 @@ ErrCode FooProxy::string_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_STRING_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -315,7 +315,7 @@ ErrCode FooProxy::float_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_FLOAT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -356,7 +356,7 @@ ErrCode FooProxy::double_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_DOUBLE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -397,7 +397,7 @@ ErrCode FooProxy::char_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_CHAR_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -438,7 +438,7 @@ ErrCode FooProxy::seq_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SEQ_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -497,7 +497,7 @@ ErrCode FooProxy::interface_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_INTERFACE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/cmd_hitrace_tag/target/foo_proxy.h.txt b/test/sa_test/cmd_hitrace_tag/target/foo_proxy.h.txt index 1873b8d..e8a8046 100644 --- a/test/sa_test/cmd_hitrace_tag/target/foo_proxy.h.txt +++ b/test/sa_test/cmd_hitrace_tag/target/foo_proxy.h.txt @@ -99,19 +99,6 @@ public: sptr& funcResult) override; private: - static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_BYTE_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_SHORT_TEST_FUNC = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_INT_TEST_FUNC = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_LONG_TEST_FUNC = MIN_TRANSACTION_ID + 5; - static constexpr int32_t COMMAND_STRING_TEST_FUNC = MIN_TRANSACTION_ID + 6; - static constexpr int32_t COMMAND_FLOAT_TEST_FUNC = MIN_TRANSACTION_ID + 7; - static constexpr int32_t COMMAND_DOUBLE_TEST_FUNC = MIN_TRANSACTION_ID + 8; - static constexpr int32_t COMMAND_CHAR_TEST_FUNC = MIN_TRANSACTION_ID + 9; - static constexpr int32_t COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID + 10; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC = MIN_TRANSACTION_ID + 11; - static inline BrokerDelegator delegator_; }; } // namespace test diff --git a/test/sa_test/cmd_hitrace_tag/target/foo_stub.cpp.txt b/test/sa_test/cmd_hitrace_tag/target/foo_stub.cpp.txt index ab46269..77f87aa 100644 --- a/test/sa_test/cmd_hitrace_tag/target/foo_stub.cpp.txt +++ b/test/sa_test/cmd_hitrace_tag/target/foo_stub.cpp.txt @@ -27,15 +27,15 @@ int32_t FooStub::OnRemoteRequest( if (localDescriptor != remoteDescriptor) { return ERR_TRANSACTION_FAILED; } - switch (code) { - case COMMAND_VOID_TEST_FUNC: { + switch (static_cast(code)) { + case IFooIpcCode::COMMAND_VOID_TEST_FUNC: { ErrCode errCode = void_test_func(); if (!reply.WriteInt32(errCode)) { return ERR_INVALID_VALUE; } return ERR_NONE; } - case COMMAND_BOOL_TEST_FUNC: { + case IFooIpcCode::COMMAND_BOOL_TEST_FUNC: { bool inParam = data.ReadInt32() == 1 ? true : false; bool outParam; bool inoutParam = data.ReadInt32() == 1 ? true : false; @@ -57,7 +57,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_BYTE_TEST_FUNC: { + case IFooIpcCode::COMMAND_BYTE_TEST_FUNC: { int8_t inParam = (int8_t)data.ReadInt32(); int8_t outParam; int8_t inoutParam = (int8_t)data.ReadInt32(); @@ -79,7 +79,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SHORT_TEST_FUNC: { + case IFooIpcCode::COMMAND_SHORT_TEST_FUNC: { short inParam = (short)data.ReadInt32(); short outParam; short inoutParam = (short)data.ReadInt32(); @@ -101,7 +101,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_INT_TEST_FUNC: { + case IFooIpcCode::COMMAND_INT_TEST_FUNC: { int32_t inParam = data.ReadInt32(); int32_t outParam; int32_t inoutParam = data.ReadInt32(); @@ -123,7 +123,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_LONG_TEST_FUNC: { + case IFooIpcCode::COMMAND_LONG_TEST_FUNC: { int64_t inParam = data.ReadInt64(); int64_t outParam; int64_t inoutParam = data.ReadInt64(); @@ -145,7 +145,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_STRING_TEST_FUNC: { + case IFooIpcCode::COMMAND_STRING_TEST_FUNC: { std::string inParam = Str16ToStr8(data.ReadString16()); std::string outParam; std::string inoutParam = Str16ToStr8(data.ReadString16()); @@ -167,7 +167,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_FLOAT_TEST_FUNC: { + case IFooIpcCode::COMMAND_FLOAT_TEST_FUNC: { float inParam = data.ReadFloat(); float outParam; float inoutParam = data.ReadFloat(); @@ -189,7 +189,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_DOUBLE_TEST_FUNC: { + case IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC: { double inParam = data.ReadDouble(); double outParam; double inoutParam = data.ReadDouble(); @@ -211,7 +211,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_CHAR_TEST_FUNC: { + case IFooIpcCode::COMMAND_CHAR_TEST_FUNC: { zchar inParam = (zchar)data.ReadInt32(); zchar outParam; zchar inoutParam = (zchar)data.ReadInt32(); @@ -233,7 +233,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SEQ_TEST_FUNC: { + case IFooIpcCode::COMMAND_SEQ_TEST_FUNC: { std::unique_ptr inParam(data.ReadParcelable()); if (!inParam) { return ERR_INVALID_DATA; @@ -263,7 +263,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_INTERFACE_TEST_FUNC: { + case IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC: { sptr inParam = iface_cast(data.ReadRemoteObject()); if (inParam == nullptr) { return ERR_INVALID_DATA; diff --git a/test/sa_test/cmd_hitrace_tag/target/foo_stub.h.txt b/test/sa_test/cmd_hitrace_tag/target/foo_stub.h.txt index 6204fc3..dab4ecd 100644 --- a/test/sa_test/cmd_hitrace_tag/target/foo_stub.h.txt +++ b/test/sa_test/cmd_hitrace_tag/target/foo_stub.h.txt @@ -27,20 +27,6 @@ public: MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - -private: - static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_BYTE_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_SHORT_TEST_FUNC = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_INT_TEST_FUNC = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_LONG_TEST_FUNC = MIN_TRANSACTION_ID + 5; - static constexpr int32_t COMMAND_STRING_TEST_FUNC = MIN_TRANSACTION_ID + 6; - static constexpr int32_t COMMAND_FLOAT_TEST_FUNC = MIN_TRANSACTION_ID + 7; - static constexpr int32_t COMMAND_DOUBLE_TEST_FUNC = MIN_TRANSACTION_ID + 8; - static constexpr int32_t COMMAND_CHAR_TEST_FUNC = MIN_TRANSACTION_ID + 9; - static constexpr int32_t COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID + 10; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC = MIN_TRANSACTION_ID + 11; }; } // namespace test #endif // TEST_FOOSTUB_H diff --git a/test/sa_test/cmd_hitrace_tag/target/ifoo.h.txt b/test/sa_test/cmd_hitrace_tag/target/ifoo.h.txt index 3bde861..3b9ac5d 100644 --- a/test/sa_test/cmd_hitrace_tag/target/ifoo.h.txt +++ b/test/sa_test/cmd_hitrace_tag/target/ifoo.h.txt @@ -26,6 +26,21 @@ using test::myseq; using test::myinterface; namespace test { +enum class IFooIpcCode { + COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID, + COMMAND_BOOL_TEST_FUNC, + COMMAND_BYTE_TEST_FUNC, + COMMAND_SHORT_TEST_FUNC, + COMMAND_INT_TEST_FUNC, + COMMAND_LONG_TEST_FUNC, + COMMAND_STRING_TEST_FUNC, + COMMAND_FLOAT_TEST_FUNC, + COMMAND_DOUBLE_TEST_FUNC, + COMMAND_CHAR_TEST_FUNC, + COMMAND_SEQ_TEST_FUNC, + COMMAND_INTERFACE_TEST_FUNC, +}; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); diff --git a/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.cpp.txt b/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.cpp.txt index 2f46b6f..1c1ea40 100644 --- a/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.cpp.txt +++ b/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.cpp.txt @@ -36,7 +36,7 @@ ErrCode FooProxy::void_test_func() HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_VOID_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -80,7 +80,7 @@ ErrCode FooProxy::bool_test_func( HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_BOOL_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -127,7 +127,7 @@ ErrCode FooProxy::byte_test_func( HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_BYTE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -174,7 +174,7 @@ ErrCode FooProxy::short_test_func( HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SHORT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -221,7 +221,7 @@ ErrCode FooProxy::int_test_func( HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_INT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -268,7 +268,7 @@ ErrCode FooProxy::long_test_func( HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_LONG_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -315,7 +315,7 @@ ErrCode FooProxy::string_test_func( HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_STRING_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -362,7 +362,7 @@ ErrCode FooProxy::float_test_func( HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_FLOAT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -409,7 +409,7 @@ ErrCode FooProxy::double_test_func( HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_DOUBLE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -456,7 +456,7 @@ ErrCode FooProxy::char_test_func( HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_CHAR_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -503,7 +503,7 @@ ErrCode FooProxy::seq_test_func( HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SEQ_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -570,7 +570,7 @@ ErrCode FooProxy::interface_test_func( HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_INTERFACE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; diff --git a/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.h.txt b/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.h.txt index 1873b8d..e8a8046 100644 --- a/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.h.txt +++ b/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.h.txt @@ -99,19 +99,6 @@ public: sptr& funcResult) override; private: - static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_BYTE_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_SHORT_TEST_FUNC = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_INT_TEST_FUNC = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_LONG_TEST_FUNC = MIN_TRANSACTION_ID + 5; - static constexpr int32_t COMMAND_STRING_TEST_FUNC = MIN_TRANSACTION_ID + 6; - static constexpr int32_t COMMAND_FLOAT_TEST_FUNC = MIN_TRANSACTION_ID + 7; - static constexpr int32_t COMMAND_DOUBLE_TEST_FUNC = MIN_TRANSACTION_ID + 8; - static constexpr int32_t COMMAND_CHAR_TEST_FUNC = MIN_TRANSACTION_ID + 9; - static constexpr int32_t COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID + 10; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC = MIN_TRANSACTION_ID + 11; - static inline BrokerDelegator delegator_; }; } // namespace test diff --git a/test/sa_test/cmd_log_tag_domainid/target/foo_stub.cpp.txt b/test/sa_test/cmd_log_tag_domainid/target/foo_stub.cpp.txt index adee1dd..70f6801 100644 --- a/test/sa_test/cmd_log_tag_domainid/target/foo_stub.cpp.txt +++ b/test/sa_test/cmd_log_tag_domainid/target/foo_stub.cpp.txt @@ -30,8 +30,8 @@ int32_t FooStub::OnRemoteRequest( if (localDescriptor != remoteDescriptor) { return ERR_TRANSACTION_FAILED; } - switch (code) { - case COMMAND_VOID_TEST_FUNC: { + switch (static_cast(code)) { + case IFooIpcCode::COMMAND_VOID_TEST_FUNC: { ErrCode errCode = void_test_func(); if (!reply.WriteInt32(errCode)) { HiLog::Error(LABEL, "Write Int32 failed!"); @@ -39,7 +39,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_BOOL_TEST_FUNC: { + case IFooIpcCode::COMMAND_BOOL_TEST_FUNC: { bool inParam = data.ReadInt32() == 1 ? true : false; bool outParam; bool inoutParam = data.ReadInt32() == 1 ? true : false; @@ -65,7 +65,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_BYTE_TEST_FUNC: { + case IFooIpcCode::COMMAND_BYTE_TEST_FUNC: { int8_t inParam = (int8_t)data.ReadInt32(); int8_t outParam; int8_t inoutParam = (int8_t)data.ReadInt32(); @@ -91,7 +91,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SHORT_TEST_FUNC: { + case IFooIpcCode::COMMAND_SHORT_TEST_FUNC: { short inParam = (short)data.ReadInt32(); short outParam; short inoutParam = (short)data.ReadInt32(); @@ -117,7 +117,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_INT_TEST_FUNC: { + case IFooIpcCode::COMMAND_INT_TEST_FUNC: { int32_t inParam = data.ReadInt32(); int32_t outParam; int32_t inoutParam = data.ReadInt32(); @@ -143,7 +143,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_LONG_TEST_FUNC: { + case IFooIpcCode::COMMAND_LONG_TEST_FUNC: { int64_t inParam = data.ReadInt64(); int64_t outParam; int64_t inoutParam = data.ReadInt64(); @@ -169,7 +169,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_STRING_TEST_FUNC: { + case IFooIpcCode::COMMAND_STRING_TEST_FUNC: { std::string inParam = Str16ToStr8(data.ReadString16()); std::string outParam; std::string inoutParam = Str16ToStr8(data.ReadString16()); @@ -195,7 +195,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_FLOAT_TEST_FUNC: { + case IFooIpcCode::COMMAND_FLOAT_TEST_FUNC: { float inParam = data.ReadFloat(); float outParam; float inoutParam = data.ReadFloat(); @@ -221,7 +221,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_DOUBLE_TEST_FUNC: { + case IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC: { double inParam = data.ReadDouble(); double outParam; double inoutParam = data.ReadDouble(); @@ -247,7 +247,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_CHAR_TEST_FUNC: { + case IFooIpcCode::COMMAND_CHAR_TEST_FUNC: { zchar inParam = (zchar)data.ReadInt32(); zchar outParam; zchar inoutParam = (zchar)data.ReadInt32(); @@ -273,7 +273,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SEQ_TEST_FUNC: { + case IFooIpcCode::COMMAND_SEQ_TEST_FUNC: { std::unique_ptr inParam(data.ReadParcelable()); if (!inParam) { HiLog::Error(LABEL, "Read [myseq] failed!"); @@ -309,7 +309,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_INTERFACE_TEST_FUNC: { + case IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC: { sptr inParam = iface_cast(data.ReadRemoteObject()); if (inParam == nullptr) { HiLog::Error(LABEL, "Read [inParam] failed!"); diff --git a/test/sa_test/cmd_log_tag_domainid/target/foo_stub.h.txt b/test/sa_test/cmd_log_tag_domainid/target/foo_stub.h.txt index 6204fc3..dab4ecd 100644 --- a/test/sa_test/cmd_log_tag_domainid/target/foo_stub.h.txt +++ b/test/sa_test/cmd_log_tag_domainid/target/foo_stub.h.txt @@ -27,20 +27,6 @@ public: MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - -private: - static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_BYTE_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_SHORT_TEST_FUNC = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_INT_TEST_FUNC = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_LONG_TEST_FUNC = MIN_TRANSACTION_ID + 5; - static constexpr int32_t COMMAND_STRING_TEST_FUNC = MIN_TRANSACTION_ID + 6; - static constexpr int32_t COMMAND_FLOAT_TEST_FUNC = MIN_TRANSACTION_ID + 7; - static constexpr int32_t COMMAND_DOUBLE_TEST_FUNC = MIN_TRANSACTION_ID + 8; - static constexpr int32_t COMMAND_CHAR_TEST_FUNC = MIN_TRANSACTION_ID + 9; - static constexpr int32_t COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID + 10; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC = MIN_TRANSACTION_ID + 11; }; } // namespace test #endif // TEST_FOOSTUB_H diff --git a/test/sa_test/cmd_log_tag_domainid/target/ifoo.h.txt b/test/sa_test/cmd_log_tag_domainid/target/ifoo.h.txt index ad86778..68d2123 100644 --- a/test/sa_test/cmd_log_tag_domainid/target/ifoo.h.txt +++ b/test/sa_test/cmd_log_tag_domainid/target/ifoo.h.txt @@ -27,6 +27,21 @@ using test::myseq; using test::myinterface; namespace test { +enum class IFooIpcCode { + COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID, + COMMAND_BOOL_TEST_FUNC, + COMMAND_BYTE_TEST_FUNC, + COMMAND_SHORT_TEST_FUNC, + COMMAND_INT_TEST_FUNC, + COMMAND_LONG_TEST_FUNC, + COMMAND_STRING_TEST_FUNC, + COMMAND_FLOAT_TEST_FUNC, + COMMAND_DOUBLE_TEST_FUNC, + COMMAND_CHAR_TEST_FUNC, + COMMAND_SEQ_TEST_FUNC, + COMMAND_INTERFACE_TEST_FUNC, +}; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); diff --git a/test/sa_test/cmd_save_metadata/target/foo_proxy.cpp.txt b/test/sa_test/cmd_save_metadata/target/foo_proxy.cpp.txt index b44afeb..92dc6d5 100644 --- a/test/sa_test/cmd_save_metadata/target/foo_proxy.cpp.txt +++ b/test/sa_test/cmd_save_metadata/target/foo_proxy.cpp.txt @@ -31,7 +31,7 @@ ErrCode FooProxy::void_test_func() if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_VOID_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -69,7 +69,7 @@ ErrCode FooProxy::bool_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_BOOL_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -110,7 +110,7 @@ ErrCode FooProxy::byte_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_BYTE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -151,7 +151,7 @@ ErrCode FooProxy::short_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SHORT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -192,7 +192,7 @@ ErrCode FooProxy::int_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_INT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -233,7 +233,7 @@ ErrCode FooProxy::long_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_LONG_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -274,7 +274,7 @@ ErrCode FooProxy::string_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_STRING_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -315,7 +315,7 @@ ErrCode FooProxy::float_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_FLOAT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -356,7 +356,7 @@ ErrCode FooProxy::double_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_DOUBLE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -397,7 +397,7 @@ ErrCode FooProxy::char_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_CHAR_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -438,7 +438,7 @@ ErrCode FooProxy::seq_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SEQ_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -497,7 +497,7 @@ ErrCode FooProxy::interface_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_INTERFACE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/cmd_save_metadata/target/foo_proxy.h.txt b/test/sa_test/cmd_save_metadata/target/foo_proxy.h.txt index 1873b8d..e8a8046 100644 --- a/test/sa_test/cmd_save_metadata/target/foo_proxy.h.txt +++ b/test/sa_test/cmd_save_metadata/target/foo_proxy.h.txt @@ -99,19 +99,6 @@ public: sptr& funcResult) override; private: - static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_BYTE_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_SHORT_TEST_FUNC = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_INT_TEST_FUNC = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_LONG_TEST_FUNC = MIN_TRANSACTION_ID + 5; - static constexpr int32_t COMMAND_STRING_TEST_FUNC = MIN_TRANSACTION_ID + 6; - static constexpr int32_t COMMAND_FLOAT_TEST_FUNC = MIN_TRANSACTION_ID + 7; - static constexpr int32_t COMMAND_DOUBLE_TEST_FUNC = MIN_TRANSACTION_ID + 8; - static constexpr int32_t COMMAND_CHAR_TEST_FUNC = MIN_TRANSACTION_ID + 9; - static constexpr int32_t COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID + 10; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC = MIN_TRANSACTION_ID + 11; - static inline BrokerDelegator delegator_; }; } // namespace test diff --git a/test/sa_test/cmd_save_metadata/target/foo_stub.cpp.txt b/test/sa_test/cmd_save_metadata/target/foo_stub.cpp.txt index ab46269..77f87aa 100644 --- a/test/sa_test/cmd_save_metadata/target/foo_stub.cpp.txt +++ b/test/sa_test/cmd_save_metadata/target/foo_stub.cpp.txt @@ -27,15 +27,15 @@ int32_t FooStub::OnRemoteRequest( if (localDescriptor != remoteDescriptor) { return ERR_TRANSACTION_FAILED; } - switch (code) { - case COMMAND_VOID_TEST_FUNC: { + switch (static_cast(code)) { + case IFooIpcCode::COMMAND_VOID_TEST_FUNC: { ErrCode errCode = void_test_func(); if (!reply.WriteInt32(errCode)) { return ERR_INVALID_VALUE; } return ERR_NONE; } - case COMMAND_BOOL_TEST_FUNC: { + case IFooIpcCode::COMMAND_BOOL_TEST_FUNC: { bool inParam = data.ReadInt32() == 1 ? true : false; bool outParam; bool inoutParam = data.ReadInt32() == 1 ? true : false; @@ -57,7 +57,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_BYTE_TEST_FUNC: { + case IFooIpcCode::COMMAND_BYTE_TEST_FUNC: { int8_t inParam = (int8_t)data.ReadInt32(); int8_t outParam; int8_t inoutParam = (int8_t)data.ReadInt32(); @@ -79,7 +79,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SHORT_TEST_FUNC: { + case IFooIpcCode::COMMAND_SHORT_TEST_FUNC: { short inParam = (short)data.ReadInt32(); short outParam; short inoutParam = (short)data.ReadInt32(); @@ -101,7 +101,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_INT_TEST_FUNC: { + case IFooIpcCode::COMMAND_INT_TEST_FUNC: { int32_t inParam = data.ReadInt32(); int32_t outParam; int32_t inoutParam = data.ReadInt32(); @@ -123,7 +123,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_LONG_TEST_FUNC: { + case IFooIpcCode::COMMAND_LONG_TEST_FUNC: { int64_t inParam = data.ReadInt64(); int64_t outParam; int64_t inoutParam = data.ReadInt64(); @@ -145,7 +145,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_STRING_TEST_FUNC: { + case IFooIpcCode::COMMAND_STRING_TEST_FUNC: { std::string inParam = Str16ToStr8(data.ReadString16()); std::string outParam; std::string inoutParam = Str16ToStr8(data.ReadString16()); @@ -167,7 +167,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_FLOAT_TEST_FUNC: { + case IFooIpcCode::COMMAND_FLOAT_TEST_FUNC: { float inParam = data.ReadFloat(); float outParam; float inoutParam = data.ReadFloat(); @@ -189,7 +189,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_DOUBLE_TEST_FUNC: { + case IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC: { double inParam = data.ReadDouble(); double outParam; double inoutParam = data.ReadDouble(); @@ -211,7 +211,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_CHAR_TEST_FUNC: { + case IFooIpcCode::COMMAND_CHAR_TEST_FUNC: { zchar inParam = (zchar)data.ReadInt32(); zchar outParam; zchar inoutParam = (zchar)data.ReadInt32(); @@ -233,7 +233,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SEQ_TEST_FUNC: { + case IFooIpcCode::COMMAND_SEQ_TEST_FUNC: { std::unique_ptr inParam(data.ReadParcelable()); if (!inParam) { return ERR_INVALID_DATA; @@ -263,7 +263,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_INTERFACE_TEST_FUNC: { + case IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC: { sptr inParam = iface_cast(data.ReadRemoteObject()); if (inParam == nullptr) { return ERR_INVALID_DATA; diff --git a/test/sa_test/cmd_save_metadata/target/foo_stub.h.txt b/test/sa_test/cmd_save_metadata/target/foo_stub.h.txt index 6204fc3..dab4ecd 100644 --- a/test/sa_test/cmd_save_metadata/target/foo_stub.h.txt +++ b/test/sa_test/cmd_save_metadata/target/foo_stub.h.txt @@ -27,20 +27,6 @@ public: MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - -private: - static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_BYTE_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_SHORT_TEST_FUNC = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_INT_TEST_FUNC = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_LONG_TEST_FUNC = MIN_TRANSACTION_ID + 5; - static constexpr int32_t COMMAND_STRING_TEST_FUNC = MIN_TRANSACTION_ID + 6; - static constexpr int32_t COMMAND_FLOAT_TEST_FUNC = MIN_TRANSACTION_ID + 7; - static constexpr int32_t COMMAND_DOUBLE_TEST_FUNC = MIN_TRANSACTION_ID + 8; - static constexpr int32_t COMMAND_CHAR_TEST_FUNC = MIN_TRANSACTION_ID + 9; - static constexpr int32_t COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID + 10; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC = MIN_TRANSACTION_ID + 11; }; } // namespace test #endif // TEST_FOOSTUB_H diff --git a/test/sa_test/cmd_save_metadata/target/ifoo.h.txt b/test/sa_test/cmd_save_metadata/target/ifoo.h.txt index 3bde861..3b9ac5d 100644 --- a/test/sa_test/cmd_save_metadata/target/ifoo.h.txt +++ b/test/sa_test/cmd_save_metadata/target/ifoo.h.txt @@ -26,6 +26,21 @@ using test::myseq; using test::myinterface; namespace test { +enum class IFooIpcCode { + COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID, + COMMAND_BOOL_TEST_FUNC, + COMMAND_BYTE_TEST_FUNC, + COMMAND_SHORT_TEST_FUNC, + COMMAND_INT_TEST_FUNC, + COMMAND_LONG_TEST_FUNC, + COMMAND_STRING_TEST_FUNC, + COMMAND_FLOAT_TEST_FUNC, + COMMAND_DOUBLE_TEST_FUNC, + COMMAND_CHAR_TEST_FUNC, + COMMAND_SEQ_TEST_FUNC, + COMMAND_INTERFACE_TEST_FUNC, +}; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); diff --git a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.cpp.txt index a0220af..28b98c3 100644 --- a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.cpp.txt @@ -41,7 +41,7 @@ ErrCode AppFwkUpdateServiceProxy::VerifyPackageInstall( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_VERIFY_PACKAGE_INSTALL, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IAppFwkUpdateServiceIpcCode::COMMAND_VERIFY_PACKAGE_INSTALL), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.h.txt index 33e20d5..2f79390 100644 --- a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.h.txt @@ -37,8 +37,6 @@ public: int32_t& success) override; private: - static constexpr int32_t COMMAND_VERIFY_PACKAGE_INSTALL = MIN_TRANSACTION_ID + 0; - static inline BrokerDelegator delegator_; }; } // namespace NWeb diff --git a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_stub.cpp.txt b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_stub.cpp.txt index 565d956..d678322 100644 --- a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_stub.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_stub.cpp.txt @@ -28,8 +28,8 @@ int32_t AppFwkUpdateServiceStub::OnRemoteRequest( if (localDescriptor != remoteDescriptor) { return ERR_TRANSACTION_FAILED; } - switch (code) { - case COMMAND_VERIFY_PACKAGE_INSTALL: { + switch (static_cast(code)) { + case IAppFwkUpdateServiceIpcCode::COMMAND_VERIFY_PACKAGE_INSTALL: { std::string bundleName = Str16ToStr8(data.ReadString16()); std::string hapPath = Str16ToStr8(data.ReadString16()); int32_t success; diff --git a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_stub.h.txt b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_stub.h.txt index 369de91..3a57def 100644 --- a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_stub.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_stub.h.txt @@ -28,9 +28,6 @@ public: MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - -private: - static constexpr int32_t COMMAND_VERIFY_PACKAGE_INSTALL = MIN_TRANSACTION_ID + 0; }; } // namespace NWeb } // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.cpp.txt index b151a61..a9864e9 100644 --- a/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.cpp.txt @@ -37,7 +37,7 @@ ErrCode EsimServiceProxy::GetEid( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_GET_EID, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_GET_EID), data, reply, option); if (FAILED(result)) { return result; } @@ -71,7 +71,7 @@ ErrCode EsimServiceProxy::GetOsuStatus( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_GET_OSU_STATUS, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_GET_OSU_STATUS), data, reply, option); if (FAILED(result)) { return result; } @@ -105,7 +105,7 @@ ErrCode EsimServiceProxy::StartOsu( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_START_OSU, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_START_OSU), data, reply, option); if (FAILED(result)) { return result; } @@ -151,7 +151,7 @@ ErrCode EsimServiceProxy::GetDownloadableProfileMetadata( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_GET_DOWNLOADABLE_PROFILE_METADATA, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_GET_DOWNLOADABLE_PROFILE_METADATA), data, reply, option); if (FAILED(result)) { return result; } @@ -197,7 +197,7 @@ ErrCode EsimServiceProxy::GetDownloadableProfiles( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_GET_DOWNLOADABLE_PROFILES, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_GET_DOWNLOADABLE_PROFILES), data, reply, option); if (FAILED(result)) { return result; } @@ -243,7 +243,7 @@ ErrCode EsimServiceProxy::DownloadProfile( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_DOWNLOAD_PROFILE, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_DOWNLOAD_PROFILE), data, reply, option); if (FAILED(result)) { return result; } @@ -281,7 +281,7 @@ ErrCode EsimServiceProxy::GetEuiccProfileInfoList( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_GET_EUICC_PROFILE_INFO_LIST, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_GET_EUICC_PROFILE_INFO_LIST), data, reply, option); if (FAILED(result)) { return result; } @@ -319,7 +319,7 @@ ErrCode EsimServiceProxy::GetEuiccInfo( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_GET_EUICC_INFO, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_GET_EUICC_INFO), data, reply, option); if (FAILED(result)) { return result; } @@ -361,7 +361,7 @@ ErrCode EsimServiceProxy::DeleteProfile( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_DELETE_PROFILE, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_DELETE_PROFILE), data, reply, option); if (FAILED(result)) { return result; } @@ -407,7 +407,7 @@ ErrCode EsimServiceProxy::SwitchToProfile( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SWITCH_TO_PROFILE, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_SWITCH_TO_PROFILE), data, reply, option); if (FAILED(result)) { return result; } @@ -449,7 +449,7 @@ ErrCode EsimServiceProxy::SetProfileNickname( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SET_PROFILE_NICKNAME, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_SET_PROFILE_NICKNAME), data, reply, option); if (FAILED(result)) { return result; } @@ -487,7 +487,7 @@ ErrCode EsimServiceProxy::ResetMemory( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_RESET_MEMORY, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_RESET_MEMORY), data, reply, option); if (FAILED(result)) { return result; } @@ -521,7 +521,7 @@ ErrCode EsimServiceProxy::ReserveProfilesForFactoryRestore( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_RESERVE_PROFILES_FOR_FACTORY_RESTORE, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_RESERVE_PROFILES_FOR_FACTORY_RESTORE), data, reply, option); if (FAILED(result)) { return result; } @@ -559,7 +559,7 @@ ErrCode EsimServiceProxy::SetDefaultSmdpAddress( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SET_DEFAULT_SMDP_ADDRESS, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_SET_DEFAULT_SMDP_ADDRESS), data, reply, option); if (FAILED(result)) { return result; } @@ -593,7 +593,7 @@ ErrCode EsimServiceProxy::GetDefaultSmdpAddress( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_GET_DEFAULT_SMDP_ADDRESS, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_GET_DEFAULT_SMDP_ADDRESS), data, reply, option); if (FAILED(result)) { return result; } @@ -635,7 +635,7 @@ ErrCode EsimServiceProxy::CancelSession( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_CANCEL_SESSION, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_CANCEL_SESSION), data, reply, option); if (FAILED(result)) { return result; } @@ -672,7 +672,7 @@ ErrCode EsimServiceProxy::IsEsimSupported( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_IS_ESIM_SUPPORTED, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_IS_ESIM_SUPPORTED), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.h.txt index 87ab698..b20d483 100644 --- a/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.h.txt @@ -116,24 +116,6 @@ public: int32_t slotId) override; private: - static constexpr int32_t COMMAND_GET_EID = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_GET_OSU_STATUS = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_START_OSU = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_GET_DOWNLOADABLE_PROFILE_METADATA = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_GET_DOWNLOADABLE_PROFILES = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_DOWNLOAD_PROFILE = MIN_TRANSACTION_ID + 5; - static constexpr int32_t COMMAND_GET_EUICC_PROFILE_INFO_LIST = MIN_TRANSACTION_ID + 6; - static constexpr int32_t COMMAND_GET_EUICC_INFO = MIN_TRANSACTION_ID + 7; - static constexpr int32_t COMMAND_DELETE_PROFILE = MIN_TRANSACTION_ID + 8; - static constexpr int32_t COMMAND_SWITCH_TO_PROFILE = MIN_TRANSACTION_ID + 9; - static constexpr int32_t COMMAND_SET_PROFILE_NICKNAME = MIN_TRANSACTION_ID + 10; - static constexpr int32_t COMMAND_RESET_MEMORY = MIN_TRANSACTION_ID + 11; - static constexpr int32_t COMMAND_RESERVE_PROFILES_FOR_FACTORY_RESTORE = MIN_TRANSACTION_ID + 12; - static constexpr int32_t COMMAND_SET_DEFAULT_SMDP_ADDRESS = MIN_TRANSACTION_ID + 13; - static constexpr int32_t COMMAND_GET_DEFAULT_SMDP_ADDRESS = MIN_TRANSACTION_ID + 14; - static constexpr int32_t COMMAND_CANCEL_SESSION = MIN_TRANSACTION_ID + 15; - static constexpr int32_t COMMAND_IS_ESIM_SUPPORTED = MIN_TRANSACTION_ID + 16; - static inline BrokerDelegator delegator_; }; } // namespace Telephony diff --git a/test/sa_test/in_use_idl/target_cpp/esim_service_stub.cpp.txt b/test/sa_test/in_use_idl/target_cpp/esim_service_stub.cpp.txt index a39c85e..04e638f 100644 --- a/test/sa_test/in_use_idl/target_cpp/esim_service_stub.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/esim_service_stub.cpp.txt @@ -28,8 +28,8 @@ int32_t EsimServiceStub::OnRemoteRequest( if (localDescriptor != remoteDescriptor) { return ERR_TRANSACTION_FAILED; } - switch (code) { - case COMMAND_GET_EID: { + switch (static_cast(code)) { + case IEsimServiceIpcCode::COMMAND_GET_EID: { int32_t slotId = data.ReadInt32(); std::string eId; ErrCode errCode = GetEid(slotId, eId); @@ -43,7 +43,7 @@ int32_t EsimServiceStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_GET_OSU_STATUS: { + case IEsimServiceIpcCode::COMMAND_GET_OSU_STATUS: { int32_t slotId = data.ReadInt32(); int32_t osuStatus; ErrCode errCode = GetOsuStatus(slotId, osuStatus); @@ -57,7 +57,7 @@ int32_t EsimServiceStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_START_OSU: { + case IEsimServiceIpcCode::COMMAND_START_OSU: { int32_t slotId = data.ReadInt32(); int32_t startOsuResult; ErrCode errCode = StartOsu(slotId, startOsuResult); @@ -71,7 +71,7 @@ int32_t EsimServiceStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_GET_DOWNLOADABLE_PROFILE_METADATA: { + case IEsimServiceIpcCode::COMMAND_GET_DOWNLOADABLE_PROFILE_METADATA: { int32_t slotId = data.ReadInt32(); int32_t portIndex = data.ReadInt32(); std::unique_ptr profile(data.ReadParcelable()); @@ -92,7 +92,7 @@ int32_t EsimServiceStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_GET_DOWNLOADABLE_PROFILES: { + case IEsimServiceIpcCode::COMMAND_GET_DOWNLOADABLE_PROFILES: { int32_t slotId = data.ReadInt32(); int32_t portIndex = data.ReadInt32(); bool forceDisableProfile = data.ReadInt32() == 1 ? true : false; @@ -108,7 +108,7 @@ int32_t EsimServiceStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_DOWNLOAD_PROFILE: { + case IEsimServiceIpcCode::COMMAND_DOWNLOAD_PROFILE: { int32_t slotId = data.ReadInt32(); std::unique_ptr configInfo(data.ReadParcelable()); if (!configInfo) { @@ -132,7 +132,7 @@ int32_t EsimServiceStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_GET_EUICC_PROFILE_INFO_LIST: { + case IEsimServiceIpcCode::COMMAND_GET_EUICC_PROFILE_INFO_LIST: { int32_t slotId = data.ReadInt32(); GetEuiccProfileInfoListResult euiccProfileInfoList; ErrCode errCode = GetEuiccProfileInfoList(slotId, euiccProfileInfoList); @@ -146,7 +146,7 @@ int32_t EsimServiceStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_GET_EUICC_INFO: { + case IEsimServiceIpcCode::COMMAND_GET_EUICC_INFO: { int32_t slotId = data.ReadInt32(); EuiccInfo eUiccInfo; ErrCode errCode = GetEuiccInfo(slotId, eUiccInfo); @@ -160,7 +160,7 @@ int32_t EsimServiceStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_DELETE_PROFILE: { + case IEsimServiceIpcCode::COMMAND_DELETE_PROFILE: { int32_t slotId = data.ReadInt32(); std::string iccId = Str16ToStr8(data.ReadString16()); int32_t deleteProfileResult; @@ -175,7 +175,7 @@ int32_t EsimServiceStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SWITCH_TO_PROFILE: { + case IEsimServiceIpcCode::COMMAND_SWITCH_TO_PROFILE: { int32_t slotId = data.ReadInt32(); int32_t portIndex = data.ReadInt32(); std::string iccId = Str16ToStr8(data.ReadString16()); @@ -192,7 +192,7 @@ int32_t EsimServiceStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SET_PROFILE_NICKNAME: { + case IEsimServiceIpcCode::COMMAND_SET_PROFILE_NICKNAME: { int32_t slotId = data.ReadInt32(); std::string iccId = Str16ToStr8(data.ReadString16()); std::string nickname = Str16ToStr8(data.ReadString16()); @@ -208,7 +208,7 @@ int32_t EsimServiceStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_RESET_MEMORY: { + case IEsimServiceIpcCode::COMMAND_RESET_MEMORY: { int32_t slotId = data.ReadInt32(); int32_t resetOption = data.ReadInt32(); int32_t resetMemoryResult; @@ -223,7 +223,7 @@ int32_t EsimServiceStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_RESERVE_PROFILES_FOR_FACTORY_RESTORE: { + case IEsimServiceIpcCode::COMMAND_RESERVE_PROFILES_FOR_FACTORY_RESTORE: { int32_t slotId = data.ReadInt32(); int32_t restoreResult; ErrCode errCode = ReserveProfilesForFactoryRestore(slotId, restoreResult); @@ -237,7 +237,7 @@ int32_t EsimServiceStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SET_DEFAULT_SMDP_ADDRESS: { + case IEsimServiceIpcCode::COMMAND_SET_DEFAULT_SMDP_ADDRESS: { int32_t slotId = data.ReadInt32(); std::string defaultSmdpAddress = Str16ToStr8(data.ReadString16()); int32_t setDefaultSmdpAddressResult; @@ -252,7 +252,7 @@ int32_t EsimServiceStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_GET_DEFAULT_SMDP_ADDRESS: { + case IEsimServiceIpcCode::COMMAND_GET_DEFAULT_SMDP_ADDRESS: { int32_t slotId = data.ReadInt32(); std::string defaultSmdpAddress; ErrCode errCode = GetDefaultSmdpAddress(slotId, defaultSmdpAddress); @@ -266,7 +266,7 @@ int32_t EsimServiceStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_CANCEL_SESSION: { + case IEsimServiceIpcCode::COMMAND_CANCEL_SESSION: { int32_t slotId = data.ReadInt32(); std::string transactionId = Str16ToStr8(data.ReadString16()); int32_t cancelReason = data.ReadInt32(); @@ -282,7 +282,7 @@ int32_t EsimServiceStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_IS_ESIM_SUPPORTED: { + case IEsimServiceIpcCode::COMMAND_IS_ESIM_SUPPORTED: { int32_t slotId = data.ReadInt32(); ErrCode errCode = IsEsimSupported(slotId); if (!reply.WriteInt32(errCode)) { diff --git a/test/sa_test/in_use_idl/target_cpp/esim_service_stub.h.txt b/test/sa_test/in_use_idl/target_cpp/esim_service_stub.h.txt index 87b1b98..b2153a5 100644 --- a/test/sa_test/in_use_idl/target_cpp/esim_service_stub.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/esim_service_stub.h.txt @@ -28,25 +28,6 @@ public: MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - -private: - static constexpr int32_t COMMAND_GET_EID = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_GET_OSU_STATUS = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_START_OSU = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_GET_DOWNLOADABLE_PROFILE_METADATA = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_GET_DOWNLOADABLE_PROFILES = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_DOWNLOAD_PROFILE = MIN_TRANSACTION_ID + 5; - static constexpr int32_t COMMAND_GET_EUICC_PROFILE_INFO_LIST = MIN_TRANSACTION_ID + 6; - static constexpr int32_t COMMAND_GET_EUICC_INFO = MIN_TRANSACTION_ID + 7; - static constexpr int32_t COMMAND_DELETE_PROFILE = MIN_TRANSACTION_ID + 8; - static constexpr int32_t COMMAND_SWITCH_TO_PROFILE = MIN_TRANSACTION_ID + 9; - static constexpr int32_t COMMAND_SET_PROFILE_NICKNAME = MIN_TRANSACTION_ID + 10; - static constexpr int32_t COMMAND_RESET_MEMORY = MIN_TRANSACTION_ID + 11; - static constexpr int32_t COMMAND_RESERVE_PROFILES_FOR_FACTORY_RESTORE = MIN_TRANSACTION_ID + 12; - static constexpr int32_t COMMAND_SET_DEFAULT_SMDP_ADDRESS = MIN_TRANSACTION_ID + 13; - static constexpr int32_t COMMAND_GET_DEFAULT_SMDP_ADDRESS = MIN_TRANSACTION_ID + 14; - static constexpr int32_t COMMAND_CANCEL_SESSION = MIN_TRANSACTION_ID + 15; - static constexpr int32_t COMMAND_IS_ESIM_SUPPORTED = MIN_TRANSACTION_ID + 16; }; } // namespace Telephony } // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/iapp_fwk_update_service.h.txt b/test/sa_test/in_use_idl/target_cpp/iapp_fwk_update_service.h.txt index 30ce753..ea419ef 100644 --- a/test/sa_test/in_use_idl/target_cpp/iapp_fwk_update_service.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/iapp_fwk_update_service.h.txt @@ -22,6 +22,10 @@ namespace OHOS { namespace NWeb { +enum class IAppFwkUpdateServiceIpcCode { + COMMAND_VERIFY_PACKAGE_INSTALL = MIN_TRANSACTION_ID, +}; + class IAppFwkUpdateService : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.NWeb.IAppFwkUpdateService"); diff --git a/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.cpp.txt index ffff89d..e9be07f 100644 --- a/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.cpp.txt @@ -35,7 +35,7 @@ ErrCode IdlTestServiceProxy::TestIntTransaction( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_TEST_INT_TRANSACTION, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IIdlTestServiceIpcCode::COMMAND_TEST_INT_TRANSACTION), data, reply, option); if (FAILED(result)) { return result; } @@ -67,7 +67,7 @@ ErrCode IdlTestServiceProxy::TestStringTransaction( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_TEST_STRING_TRANSACTION, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IIdlTestServiceIpcCode::COMMAND_TEST_STRING_TRANSACTION), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.h.txt index 3d8c19a..367ac7d 100644 --- a/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.h.txt @@ -37,9 +37,6 @@ public: const std::string& val) override; private: - static constexpr int32_t COMMAND_TEST_INT_TRANSACTION = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_TEST_STRING_TRANSACTION = MIN_TRANSACTION_ID + 1; - static inline BrokerDelegator delegator_; }; } // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/idl_test_service_stub.cpp.txt b/test/sa_test/in_use_idl/target_cpp/idl_test_service_stub.cpp.txt index c6993c5..c7fc962 100644 --- a/test/sa_test/in_use_idl/target_cpp/idl_test_service_stub.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/idl_test_service_stub.cpp.txt @@ -27,8 +27,8 @@ int32_t IdlTestServiceStub::OnRemoteRequest( if (localDescriptor != remoteDescriptor) { return ERR_TRANSACTION_FAILED; } - switch (code) { - case COMMAND_TEST_INT_TRANSACTION: { + switch (static_cast(code)) { + case IIdlTestServiceIpcCode::COMMAND_TEST_INT_TRANSACTION: { int32_t val = data.ReadInt32(); ErrCode errCode = TestIntTransaction(val); if (!reply.WriteInt32(errCode)) { @@ -36,7 +36,7 @@ int32_t IdlTestServiceStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_TEST_STRING_TRANSACTION: { + case IIdlTestServiceIpcCode::COMMAND_TEST_STRING_TRANSACTION: { std::string val = Str16ToStr8(data.ReadString16()); ErrCode errCode = TestStringTransaction(val); if (!reply.WriteInt32(errCode)) { diff --git a/test/sa_test/in_use_idl/target_cpp/idl_test_service_stub.h.txt b/test/sa_test/in_use_idl/target_cpp/idl_test_service_stub.h.txt index 83ad285..b19c6be 100644 --- a/test/sa_test/in_use_idl/target_cpp/idl_test_service_stub.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/idl_test_service_stub.h.txt @@ -27,10 +27,6 @@ public: MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - -private: - static constexpr int32_t COMMAND_TEST_INT_TRANSACTION = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_TEST_STRING_TRANSACTION = MIN_TRANSACTION_ID + 1; }; } // namespace OHOS #endif // OHOS_IDLTESTSERVICESTUB_H diff --git a/test/sa_test/in_use_idl/target_cpp/iesim_service.h.txt b/test/sa_test/in_use_idl/target_cpp/iesim_service.h.txt index c032151..ab955f7 100644 --- a/test/sa_test/in_use_idl/target_cpp/iesim_service.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/iesim_service.h.txt @@ -39,6 +39,26 @@ using OHOS::Telephony::ResponseEsimResult; namespace OHOS { namespace Telephony { +enum class IEsimServiceIpcCode { + COMMAND_GET_EID = MIN_TRANSACTION_ID, + COMMAND_GET_OSU_STATUS, + COMMAND_START_OSU, + COMMAND_GET_DOWNLOADABLE_PROFILE_METADATA, + COMMAND_GET_DOWNLOADABLE_PROFILES, + COMMAND_DOWNLOAD_PROFILE, + COMMAND_GET_EUICC_PROFILE_INFO_LIST, + COMMAND_GET_EUICC_INFO, + COMMAND_DELETE_PROFILE, + COMMAND_SWITCH_TO_PROFILE, + COMMAND_SET_PROFILE_NICKNAME, + COMMAND_RESET_MEMORY, + COMMAND_RESERVE_PROFILES_FOR_FACTORY_RESTORE, + COMMAND_SET_DEFAULT_SMDP_ADDRESS, + COMMAND_GET_DEFAULT_SMDP_ADDRESS, + COMMAND_CANCEL_SESSION, + COMMAND_IS_ESIM_SUPPORTED, +}; + class IEsimService : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Telephony.IEsimService"); diff --git a/test/sa_test/in_use_idl/target_cpp/iidl_test_service.h.txt b/test/sa_test/in_use_idl/target_cpp/iidl_test_service.h.txt index 947e5f0..9bc066b 100644 --- a/test/sa_test/in_use_idl/target_cpp/iidl_test_service.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/iidl_test_service.h.txt @@ -21,6 +21,11 @@ #include namespace OHOS { +enum class IIdlTestServiceIpcCode { + COMMAND_TEST_INT_TRANSACTION = MIN_TRANSACTION_ID, + COMMAND_TEST_STRING_TRANSACTION, +}; + class IIdlTestService : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IIdlTestService"); diff --git a/test/sa_test/in_use_idl/target_cpp/iquick_fix_manager.h.txt b/test/sa_test/in_use_idl/target_cpp/iquick_fix_manager.h.txt index aed70f0..bbb2e8f 100644 --- a/test/sa_test/in_use_idl/target_cpp/iquick_fix_manager.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/iquick_fix_manager.h.txt @@ -26,6 +26,12 @@ using OHOS::AAFwk::ApplicationQuickFixInfo; namespace OHOS { namespace AAFwk { +enum class IQuickFixManagerIpcCode { + COMMAND_APPLY_QUICK_FIX = MIN_TRANSACTION_ID, + COMMAND_GET_APPLYED_QUICK_FIX_INFO, + COMMAND_REVOKE_QUICK_FIX, +}; + class IQuickFixManager : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.AAFwk.IQuickFixManager"); diff --git a/test/sa_test/in_use_idl/target_cpp/itest_server_interface.h.txt b/test/sa_test/in_use_idl/target_cpp/itest_server_interface.h.txt index 80de32a..51f8894 100644 --- a/test/sa_test/in_use_idl/target_cpp/itest_server_interface.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/itest_server_interface.h.txt @@ -27,6 +27,12 @@ using OHOS::EventFwk::CommonEventData; namespace OHOS { namespace testserver { +enum class ITestServerInterfaceIpcCode { + COMMAND_CREATE_SESSION = MIN_TRANSACTION_ID, + COMMAND_SET_PASTE_DATA, + COMMAND_PUBLISH_COMMON_EVENT, +}; + class ITestServerInterface : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.testserver.ITestServerInterface"); diff --git a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.cpp.txt index 2051f96..28e873b 100644 --- a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.cpp.txt @@ -46,7 +46,7 @@ ErrCode QuickFixManagerProxy::ApplyQuickFix( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_APPLY_QUICK_FIX, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IQuickFixManagerIpcCode::COMMAND_APPLY_QUICK_FIX), data, reply, option); if (FAILED(result)) { return result; } @@ -79,7 +79,7 @@ ErrCode QuickFixManagerProxy::GetApplyedQuickFixInfo( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_GET_APPLYED_QUICK_FIX_INFO, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IQuickFixManagerIpcCode::COMMAND_GET_APPLYED_QUICK_FIX_INFO), data, reply, option); if (FAILED(result)) { return result; } @@ -116,7 +116,7 @@ ErrCode QuickFixManagerProxy::RevokeQuickFix( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_REVOKE_QUICK_FIX, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IQuickFixManagerIpcCode::COMMAND_REVOKE_QUICK_FIX), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.h.txt index 0c58c3e..4497777 100644 --- a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.h.txt @@ -43,10 +43,6 @@ public: const std::string& bundleName) override; private: - static constexpr int32_t COMMAND_APPLY_QUICK_FIX = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_GET_APPLYED_QUICK_FIX_INFO = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_REVOKE_QUICK_FIX = MIN_TRANSACTION_ID + 2; - static inline BrokerDelegator delegator_; }; } // namespace AAFwk diff --git a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_stub.cpp.txt b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_stub.cpp.txt index 76bdfb2..8e53db8 100644 --- a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_stub.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_stub.cpp.txt @@ -28,8 +28,8 @@ int32_t QuickFixManagerStub::OnRemoteRequest( if (localDescriptor != remoteDescriptor) { return ERR_TRANSACTION_FAILED; } - switch (code) { - case COMMAND_APPLY_QUICK_FIX: { + switch (static_cast(code)) { + case IQuickFixManagerIpcCode::COMMAND_APPLY_QUICK_FIX: { std::vector quickFixFiles; int32_t quickFixFilesSize = data.ReadInt32(); if (quickFixFilesSize > static_cast(VECTOR_MAX_SIZE)) { @@ -46,7 +46,7 @@ int32_t QuickFixManagerStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_GET_APPLYED_QUICK_FIX_INFO: { + case IQuickFixManagerIpcCode::COMMAND_GET_APPLYED_QUICK_FIX_INFO: { std::string bundleName = Str16ToStr8(data.ReadString16()); ApplicationQuickFixInfo quickFixInfo; ErrCode errCode = GetApplyedQuickFixInfo(bundleName, quickFixInfo); @@ -60,7 +60,7 @@ int32_t QuickFixManagerStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_REVOKE_QUICK_FIX: { + case IQuickFixManagerIpcCode::COMMAND_REVOKE_QUICK_FIX: { std::string bundleName = Str16ToStr8(data.ReadString16()); ErrCode errCode = RevokeQuickFix(bundleName); if (!reply.WriteInt32(errCode)) { diff --git a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_stub.h.txt b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_stub.h.txt index a3c8807..de030e1 100644 --- a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_stub.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_stub.h.txt @@ -28,11 +28,6 @@ public: MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - -private: - static constexpr int32_t COMMAND_APPLY_QUICK_FIX = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_GET_APPLYED_QUICK_FIX_INFO = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_REVOKE_QUICK_FIX = MIN_TRANSACTION_ID + 2; }; } // namespace AAFwk } // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.cpp.txt index 69d85b0..bf3a9e7 100644 --- a/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.cpp.txt @@ -36,7 +36,7 @@ ErrCode TestServerInterfaceProxy::CreateSession( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_CREATE_SESSION, data, reply, option); + int32_t result = remote->SendRequest(static_cast(ITestServerInterfaceIpcCode::COMMAND_CREATE_SESSION), data, reply, option); if (FAILED(result)) { return result; } @@ -68,7 +68,7 @@ ErrCode TestServerInterfaceProxy::SetPasteData( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SET_PASTE_DATA, data, reply, option); + int32_t result = remote->SendRequest(static_cast(ITestServerInterfaceIpcCode::COMMAND_SET_PASTE_DATA), data, reply, option); if (FAILED(result)) { return result; } @@ -101,7 +101,7 @@ ErrCode TestServerInterfaceProxy::PublishCommonEvent( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_PUBLISH_COMMON_EVENT, data, reply, option); + int32_t result = remote->SendRequest(static_cast(ITestServerInterfaceIpcCode::COMMAND_PUBLISH_COMMON_EVENT), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.h.txt index ded8218..b5e2d80 100644 --- a/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.h.txt @@ -42,10 +42,6 @@ public: bool& re) override; private: - static constexpr int32_t COMMAND_CREATE_SESSION = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_SET_PASTE_DATA = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_PUBLISH_COMMON_EVENT = MIN_TRANSACTION_ID + 2; - static inline BrokerDelegator delegator_; }; } // namespace testserver diff --git a/test/sa_test/in_use_idl/target_cpp/test_server_interface_stub.cpp.txt b/test/sa_test/in_use_idl/target_cpp/test_server_interface_stub.cpp.txt index c85a0c6..8a7019a 100644 --- a/test/sa_test/in_use_idl/target_cpp/test_server_interface_stub.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/test_server_interface_stub.cpp.txt @@ -28,8 +28,8 @@ int32_t TestServerInterfaceStub::OnRemoteRequest( if (localDescriptor != remoteDescriptor) { return ERR_TRANSACTION_FAILED; } - switch (code) { - case COMMAND_CREATE_SESSION: { + switch (static_cast(code)) { + case ITestServerInterfaceIpcCode::COMMAND_CREATE_SESSION: { std::unique_ptr sessionToken(data.ReadParcelable()); if (!sessionToken) { return ERR_INVALID_DATA; @@ -41,7 +41,7 @@ int32_t TestServerInterfaceStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SET_PASTE_DATA: { + case ITestServerInterfaceIpcCode::COMMAND_SET_PASTE_DATA: { std::string text = Str16ToStr8(data.ReadString16()); ErrCode errCode = SetPasteData(text); if (!reply.WriteInt32(errCode)) { @@ -49,7 +49,7 @@ int32_t TestServerInterfaceStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_PUBLISH_COMMON_EVENT: { + case ITestServerInterfaceIpcCode::COMMAND_PUBLISH_COMMON_EVENT: { std::unique_ptr event(data.ReadParcelable()); if (!event) { return ERR_INVALID_DATA; diff --git a/test/sa_test/in_use_idl/target_cpp/test_server_interface_stub.h.txt b/test/sa_test/in_use_idl/target_cpp/test_server_interface_stub.h.txt index 2c7628a..4343cdc 100644 --- a/test/sa_test/in_use_idl/target_cpp/test_server_interface_stub.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/test_server_interface_stub.h.txt @@ -28,11 +28,6 @@ public: MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - -private: - static constexpr int32_t COMMAND_CREATE_SESSION = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_SET_PASTE_DATA = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_PUBLISH_COMMON_EVENT = MIN_TRANSACTION_ID + 2; }; } // namespace testserver } // namespace OHOS diff --git a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.cpp.txt b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.cpp.txt index 6c9ec10..a7b9e30 100644 --- a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.cpp.txt @@ -33,7 +33,7 @@ ErrCode FooProxy::test001( return ERR_INVALID_DATA; } - bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), COMMAND_TEST001, data, reply); + bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST001), data, reply); if (hitCache == true) { ErrCode errCode = reply.ReadInt32(); if (FAILED(errCode)) { @@ -47,7 +47,7 @@ ErrCode FooProxy::test001( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_TEST001, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_TEST001), data, reply, option); if (FAILED(result)) { return result; } @@ -57,7 +57,7 @@ ErrCode FooProxy::test001( return errCode; } - ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), COMMAND_TEST001, data, reply); + ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST001), data, reply); funcResult = reply.ReadInt32(); return ERR_OK; } @@ -77,7 +77,7 @@ ErrCode FooProxy::test002( return ERR_INVALID_DATA; } - bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), COMMAND_TEST002, data, reply); + bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST002), data, reply); if (hitCache == true) { ErrCode errCode = reply.ReadInt32(); if (FAILED(errCode)) { @@ -90,7 +90,7 @@ ErrCode FooProxy::test002( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_TEST002, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_TEST002), data, reply, option); if (FAILED(result)) { return result; } @@ -100,7 +100,7 @@ ErrCode FooProxy::test002( return errCode; } - ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), COMMAND_TEST002, data, reply); + ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST002), data, reply); return ERR_OK; } @@ -120,7 +120,7 @@ ErrCode FooProxy::test003( return ERR_INVALID_DATA; } - bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), COMMAND_TEST003, data, reply); + bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST003), data, reply); if (hitCache == true) { ErrCode errCode = reply.ReadInt32(); if (FAILED(errCode)) { @@ -134,7 +134,7 @@ ErrCode FooProxy::test003( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_TEST003, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_TEST003), data, reply, option); if (FAILED(result)) { return result; } @@ -144,7 +144,7 @@ ErrCode FooProxy::test003( return errCode; } - ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), COMMAND_TEST003, data, reply); + ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST003), data, reply); param2 = reply.ReadInt32(); return ERR_OK; } @@ -175,7 +175,7 @@ ErrCode FooProxy::test004( } } - bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), COMMAND_TEST004, data, reply); + bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST004), data, reply); if (hitCache == true) { ErrCode errCode = reply.ReadInt32(); if (FAILED(errCode)) { @@ -194,7 +194,7 @@ ErrCode FooProxy::test004( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_TEST004, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_TEST004), data, reply, option); if (FAILED(result)) { return result; } @@ -204,7 +204,7 @@ ErrCode FooProxy::test004( return errCode; } - ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), COMMAND_TEST004, data, reply); + ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST004), data, reply); int32_t outParamSize = reply.ReadInt32(); for (int32_t i = 0; i < outParamSize; ++i) { int64_t key = reply.ReadInt64(); @@ -230,7 +230,7 @@ ErrCode FooProxy::test005( return ERR_INVALID_DATA; } - bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), COMMAND_TEST005, data, reply); + bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005), data, reply); if (hitCache == true) { ErrCode errCode = reply.ReadInt32(); if (FAILED(errCode)) { @@ -244,7 +244,7 @@ ErrCode FooProxy::test005( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_TEST005, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_TEST005), data, reply, option); if (FAILED(result)) { return result; } @@ -254,7 +254,7 @@ ErrCode FooProxy::test005( return errCode; } - ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), COMMAND_TEST005, data, reply); + ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005), data, reply); param2 = reply.ReadDouble(); return ERR_OK; } diff --git a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.h.txt b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.h.txt index 3ec76dc..3b67fc9 100644 --- a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.h.txt @@ -28,11 +28,11 @@ public: const sptr& remote) : IRemoteProxy(remote) { - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), COMMAND_TEST001, 100000); - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), COMMAND_TEST002, 0); - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), COMMAND_TEST003, 0); - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), COMMAND_TEST004, 200000); - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), COMMAND_TEST005, 2147483647000); + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST001), 100000); + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST002), 0); + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST003), 0); + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST004), 200000); + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005), 2147483647000); if (remote != nullptr) { if (!remote->IsProxyObject()) { @@ -60,11 +60,11 @@ public: remote_->RemoveDeathRecipient(deathRecipient_); remote_ = nullptr; - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), COMMAND_TEST001); - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), COMMAND_TEST002); - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), COMMAND_TEST003); - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), COMMAND_TEST004); - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), COMMAND_TEST005); + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST001)); + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST002)); + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST003)); + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST004)); + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005)); } ErrCode test001( @@ -106,12 +106,6 @@ private: } sptr remote_ = nullptr; sptr deathRecipient_ = nullptr; - static constexpr int32_t COMMAND_TEST001 = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_TEST002 = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_TEST003 = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_TEST004 = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_TEST005 = MIN_TRANSACTION_ID + 4; - static inline BrokerDelegator delegator_; }; } // namespace OHOS diff --git a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_stub.cpp.txt b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_stub.cpp.txt index aef3bef..16e77ab 100644 --- a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_stub.cpp.txt +++ b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_stub.cpp.txt @@ -28,8 +28,8 @@ int32_t FooStub::OnRemoteRequest( if (localDescriptor != remoteDescriptor) { return ERR_TRANSACTION_FAILED; } - switch (code) { - case COMMAND_TEST001: { + switch (static_cast(code)) { + case IFooIpcCode::COMMAND_TEST001: { short param1 = (short)data.ReadInt32(); int32_t result; ErrCode errCode = test001(param1, result); @@ -43,7 +43,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_TEST002: { + case IFooIpcCode::COMMAND_TEST002: { int32_t param1 = data.ReadInt32(); ErrCode errCode = test002(param1); if (!reply.WriteInt32(errCode)) { @@ -51,7 +51,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_TEST003: { + case IFooIpcCode::COMMAND_TEST003: { float param1 = data.ReadFloat(); int32_t param2; ErrCode errCode = test003(param1, param2); @@ -65,7 +65,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_TEST004: { + case IFooIpcCode::COMMAND_TEST004: { std::unordered_map inParam; int32_t inParamSize = data.ReadInt32(); for (int32_t i = 0; i < inParamSize; ++i) { @@ -95,7 +95,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_TEST005: { + case IFooIpcCode::COMMAND_TEST005: { short param1 = (short)data.ReadInt32(); double param2; ErrCode errCode = test005(param1, param2); diff --git a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_stub.h.txt b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_stub.h.txt index ad31c1a..9490e0d 100644 --- a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_stub.h.txt +++ b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_stub.h.txt @@ -28,13 +28,6 @@ public: MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - -private: - static constexpr int32_t COMMAND_TEST001 = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_TEST002 = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_TEST003 = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_TEST004 = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_TEST005 = MIN_TRANSACTION_ID + 4; }; } // namespace OHOS } // namespace idl diff --git a/test/sa_test/keyword_cacheable_test_001/target_cpp/ifoo.h.txt b/test/sa_test/keyword_cacheable_test_001/target_cpp/ifoo.h.txt index 1cddb80..f47d3c9 100644 --- a/test/sa_test/keyword_cacheable_test_001/target_cpp/ifoo.h.txt +++ b/test/sa_test/keyword_cacheable_test_001/target_cpp/ifoo.h.txt @@ -23,6 +23,14 @@ namespace idl { namespace OHOS { +enum class IFooIpcCode { + COMMAND_TEST001 = MIN_TRANSACTION_ID, + COMMAND_TEST002, + COMMAND_TEST003, + COMMAND_TEST004, + COMMAND_TEST005, +}; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"idl.OHOS.IFoo"); diff --git a/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.cpp.txt b/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.cpp.txt index 751300f..84946f5 100644 --- a/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.cpp.txt @@ -36,7 +36,7 @@ ErrCode FooProxy::test001( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_TEST001, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_TEST001), data, reply, option); if (FAILED(result)) { return result; } @@ -62,7 +62,7 @@ ErrCode FooProxy::test002( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_TEST002, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_TEST002), data, reply, option); if (FAILED(result)) { return result; } @@ -85,7 +85,7 @@ ErrCode FooProxy::test005( return ERR_INVALID_DATA; } - bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), COMMAND_TEST005, data, reply); + bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005), data, reply); if (hitCache == true) { ErrCode errCode = reply.ReadInt32(); if (FAILED(errCode)) { @@ -99,7 +99,7 @@ ErrCode FooProxy::test005( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_TEST005, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_TEST005), data, reply, option); if (FAILED(result)) { return result; } @@ -109,7 +109,7 @@ ErrCode FooProxy::test005( return errCode; } - ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), COMMAND_TEST005, data, reply); + ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005), data, reply); param2 = reply.ReadDouble(); return ERR_OK; } @@ -130,7 +130,7 @@ ErrCode FooProxy::test005( return ERR_INVALID_DATA; } - bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), COMMAND_TEST005, data, reply); + bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005), data, reply); if (hitCache == true) { ErrCode errCode = reply.ReadInt32(); if (FAILED(errCode)) { @@ -144,7 +144,7 @@ ErrCode FooProxy::test005( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_TEST005, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_TEST005), data, reply, option); if (FAILED(result)) { return result; } @@ -154,7 +154,7 @@ ErrCode FooProxy::test005( return errCode; } - ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), COMMAND_TEST005, data, reply); + ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005), data, reply); param2 = reply.ReadInt32(); return ERR_OK; } diff --git a/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.h.txt b/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.h.txt index 9deaa49..40f60c7 100644 --- a/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.h.txt @@ -28,8 +28,8 @@ public: const sptr& remote) : IRemoteProxy(remote) { - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), COMMAND_TEST005, 0); - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), COMMAND_TEST005, 2000); + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005), 0); + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005), 2000); if (remote != nullptr) { if (!remote->IsProxyObject()) { @@ -57,8 +57,8 @@ public: remote_->RemoveDeathRecipient(deathRecipient_); remote_ = nullptr; - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), COMMAND_TEST005); - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), COMMAND_TEST005); + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005)); + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005)); } ErrCode test001( @@ -95,11 +95,6 @@ private: } sptr remote_ = nullptr; sptr deathRecipient_ = nullptr; - static constexpr int32_t COMMAND_TEST001 = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_TEST002 = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_TEST005 = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_TEST005 = MIN_TRANSACTION_ID + 3; - static inline BrokerDelegator delegator_; }; } // namespace OHOS diff --git a/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_stub.cpp.txt b/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_stub.cpp.txt index 28664d2..1f27a1b 100644 --- a/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_stub.cpp.txt +++ b/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_stub.cpp.txt @@ -28,8 +28,8 @@ int32_t FooStub::OnRemoteRequest( if (localDescriptor != remoteDescriptor) { return ERR_TRANSACTION_FAILED; } - switch (code) { - case COMMAND_TEST001: { + switch (static_cast(code)) { + case IFooIpcCode::COMMAND_TEST001: { int32_t param1 = data.ReadInt32(); ErrCode errCode = test001(param1); if (!reply.WriteInt32(errCode)) { @@ -37,7 +37,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_TEST002: { + case IFooIpcCode::COMMAND_TEST002: { double param1 = data.ReadDouble(); ErrCode errCode = test002(param1); if (!reply.WriteInt32(errCode)) { @@ -45,7 +45,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_TEST005: { + case IFooIpcCode::COMMAND_TEST005: { short param1 = (short)data.ReadInt32(); double param2; ErrCode errCode = test005(param1, param2); @@ -59,7 +59,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_TEST005: { + case IFooIpcCode::COMMAND_TEST005: { int32_t param1 = data.ReadInt32(); int32_t param2; ErrCode errCode = test005(param1, param2); diff --git a/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_stub.h.txt b/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_stub.h.txt index 1a16917..9490e0d 100644 --- a/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_stub.h.txt +++ b/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_stub.h.txt @@ -28,12 +28,6 @@ public: MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - -private: - static constexpr int32_t COMMAND_TEST001 = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_TEST002 = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_TEST005 = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_TEST005 = MIN_TRANSACTION_ID + 3; }; } // namespace OHOS } // namespace idl diff --git a/test/sa_test/keyword_cacheable_test_002/target_cpp/ifoo.h.txt b/test/sa_test/keyword_cacheable_test_002/target_cpp/ifoo.h.txt index 909522c..9a1e224 100644 --- a/test/sa_test/keyword_cacheable_test_002/target_cpp/ifoo.h.txt +++ b/test/sa_test/keyword_cacheable_test_002/target_cpp/ifoo.h.txt @@ -22,6 +22,13 @@ namespace idl { namespace OHOS { +enum class IFooIpcCode { + COMMAND_TEST001 = MIN_TRANSACTION_ID, + COMMAND_TEST002, + COMMAND_TEST005, + COMMAND_TEST005, +}; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"idl.OHOS.IFoo"); diff --git a/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.cpp.txt b/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.cpp.txt index 3590686..ef08645 100644 --- a/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.cpp.txt @@ -40,7 +40,7 @@ ErrCode FooProxy::seq_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SEQ_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -87,7 +87,7 @@ ErrCode FooProxy::seq_test_func2( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SEQ_TEST_FUNC2, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC2), data, reply, option); if (FAILED(result)) { return result; } @@ -140,7 +140,7 @@ ErrCode FooProxy::interface_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_INTERFACE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -185,7 +185,7 @@ ErrCode FooProxy::interface_test_func2( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_INTERFACE_TEST_FUNC2, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC2), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.h.txt b/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.h.txt index 99b7f33..51b1f0c 100644 --- a/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.h.txt @@ -51,11 +51,6 @@ public: const sptr& inoutParam) override; private: - static constexpr int32_t COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_SEQ_TEST_FUNC2 = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC2 = MIN_TRANSACTION_ID + 3; - static inline BrokerDelegator delegator_; }; } // namespace test diff --git a/test/sa_test/keyword_import_dir/target_cpp/foo_stub.cpp.txt b/test/sa_test/keyword_import_dir/target_cpp/foo_stub.cpp.txt index 9db880c..8091683 100644 --- a/test/sa_test/keyword_import_dir/target_cpp/foo_stub.cpp.txt +++ b/test/sa_test/keyword_import_dir/target_cpp/foo_stub.cpp.txt @@ -27,8 +27,8 @@ int32_t FooStub::OnRemoteRequest( if (localDescriptor != remoteDescriptor) { return ERR_TRANSACTION_FAILED; } - switch (code) { - case COMMAND_SEQ_TEST_FUNC: { + switch (static_cast(code)) { + case IFooIpcCode::COMMAND_SEQ_TEST_FUNC: { std::unique_ptr inParam(data.ReadParcelable()); if (!inParam) { return ERR_INVALID_DATA; @@ -54,7 +54,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SEQ_TEST_FUNC2: { + case IFooIpcCode::COMMAND_SEQ_TEST_FUNC2: { std::unique_ptr inParam(data.ReadParcelable()); if (!inParam) { return ERR_INVALID_DATA; @@ -80,7 +80,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_INTERFACE_TEST_FUNC: { + case IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC: { sptr inParam = iface_cast(data.ReadRemoteObject()); if (inParam == nullptr) { return ERR_INVALID_DATA; @@ -112,7 +112,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_INTERFACE_TEST_FUNC2: { + case IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC2: { sptr inParam = iface_cast(data.ReadRemoteObject()); if (inParam == nullptr) { return ERR_INVALID_DATA; diff --git a/test/sa_test/keyword_import_dir/target_cpp/foo_stub.h.txt b/test/sa_test/keyword_import_dir/target_cpp/foo_stub.h.txt index 79c3a3e..dab4ecd 100644 --- a/test/sa_test/keyword_import_dir/target_cpp/foo_stub.h.txt +++ b/test/sa_test/keyword_import_dir/target_cpp/foo_stub.h.txt @@ -27,12 +27,6 @@ public: MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - -private: - static constexpr int32_t COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_SEQ_TEST_FUNC2 = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC2 = MIN_TRANSACTION_ID + 3; }; } // namespace test #endif // TEST_FOOSTUB_H diff --git a/test/sa_test/keyword_import_dir/target_cpp/ifoo.h.txt b/test/sa_test/keyword_import_dir/target_cpp/ifoo.h.txt index bb326e6..765ffd9 100644 --- a/test/sa_test/keyword_import_dir/target_cpp/ifoo.h.txt +++ b/test/sa_test/keyword_import_dir/target_cpp/ifoo.h.txt @@ -30,6 +30,13 @@ using test::myinterface; using ::myinterface2; namespace test { +enum class IFooIpcCode { + COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID, + COMMAND_SEQ_TEST_FUNC2, + COMMAND_INTERFACE_TEST_FUNC, + COMMAND_INTERFACE_TEST_FUNC2, +}; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); diff --git a/test/sa_test/keyword_ipccode_test_001.py b/test/sa_test/keyword_ipccode_test_001.py new file mode 100644 index 0000000..41cf059 --- /dev/null +++ b/test/sa_test/keyword_ipccode_test_001.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from test_base import Test + + +class KeywordIpccodeTest001(Test): + def get_file_name(self): + return __file__ + + def run_cpp(self): + self.set_gen_cpp_env() + return self.run_choose(True) + + def run(self): + return self.run_cpp() + +if __name__ == "__main__": + KeywordIpccodeTest001().test() \ No newline at end of file diff --git a/test/sa_test/keyword_ipccode_test_001/foo/IFoo.idl b/test/sa_test/keyword_ipccode_test_001/foo/IFoo.idl new file mode 100644 index 0000000..b032761 --- /dev/null +++ b/test/sa_test/keyword_ipccode_test_001/foo/IFoo.idl @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +sequenceable test.myseq; +interface test.myinterface; + +interface test.IFoo { + void void_test_func(); + [ipccode 20] void bool_test_func([in] boolean inParam, [out] boolean outParam, [inout] boolean inoutParam); + void byte_test_func([in] byte inParam, [out] byte outParam, [inout] byte inoutParam); + [ipccode 0X2, cacheable 200] void short_test_func([in] short inParam, [out] short outParam, [inout] short inoutParam); + void int_test_func([in] int inParam, [out] int outParam, [inout] int inoutParam); + [ipccode 5] void long_test_func([in] long inParam, [out] long outParam, [inout] long inoutParam); + [oneway, ipccode 009] void string_test_func([in] String inParam, [in] String outParam, [in] String inoutParam); + [ipccode 0x0b, oneway] void float_test_func([in] float inParam, [in] float outParam, [in] float inoutParam); + void double_test_func([in] double inParam, [out] double outParam, [inout] double inoutParam); + void seq_test_func([in] myseq inParam, [out] myseq outParam, [inout] myseq inoutParam); + void interface_test_func([in] myinterface inParam, [out] myinterface outParam, [inout] myinterface inoutParam); +} diff --git a/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.cpp.txt b/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.cpp.txt new file mode 100644 index 0000000..caa597e --- /dev/null +++ b/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.cpp.txt @@ -0,0 +1,452 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "foo_proxy.h" + +namespace test { +ErrCode FooProxy::void_test_func() +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + return ERR_OK; +} + +ErrCode FooProxy::bool_test_func( + bool inParam, + bool& outParam, + bool inoutParam) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(inParam ? 1 : 0)) { + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(inoutParam ? 1 : 0)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = reply.ReadInt32() == 1 ? true : false; + inoutParam = reply.ReadInt32() == 1 ? true : false; + return ERR_OK; +} + +ErrCode FooProxy::byte_test_func( + int8_t inParam, + int8_t& outParam, + int8_t inoutParam) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = (int8_t)reply.ReadInt32(); + inoutParam = (int8_t)reply.ReadInt32(); + return ERR_OK; +} + +ErrCode FooProxy::short_test_func( + short inParam, + short& outParam, + short inoutParam) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(inoutParam)) { + return ERR_INVALID_DATA; + } + + bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply); + if (hitCache == true) { + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + outParam = (short)reply.ReadInt32(); + inoutParam = (short)reply.ReadInt32(); + return ERR_OK; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply); + outParam = (short)reply.ReadInt32(); + inoutParam = (short)reply.ReadInt32(); + return ERR_OK; +} + +ErrCode FooProxy::int_test_func( + int32_t inParam, + int32_t& outParam, + int32_t inoutParam) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = reply.ReadInt32(); + inoutParam = reply.ReadInt32(); + return ERR_OK; +} + +ErrCode FooProxy::long_test_func( + int64_t inParam, + int64_t& outParam, + int64_t inoutParam) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt64(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteInt64(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = reply.ReadInt64(); + inoutParam = reply.ReadInt64(); + return ERR_OK; +} + +ErrCode FooProxy::string_test_func( + const std::string& inParam, + const std::string& outParam, + const std::string& inoutParam) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(inParam))) { + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(outParam))) { + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(inoutParam))) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + return ERR_OK; +} + +ErrCode FooProxy::float_test_func( + float inParam, + float outParam, + float inoutParam) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteFloat(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteFloat(outParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteFloat(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + return ERR_OK; +} + +ErrCode FooProxy::double_test_func( + double inParam, + double& outParam, + double inoutParam) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteDouble(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteDouble(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = reply.ReadDouble(); + inoutParam = reply.ReadDouble(); + return ERR_OK; +} + +ErrCode FooProxy::seq_test_func( + const myseq& inParam, + myseq& outParam, + myseq* inoutParam) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteParcelable(&inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteParcelable(&inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + std::unique_ptr outParamInfo(reply.ReadParcelable()); + if (outParamInfo != nullptr) { + outParam = *outParamInfo; + } + + std::unique_ptr inoutParamInfo(reply.ReadParcelable()); + if (inoutParamInfo != nullptr) { + inoutParam = *inoutParamInfo; + } + + return ERR_OK; +} + +ErrCode FooProxy::interface_test_func( + const sptr& inParam, + sptr& outParam, + const sptr& inoutParam) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (inParam == nullptr) { + return ERR_INVALID_DATA; + } + if (!data.WriteRemoteObject(inParam->AsObject())) { + return ERR_INVALID_DATA; + } + if (inoutParam == nullptr) { + return ERR_INVALID_DATA; + } + if (!data.WriteRemoteObject(inoutParam->AsObject())) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = iface_cast(reply.ReadRemoteObject()); + inoutParam = iface_cast(reply.ReadRemoteObject()); + return ERR_OK; +} +} // namespace test diff --git a/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.h.txt b/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.h.txt new file mode 100644 index 0000000..8fe1620 --- /dev/null +++ b/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.h.txt @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FOOPROXY_H +#define TEST_FOOPROXY_H + +#include "ifoo.h" +#include + +namespace test { +class FooProxy : public IRemoteProxy { +public: + explicit FooProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} + + virtual ~FooProxy() + {} + + ErrCode void_test_func() override; + + ErrCode bool_test_func( + bool inParam, + bool& outParam, + bool inoutParam) override; + + ErrCode byte_test_func( + int8_t inParam, + int8_t& outParam, + int8_t inoutParam) override; + + ErrCode short_test_func( + short inParam, + short& outParam, + short inoutParam) override; + + ErrCode int_test_func( + int32_t inParam, + int32_t& outParam, + int32_t inoutParam) override; + + ErrCode long_test_func( + int64_t inParam, + int64_t& outParam, + int64_t inoutParam) override; + + ErrCode string_test_func( + const std::string& inParam, + const std::string& outParam, + const std::string& inoutParam) override; + + ErrCode float_test_func( + float inParam, + float outParam, + float inoutParam) override; + + ErrCode double_test_func( + double inParam, + double& outParam, + double inoutParam) override; + + ErrCode seq_test_func( + const myseq& inParam, + myseq& outParam, + myseq* inoutParam) override; + + ErrCode interface_test_func( + const sptr& inParam, + sptr& outParam, + const sptr& inoutParam) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace test +#endif // TEST_FOOPROXY_H + diff --git a/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_stub.cpp.txt b/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_stub.cpp.txt new file mode 100644 index 0000000..cc812e6 --- /dev/null +++ b/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_stub.cpp.txt @@ -0,0 +1,230 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "foo_stub.h" + +namespace test { +int32_t FooStub::OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) +{ + std::u16string localDescriptor = GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (localDescriptor != remoteDescriptor) { + return ERR_TRANSACTION_FAILED; + } + switch (static_cast(code)) { + case IFooIpcCode::COMMAND_VOID_TEST_FUNC: { + ErrCode errCode = void_test_func(); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IFooIpcCode::COMMAND_BOOL_TEST_FUNC: { + bool inParam = data.ReadInt32() == 1 ? true : false; + bool outParam; + bool inoutParam = data.ReadInt32() == 1 ? true : false; + ErrCode errCode = bool_test_func(inParam, outParam, inoutParam); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(outParam ? 1 : 0)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(inoutParam ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IFooIpcCode::COMMAND_BYTE_TEST_FUNC: { + int8_t inParam = (int8_t)data.ReadInt32(); + int8_t outParam; + int8_t inoutParam = (int8_t)data.ReadInt32(); + ErrCode errCode = byte_test_func(inParam, outParam, inoutParam); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(inoutParam)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IFooIpcCode::COMMAND_SHORT_TEST_FUNC: { + short inParam = (short)data.ReadInt32(); + short outParam; + short inoutParam = (short)data.ReadInt32(); + ErrCode errCode = short_test_func(inParam, outParam, inoutParam); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(inoutParam)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IFooIpcCode::COMMAND_INT_TEST_FUNC: { + int32_t inParam = data.ReadInt32(); + int32_t outParam; + int32_t inoutParam = data.ReadInt32(); + ErrCode errCode = int_test_func(inParam, outParam, inoutParam); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(inoutParam)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IFooIpcCode::COMMAND_LONG_TEST_FUNC: { + int64_t inParam = data.ReadInt64(); + int64_t outParam; + int64_t inoutParam = data.ReadInt64(); + ErrCode errCode = long_test_func(inParam, outParam, inoutParam); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt64(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt64(inoutParam)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IFooIpcCode::COMMAND_STRING_TEST_FUNC: { + std::string inParam = Str16ToStr8(data.ReadString16()); + std::string outParam = Str16ToStr8(data.ReadString16()); + std::string inoutParam = Str16ToStr8(data.ReadString16()); + ErrCode errCode = string_test_func(inParam, outParam, inoutParam); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IFooIpcCode::COMMAND_FLOAT_TEST_FUNC: { + float inParam = data.ReadFloat(); + float outParam = data.ReadFloat(); + float inoutParam = data.ReadFloat(); + ErrCode errCode = float_test_func(inParam, outParam, inoutParam); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC: { + double inParam = data.ReadDouble(); + double outParam; + double inoutParam = data.ReadDouble(); + ErrCode errCode = double_test_func(inParam, outParam, inoutParam); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteDouble(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteDouble(inoutParam)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IFooIpcCode::COMMAND_SEQ_TEST_FUNC: { + std::unique_ptr inParam(data.ReadParcelable()); + if (!inParam) { + return ERR_INVALID_DATA; + } + + myseq outParam; + std::unique_ptr inoutParam(data.ReadParcelable()); + if (!inoutParam) { + return ERR_INVALID_DATA; + } + + ErrCode errCode = seq_test_func(*inParam, outParam, *inoutParam); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteParcelable(&outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteParcelable(&inoutParam)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC: { + sptr inParam = iface_cast(data.ReadRemoteObject()); + if (inParam == nullptr) { + return ERR_INVALID_DATA; + } + + sptr outParam; + sptr inoutParam = iface_cast(data.ReadRemoteObject()); + if (inoutParam == nullptr) { + return ERR_INVALID_DATA; + } + + ErrCode errCode = interface_test_func(inParam, outParam, inoutParam); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (outParam == nullptr) { + return ERR_INVALID_DATA; + } + if (!reply.WriteRemoteObject(outParam->AsObject())) { + return ERR_INVALID_DATA; + } + if (inoutParam == nullptr) { + return ERR_INVALID_DATA; + } + if (!reply.WriteRemoteObject(inoutParam->AsObject())) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + + return ERR_TRANSACTION_FAILED; +} +} // namespace test diff --git a/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_stub.h.txt b/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_stub.h.txt new file mode 100644 index 0000000..dab4ecd --- /dev/null +++ b/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_stub.h.txt @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FOOSTUB_H +#define TEST_FOOSTUB_H + +#include "ifoo.h" +#include + +namespace test { +class FooStub : public IRemoteStub { +public: + int32_t OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) override; +}; +} // namespace test +#endif // TEST_FOOSTUB_H + diff --git a/test/sa_test/keyword_ipccode_test_001/target_cpp/ifoo.h.txt b/test/sa_test/keyword_ipccode_test_001/target_cpp/ifoo.h.txt new file mode 100644 index 0000000..90e0f58 --- /dev/null +++ b/test/sa_test/keyword_ipccode_test_001/target_cpp/ifoo.h.txt @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_IFOO_H +#define TEST_IFOO_H + +#include +#include +#include +#include "myinterface.h" +#include "myseq.h" + +using test::myseq; +using test::myinterface; + +namespace test { +enum class IFooIpcCode { + COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID, + COMMAND_BOOL_TEST_FUNC = 20, + COMMAND_BYTE_TEST_FUNC, + COMMAND_SHORT_TEST_FUNC = 2, + COMMAND_INT_TEST_FUNC, + COMMAND_LONG_TEST_FUNC = 5, + COMMAND_STRING_TEST_FUNC = 9, + COMMAND_FLOAT_TEST_FUNC = 11, + COMMAND_DOUBLE_TEST_FUNC, + COMMAND_SEQ_TEST_FUNC, + COMMAND_INTERFACE_TEST_FUNC, +}; + +class IFoo : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); + + virtual ErrCode void_test_func() = 0; + + virtual ErrCode bool_test_func( + bool inParam, + bool& outParam, + bool inoutParam) = 0; + + virtual ErrCode byte_test_func( + int8_t inParam, + int8_t& outParam, + int8_t inoutParam) = 0; + + virtual ErrCode short_test_func( + short inParam, + short& outParam, + short inoutParam) = 0; + + virtual ErrCode int_test_func( + int32_t inParam, + int32_t& outParam, + int32_t inoutParam) = 0; + + virtual ErrCode long_test_func( + int64_t inParam, + int64_t& outParam, + int64_t inoutParam) = 0; + + virtual ErrCode string_test_func( + const std::string& inParam, + const std::string& outParam, + const std::string& inoutParam) = 0; + + virtual ErrCode float_test_func( + float inParam, + float outParam, + float inoutParam) = 0; + + virtual ErrCode double_test_func( + double inParam, + double& outParam, + double inoutParam) = 0; + + virtual ErrCode seq_test_func( + const myseq& inParam, + myseq& outParam, + myseq* inoutParam) = 0; + + virtual ErrCode interface_test_func( + const sptr& inParam, + sptr& outParam, + const sptr& inoutParam) = 0; +protected: + const int VECTOR_MAX_SIZE = 102400; + const int LIST_MAX_SIZE = 102400; + const int MAP_MAX_SIZE = 102400; +}; +} // namespace test +#endif // TEST_IFOO_H + diff --git a/test/sa_test/keyword_ipccode_test_002.py b/test/sa_test/keyword_ipccode_test_002.py new file mode 100644 index 0000000..499fcbd --- /dev/null +++ b/test/sa_test/keyword_ipccode_test_002.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from test_base import Test + + +class KeywordIpccodeTest002(Test): + def get_file_name(self): + return __file__ + + def run_cpp(self): + self.set_gen_cpp_env() + return self.run_choose(False) + + def run(self): + return self.run_cpp() + +if __name__ == "__main__": + KeywordIpccodeTest002().test() \ No newline at end of file diff --git a/test/sa_test/keyword_ipccode_test_002/foo/IFoo.idl b/test/sa_test/keyword_ipccode_test_002/foo/IFoo.idl new file mode 100644 index 0000000..93365db --- /dev/null +++ b/test/sa_test/keyword_ipccode_test_002/foo/IFoo.idl @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +interface test.IFoo { + void test_func1(); + [ipccode] void test_func2(); + void test_func3(); + [ipccode 0] void test_func4(); + void test_func5(); + [ipccode 100000000] void test_func6(); + void test_func7(); + [ipccode 100000000000000] void test_func8(); + void test_func9(); + [ipccode 1, cacheable 200] void test_func10(); + void test_func11(); + [cacheable 200, ipccode] void test_func12(); + void test_func13(); + [ipccode, cacheable 200] void test_func14(); + void test_func15(); + [cacheable 200, ipccode 1] void test_func16(); + void test_func17(); + [ipccode 100, cacheable 200] void test_func18(); + void test_func19(); + [cacheable 200, ipccode 102] void test_func20(); + void test_func21(); + [cacheable 200, ipccode 104, oneway] void test_func22(); + void test_func23(); + [ipccode 10a, cacheable 200] void test_func24(); + [ipccode 10.1, cacheable 200] void test_func25(); + [ipccode 0x1000, cacheable 200] void test_func26(); + [ipccode 0x, cacheable 200] void test_func27(); + [ipccode 0xffffff, cacheable 200] void test_func28(); + [cacheable 200] void test_func29(); + [ipccode] void test_func30(); + [ipccode 200, ipccode] void test_func31(); + [ipccode 201, ipccode 1] void test_func32(); + [ipccode, ipccode 300] void test_func33(); + [ipccode \ No newline at end of file diff --git a/test/sa_test/keyword_ipccode_test_002/target_cpp/fail_output.txt b/test/sa_test/keyword_ipccode_test_002/target_cpp/fail_output.txt new file mode 100644 index 0000000..c8d43fb --- /dev/null +++ b/test/sa_test/keyword_ipccode_test_002/target_cpp/fail_output.txt @@ -0,0 +1,31 @@ +[IDL-GEN]: [ParseAttrUnitIpccode:551] [IFoo.idl:18:13] error:Ipccode attr cannot be empty +[IDL-GEN]: [ParseAttrUnitIpccode:570] [IFoo.idl:20:14] error:ipccode 0 is out of range [1, 16777215] +[IDL-GEN]: [ParseAttrUnitIpccode:570] [IFoo.idl:22:14] error:ipccode 100000000 is out of range [1, 16777215] +[IDL-GEN]: [ParseAttrUnitIpccode:567] [IFoo.idl:24:14] error:100000000000000 is illegal ipccode value +[IDL-GEN]: [CheckIpcCodeValue:696] error:the ipccode 1 is duplicated +[IDL-GEN]: [CheckIpcCodeValue:696] error:the ipccode 2 is duplicated +[IDL-GEN]: [ParseAttrUnitIpccode:551] [IFoo.idl:28:28] error:Ipccode attr cannot be empty +[IDL-GEN]: [CheckIpcCodeValue:696] error:the ipccode 3 is duplicated +[IDL-GEN]: [CheckIpcCodeValue:696] error:the ipccode 4 is duplicated +[IDL-GEN]: [ParseAttrUnitIpccode:551] [IFoo.idl:30:13] error:Ipccode attr cannot be empty +[IDL-GEN]: [CheckIpcCodeValue:696] error:the ipccode 5 is duplicated +[IDL-GEN]: [CheckIpcCodeValue:696] error:the ipccode 6 is duplicated +[IDL-GEN]: [CheckIpcCodeValue:696] error:the ipccode 1 is duplicated +[IDL-GEN]: [CheckIpcCodeValue:696] error:the ipccode 2 is duplicated +[IDL-GEN]: [ParseAttrUnitIpccode:567] [IFoo.idl:40:14] error:10a is illegal ipccode value +[IDL-GEN]: [ParseAttrUnitIpccode:567] [IFoo.idl:41:14] error:10.1 is illegal ipccode value +[IDL-GEN]: [ParseAttrUnitIpccode:567] [IFoo.idl:43:14] error:0x is illegal ipccode value +[IDL-GEN]: [CheckIpcCodeValue:693] error:the ipccode 16777216 is out of range [1, 16777215] +[IDL-GEN]: [ParseAttrUnitIpccode:551] [IFoo.idl:46:13] error:Ipccode attr cannot be empty +[IDL-GEN]: [CheckIpcCodeValue:693] error:the ipccode 16777217 is out of range [1, 16777215] +[IDL-GEN]: [ParseAttrUnitIpccode:542] [IFoo.idl:47:19] error:Duplicate declared attr ipc code +[IDL-GEN]: [ParseAttrUnitIpccode:542] [IFoo.idl:48:19] error:Duplicate declared attr ipc code +[IDL-GEN]: [ParseAttributeInfo:461] [IFoo.idl:48:27] error:expected ',' or ']' before '1' token +[IDL-GEN]: [ParseAttrUnitIpccode:551] [IFoo.idl:49:13] error:Ipccode attr cannot be empty +[IDL-GEN]: [ParseAttrUnitIpccode:551] [IFoo.idl:50:6] error:Ipccode attr cannot be empty +[IDL-GEN]: [ParseAttributeInfo:461] [IFoo.idl:50:6] error:expected ',' or ']' before '' token +[IDL-GEN]: [ParseMethod:765] [IFoo.idl:50:6] error:expected method name before '' token +[IDL-GEN]: [ParseMethodParamList:907] [IFoo.idl:50:6] error:expected '(' before '' token +[IDL-GEN]: [ParseMethod:778] [IFoo.idl:50:6] error:expected ';' before '' token +[IDL-GEN]: [ParseInterfaceBody:738] [IFoo.idl:50:6] error:expected '}' before '' token +[IDL-GEN]: failed to parse file \ No newline at end of file diff --git a/test/sa_test/keyword_oneway/target_cpp/foo_proxy.cpp.txt.txt b/test/sa_test/keyword_oneway/target_cpp/foo_proxy.cpp.txt.txt index 4c27e09..617cb40 100644 --- a/test/sa_test/keyword_oneway/target_cpp/foo_proxy.cpp.txt.txt +++ b/test/sa_test/keyword_oneway/target_cpp/foo_proxy.cpp.txt.txt @@ -31,7 +31,7 @@ ErrCode FooProxy::void_test_func() if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_VOID_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -57,7 +57,7 @@ ErrCode FooProxy::bool_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_BOOL_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -83,7 +83,7 @@ ErrCode FooProxy::byte_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_BYTE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -109,7 +109,7 @@ ErrCode FooProxy::short_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SHORT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -135,7 +135,7 @@ ErrCode FooProxy::int_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_INT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -143,7 +143,7 @@ ErrCode FooProxy::int_test_func( } ErrCode FooProxy::long_test_func( - long inParam) + int64_t inParam) { MessageParcel data; MessageParcel reply; @@ -161,7 +161,7 @@ ErrCode FooProxy::long_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_LONG_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -187,7 +187,7 @@ ErrCode FooProxy::string_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_STRING_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -213,7 +213,7 @@ ErrCode FooProxy::float_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_FLOAT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -239,7 +239,7 @@ ErrCode FooProxy::double_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_DOUBLE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -265,7 +265,7 @@ ErrCode FooProxy::char_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_CHAR_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -291,7 +291,7 @@ ErrCode FooProxy::seq_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SEQ_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -309,7 +309,10 @@ ErrCode FooProxy::interface_test_func( return ERR_INVALID_VALUE; } - if (!data.WriteRemoteObject(inParam)) { + if (inParam == nullptr) { + return ERR_INVALID_DATA; + } + if (!data.WriteRemoteObject(inParam->AsObject())) { return ERR_INVALID_DATA; } @@ -317,7 +320,7 @@ ErrCode FooProxy::interface_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_INTERFACE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/keyword_oneway/target_cpp/foo_proxy.h.txt.txt b/test/sa_test/keyword_oneway/target_cpp/foo_proxy.h.txt.txt index 825dd6a..94963ea 100644 --- a/test/sa_test/keyword_oneway/target_cpp/foo_proxy.h.txt.txt +++ b/test/sa_test/keyword_oneway/target_cpp/foo_proxy.h.txt.txt @@ -45,7 +45,7 @@ public: int32_t inParam) override; ErrCode long_test_func( - long inParam) override; + int64_t inParam) override; ErrCode string_test_func( const std::string& inParam) override; @@ -66,19 +66,6 @@ public: const sptr& inParam) override; private: - static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_BYTE_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_SHORT_TEST_FUNC = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_INT_TEST_FUNC = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_LONG_TEST_FUNC = MIN_TRANSACTION_ID + 5; - static constexpr int32_t COMMAND_STRING_TEST_FUNC = MIN_TRANSACTION_ID + 6; - static constexpr int32_t COMMAND_FLOAT_TEST_FUNC = MIN_TRANSACTION_ID + 7; - static constexpr int32_t COMMAND_DOUBLE_TEST_FUNC = MIN_TRANSACTION_ID + 8; - static constexpr int32_t COMMAND_CHAR_TEST_FUNC = MIN_TRANSACTION_ID + 9; - static constexpr int32_t COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID + 10; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC = MIN_TRANSACTION_ID + 11; - static inline BrokerDelegator delegator_; }; } // namespace test diff --git a/test/sa_test/keyword_oneway/target_cpp/foo_stub.cpp.txt.txt b/test/sa_test/keyword_oneway/target_cpp/foo_stub.cpp.txt.txt index 7f38ac9..30db658 100644 --- a/test/sa_test/keyword_oneway/target_cpp/foo_stub.cpp.txt.txt +++ b/test/sa_test/keyword_oneway/target_cpp/foo_stub.cpp.txt.txt @@ -27,15 +27,15 @@ int32_t FooStub::OnRemoteRequest( if (localDescriptor != remoteDescriptor) { return ERR_TRANSACTION_FAILED; } - switch (code) { - case COMMAND_VOID_TEST_FUNC: { + switch (static_cast(code)) { + case IFooIpcCode::COMMAND_VOID_TEST_FUNC: { ErrCode errCode = void_test_func(); if (!reply.WriteInt32(errCode)) { return ERR_INVALID_VALUE; } return ERR_NONE; } - case COMMAND_BOOL_TEST_FUNC: { + case IFooIpcCode::COMMAND_BOOL_TEST_FUNC: { bool inParam = data.ReadInt32() == 1 ? true : false; ErrCode errCode = bool_test_func(inParam); if (!reply.WriteInt32(errCode)) { @@ -43,7 +43,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_BYTE_TEST_FUNC: { + case IFooIpcCode::COMMAND_BYTE_TEST_FUNC: { int8_t inParam = (int8_t)data.ReadInt32(); ErrCode errCode = byte_test_func(inParam); if (!reply.WriteInt32(errCode)) { @@ -51,7 +51,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SHORT_TEST_FUNC: { + case IFooIpcCode::COMMAND_SHORT_TEST_FUNC: { short inParam = (short)data.ReadInt32(); ErrCode errCode = short_test_func(inParam); if (!reply.WriteInt32(errCode)) { @@ -59,7 +59,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_INT_TEST_FUNC: { + case IFooIpcCode::COMMAND_INT_TEST_FUNC: { int32_t inParam = data.ReadInt32(); ErrCode errCode = int_test_func(inParam); if (!reply.WriteInt32(errCode)) { @@ -67,15 +67,15 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_LONG_TEST_FUNC: { - long inParam = data.ReadInt64(); + case IFooIpcCode::COMMAND_LONG_TEST_FUNC: { + int64_t inParam = data.ReadInt64(); ErrCode errCode = long_test_func(inParam); if (!reply.WriteInt32(errCode)) { return ERR_INVALID_VALUE; } return ERR_NONE; } - case COMMAND_STRING_TEST_FUNC: { + case IFooIpcCode::COMMAND_STRING_TEST_FUNC: { std::string inParam = Str16ToStr8(data.ReadString16()); ErrCode errCode = string_test_func(inParam); if (!reply.WriteInt32(errCode)) { @@ -83,7 +83,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_FLOAT_TEST_FUNC: { + case IFooIpcCode::COMMAND_FLOAT_TEST_FUNC: { float inParam = data.ReadFloat(); ErrCode errCode = float_test_func(inParam); if (!reply.WriteInt32(errCode)) { @@ -91,7 +91,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_DOUBLE_TEST_FUNC: { + case IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC: { double inParam = data.ReadDouble(); ErrCode errCode = double_test_func(inParam); if (!reply.WriteInt32(errCode)) { @@ -99,7 +99,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_CHAR_TEST_FUNC: { + case IFooIpcCode::COMMAND_CHAR_TEST_FUNC: { zchar inParam = (zchar)data.ReadInt32(); ErrCode errCode = char_test_func(inParam); if (!reply.WriteInt32(errCode)) { @@ -107,11 +107,11 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SEQ_TEST_FUNC: { - if ((!data.ReadParcelable())) { + case IFooIpcCode::COMMAND_SEQ_TEST_FUNC: { + std::unique_ptr inParam(data.ReadParcelable()); + if (!inParam) { return ERR_INVALID_DATA; } - std::unique_ptr inParam(data.ReadParcelable()); ErrCode errCode = seq_test_func(*inParam); if (!reply.WriteInt32(errCode)) { @@ -119,8 +119,8 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_INTERFACE_TEST_FUNC: { - sptr inParam = data.ReadRemoteObject(); + case IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC: { + sptr inParam = iface_cast(data.ReadRemoteObject()); if (inParam == nullptr) { return ERR_INVALID_DATA; } diff --git a/test/sa_test/keyword_oneway/target_cpp/foo_stub.h.txt.txt b/test/sa_test/keyword_oneway/target_cpp/foo_stub.h.txt.txt index 6204fc3..dab4ecd 100644 --- a/test/sa_test/keyword_oneway/target_cpp/foo_stub.h.txt.txt +++ b/test/sa_test/keyword_oneway/target_cpp/foo_stub.h.txt.txt @@ -27,20 +27,6 @@ public: MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - -private: - static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_BYTE_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_SHORT_TEST_FUNC = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_INT_TEST_FUNC = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_LONG_TEST_FUNC = MIN_TRANSACTION_ID + 5; - static constexpr int32_t COMMAND_STRING_TEST_FUNC = MIN_TRANSACTION_ID + 6; - static constexpr int32_t COMMAND_FLOAT_TEST_FUNC = MIN_TRANSACTION_ID + 7; - static constexpr int32_t COMMAND_DOUBLE_TEST_FUNC = MIN_TRANSACTION_ID + 8; - static constexpr int32_t COMMAND_CHAR_TEST_FUNC = MIN_TRANSACTION_ID + 9; - static constexpr int32_t COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID + 10; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC = MIN_TRANSACTION_ID + 11; }; } // namespace test #endif // TEST_FOOSTUB_H diff --git a/test/sa_test/keyword_oneway/target_cpp/ifoo.h.txt.txt b/test/sa_test/keyword_oneway/target_cpp/ifoo.h.txt.txt index 7f618a8..c4d2e10 100644 --- a/test/sa_test/keyword_oneway/target_cpp/ifoo.h.txt.txt +++ b/test/sa_test/keyword_oneway/target_cpp/ifoo.h.txt.txt @@ -16,16 +16,31 @@ #ifndef TEST_IFOO_H #define TEST_IFOO_H -#include #include #include -#include "myseq.h" +#include #include "myinterface.h" +#include "myseq.h" using test::myseq; using test::myinterface; namespace test { +enum class IFooIpcCode { + COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID, + COMMAND_BOOL_TEST_FUNC, + COMMAND_BYTE_TEST_FUNC, + COMMAND_SHORT_TEST_FUNC, + COMMAND_INT_TEST_FUNC, + COMMAND_LONG_TEST_FUNC, + COMMAND_STRING_TEST_FUNC, + COMMAND_FLOAT_TEST_FUNC, + COMMAND_DOUBLE_TEST_FUNC, + COMMAND_CHAR_TEST_FUNC, + COMMAND_SEQ_TEST_FUNC, + COMMAND_INTERFACE_TEST_FUNC, +}; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); @@ -45,7 +60,7 @@ public: int32_t inParam) = 0; virtual ErrCode long_test_func( - long inParam) = 0; + int64_t inParam) = 0; virtual ErrCode string_test_func( const std::string& inParam) = 0; diff --git a/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt index 228f189..666bb49 100644 --- a/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt @@ -31,7 +31,7 @@ ErrCode FooProxy::void_test_func() if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_VOID_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -81,7 +81,7 @@ ErrCode FooProxy::bool_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_BOOL_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -155,7 +155,7 @@ ErrCode FooProxy::byte_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_BYTE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -229,7 +229,7 @@ ErrCode FooProxy::short_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SHORT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -303,7 +303,7 @@ ErrCode FooProxy::int_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_INT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -377,7 +377,7 @@ ErrCode FooProxy::long_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_LONG_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -451,7 +451,7 @@ ErrCode FooProxy::string_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_STRING_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -525,7 +525,7 @@ ErrCode FooProxy::float_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_FLOAT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -599,7 +599,7 @@ ErrCode FooProxy::double_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_DOUBLE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -673,7 +673,7 @@ ErrCode FooProxy::char_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_CHAR_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -747,7 +747,7 @@ ErrCode FooProxy::seq_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SEQ_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -839,7 +839,7 @@ ErrCode FooProxy::interface_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_INTERFACE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/type_array/target_cpp/foo_proxy.h.txt b/test/sa_test/type_array/target_cpp/foo_proxy.h.txt index ccd71b8..eff3259 100644 --- a/test/sa_test/type_array/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_array/target_cpp/foo_proxy.h.txt @@ -99,19 +99,6 @@ public: std::vector>& funcResult) override; private: - static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_BYTE_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_SHORT_TEST_FUNC = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_INT_TEST_FUNC = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_LONG_TEST_FUNC = MIN_TRANSACTION_ID + 5; - static constexpr int32_t COMMAND_STRING_TEST_FUNC = MIN_TRANSACTION_ID + 6; - static constexpr int32_t COMMAND_FLOAT_TEST_FUNC = MIN_TRANSACTION_ID + 7; - static constexpr int32_t COMMAND_DOUBLE_TEST_FUNC = MIN_TRANSACTION_ID + 8; - static constexpr int32_t COMMAND_CHAR_TEST_FUNC = MIN_TRANSACTION_ID + 9; - static constexpr int32_t COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID + 10; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC = MIN_TRANSACTION_ID + 11; - static inline BrokerDelegator delegator_; }; } // namespace test diff --git a/test/sa_test/type_array/target_cpp/foo_stub.cpp.txt b/test/sa_test/type_array/target_cpp/foo_stub.cpp.txt index c34fd1f..cbe79f8 100644 --- a/test/sa_test/type_array/target_cpp/foo_stub.cpp.txt +++ b/test/sa_test/type_array/target_cpp/foo_stub.cpp.txt @@ -27,15 +27,15 @@ int32_t FooStub::OnRemoteRequest( if (localDescriptor != remoteDescriptor) { return ERR_TRANSACTION_FAILED; } - switch (code) { - case COMMAND_VOID_TEST_FUNC: { + switch (static_cast(code)) { + case IFooIpcCode::COMMAND_VOID_TEST_FUNC: { ErrCode errCode = void_test_func(); if (!reply.WriteInt32(errCode)) { return ERR_INVALID_VALUE; } return ERR_NONE; } - case COMMAND_BOOL_TEST_FUNC: { + case IFooIpcCode::COMMAND_BOOL_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -91,7 +91,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_BYTE_TEST_FUNC: { + case IFooIpcCode::COMMAND_BYTE_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -147,7 +147,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SHORT_TEST_FUNC: { + case IFooIpcCode::COMMAND_SHORT_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -203,7 +203,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_INT_TEST_FUNC: { + case IFooIpcCode::COMMAND_INT_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -259,7 +259,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_LONG_TEST_FUNC: { + case IFooIpcCode::COMMAND_LONG_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -315,7 +315,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_STRING_TEST_FUNC: { + case IFooIpcCode::COMMAND_STRING_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -371,7 +371,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_FLOAT_TEST_FUNC: { + case IFooIpcCode::COMMAND_FLOAT_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -427,7 +427,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_DOUBLE_TEST_FUNC: { + case IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -483,7 +483,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_CHAR_TEST_FUNC: { + case IFooIpcCode::COMMAND_CHAR_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -539,7 +539,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SEQ_TEST_FUNC: { + case IFooIpcCode::COMMAND_SEQ_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -603,7 +603,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_INTERFACE_TEST_FUNC: { + case IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC: { std::vector> inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { diff --git a/test/sa_test/type_array/target_cpp/foo_stub.h.txt b/test/sa_test/type_array/target_cpp/foo_stub.h.txt index 6204fc3..dab4ecd 100644 --- a/test/sa_test/type_array/target_cpp/foo_stub.h.txt +++ b/test/sa_test/type_array/target_cpp/foo_stub.h.txt @@ -27,20 +27,6 @@ public: MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - -private: - static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_BYTE_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_SHORT_TEST_FUNC = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_INT_TEST_FUNC = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_LONG_TEST_FUNC = MIN_TRANSACTION_ID + 5; - static constexpr int32_t COMMAND_STRING_TEST_FUNC = MIN_TRANSACTION_ID + 6; - static constexpr int32_t COMMAND_FLOAT_TEST_FUNC = MIN_TRANSACTION_ID + 7; - static constexpr int32_t COMMAND_DOUBLE_TEST_FUNC = MIN_TRANSACTION_ID + 8; - static constexpr int32_t COMMAND_CHAR_TEST_FUNC = MIN_TRANSACTION_ID + 9; - static constexpr int32_t COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID + 10; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC = MIN_TRANSACTION_ID + 11; }; } // namespace test #endif // TEST_FOOSTUB_H diff --git a/test/sa_test/type_array/target_cpp/ifoo.h.txt b/test/sa_test/type_array/target_cpp/ifoo.h.txt index b24be16..dcbf6d4 100644 --- a/test/sa_test/type_array/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_array/target_cpp/ifoo.h.txt @@ -27,6 +27,21 @@ using test::myseq; using test::myinterface; namespace test { +enum class IFooIpcCode { + COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID, + COMMAND_BOOL_TEST_FUNC, + COMMAND_BYTE_TEST_FUNC, + COMMAND_SHORT_TEST_FUNC, + COMMAND_INT_TEST_FUNC, + COMMAND_LONG_TEST_FUNC, + COMMAND_STRING_TEST_FUNC, + COMMAND_FLOAT_TEST_FUNC, + COMMAND_DOUBLE_TEST_FUNC, + COMMAND_CHAR_TEST_FUNC, + COMMAND_SEQ_TEST_FUNC, + COMMAND_INTERFACE_TEST_FUNC, +}; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); diff --git a/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt index b49f076..5483302 100644 --- a/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt @@ -53,7 +53,7 @@ ErrCode FooProxy::bool_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_BOOL_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -127,7 +127,7 @@ ErrCode FooProxy::byte_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_BYTE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -201,7 +201,7 @@ ErrCode FooProxy::short_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SHORT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -275,7 +275,7 @@ ErrCode FooProxy::int_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_INT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -349,7 +349,7 @@ ErrCode FooProxy::long_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_LONG_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -423,7 +423,7 @@ ErrCode FooProxy::string_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_STRING_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -497,7 +497,7 @@ ErrCode FooProxy::float_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_FLOAT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -571,7 +571,7 @@ ErrCode FooProxy::double_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_DOUBLE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -645,7 +645,7 @@ ErrCode FooProxy::char_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_CHAR_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -719,7 +719,7 @@ ErrCode FooProxy::seq_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SEQ_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -811,7 +811,7 @@ ErrCode FooProxy::interface_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_INTERFACE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/type_list/target_cpp/foo_proxy.h.txt b/test/sa_test/type_list/target_cpp/foo_proxy.h.txt index 2272a78..5d882af 100644 --- a/test/sa_test/type_list/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_list/target_cpp/foo_proxy.h.txt @@ -97,18 +97,6 @@ public: std::vector>& funcResult) override; private: - static constexpr int32_t COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_BYTE_TEST_FUNC = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_SHORT_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_INT_TEST_FUNC = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_LONG_TEST_FUNC = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_STRING_TEST_FUNC = MIN_TRANSACTION_ID + 5; - static constexpr int32_t COMMAND_FLOAT_TEST_FUNC = MIN_TRANSACTION_ID + 6; - static constexpr int32_t COMMAND_DOUBLE_TEST_FUNC = MIN_TRANSACTION_ID + 7; - static constexpr int32_t COMMAND_CHAR_TEST_FUNC = MIN_TRANSACTION_ID + 8; - static constexpr int32_t COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID + 9; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC = MIN_TRANSACTION_ID + 10; - static inline BrokerDelegator delegator_; }; } // namespace test diff --git a/test/sa_test/type_list/target_cpp/foo_stub.cpp.txt b/test/sa_test/type_list/target_cpp/foo_stub.cpp.txt index 6af9e2b..39fe84f 100644 --- a/test/sa_test/type_list/target_cpp/foo_stub.cpp.txt +++ b/test/sa_test/type_list/target_cpp/foo_stub.cpp.txt @@ -27,8 +27,8 @@ int32_t FooStub::OnRemoteRequest( if (localDescriptor != remoteDescriptor) { return ERR_TRANSACTION_FAILED; } - switch (code) { - case COMMAND_BOOL_TEST_FUNC: { + switch (static_cast(code)) { + case IFooIpcCode::COMMAND_BOOL_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -84,7 +84,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_BYTE_TEST_FUNC: { + case IFooIpcCode::COMMAND_BYTE_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -140,7 +140,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SHORT_TEST_FUNC: { + case IFooIpcCode::COMMAND_SHORT_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -196,7 +196,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_INT_TEST_FUNC: { + case IFooIpcCode::COMMAND_INT_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -252,7 +252,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_LONG_TEST_FUNC: { + case IFooIpcCode::COMMAND_LONG_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -308,7 +308,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_STRING_TEST_FUNC: { + case IFooIpcCode::COMMAND_STRING_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -364,7 +364,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_FLOAT_TEST_FUNC: { + case IFooIpcCode::COMMAND_FLOAT_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -420,7 +420,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_DOUBLE_TEST_FUNC: { + case IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -476,7 +476,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_CHAR_TEST_FUNC: { + case IFooIpcCode::COMMAND_CHAR_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -532,7 +532,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SEQ_TEST_FUNC: { + case IFooIpcCode::COMMAND_SEQ_TEST_FUNC: { std::vector inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { @@ -596,7 +596,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_INTERFACE_TEST_FUNC: { + case IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC: { std::vector> inParam; int32_t inParamSize = data.ReadInt32(); if (inParamSize > static_cast(VECTOR_MAX_SIZE)) { diff --git a/test/sa_test/type_list/target_cpp/foo_stub.h.txt b/test/sa_test/type_list/target_cpp/foo_stub.h.txt index 9b4766a..dab4ecd 100644 --- a/test/sa_test/type_list/target_cpp/foo_stub.h.txt +++ b/test/sa_test/type_list/target_cpp/foo_stub.h.txt @@ -27,19 +27,6 @@ public: MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - -private: - static constexpr int32_t COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_BYTE_TEST_FUNC = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_SHORT_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_INT_TEST_FUNC = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_LONG_TEST_FUNC = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_STRING_TEST_FUNC = MIN_TRANSACTION_ID + 5; - static constexpr int32_t COMMAND_FLOAT_TEST_FUNC = MIN_TRANSACTION_ID + 6; - static constexpr int32_t COMMAND_DOUBLE_TEST_FUNC = MIN_TRANSACTION_ID + 7; - static constexpr int32_t COMMAND_CHAR_TEST_FUNC = MIN_TRANSACTION_ID + 8; - static constexpr int32_t COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID + 9; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC = MIN_TRANSACTION_ID + 10; }; } // namespace test #endif // TEST_FOOSTUB_H diff --git a/test/sa_test/type_list/target_cpp/ifoo.h.txt b/test/sa_test/type_list/target_cpp/ifoo.h.txt index ea7527b..a4c98d2 100644 --- a/test/sa_test/type_list/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_list/target_cpp/ifoo.h.txt @@ -27,6 +27,20 @@ using test::myseq; using test::myinterface; namespace test { +enum class IFooIpcCode { + COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID, + COMMAND_BYTE_TEST_FUNC, + COMMAND_SHORT_TEST_FUNC, + COMMAND_INT_TEST_FUNC, + COMMAND_LONG_TEST_FUNC, + COMMAND_STRING_TEST_FUNC, + COMMAND_FLOAT_TEST_FUNC, + COMMAND_DOUBLE_TEST_FUNC, + COMMAND_CHAR_TEST_FUNC, + COMMAND_SEQ_TEST_FUNC, + COMMAND_INTERFACE_TEST_FUNC, +}; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); diff --git a/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt index ec7ffba..a382704 100644 --- a/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt @@ -31,7 +31,7 @@ ErrCode FooProxy::void_test_func() if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_VOID_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -89,7 +89,7 @@ ErrCode FooProxy::bool_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_BOOL_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -165,7 +165,7 @@ ErrCode FooProxy::byte_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_BYTE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -241,7 +241,7 @@ ErrCode FooProxy::short_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SHORT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -317,7 +317,7 @@ ErrCode FooProxy::int_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_INT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -393,7 +393,7 @@ ErrCode FooProxy::long_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_LONG_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -469,7 +469,7 @@ ErrCode FooProxy::string_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_STRING_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -545,7 +545,7 @@ ErrCode FooProxy::float_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_FLOAT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -621,7 +621,7 @@ ErrCode FooProxy::double_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_DOUBLE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -697,7 +697,7 @@ ErrCode FooProxy::char_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_CHAR_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -773,7 +773,7 @@ ErrCode FooProxy::seq_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SEQ_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -885,7 +885,7 @@ ErrCode FooProxy::interface_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_INTERFACE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/type_map/target_cpp/foo_proxy.h.txt b/test/sa_test/type_map/target_cpp/foo_proxy.h.txt index e24ceb2..ffefacb 100644 --- a/test/sa_test/type_map/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_map/target_cpp/foo_proxy.h.txt @@ -99,19 +99,6 @@ public: std::unordered_map, sptr>& funcResult) override; private: - static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_BYTE_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_SHORT_TEST_FUNC = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_INT_TEST_FUNC = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_LONG_TEST_FUNC = MIN_TRANSACTION_ID + 5; - static constexpr int32_t COMMAND_STRING_TEST_FUNC = MIN_TRANSACTION_ID + 6; - static constexpr int32_t COMMAND_FLOAT_TEST_FUNC = MIN_TRANSACTION_ID + 7; - static constexpr int32_t COMMAND_DOUBLE_TEST_FUNC = MIN_TRANSACTION_ID + 8; - static constexpr int32_t COMMAND_CHAR_TEST_FUNC = MIN_TRANSACTION_ID + 9; - static constexpr int32_t COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID + 10; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC = MIN_TRANSACTION_ID + 11; - static inline BrokerDelegator delegator_; }; } // namespace test diff --git a/test/sa_test/type_map/target_cpp/foo_stub.cpp.txt b/test/sa_test/type_map/target_cpp/foo_stub.cpp.txt index 0c2c3d0..76e680d 100644 --- a/test/sa_test/type_map/target_cpp/foo_stub.cpp.txt +++ b/test/sa_test/type_map/target_cpp/foo_stub.cpp.txt @@ -27,15 +27,15 @@ int32_t FooStub::OnRemoteRequest( if (localDescriptor != remoteDescriptor) { return ERR_TRANSACTION_FAILED; } - switch (code) { - case COMMAND_VOID_TEST_FUNC: { + switch (static_cast(code)) { + case IFooIpcCode::COMMAND_VOID_TEST_FUNC: { ErrCode errCode = void_test_func(); if (!reply.WriteInt32(errCode)) { return ERR_INVALID_VALUE; } return ERR_NONE; } - case COMMAND_BOOL_TEST_FUNC: { + case IFooIpcCode::COMMAND_BOOL_TEST_FUNC: { std::unordered_map inParam; int32_t inParamSize = data.ReadInt32(); for (int32_t i = 0; i < inParamSize; ++i) { @@ -99,7 +99,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_BYTE_TEST_FUNC: { + case IFooIpcCode::COMMAND_BYTE_TEST_FUNC: { std::unordered_map inParam; int32_t inParamSize = data.ReadInt32(); for (int32_t i = 0; i < inParamSize; ++i) { @@ -163,7 +163,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SHORT_TEST_FUNC: { + case IFooIpcCode::COMMAND_SHORT_TEST_FUNC: { std::unordered_map inParam; int32_t inParamSize = data.ReadInt32(); for (int32_t i = 0; i < inParamSize; ++i) { @@ -227,7 +227,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_INT_TEST_FUNC: { + case IFooIpcCode::COMMAND_INT_TEST_FUNC: { std::unordered_map inParam; int32_t inParamSize = data.ReadInt32(); for (int32_t i = 0; i < inParamSize; ++i) { @@ -291,7 +291,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_LONG_TEST_FUNC: { + case IFooIpcCode::COMMAND_LONG_TEST_FUNC: { std::unordered_map inParam; int32_t inParamSize = data.ReadInt32(); for (int32_t i = 0; i < inParamSize; ++i) { @@ -355,7 +355,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_STRING_TEST_FUNC: { + case IFooIpcCode::COMMAND_STRING_TEST_FUNC: { std::unordered_map inParam; int32_t inParamSize = data.ReadInt32(); for (int32_t i = 0; i < inParamSize; ++i) { @@ -419,7 +419,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_FLOAT_TEST_FUNC: { + case IFooIpcCode::COMMAND_FLOAT_TEST_FUNC: { std::unordered_map inParam; int32_t inParamSize = data.ReadInt32(); for (int32_t i = 0; i < inParamSize; ++i) { @@ -483,7 +483,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_DOUBLE_TEST_FUNC: { + case IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC: { std::unordered_map inParam; int32_t inParamSize = data.ReadInt32(); for (int32_t i = 0; i < inParamSize; ++i) { @@ -547,7 +547,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_CHAR_TEST_FUNC: { + case IFooIpcCode::COMMAND_CHAR_TEST_FUNC: { std::unordered_map inParam; int32_t inParamSize = data.ReadInt32(); for (int32_t i = 0; i < inParamSize; ++i) { @@ -611,7 +611,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SEQ_TEST_FUNC: { + case IFooIpcCode::COMMAND_SEQ_TEST_FUNC: { std::unordered_map inParam; int32_t inParamSize = data.ReadInt32(); for (int32_t i = 0; i < inParamSize; ++i) { @@ -691,7 +691,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_INTERFACE_TEST_FUNC: { + case IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC: { std::unordered_map, sptr> inParam; int32_t inParamSize = data.ReadInt32(); for (int32_t i = 0; i < inParamSize; ++i) { diff --git a/test/sa_test/type_map/target_cpp/foo_stub.h.txt b/test/sa_test/type_map/target_cpp/foo_stub.h.txt index 6204fc3..dab4ecd 100644 --- a/test/sa_test/type_map/target_cpp/foo_stub.h.txt +++ b/test/sa_test/type_map/target_cpp/foo_stub.h.txt @@ -27,20 +27,6 @@ public: MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - -private: - static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_BYTE_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_SHORT_TEST_FUNC = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_INT_TEST_FUNC = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_LONG_TEST_FUNC = MIN_TRANSACTION_ID + 5; - static constexpr int32_t COMMAND_STRING_TEST_FUNC = MIN_TRANSACTION_ID + 6; - static constexpr int32_t COMMAND_FLOAT_TEST_FUNC = MIN_TRANSACTION_ID + 7; - static constexpr int32_t COMMAND_DOUBLE_TEST_FUNC = MIN_TRANSACTION_ID + 8; - static constexpr int32_t COMMAND_CHAR_TEST_FUNC = MIN_TRANSACTION_ID + 9; - static constexpr int32_t COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID + 10; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC = MIN_TRANSACTION_ID + 11; }; } // namespace test #endif // TEST_FOOSTUB_H diff --git a/test/sa_test/type_map/target_cpp/ifoo.h.txt b/test/sa_test/type_map/target_cpp/ifoo.h.txt index a8fcc32..de740a7 100644 --- a/test/sa_test/type_map/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_map/target_cpp/ifoo.h.txt @@ -27,6 +27,21 @@ using test::myseq; using test::myinterface; namespace test { +enum class IFooIpcCode { + COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID, + COMMAND_BOOL_TEST_FUNC, + COMMAND_BYTE_TEST_FUNC, + COMMAND_SHORT_TEST_FUNC, + COMMAND_INT_TEST_FUNC, + COMMAND_LONG_TEST_FUNC, + COMMAND_STRING_TEST_FUNC, + COMMAND_FLOAT_TEST_FUNC, + COMMAND_DOUBLE_TEST_FUNC, + COMMAND_CHAR_TEST_FUNC, + COMMAND_SEQ_TEST_FUNC, + COMMAND_INTERFACE_TEST_FUNC, +}; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); diff --git a/test/sa_test/type_single/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_single/target_cpp/foo_proxy.cpp.txt index c629e17..ecf12f4 100644 --- a/test/sa_test/type_single/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_single/target_cpp/foo_proxy.cpp.txt @@ -31,7 +31,7 @@ ErrCode FooProxy::void_test_func() if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_VOID_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -69,7 +69,7 @@ ErrCode FooProxy::bool_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_BOOL_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -110,7 +110,7 @@ ErrCode FooProxy::byte_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_BYTE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -151,7 +151,7 @@ ErrCode FooProxy::short_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SHORT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -192,7 +192,7 @@ ErrCode FooProxy::int_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_INT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -233,7 +233,7 @@ ErrCode FooProxy::long_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_LONG_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -274,7 +274,7 @@ ErrCode FooProxy::string_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_STRING_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -315,7 +315,7 @@ ErrCode FooProxy::float_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_FLOAT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -356,7 +356,7 @@ ErrCode FooProxy::double_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_DOUBLE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -397,7 +397,7 @@ ErrCode FooProxy::char_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_CHAR_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -438,7 +438,7 @@ ErrCode FooProxy::seq_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_SEQ_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -497,7 +497,7 @@ ErrCode FooProxy::interface_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_INTERFACE_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -544,7 +544,7 @@ ErrCode FooProxy::interface_test_func2( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_INTERFACE_TEST_FUNC2, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC2), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/type_single/target_cpp/foo_proxy.h.txt b/test/sa_test/type_single/target_cpp/foo_proxy.h.txt index 9c59ce3..0476b81 100644 --- a/test/sa_test/type_single/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_single/target_cpp/foo_proxy.h.txt @@ -105,20 +105,6 @@ public: sptr& funcResult) override; private: - static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_BYTE_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_SHORT_TEST_FUNC = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_INT_TEST_FUNC = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_LONG_TEST_FUNC = MIN_TRANSACTION_ID + 5; - static constexpr int32_t COMMAND_STRING_TEST_FUNC = MIN_TRANSACTION_ID + 6; - static constexpr int32_t COMMAND_FLOAT_TEST_FUNC = MIN_TRANSACTION_ID + 7; - static constexpr int32_t COMMAND_DOUBLE_TEST_FUNC = MIN_TRANSACTION_ID + 8; - static constexpr int32_t COMMAND_CHAR_TEST_FUNC = MIN_TRANSACTION_ID + 9; - static constexpr int32_t COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID + 10; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC = MIN_TRANSACTION_ID + 11; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC2 = MIN_TRANSACTION_ID + 12; - static inline BrokerDelegator delegator_; }; } // namespace test diff --git a/test/sa_test/type_single/target_cpp/foo_stub.cpp.txt b/test/sa_test/type_single/target_cpp/foo_stub.cpp.txt index f4f0c0e..d4ecc8b 100644 --- a/test/sa_test/type_single/target_cpp/foo_stub.cpp.txt +++ b/test/sa_test/type_single/target_cpp/foo_stub.cpp.txt @@ -27,15 +27,15 @@ int32_t FooStub::OnRemoteRequest( if (localDescriptor != remoteDescriptor) { return ERR_TRANSACTION_FAILED; } - switch (code) { - case COMMAND_VOID_TEST_FUNC: { + switch (static_cast(code)) { + case IFooIpcCode::COMMAND_VOID_TEST_FUNC: { ErrCode errCode = void_test_func(); if (!reply.WriteInt32(errCode)) { return ERR_INVALID_VALUE; } return ERR_NONE; } - case COMMAND_BOOL_TEST_FUNC: { + case IFooIpcCode::COMMAND_BOOL_TEST_FUNC: { bool inParam = data.ReadInt32() == 1 ? true : false; bool outParam; bool inoutParam = data.ReadInt32() == 1 ? true : false; @@ -57,7 +57,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_BYTE_TEST_FUNC: { + case IFooIpcCode::COMMAND_BYTE_TEST_FUNC: { int8_t inParam = (int8_t)data.ReadInt32(); int8_t outParam; int8_t inoutParam = (int8_t)data.ReadInt32(); @@ -79,7 +79,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SHORT_TEST_FUNC: { + case IFooIpcCode::COMMAND_SHORT_TEST_FUNC: { short inParam = (short)data.ReadInt32(); short outParam; short inoutParam = (short)data.ReadInt32(); @@ -101,7 +101,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_INT_TEST_FUNC: { + case IFooIpcCode::COMMAND_INT_TEST_FUNC: { int32_t inParam = data.ReadInt32(); int32_t outParam; int32_t inoutParam = data.ReadInt32(); @@ -123,7 +123,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_LONG_TEST_FUNC: { + case IFooIpcCode::COMMAND_LONG_TEST_FUNC: { int64_t inParam = data.ReadInt64(); int64_t outParam; int64_t inoutParam = data.ReadInt64(); @@ -145,7 +145,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_STRING_TEST_FUNC: { + case IFooIpcCode::COMMAND_STRING_TEST_FUNC: { std::string inParam = Str16ToStr8(data.ReadString16()); std::string outParam; std::string inoutParam = Str16ToStr8(data.ReadString16()); @@ -167,7 +167,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_FLOAT_TEST_FUNC: { + case IFooIpcCode::COMMAND_FLOAT_TEST_FUNC: { float inParam = data.ReadFloat(); float outParam; float inoutParam = data.ReadFloat(); @@ -189,7 +189,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_DOUBLE_TEST_FUNC: { + case IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC: { double inParam = data.ReadDouble(); double outParam; double inoutParam = data.ReadDouble(); @@ -211,7 +211,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_CHAR_TEST_FUNC: { + case IFooIpcCode::COMMAND_CHAR_TEST_FUNC: { zchar inParam = (zchar)data.ReadInt32(); zchar outParam; zchar inoutParam = (zchar)data.ReadInt32(); @@ -233,7 +233,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_SEQ_TEST_FUNC: { + case IFooIpcCode::COMMAND_SEQ_TEST_FUNC: { std::unique_ptr inParam(data.ReadParcelable()); if (!inParam) { return ERR_INVALID_DATA; @@ -263,7 +263,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_INTERFACE_TEST_FUNC: { + case IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC: { sptr inParam = iface_cast(data.ReadRemoteObject()); if (inParam == nullptr) { return ERR_INVALID_DATA; @@ -302,7 +302,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_INTERFACE_TEST_FUNC2: { + case IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC2: { sptr inParam = iface_cast(data.ReadRemoteObject()); if (inParam == nullptr) { return ERR_INVALID_DATA; diff --git a/test/sa_test/type_single/target_cpp/foo_stub.h.txt b/test/sa_test/type_single/target_cpp/foo_stub.h.txt index 8faddb2..dab4ecd 100644 --- a/test/sa_test/type_single/target_cpp/foo_stub.h.txt +++ b/test/sa_test/type_single/target_cpp/foo_stub.h.txt @@ -27,21 +27,6 @@ public: MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - -private: - static constexpr int32_t COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_BYTE_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_SHORT_TEST_FUNC = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_INT_TEST_FUNC = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_LONG_TEST_FUNC = MIN_TRANSACTION_ID + 5; - static constexpr int32_t COMMAND_STRING_TEST_FUNC = MIN_TRANSACTION_ID + 6; - static constexpr int32_t COMMAND_FLOAT_TEST_FUNC = MIN_TRANSACTION_ID + 7; - static constexpr int32_t COMMAND_DOUBLE_TEST_FUNC = MIN_TRANSACTION_ID + 8; - static constexpr int32_t COMMAND_CHAR_TEST_FUNC = MIN_TRANSACTION_ID + 9; - static constexpr int32_t COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID + 10; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC = MIN_TRANSACTION_ID + 11; - static constexpr int32_t COMMAND_INTERFACE_TEST_FUNC2 = MIN_TRANSACTION_ID + 12; }; } // namespace test #endif // TEST_FOOSTUB_H diff --git a/test/sa_test/type_single/target_cpp/ifoo.h.txt b/test/sa_test/type_single/target_cpp/ifoo.h.txt index 644e139..92b1885 100644 --- a/test/sa_test/type_single/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_single/target_cpp/ifoo.h.txt @@ -28,6 +28,22 @@ using test::myinterface; using test::myinterface2; namespace test { +enum class IFooIpcCode { + COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID, + COMMAND_BOOL_TEST_FUNC, + COMMAND_BYTE_TEST_FUNC, + COMMAND_SHORT_TEST_FUNC, + COMMAND_INT_TEST_FUNC, + COMMAND_LONG_TEST_FUNC, + COMMAND_STRING_TEST_FUNC, + COMMAND_FLOAT_TEST_FUNC, + COMMAND_DOUBLE_TEST_FUNC, + COMMAND_CHAR_TEST_FUNC, + COMMAND_SEQ_TEST_FUNC, + COMMAND_INTERFACE_TEST_FUNC, + COMMAND_INTERFACE_TEST_FUNC2, +}; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt index c38fe7a..789ca15 100644 --- a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt @@ -41,7 +41,7 @@ ErrCode FooProxy::uchar_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_UCHAR_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_UCHAR_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -82,7 +82,7 @@ ErrCode FooProxy::ushort_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_USHORT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_USHORT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -123,7 +123,7 @@ ErrCode FooProxy::uint_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_UINT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_UINT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -164,7 +164,7 @@ ErrCode FooProxy::ulong_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_ULONG_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_ULONG_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -205,7 +205,7 @@ ErrCode FooProxy::fd_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_FD_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FD_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -246,7 +246,7 @@ ErrCode FooProxy::remote_object_test_func( if (remote == nullptr) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(COMMAND_REMOTE_OBJECT_TEST_FUNC, data, reply, option); + int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_REMOTE_OBJECT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt index a05ea66..24c0f24 100644 --- a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt @@ -67,13 +67,6 @@ public: sptr& funcResult) override; private: - static constexpr int32_t COMMAND_UCHAR_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_USHORT_TEST_FUNC = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_UINT_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_ULONG_TEST_FUNC = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_FD_TEST_FUNC = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_REMOTE_OBJECT_TEST_FUNC = MIN_TRANSACTION_ID + 5; - static inline BrokerDelegator delegator_; }; } // namespace test diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.cpp.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.cpp.txt index 4010aca..419c078 100644 --- a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.cpp.txt +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.cpp.txt @@ -27,8 +27,8 @@ int32_t FooStub::OnRemoteRequest( if (localDescriptor != remoteDescriptor) { return ERR_TRANSACTION_FAILED; } - switch (code) { - case COMMAND_UCHAR_TEST_FUNC: { + switch (static_cast(code)) { + case IFooIpcCode::COMMAND_UCHAR_TEST_FUNC: { uint8_t inParam = data.ReadUint8(); uint8_t outParam; uint8_t inoutParam = data.ReadUint8(); @@ -50,7 +50,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_USHORT_TEST_FUNC: { + case IFooIpcCode::COMMAND_USHORT_TEST_FUNC: { uint16_t inParam = data.ReadUint16(); uint16_t outParam; uint16_t inoutParam = data.ReadUint16(); @@ -72,7 +72,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_UINT_TEST_FUNC: { + case IFooIpcCode::COMMAND_UINT_TEST_FUNC: { uint32_t inParam = data.ReadUint32(); uint32_t outParam; uint32_t inoutParam = data.ReadUint32(); @@ -94,7 +94,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_ULONG_TEST_FUNC: { + case IFooIpcCode::COMMAND_ULONG_TEST_FUNC: { uint64_t inParam = data.ReadUint64(); uint64_t outParam; uint64_t inoutParam = data.ReadUint64(); @@ -116,7 +116,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_FD_TEST_FUNC: { + case IFooIpcCode::COMMAND_FD_TEST_FUNC: { int inParam = data.ReadFileDescriptor(); int outParam; int inoutParam = data.ReadFileDescriptor(); @@ -138,7 +138,7 @@ int32_t FooStub::OnRemoteRequest( } return ERR_NONE; } - case COMMAND_REMOTE_OBJECT_TEST_FUNC: { + case IFooIpcCode::COMMAND_REMOTE_OBJECT_TEST_FUNC: { sptr inParam = data.ReadRemoteObject(); if (!inParam) { return ERR_INVALID_DATA; diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.h.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.h.txt index 4cadec5..dab4ecd 100644 --- a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.h.txt +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.h.txt @@ -27,14 +27,6 @@ public: MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - -private: - static constexpr int32_t COMMAND_UCHAR_TEST_FUNC = MIN_TRANSACTION_ID + 0; - static constexpr int32_t COMMAND_USHORT_TEST_FUNC = MIN_TRANSACTION_ID + 1; - static constexpr int32_t COMMAND_UINT_TEST_FUNC = MIN_TRANSACTION_ID + 2; - static constexpr int32_t COMMAND_ULONG_TEST_FUNC = MIN_TRANSACTION_ID + 3; - static constexpr int32_t COMMAND_FD_TEST_FUNC = MIN_TRANSACTION_ID + 4; - static constexpr int32_t COMMAND_REMOTE_OBJECT_TEST_FUNC = MIN_TRANSACTION_ID + 5; }; } // namespace test #endif // TEST_FOOSTUB_H diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt index 1624874..9e8495d 100644 --- a/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt @@ -21,6 +21,15 @@ #include namespace test { +enum class IFooIpcCode { + COMMAND_UCHAR_TEST_FUNC = MIN_TRANSACTION_ID, + COMMAND_USHORT_TEST_FUNC, + COMMAND_UINT_TEST_FUNC, + COMMAND_ULONG_TEST_FUNC, + COMMAND_FD_TEST_FUNC, + COMMAND_REMOTE_OBJECT_TEST_FUNC, +}; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); -- Gitee From b1969407d7711477af7cd4a482850cb4718de81c Mon Sep 17 00:00:00 2001 From: wenyu Date: Wed, 27 Nov 2024 11:00:09 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=AD=BB=E4=BA=A1?= =?UTF-8?q?=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wenyu --- .../cpp/sa_cpp_client_proxy_code_emitter.cpp | 277 ++++++++++-------- .../SA/cpp/sa_cpp_client_proxy_code_emitter.h | 14 +- .../codegen/SA/cpp/sa_cpp_code_emitter.cpp | 2 +- .../SA/cpp/sa_cpp_interface_code_emitter.cpp | 12 +- .../SA/cpp/sa_cpp_interface_code_emitter.h | 2 + .../cmd_hitrace_tag/target/foo_proxy.cpp.txt | 107 +++++-- .../cmd_hitrace_tag/target/foo_proxy.h.txt | 35 ++- .../sa_test/cmd_hitrace_tag/target/ifoo.h.txt | 5 + .../target/foo_proxy.cpp.txt | 112 +++++-- .../target/foo_proxy.h.txt | 35 ++- .../cmd_log_tag_domainid/target/ifoo.h.txt | 5 + .../target/foo_proxy.cpp.txt | 107 +++++-- .../cmd_save_metadata/target/foo_proxy.h.txt | 35 ++- .../cmd_save_metadata/target/ifoo.h.txt | 5 + .../app_fwk_update_service_proxy.cpp.txt | 51 +++- .../app_fwk_update_service_proxy.h.txt | 35 ++- .../target_cpp/esim_service_proxy.cpp.txt | 131 ++++++--- .../target_cpp/esim_service_proxy.h.txt | 35 ++- .../target_cpp/iapp_fwk_update_service.h.txt | 5 + .../target_cpp/idl_test_service_proxy.cpp.txt | 56 +++- .../target_cpp/idl_test_service_proxy.h.txt | 35 ++- .../in_use_idl/target_cpp/iesim_service.h.txt | 5 + .../target_cpp/iidl_test_service.h.txt | 5 + .../target_cpp/iquick_fix_manager.h.txt | 5 + .../target_cpp/itest_server_interface.h.txt | 5 + .../quick_fix_manager_proxy.cpp.txt | 61 +++- .../target_cpp/quick_fix_manager_proxy.h.txt | 35 ++- .../test_server_interface_proxy.cpp.txt | 61 +++- .../test_server_interface_proxy.h.txt | 35 ++- .../target_cpp/foo_proxy.cpp.txt | 135 +++++++-- .../target_cpp/foo_proxy.h.txt | 65 +--- .../target_cpp/ifoo.h.txt | 5 + .../target_cpp/foo_proxy.cpp.txt | 94 +++++- .../target_cpp/foo_proxy.h.txt | 59 +--- .../target_cpp/ifoo.h.txt | 5 + .../target_cpp/foo_proxy.cpp.txt | 66 ++++- .../target_cpp/foo_proxy.h.txt | 35 ++- .../keyword_import_dir/target_cpp/ifoo.h.txt | 5 + .../target_cpp/foo_proxy.cpp.txt | 110 +++++-- .../target_cpp/foo_proxy.h.txt | 35 ++- .../target_cpp/ifoo.h.txt | 5 + ...oo_proxy.cpp.txt.txt => foo_proxy.cpp.txt} | 107 +++++-- .../{foo_proxy.h.txt.txt => foo_proxy.h.txt} | 35 ++- ...{foo_stub.cpp.txt.txt => foo_stub.cpp.txt} | 0 .../{foo_stub.h.txt.txt => foo_stub.h.txt} | 0 .../target_cpp/{ifoo.h.txt.txt => ifoo.h.txt} | 5 + .../type_array/target_cpp/foo_proxy.cpp.txt | 107 +++++-- .../type_array/target_cpp/foo_proxy.h.txt | 35 ++- test/sa_test/type_array/target_cpp/ifoo.h.txt | 5 + .../type_list/target_cpp/foo_proxy.cpp.txt | 101 +++++-- .../type_list/target_cpp/foo_proxy.h.txt | 35 ++- test/sa_test/type_list/target_cpp/ifoo.h.txt | 5 + .../type_map/target_cpp/foo_proxy.cpp.txt | 107 +++++-- .../type_map/target_cpp/foo_proxy.h.txt | 35 ++- test/sa_test/type_map/target_cpp/ifoo.h.txt | 5 + .../type_single/target_cpp/foo_proxy.cpp.txt | 112 +++++-- .../type_single/target_cpp/foo_proxy.h.txt | 35 ++- .../sa_test/type_single/target_cpp/ifoo.h.txt | 5 + .../target_cpp/foo_proxy.cpp.txt | 76 ++++- .../target_cpp/foo_proxy.h.txt | 35 ++- .../target_cpp/ifoo.h.txt | 5 + 61 files changed, 2115 insertions(+), 667 deletions(-) rename test/sa_test/keyword_oneway/target_cpp/{foo_proxy.cpp.txt.txt => foo_proxy.cpp.txt} (69%) rename test/sa_test/keyword_oneway/target_cpp/{foo_proxy.h.txt.txt => foo_proxy.h.txt} (65%) rename test/sa_test/keyword_oneway/target_cpp/{foo_stub.cpp.txt.txt => foo_stub.cpp.txt} (100%) rename test/sa_test/keyword_oneway/target_cpp/{foo_stub.h.txt.txt => foo_stub.h.txt} (100%) rename test/sa_test/keyword_oneway/target_cpp/{ifoo.h.txt.txt => ifoo.h.txt} (92%) diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp b/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp index 307b985..38c0276 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp @@ -35,9 +35,9 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyHeaderFile() EmitLicense(sb); EmitHeadMacro(sb, proxyFullName_); - sb.Append("\n"); - sb.AppendFormat("#include \"%s.h\"\n", FileName(interfaceName_).c_str()); - sb.Append("#include \n"); + sb.Append("\n").Append("#include \n") + .Append("#include \n") + .AppendFormat("#include \"%s.h\"\n", FileName(interfaceName_).c_str()); if (ast_ != nullptr && ast_->GetHasCacheableProxyMethods()) { sb.Append("#include \"api_cache_manager.h\"\n"); } @@ -55,13 +55,15 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyInHeaderFile(StringBuilder & { EmitBeginNamespace(sb); sb.AppendFormat("class %s : public IRemoteProxy<%s> {\n", proxyName_.c_str(), interfaceName_.c_str()); + sb.Append("public:\n"); - EmitInterfaceProxyConstructor(sb, TAB); - sb.Append("\n"); + EmitInterfaceProxyConstructorDecl(sb, TAB); + EmitInterfaceProxyRemoteDiedCallback(sb, TAB); EmitInterfaceProxyMethodDecls(sb, TAB); - sb.Append("\n"); + sb.Append("private:\n"); EmitInterfaceProxyConstants(sb, TAB); + sb.Append("};\n"); EmitEndNamespace(sb); } @@ -69,117 +71,96 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyInHeaderFile(StringBuilder & void SaCppClientProxyCodeEmitter::EmitInterfaceProxyRegisterDeathRecipient(StringBuilder &sb, const std::string &prefix) const { - sb.Append(prefix).Append("if (remote != nullptr) {\n"); - sb.Append(prefix + TAB).Append("if (!remote->IsProxyObject()) {\n"); + sb.Append(prefix).Append("if (remote_ && remote_ != remote) {\n") + .Append(prefix + TAB).Append("RemoveDeathRecipient();\n") + .Append(prefix).Append("}\n") + .Append(prefix).Append("if (remote) {\n") + .Append(prefix + TAB).Append("if (!remote->IsProxyObject()) {\n"); if (logOn_) { sb.Append(prefix + TAB + TAB).Append("HiLog::Error(LABEL, \"remote is not proxy object!\");\n"); } - sb.Append(prefix + TAB + TAB).Append("return;\n"); - sb.Append(prefix + TAB).Append("}\n"); - sb.Append(prefix + TAB).AppendFormat("deathRecipient_ = new (std::nothrow) %s(*this);\n", - deathRecipientName_.c_str()); - sb.Append(prefix + TAB).Append("if (deathRecipient_ == nullptr) {\n"); + sb.Append(prefix + TAB + TAB).Append("return;\n") + .Append(prefix + TAB).Append("}\n") + .Append(prefix + TAB) + .AppendFormat("deathRecipient_ = new (std::nothrow) %s(*this);\n", deathRecipientName_.c_str()) + .Append(prefix + TAB).Append("if (!deathRecipient_) {\n"); if (logOn_) { sb.Append(prefix + TAB + TAB).Append("HiLog::Error(LABEL, \"deathRecipient_ is nullptr!\");\n"); } - sb.Append(prefix + TAB + TAB).Append("return;\n"); - sb.Append(prefix + TAB).Append("}\n"); - sb.Append(prefix + TAB).Append("if (!remote->AddDeathRecipient(deathRecipient_)) {\n"); + sb.Append(prefix + TAB + TAB).Append("return;\n") + .Append(prefix + TAB).Append("}\n") + .Append(prefix + TAB).Append("if (!remote->AddDeathRecipient(deathRecipient_)) {\n"); if (logOn_) { sb.Append(prefix + TAB + TAB).Append("HiLog::Error(LABEL, \"AddDeathRecipient failed!\");\n"); } - sb.Append(prefix + TAB + TAB).Append("return;\n"); - sb.Append(prefix + TAB).Append("}\n"); - sb.Append(prefix + TAB).Append("remote_ = remote;\n"); - sb.Append(prefix).Append("}\n"); + sb.Append(prefix + TAB + TAB).Append("return;\n") + .Append(prefix + TAB).Append("}\n") + .Append(prefix + TAB).Append("remote_ = remote;\n") + .Append(prefix).Append("}\n"); } -void SaCppClientProxyCodeEmitter::EmitInterfaceProxyAddCacheAbleAPI(StringBuilder &sb, const std::string &prefix) const +void SaCppClientProxyCodeEmitter::EmitInterfaceProxyAddCacheApi(StringBuilder &sb, const std::string &prefix) const { - sb.Append(prefix).Append("{\n"); - int methodNumber = static_cast(interface_->GetMethodNumber()); - for (int i = 0; i < methodNumber; i++) { + size_t methodNumber = interface_->GetMethodNumber(); + for (size_t i = 0; i < methodNumber; i++) { AutoPtr method = interface_->GetMethod(i); if (!method->GetCacheable() || method->IsOneWay()) { continue; } int32_t cacheableTime = method->GetCacheableTime(); if (cacheableTime != 0) { - sb.Append(prefix + TAB).AppendFormat( - "ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), " - "static_cast(%sIpcCode::COMMAND_%s), %d000);\n", - interface_->GetName().c_str(), ConstantName(method->GetName()).c_str(), cacheableTime); + sb.Append(prefix).Append("ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(),\n") + .Append(prefix + TAB).AppendFormat("static_cast(%sIpcCode::COMMAND_%s), %d000);\n", + interface_->GetName().c_str(), ConstantName(method->GetName()).c_str(), cacheableTime); } else { - sb.Append(prefix + TAB).AppendFormat( - "ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), " - "static_cast(%sIpcCode::COMMAND_%s), 0);\n", - interface_->GetName().c_str(), ConstantName(method->GetName()).c_str()); + sb.Append(prefix).Append("ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(),\n") + .Append(prefix + TAB).AppendFormat("static_cast(%sIpcCode::COMMAND_%s), 0);\n", + interface_->GetName().c_str(), ConstantName(method->GetName()).c_str()); } } sb.Append("\n"); - EmitInterfaceProxyRegisterDeathRecipient(sb, prefix + TAB); - sb.Append(prefix).Append("}\n"); } -void SaCppClientProxyCodeEmitter::EmitInterfaceProxyUnRegisterDeathRecipient(StringBuilder &sb, - const std::string &prefix) const +void SaCppClientProxyCodeEmitter::EmitInterfaceProxyDelCacheApi(StringBuilder &sb, const std::string &prefix) const { - sb.Append(prefix).Append("{\n"); - sb.Append(prefix + TAB).Append("if (remote_ == nullptr) {\n"); - sb.Append(prefix + TAB).Append(TAB).Append("return;\n"); - sb.Append(prefix + TAB).Append("}\n"); - sb.Append(prefix + TAB).Append("if (deathRecipient_ == nullptr) {\n"); - sb.Append(prefix + TAB).Append(TAB).Append("return;\n"); - sb.Append(prefix + TAB).Append("}\n"); - sb.Append(prefix + TAB).Append("remote_->RemoveDeathRecipient(deathRecipient_);\n"); - sb.Append(prefix + TAB).Append("remote_ = nullptr;\n"); - int methodNumber = static_cast(interface_->GetMethodNumber()); + size_t methodNumber = interface_->GetMethodNumber(); if (methodNumber > 0) { sb.Append("\n"); - for (int i = 0; i < methodNumber; i++) { + for (size_t i = 0; i < methodNumber; i++) { AutoPtr method = interface_->GetMethod(i); if (method->GetCacheable() && !method->IsOneWay()) { - sb.Append(prefix + TAB).AppendFormat( - "ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), " - "static_cast(%sIpcCode::COMMAND_%s));\n", - interface_->GetName().c_str(), ConstantName(method->GetName()).c_str()); + sb.Append(prefix).Append("ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(),\n") + .Append(prefix + TAB).AppendFormat("static_cast(%sIpcCode::COMMAND_%s));\n", + interface_->GetName().c_str(), ConstantName(method->GetName()).c_str()); } } } - sb.Append(prefix).Append("}\n"); } -void SaCppClientProxyCodeEmitter::EmitInterfaceProxyConstructor(StringBuilder &sb, const std::string &prefix) const +void SaCppClientProxyCodeEmitter::EmitInterfaceProxyConstructorDecl(StringBuilder &sb, const std::string &prefix) const { - sb.Append(prefix).AppendFormat("explicit %s(\n", proxyName_.c_str()); - sb.Append(prefix + TAB).Append("const sptr& remote)\n"); - sb.Append(prefix + TAB).AppendFormat(": IRemoteProxy<%s>(remote)\n", interfaceName_.c_str()); - if (ast_->GetHasCacheableProxyMethods()) { - EmitInterfaceProxyAddCacheAbleAPI(sb, prefix); - } else { - sb.Append(prefix).Append("{}\n"); - } - sb.Append("\n"); - sb.Append(prefix).AppendFormat("virtual ~%s()\n", proxyName_.c_str()); - if (ast_->GetHasCacheableProxyMethods()) { - EmitInterfaceProxyUnRegisterDeathRecipient(sb, prefix); - } else { - sb.Append(prefix).Append("{}\n"); - } + sb.Append(prefix).AppendFormat("explicit %s(const sptr& remote);\n\n", proxyName_.c_str()) + .Append(prefix).AppendFormat("~%s() override;\n\n", proxyName_.c_str()); } void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodDecls(StringBuilder &sb, const std::string &prefix) const { - int methodNumber = static_cast(interface_->GetMethodNumber()); - for (int i = 0; i < methodNumber; i++) { + size_t methodNumber = interface_->GetMethodNumber(); + for (size_t i = 0; i < methodNumber; i++) { AutoPtr method = interface_->GetMethod(i); EmitInterfaceProxyMethodDecl(method, sb, prefix); - if (i != methodNumber - 1) { - sb.Append("\n"); - } + sb.Append("\n"); } } +void SaCppClientProxyCodeEmitter::EmitInterfaceProxyRemoteDiedCallback(StringBuilder &sb, const std::string &prefix) +{ + sb.Append(prefix).Append("void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override\n") + .Append(prefix).Append("{\n") + .Append(prefix + TAB).Append("remoteDiedCallback_ = callback;\n") + .Append(prefix).Append("}\n\n"); +} + void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodDecl(AutoPtr &method, StringBuilder &sb, const std::string &prefix) const { @@ -192,32 +173,28 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyDeathRecipient(StringBuilder { sb.Append(prefix).AppendFormat("class %s : public IRemoteObject::DeathRecipient {\n", deathRecipientName_.c_str()); sb.Append(prefix).Append("public:\n"); - sb.Append(prefix + TAB).AppendFormat("explicit %s(%s &client) : client_(client) {}\n", deathRecipientName_.c_str(), + sb.Append(prefix + TAB).AppendFormat("explicit %s(%s& client) : client_(client) {}\n", deathRecipientName_.c_str(), proxyName_.c_str()); sb.Append(prefix + TAB).AppendFormat("~%s() override = default;\n", deathRecipientName_.c_str()); - sb.Append(prefix + TAB).Append("void OnRemoteDied(const wptr &remote) override\n"); + sb.Append(prefix + TAB).Append("void OnRemoteDied(const wptr& remote) override\n"); sb.Append(prefix + TAB).Append("{\n"); sb.Append(prefix + TAB + TAB).Append("client_.OnRemoteDied(remote);\n"); sb.Append(prefix + TAB).Append("}\n"); sb.Append(prefix).Append("private:\n"); - sb.Append(prefix + TAB).AppendFormat("%s &client_;\n", proxyName_.c_str()); + sb.Append(prefix + TAB).AppendFormat("%s& client_;\n", proxyName_.c_str()); sb.Append(prefix).Append("};\n\n"); - - sb.Append(prefix).Append("void OnRemoteDied(const wptr &remoteObject)\n"); - sb.Append(prefix).Append("{\n"); - sb.Append(prefix + TAB).Append("(void)remoteObject;\n"); - sb.Append(prefix + TAB).Append("ApiCacheManager::GetInstance().ClearCache(GetDescriptor());\n"); - sb.Append(prefix).Append("}\n"); - sb.Append(prefix).Append("sptr remote_ = nullptr;\n"); - sb.Append(prefix).Append("sptr deathRecipient_ = nullptr;\n"); + sb.Append(prefix).Append("void RemoveDeathRecipient();\n"); + sb.Append(prefix).Append("void OnRemoteDied(const wptr& remote);\n\n"); } void SaCppClientProxyCodeEmitter::EmitInterfaceProxyConstants(StringBuilder &sb, const std::string &prefix) { - if (ast_->GetHasCacheableProxyMethods()) { - EmitInterfaceProxyDeathRecipient(sb, prefix); - } - sb.Append(prefix).AppendFormat("static inline BrokerDelegator<%s> delegator_;\n", proxyName_.c_str()); + EmitInterfaceProxyDeathRecipient(sb, prefix); + sb.Append(prefix).AppendFormat("static inline BrokerDelegator<%s> delegator_;\n", proxyName_.c_str()) + .Append(prefix + "sptr remote_;\n") + .Append(prefix + "sptr deathRecipient_;\n") + .Append(prefix + "OnRemoteDiedCallback remoteDiedCallback_;\n") + .Append(prefix + "std::mutex mutex_;\n"); } void SaCppClientProxyCodeEmitter::EmitInterfaceProxyCppFile() @@ -240,6 +217,9 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyCppFile() sb.Append("using OHOS::HiviewDFX::HiLog;\n\n"); } EmitBeginNamespace(sb); + EmitInterfaceProxyConstructorImpl(sb); + EmitInterfaceProxyRemoveDeathRecipient(sb); + EmitInterfaceProxyOnRemoteDied(sb); EmitInterfaceProxyMethodImpls(sb, ""); EmitEndNamespace(sb); @@ -249,10 +229,65 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyCppFile() file.Close(); } +void SaCppClientProxyCodeEmitter::EmitInterfaceProxyConstructorImpl(StringBuilder &sb) const +{ + sb.AppendFormat("%s::%s(const sptr& remote) : IRemoteProxy<%s>(remote)\n{\n", + proxyName_.c_str(), proxyName_.c_str(), interfaceName_.c_str()); + if (ast_->GetHasCacheableProxyMethods()) { + EmitInterfaceProxyAddCacheApi(sb, TAB); + } + sb.Append(TAB).Append("std::lock_guard lock(mutex_);\n"); + EmitInterfaceProxyRegisterDeathRecipient(sb, TAB); + sb.Append("}\n\n"); + + sb.AppendFormat("%s::~%s()\n", proxyName_.c_str(), proxyName_.c_str()) + .Append("{\n") + .Append(TAB).Append("RemoveDeathRecipient();\n"); + if (ast_->GetHasCacheableProxyMethods()) { + EmitInterfaceProxyDelCacheApi(sb, TAB); + } + sb.Append("}\n\n"); +} + +void SaCppClientProxyCodeEmitter::EmitInterfaceProxyRemoveDeathRecipient(StringBuilder &sb) const +{ + sb.AppendFormat("void %s::RemoveDeathRecipient()\n", proxyName_.c_str()) + .Append("{\n") + .Append(TAB).Append("std::lock_guard lock(mutex_);\n"); + if (logOn_) { + sb.Append(TAB).Append("HiLog::Info(LABEL, \"Remove death recipient\");\n"); + } + sb.Append(TAB).Append("if (!remote_ || !deathRecipient_) {\n") + .Append(TAB).Append(TAB).Append("return;\n") + .Append(TAB).Append("}\n") + .Append(TAB).Append("remote_->RemoveDeathRecipient(deathRecipient_);\n") + .Append(TAB).Append("remote_ = nullptr;\n") + .Append(TAB).Append("deathRecipient_ = nullptr;\n") + .Append(TAB).Append("remoteDiedCallback_ = nullptr;\n") + .Append("}\n\n"); +} + +void SaCppClientProxyCodeEmitter::EmitInterfaceProxyOnRemoteDied(StringBuilder &sb) const +{ + sb.AppendFormat("void %s::OnRemoteDied(const wptr& remote)\n{\n", proxyName_.c_str()); + if (logOn_) { + sb.Append(TAB).Append("HiLog::Info(LABEL, \"On remote died\");\n"); + } + sb.Append(TAB).Append("if (remoteDiedCallback_) {\n") + .Append(TAB).Append(TAB).Append("remoteDiedCallback_(remote);\n") + .Append(TAB).Append("}\n") + .Append(TAB).Append("RemoveDeathRecipient();\n"); + + if (ast_->GetHasCacheableProxyMethods()) { + sb.Append("\n").Append(TAB).Append("ApiCacheManager::GetInstance().ClearCache(GetDescriptor());\n"); + } + sb.Append("}\n\n"); +} + void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodImpls(StringBuilder &sb, const std::string &prefix) const { - int methodNumber = static_cast(interface_->GetMethodNumber()); - for (int i = 0; i < methodNumber; i++) { + size_t methodNumber = interface_->GetMethodNumber(); + for (size_t i = 0; i < methodNumber; i++) { AutoPtr method = interface_->GetMethod(i); EmitInterfaceProxyMethodImpl(method, sb, prefix); if (i != methodNumber - 1) { @@ -274,27 +309,24 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodPreSendRequest(AutoPtr const std::string &prefix) const { if ((method->GetCacheable()) && (!method->IsOneWay())) { + sb.Append(prefix).Append("bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(),\n") + .Append(prefix + TAB).AppendFormat("static_cast(%sIpcCode::COMMAND_%s), data, reply);", + interface_->GetName().c_str(), ConstantName(method->GetName()).c_str()); sb.Append("\n"); - sb.Append(prefix + TAB).AppendFormat( - "bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), " - "static_cast(%sIpcCode::COMMAND_%s), data, reply);", - interface_->GetName().c_str(), ConstantName(method->GetName()).c_str()); - sb.Append("\n"); - sb.Append(prefix + TAB).Append("if (hitCache == true) {\n"); - EmitInterfaceProxyMethodErrCode(sb, prefix + TAB); - EmitInterfaceProxyMethodReply(method, sb, prefix + TAB); - sb.Append(prefix + TAB + TAB).Append("return ERR_OK;\n"); - sb.Append(prefix + TAB).Append("}\n"); + sb.Append(prefix).Append("if (hitCache) {\n"); + EmitInterfaceProxyMethodErrCode(sb, prefix); + EmitInterfaceProxyMethodReply(method, sb, prefix); + sb.Append(prefix + TAB).Append("return ERR_OK;\n"); + sb.Append(prefix).Append("}\n\n"); } } void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodPostSendRequest(AutoPtr &method, StringBuilder &sb, const std::string &prefix) const { - sb.Append(prefix + TAB).AppendFormat( - "ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), " - "static_cast(%sIpcCode::COMMAND_%s), data, reply);\n", - interface_->GetName().c_str(), ConstantName(method->GetName()).c_str()); + sb.Append(prefix + TAB).Append("ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(),\n") + .Append(prefix + TAB + TAB).AppendFormat("static_cast(%sIpcCode::COMMAND_%s), data, reply);\n", + interface_->GetName().c_str(), ConstantName(method->GetName()).c_str()); } void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodBody(AutoPtr &method, StringBuilder &sb, @@ -312,34 +344,37 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodBody(AutoPtr(method->GetParameterNumber()); - for (int i = 0; i < paramNumber; i++) { + size_t paramNumber = method->GetParameterNumber(); + for (size_t i = 0; i < paramNumber; i++) { AutoPtr param = method->GetParameter(i); if (param->GetAttribute() & ASTParamAttr::PARAM_IN) { EmitWriteMethodParameter(param, "data.", sb, prefix + TAB); } } - EmitInterfaceProxyMethodPreSendRequest(method, sb, prefix); - sb.Append("\n"); + if (paramNumber > 0) { + sb.Append('\n'); + } + + EmitInterfaceProxyMethodPreSendRequest(method, sb, prefix + TAB); sb.Append(prefix + TAB).Append("sptr remote = Remote();\n"); - sb.Append(prefix + TAB).Append("if (remote == nullptr) {\n"); + sb.Append(prefix + TAB).Append("if (!remote) {\n"); if (logOn_) { - sb.Append(prefix + TAB).Append(TAB).Append("HiLog::Error(LABEL, \"Remote is nullptr!\");\n"); + sb.Append(prefix + TAB + TAB).Append("HiLog::Error(LABEL, \"Remote is nullptr!\");\n"); } - sb.Append(prefix + TAB).Append(TAB).Append("return ERR_INVALID_DATA;\n"); + sb.Append(prefix + TAB + TAB).Append("return ERR_INVALID_DATA;\n"); sb.Append(prefix + TAB).Append("}\n"); - sb.Append(prefix + TAB).AppendFormat("int32_t result = remote->SendRequest(" - "static_cast(%sIpcCode::COMMAND_%s), data, reply, option);\n", - interface_->GetName().c_str(), ConstantName(method->GetName()).c_str()); + sb.Append(prefix + TAB).Append("int32_t result = remote->SendRequest(\n") + .Append(prefix + TAB + TAB) + .AppendFormat("static_cast(%sIpcCode::COMMAND_%s), data, reply, option);\n", + interface_->GetName().c_str(), ConstantName(method->GetName()).c_str()); sb.Append(prefix + TAB).Append("if (FAILED(result)) {\n"); if (logOn_) { - sb.Append(prefix + TAB).Append(TAB).Append("HiLog::Error(LABEL, \"Send request failed!\");\n"); + sb.Append(prefix + TAB + TAB).Append("HiLog::Error(LABEL, \"Send request failed!\");\n"); } sb.Append(prefix + TAB).Append(" return result;\n"); sb.Append(prefix + TAB).Append("}\n"); @@ -360,8 +395,8 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodErrCode(StringBuilder void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodReply(AutoPtr &method, StringBuilder &sb, const std::string &prefix) const { - int paramNumber = static_cast(method->GetParameterNumber()); - for (int i = 0; i < paramNumber; i++) { + size_t paramNumber = method->GetParameterNumber(); + for (size_t i = 0; i < paramNumber; i++) { AutoPtr param = method->GetParameter(i); if (param->GetAttribute() & ASTParamAttr::PARAM_OUT) { EmitReadMethodParameter(param, "reply.", false, sb, prefix + TAB); diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.h b/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.h index 629670f..f99f7fe 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.h +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.h @@ -35,11 +35,13 @@ private: void EmitInterfaceProxyRegisterDeathRecipient(StringBuilder &sb, const std::string &prefix) const; - void EmitInterfaceProxyAddCacheAbleAPI(StringBuilder &sb, const std::string &prefix) const; + void EmitInterfaceProxyAddCacheApi(StringBuilder &sb, const std::string &prefix) const; - void EmitInterfaceProxyUnRegisterDeathRecipient(StringBuilder &sb, const std::string &prefix) const; + void EmitInterfaceProxyDelCacheApi(StringBuilder &sb, const std::string &prefix) const; - void EmitInterfaceProxyConstructor(StringBuilder &sb, const std::string &prefix) const; + void EmitInterfaceProxyConstructorDecl(StringBuilder &sb, const std::string &prefix) const; + + static void EmitInterfaceProxyRemoteDiedCallback(StringBuilder &sb, const std::string &prefix); void EmitInterfaceProxyMethodDecls(StringBuilder &sb, const std::string &prefix) const; @@ -51,6 +53,12 @@ private: void EmitInterfaceProxyCppFile(); + void EmitInterfaceProxyRemoveDeathRecipient(StringBuilder &sb) const; + + void EmitInterfaceProxyOnRemoteDied(StringBuilder &sb) const; + + void EmitInterfaceProxyConstructorImpl(StringBuilder &sb) const; + void EmitInterfaceProxyMethodImpls(StringBuilder &sb, const std::string &prefix) const; void EmitInterfaceProxyMethodImpl(AutoPtr &method, StringBuilder &sb, const std::string &prefix) const; diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_code_emitter.cpp b/idl_tool_2/codegen/SA/cpp/sa_cpp_code_emitter.cpp index 858c5d8..7e3c6a8 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_code_emitter.cpp @@ -123,7 +123,7 @@ std::string SACppCodeEmitter::EmitCppParameter(AutoPtr ¶m) con void SACppCodeEmitter::EmitInterfaceMethodCommands(StringBuilder &sb, const std::string &prefix) { int methodNumber = static_cast(interface_->GetMethodNumber()); - sb.AppendFormat("enum class %sIpcCode {\n", interface_->GetName().c_str()); + sb.AppendFormat("\nenum class %sIpcCode {\n", interface_->GetName().c_str()); for (int i = 0; i < methodNumber; i++) { AutoPtr method = interface_->GetMethod(i); std::string commandCode = "COMMAND_" + ConstantName(method->GetName()); diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp b/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp index 67c3878..d91917d 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp @@ -168,6 +168,7 @@ void SaCppInterfaceCodeEmitter::EmitInterfaceDefinition(StringBuilder &sb) { EmitBeginNamespace(sb); EmitInterfaceMethodCommands(sb, TAB); + EmitCallbackDecl(sb); sb.AppendFormat("class %s : public IRemoteBroker {\n", interface_->GetName().c_str()); sb.Append("public:\n"); EmitInterfaceBody(sb, TAB); @@ -176,11 +177,18 @@ void SaCppInterfaceCodeEmitter::EmitInterfaceDefinition(StringBuilder &sb) EmitEndNamespace(sb); } +void SaCppInterfaceCodeEmitter::EmitCallbackDecl(StringBuilder &sb) +{ + sb.Append("using OnRemoteDiedCallback = std::function&)>;\n\n"); +} + void SaCppInterfaceCodeEmitter::EmitInterfaceBody(StringBuilder &sb, const std::string &prefix) const { std::string nameWithoutPath = GetNamespace(interfaceFullName_); - sb.Append(prefix).AppendFormat("DECLARE_INTERFACE_DESCRIPTOR(u\"%s\");\n", nameWithoutPath.c_str()); - sb.Append("\n"); + sb.Append(prefix).AppendFormat("DECLARE_INTERFACE_DESCRIPTOR(u\"%s\");\n\n", nameWithoutPath.c_str()) + .Append(prefix) + .Append("virtual void RegisterOnRemoteDiedCallback(" + "[[maybe_unused]] const OnRemoteDiedCallback& callback) {}\n\n"); int methodNumber = static_cast(interface_->GetMethodNumber()); for (int i = 0; i < methodNumber; i++) { diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.h b/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.h index e2d4de3..33ed166 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.h +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.h @@ -52,6 +52,8 @@ private: void EmitInterfaceMethod(AutoPtr &method, StringBuilder &sb, const std::string &prefix) const; void EmitInterfaceMemberVariables(StringBuilder &sb, const std::string &prefix) const; + + static void EmitCallbackDecl(StringBuilder &sb); }; } // namespace Idl } // namespace OHOS diff --git a/test/sa_test/cmd_hitrace_tag/target/foo_proxy.cpp.txt b/test/sa_test/cmd_hitrace_tag/target/foo_proxy.cpp.txt index 92dc6d5..c804b96 100644 --- a/test/sa_test/cmd_hitrace_tag/target/foo_proxy.cpp.txt +++ b/test/sa_test/cmd_hitrace_tag/target/foo_proxy.cpp.txt @@ -16,6 +16,52 @@ #include "foo_proxy.h" namespace test { +FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) +{ + std::lock_guard lock(mutex_); + if (remote_ && remote_ != remote) { + RemoveDeathRecipient(); + } + if (remote) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) FooRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } +} + +FooProxy::~FooProxy() +{ + RemoveDeathRecipient(); +} + +void FooProxy::RemoveDeathRecipient() +{ + std::lock_guard lock(mutex_); + if (!remote_ || !deathRecipient_) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + deathRecipient_ = nullptr; + remoteDiedCallback_ = nullptr; +} + +void FooProxy::OnRemoteDied(const wptr& remote) +{ + if (remoteDiedCallback_) { + remoteDiedCallback_(remote); + } + RemoveDeathRecipient(); +} + ErrCode FooProxy::void_test_func() { MessageParcel data; @@ -26,12 +72,12 @@ ErrCode FooProxy::void_test_func() return ERR_INVALID_VALUE; } - sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -66,10 +112,11 @@ ErrCode FooProxy::bool_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -107,10 +154,11 @@ ErrCode FooProxy::byte_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -148,10 +196,11 @@ ErrCode FooProxy::short_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -189,10 +238,11 @@ ErrCode FooProxy::int_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -230,10 +280,11 @@ ErrCode FooProxy::long_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -271,10 +322,11 @@ ErrCode FooProxy::string_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -312,10 +364,11 @@ ErrCode FooProxy::float_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -353,10 +406,11 @@ ErrCode FooProxy::double_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -394,10 +448,11 @@ ErrCode FooProxy::char_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -435,10 +490,11 @@ ErrCode FooProxy::seq_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -494,10 +550,11 @@ ErrCode FooProxy::interface_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/cmd_hitrace_tag/target/foo_proxy.h.txt b/test/sa_test/cmd_hitrace_tag/target/foo_proxy.h.txt index e8a8046..ad7e93d 100644 --- a/test/sa_test/cmd_hitrace_tag/target/foo_proxy.h.txt +++ b/test/sa_test/cmd_hitrace_tag/target/foo_proxy.h.txt @@ -16,19 +16,21 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include "ifoo.h" +#include #include +#include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy( - const sptr& remote) - : IRemoteProxy(remote) - {} + explicit FooProxy(const sptr& remote); - virtual ~FooProxy() - {} + ~FooProxy() override; + + void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override + { + remoteDiedCallback_ = callback; + } ErrCode void_test_func() override; @@ -99,7 +101,26 @@ public: sptr& funcResult) override; private: + class FooRecipient : public IRemoteObject::DeathRecipient { + public: + explicit FooRecipient(FooProxy& client) : client_(client) {} + ~FooRecipient() override = default; + void OnRemoteDied(const wptr& remote) override + { + client_.OnRemoteDied(remote); + } + private: + FooProxy& client_; + }; + + void RemoveDeathRecipient(); + void OnRemoteDied(const wptr& remote); + static inline BrokerDelegator delegator_; + sptr remote_; + sptr deathRecipient_; + OnRemoteDiedCallback remoteDiedCallback_; + std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/cmd_hitrace_tag/target/ifoo.h.txt b/test/sa_test/cmd_hitrace_tag/target/ifoo.h.txt index 3b9ac5d..ee1e92e 100644 --- a/test/sa_test/cmd_hitrace_tag/target/ifoo.h.txt +++ b/test/sa_test/cmd_hitrace_tag/target/ifoo.h.txt @@ -26,6 +26,7 @@ using test::myseq; using test::myinterface; namespace test { + enum class IFooIpcCode { COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID, COMMAND_BOOL_TEST_FUNC, @@ -41,10 +42,14 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC, }; +using OnRemoteDiedCallback = std::function&)>; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); + virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} + virtual ErrCode void_test_func() = 0; virtual ErrCode bool_test_func( diff --git a/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.cpp.txt b/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.cpp.txt index 1c1ea40..44e8420 100644 --- a/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.cpp.txt +++ b/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.cpp.txt @@ -19,6 +19,57 @@ using OHOS::HiviewDFX::HiLog; namespace test { +FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) +{ + std::lock_guard lock(mutex_); + if (remote_ && remote_ != remote) { + RemoveDeathRecipient(); + } + if (remote) { + if (!remote->IsProxyObject()) { + HiLog::Error(LABEL, "remote is not proxy object!"); + return; + } + deathRecipient_ = new (std::nothrow) FooRecipient(*this); + if (!deathRecipient_) { + HiLog::Error(LABEL, "deathRecipient_ is nullptr!"); + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + HiLog::Error(LABEL, "AddDeathRecipient failed!"); + return; + } + remote_ = remote; + } +} + +FooProxy::~FooProxy() +{ + RemoveDeathRecipient(); +} + +void FooProxy::RemoveDeathRecipient() +{ + std::lock_guard lock(mutex_); + HiLog::Info(LABEL, "Remove death recipient"); + if (!remote_ || !deathRecipient_) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + deathRecipient_ = nullptr; + remoteDiedCallback_ = nullptr; +} + +void FooProxy::OnRemoteDied(const wptr& remote) +{ + HiLog::Info(LABEL, "On remote died"); + if (remoteDiedCallback_) { + remoteDiedCallback_(remote); + } + RemoveDeathRecipient(); +} + ErrCode FooProxy::void_test_func() { MessageParcel data; @@ -30,13 +81,13 @@ ErrCode FooProxy::void_test_func() return ERR_INVALID_VALUE; } - sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -76,11 +127,12 @@ ErrCode FooProxy::bool_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -123,11 +175,12 @@ ErrCode FooProxy::byte_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -170,11 +223,12 @@ ErrCode FooProxy::short_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -217,11 +271,12 @@ ErrCode FooProxy::int_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -264,11 +319,12 @@ ErrCode FooProxy::long_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -311,11 +367,12 @@ ErrCode FooProxy::string_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -358,11 +415,12 @@ ErrCode FooProxy::float_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -405,11 +463,12 @@ ErrCode FooProxy::double_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -452,11 +511,12 @@ ErrCode FooProxy::char_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -499,11 +559,12 @@ ErrCode FooProxy::seq_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; @@ -566,11 +627,12 @@ ErrCode FooProxy::interface_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { HiLog::Error(LABEL, "Remote is nullptr!"); return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); if (FAILED(result)) { HiLog::Error(LABEL, "Send request failed!"); return result; diff --git a/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.h.txt b/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.h.txt index e8a8046..ad7e93d 100644 --- a/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.h.txt +++ b/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.h.txt @@ -16,19 +16,21 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include "ifoo.h" +#include #include +#include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy( - const sptr& remote) - : IRemoteProxy(remote) - {} + explicit FooProxy(const sptr& remote); - virtual ~FooProxy() - {} + ~FooProxy() override; + + void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override + { + remoteDiedCallback_ = callback; + } ErrCode void_test_func() override; @@ -99,7 +101,26 @@ public: sptr& funcResult) override; private: + class FooRecipient : public IRemoteObject::DeathRecipient { + public: + explicit FooRecipient(FooProxy& client) : client_(client) {} + ~FooRecipient() override = default; + void OnRemoteDied(const wptr& remote) override + { + client_.OnRemoteDied(remote); + } + private: + FooProxy& client_; + }; + + void RemoveDeathRecipient(); + void OnRemoteDied(const wptr& remote); + static inline BrokerDelegator delegator_; + sptr remote_; + sptr deathRecipient_; + OnRemoteDiedCallback remoteDiedCallback_; + std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/cmd_log_tag_domainid/target/ifoo.h.txt b/test/sa_test/cmd_log_tag_domainid/target/ifoo.h.txt index 68d2123..b2aaf9c 100644 --- a/test/sa_test/cmd_log_tag_domainid/target/ifoo.h.txt +++ b/test/sa_test/cmd_log_tag_domainid/target/ifoo.h.txt @@ -27,6 +27,7 @@ using test::myseq; using test::myinterface; namespace test { + enum class IFooIpcCode { COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID, COMMAND_BOOL_TEST_FUNC, @@ -42,10 +43,14 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC, }; +using OnRemoteDiedCallback = std::function&)>; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); + virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} + virtual ErrCode void_test_func() = 0; virtual ErrCode bool_test_func( diff --git a/test/sa_test/cmd_save_metadata/target/foo_proxy.cpp.txt b/test/sa_test/cmd_save_metadata/target/foo_proxy.cpp.txt index 92dc6d5..c804b96 100644 --- a/test/sa_test/cmd_save_metadata/target/foo_proxy.cpp.txt +++ b/test/sa_test/cmd_save_metadata/target/foo_proxy.cpp.txt @@ -16,6 +16,52 @@ #include "foo_proxy.h" namespace test { +FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) +{ + std::lock_guard lock(mutex_); + if (remote_ && remote_ != remote) { + RemoveDeathRecipient(); + } + if (remote) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) FooRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } +} + +FooProxy::~FooProxy() +{ + RemoveDeathRecipient(); +} + +void FooProxy::RemoveDeathRecipient() +{ + std::lock_guard lock(mutex_); + if (!remote_ || !deathRecipient_) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + deathRecipient_ = nullptr; + remoteDiedCallback_ = nullptr; +} + +void FooProxy::OnRemoteDied(const wptr& remote) +{ + if (remoteDiedCallback_) { + remoteDiedCallback_(remote); + } + RemoveDeathRecipient(); +} + ErrCode FooProxy::void_test_func() { MessageParcel data; @@ -26,12 +72,12 @@ ErrCode FooProxy::void_test_func() return ERR_INVALID_VALUE; } - sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -66,10 +112,11 @@ ErrCode FooProxy::bool_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -107,10 +154,11 @@ ErrCode FooProxy::byte_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -148,10 +196,11 @@ ErrCode FooProxy::short_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -189,10 +238,11 @@ ErrCode FooProxy::int_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -230,10 +280,11 @@ ErrCode FooProxy::long_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -271,10 +322,11 @@ ErrCode FooProxy::string_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -312,10 +364,11 @@ ErrCode FooProxy::float_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -353,10 +406,11 @@ ErrCode FooProxy::double_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -394,10 +448,11 @@ ErrCode FooProxy::char_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -435,10 +490,11 @@ ErrCode FooProxy::seq_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -494,10 +550,11 @@ ErrCode FooProxy::interface_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/cmd_save_metadata/target/foo_proxy.h.txt b/test/sa_test/cmd_save_metadata/target/foo_proxy.h.txt index e8a8046..ad7e93d 100644 --- a/test/sa_test/cmd_save_metadata/target/foo_proxy.h.txt +++ b/test/sa_test/cmd_save_metadata/target/foo_proxy.h.txt @@ -16,19 +16,21 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include "ifoo.h" +#include #include +#include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy( - const sptr& remote) - : IRemoteProxy(remote) - {} + explicit FooProxy(const sptr& remote); - virtual ~FooProxy() - {} + ~FooProxy() override; + + void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override + { + remoteDiedCallback_ = callback; + } ErrCode void_test_func() override; @@ -99,7 +101,26 @@ public: sptr& funcResult) override; private: + class FooRecipient : public IRemoteObject::DeathRecipient { + public: + explicit FooRecipient(FooProxy& client) : client_(client) {} + ~FooRecipient() override = default; + void OnRemoteDied(const wptr& remote) override + { + client_.OnRemoteDied(remote); + } + private: + FooProxy& client_; + }; + + void RemoveDeathRecipient(); + void OnRemoteDied(const wptr& remote); + static inline BrokerDelegator delegator_; + sptr remote_; + sptr deathRecipient_; + OnRemoteDiedCallback remoteDiedCallback_; + std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/cmd_save_metadata/target/ifoo.h.txt b/test/sa_test/cmd_save_metadata/target/ifoo.h.txt index 3b9ac5d..ee1e92e 100644 --- a/test/sa_test/cmd_save_metadata/target/ifoo.h.txt +++ b/test/sa_test/cmd_save_metadata/target/ifoo.h.txt @@ -26,6 +26,7 @@ using test::myseq; using test::myinterface; namespace test { + enum class IFooIpcCode { COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID, COMMAND_BOOL_TEST_FUNC, @@ -41,10 +42,14 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC, }; +using OnRemoteDiedCallback = std::function&)>; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); + virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} + virtual ErrCode void_test_func() = 0; virtual ErrCode bool_test_func( diff --git a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.cpp.txt index 28b98c3..c936c61 100644 --- a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.cpp.txt @@ -17,6 +17,52 @@ namespace OHOS { namespace NWeb { +AppFwkUpdateServiceProxy::AppFwkUpdateServiceProxy(const sptr& remote) : IRemoteProxy(remote) +{ + std::lock_guard lock(mutex_); + if (remote_ && remote_ != remote) { + RemoveDeathRecipient(); + } + if (remote) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) AppFwkUpdateServiceRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } +} + +AppFwkUpdateServiceProxy::~AppFwkUpdateServiceProxy() +{ + RemoveDeathRecipient(); +} + +void AppFwkUpdateServiceProxy::RemoveDeathRecipient() +{ + std::lock_guard lock(mutex_); + if (!remote_ || !deathRecipient_) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + deathRecipient_ = nullptr; + remoteDiedCallback_ = nullptr; +} + +void AppFwkUpdateServiceProxy::OnRemoteDied(const wptr& remote) +{ + if (remoteDiedCallback_) { + remoteDiedCallback_(remote); + } + RemoveDeathRecipient(); +} + ErrCode AppFwkUpdateServiceProxy::VerifyPackageInstall( const std::string& bundleName, const std::string& hapPath, @@ -38,10 +84,11 @@ ErrCode AppFwkUpdateServiceProxy::VerifyPackageInstall( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IAppFwkUpdateServiceIpcCode::COMMAND_VERIFY_PACKAGE_INSTALL), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IAppFwkUpdateServiceIpcCode::COMMAND_VERIFY_PACKAGE_INSTALL), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.h.txt index 2f79390..146b100 100644 --- a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.h.txt @@ -16,20 +16,22 @@ #ifndef OHOS_NWEB_APPFWKUPDATESERVICEPROXY_H #define OHOS_NWEB_APPFWKUPDATESERVICEPROXY_H -#include "iapp_fwk_update_service.h" +#include #include +#include "iapp_fwk_update_service.h" namespace OHOS { namespace NWeb { class AppFwkUpdateServiceProxy : public IRemoteProxy { public: - explicit AppFwkUpdateServiceProxy( - const sptr& remote) - : IRemoteProxy(remote) - {} + explicit AppFwkUpdateServiceProxy(const sptr& remote); + + ~AppFwkUpdateServiceProxy() override; - virtual ~AppFwkUpdateServiceProxy() - {} + void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override + { + remoteDiedCallback_ = callback; + } ErrCode VerifyPackageInstall( const std::string& bundleName, @@ -37,7 +39,26 @@ public: int32_t& success) override; private: + class AppFwkUpdateServiceRecipient : public IRemoteObject::DeathRecipient { + public: + explicit AppFwkUpdateServiceRecipient(AppFwkUpdateServiceProxy& client) : client_(client) {} + ~AppFwkUpdateServiceRecipient() override = default; + void OnRemoteDied(const wptr& remote) override + { + client_.OnRemoteDied(remote); + } + private: + AppFwkUpdateServiceProxy& client_; + }; + + void RemoveDeathRecipient(); + void OnRemoteDied(const wptr& remote); + static inline BrokerDelegator delegator_; + sptr remote_; + sptr deathRecipient_; + OnRemoteDiedCallback remoteDiedCallback_; + std::mutex mutex_; }; } // namespace NWeb } // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.cpp.txt index a9864e9..0505883 100644 --- a/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.cpp.txt @@ -17,6 +17,52 @@ namespace OHOS { namespace Telephony { +EsimServiceProxy::EsimServiceProxy(const sptr& remote) : IRemoteProxy(remote) +{ + std::lock_guard lock(mutex_); + if (remote_ && remote_ != remote) { + RemoveDeathRecipient(); + } + if (remote) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) EsimServiceRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } +} + +EsimServiceProxy::~EsimServiceProxy() +{ + RemoveDeathRecipient(); +} + +void EsimServiceProxy::RemoveDeathRecipient() +{ + std::lock_guard lock(mutex_); + if (!remote_ || !deathRecipient_) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + deathRecipient_ = nullptr; + remoteDiedCallback_ = nullptr; +} + +void EsimServiceProxy::OnRemoteDied(const wptr& remote) +{ + if (remoteDiedCallback_) { + remoteDiedCallback_(remote); + } + RemoveDeathRecipient(); +} + ErrCode EsimServiceProxy::GetEid( int32_t slotId, std::string& eId) @@ -34,10 +80,11 @@ ErrCode EsimServiceProxy::GetEid( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_GET_EID), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IEsimServiceIpcCode::COMMAND_GET_EID), data, reply, option); if (FAILED(result)) { return result; } @@ -68,10 +115,11 @@ ErrCode EsimServiceProxy::GetOsuStatus( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_GET_OSU_STATUS), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IEsimServiceIpcCode::COMMAND_GET_OSU_STATUS), data, reply, option); if (FAILED(result)) { return result; } @@ -102,10 +150,11 @@ ErrCode EsimServiceProxy::StartOsu( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_START_OSU), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IEsimServiceIpcCode::COMMAND_START_OSU), data, reply, option); if (FAILED(result)) { return result; } @@ -148,10 +197,11 @@ ErrCode EsimServiceProxy::GetDownloadableProfileMetadata( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_GET_DOWNLOADABLE_PROFILE_METADATA), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IEsimServiceIpcCode::COMMAND_GET_DOWNLOADABLE_PROFILE_METADATA), data, reply, option); if (FAILED(result)) { return result; } @@ -194,10 +244,11 @@ ErrCode EsimServiceProxy::GetDownloadableProfiles( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_GET_DOWNLOADABLE_PROFILES), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IEsimServiceIpcCode::COMMAND_GET_DOWNLOADABLE_PROFILES), data, reply, option); if (FAILED(result)) { return result; } @@ -240,10 +291,11 @@ ErrCode EsimServiceProxy::DownloadProfile( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_DOWNLOAD_PROFILE), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IEsimServiceIpcCode::COMMAND_DOWNLOAD_PROFILE), data, reply, option); if (FAILED(result)) { return result; } @@ -278,10 +330,11 @@ ErrCode EsimServiceProxy::GetEuiccProfileInfoList( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_GET_EUICC_PROFILE_INFO_LIST), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IEsimServiceIpcCode::COMMAND_GET_EUICC_PROFILE_INFO_LIST), data, reply, option); if (FAILED(result)) { return result; } @@ -316,10 +369,11 @@ ErrCode EsimServiceProxy::GetEuiccInfo( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_GET_EUICC_INFO), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IEsimServiceIpcCode::COMMAND_GET_EUICC_INFO), data, reply, option); if (FAILED(result)) { return result; } @@ -358,10 +412,11 @@ ErrCode EsimServiceProxy::DeleteProfile( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_DELETE_PROFILE), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IEsimServiceIpcCode::COMMAND_DELETE_PROFILE), data, reply, option); if (FAILED(result)) { return result; } @@ -404,10 +459,11 @@ ErrCode EsimServiceProxy::SwitchToProfile( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_SWITCH_TO_PROFILE), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IEsimServiceIpcCode::COMMAND_SWITCH_TO_PROFILE), data, reply, option); if (FAILED(result)) { return result; } @@ -446,10 +502,11 @@ ErrCode EsimServiceProxy::SetProfileNickname( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_SET_PROFILE_NICKNAME), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IEsimServiceIpcCode::COMMAND_SET_PROFILE_NICKNAME), data, reply, option); if (FAILED(result)) { return result; } @@ -484,10 +541,11 @@ ErrCode EsimServiceProxy::ResetMemory( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_RESET_MEMORY), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IEsimServiceIpcCode::COMMAND_RESET_MEMORY), data, reply, option); if (FAILED(result)) { return result; } @@ -518,10 +576,11 @@ ErrCode EsimServiceProxy::ReserveProfilesForFactoryRestore( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_RESERVE_PROFILES_FOR_FACTORY_RESTORE), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IEsimServiceIpcCode::COMMAND_RESERVE_PROFILES_FOR_FACTORY_RESTORE), data, reply, option); if (FAILED(result)) { return result; } @@ -556,10 +615,11 @@ ErrCode EsimServiceProxy::SetDefaultSmdpAddress( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_SET_DEFAULT_SMDP_ADDRESS), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IEsimServiceIpcCode::COMMAND_SET_DEFAULT_SMDP_ADDRESS), data, reply, option); if (FAILED(result)) { return result; } @@ -590,10 +650,11 @@ ErrCode EsimServiceProxy::GetDefaultSmdpAddress( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_GET_DEFAULT_SMDP_ADDRESS), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IEsimServiceIpcCode::COMMAND_GET_DEFAULT_SMDP_ADDRESS), data, reply, option); if (FAILED(result)) { return result; } @@ -632,10 +693,11 @@ ErrCode EsimServiceProxy::CancelSession( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_CANCEL_SESSION), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IEsimServiceIpcCode::COMMAND_CANCEL_SESSION), data, reply, option); if (FAILED(result)) { return result; } @@ -669,10 +731,11 @@ ErrCode EsimServiceProxy::IsEsimSupported( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IEsimServiceIpcCode::COMMAND_IS_ESIM_SUPPORTED), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IEsimServiceIpcCode::COMMAND_IS_ESIM_SUPPORTED), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.h.txt index b20d483..73b9e86 100644 --- a/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.h.txt @@ -16,20 +16,22 @@ #ifndef OHOS_TELEPHONY_ESIMSERVICEPROXY_H #define OHOS_TELEPHONY_ESIMSERVICEPROXY_H -#include "iesim_service.h" +#include #include +#include "iesim_service.h" namespace OHOS { namespace Telephony { class EsimServiceProxy : public IRemoteProxy { public: - explicit EsimServiceProxy( - const sptr& remote) - : IRemoteProxy(remote) - {} + explicit EsimServiceProxy(const sptr& remote); - virtual ~EsimServiceProxy() - {} + ~EsimServiceProxy() override; + + void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override + { + remoteDiedCallback_ = callback; + } ErrCode GetEid( int32_t slotId, @@ -116,7 +118,26 @@ public: int32_t slotId) override; private: + class EsimServiceRecipient : public IRemoteObject::DeathRecipient { + public: + explicit EsimServiceRecipient(EsimServiceProxy& client) : client_(client) {} + ~EsimServiceRecipient() override = default; + void OnRemoteDied(const wptr& remote) override + { + client_.OnRemoteDied(remote); + } + private: + EsimServiceProxy& client_; + }; + + void RemoveDeathRecipient(); + void OnRemoteDied(const wptr& remote); + static inline BrokerDelegator delegator_; + sptr remote_; + sptr deathRecipient_; + OnRemoteDiedCallback remoteDiedCallback_; + std::mutex mutex_; }; } // namespace Telephony } // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/iapp_fwk_update_service.h.txt b/test/sa_test/in_use_idl/target_cpp/iapp_fwk_update_service.h.txt index ea419ef..88b8029 100644 --- a/test/sa_test/in_use_idl/target_cpp/iapp_fwk_update_service.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/iapp_fwk_update_service.h.txt @@ -22,14 +22,19 @@ namespace OHOS { namespace NWeb { + enum class IAppFwkUpdateServiceIpcCode { COMMAND_VERIFY_PACKAGE_INSTALL = MIN_TRANSACTION_ID, }; +using OnRemoteDiedCallback = std::function&)>; + class IAppFwkUpdateService : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.NWeb.IAppFwkUpdateService"); + virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} + virtual ErrCode VerifyPackageInstall( const std::string& bundleName, const std::string& hapPath, diff --git a/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.cpp.txt index e9be07f..6138c02 100644 --- a/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.cpp.txt @@ -16,6 +16,52 @@ #include "idl_test_service_proxy.h" namespace OHOS { +IdlTestServiceProxy::IdlTestServiceProxy(const sptr& remote) : IRemoteProxy(remote) +{ + std::lock_guard lock(mutex_); + if (remote_ && remote_ != remote) { + RemoveDeathRecipient(); + } + if (remote) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) IdlTestServiceRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } +} + +IdlTestServiceProxy::~IdlTestServiceProxy() +{ + RemoveDeathRecipient(); +} + +void IdlTestServiceProxy::RemoveDeathRecipient() +{ + std::lock_guard lock(mutex_); + if (!remote_ || !deathRecipient_) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + deathRecipient_ = nullptr; + remoteDiedCallback_ = nullptr; +} + +void IdlTestServiceProxy::OnRemoteDied(const wptr& remote) +{ + if (remoteDiedCallback_) { + remoteDiedCallback_(remote); + } + RemoveDeathRecipient(); +} + ErrCode IdlTestServiceProxy::TestIntTransaction( int32_t val) { @@ -32,10 +78,11 @@ ErrCode IdlTestServiceProxy::TestIntTransaction( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IIdlTestServiceIpcCode::COMMAND_TEST_INT_TRANSACTION), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IIdlTestServiceIpcCode::COMMAND_TEST_INT_TRANSACTION), data, reply, option); if (FAILED(result)) { return result; } @@ -64,10 +111,11 @@ ErrCode IdlTestServiceProxy::TestStringTransaction( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IIdlTestServiceIpcCode::COMMAND_TEST_STRING_TRANSACTION), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IIdlTestServiceIpcCode::COMMAND_TEST_STRING_TRANSACTION), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.h.txt index 367ac7d..c30c57a 100644 --- a/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.h.txt @@ -16,19 +16,21 @@ #ifndef OHOS_IDLTESTSERVICEPROXY_H #define OHOS_IDLTESTSERVICEPROXY_H -#include "iidl_test_service.h" +#include #include +#include "iidl_test_service.h" namespace OHOS { class IdlTestServiceProxy : public IRemoteProxy { public: - explicit IdlTestServiceProxy( - const sptr& remote) - : IRemoteProxy(remote) - {} + explicit IdlTestServiceProxy(const sptr& remote); + + ~IdlTestServiceProxy() override; - virtual ~IdlTestServiceProxy() - {} + void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override + { + remoteDiedCallback_ = callback; + } ErrCode TestIntTransaction( int32_t val) override; @@ -37,7 +39,26 @@ public: const std::string& val) override; private: + class IdlTestServiceRecipient : public IRemoteObject::DeathRecipient { + public: + explicit IdlTestServiceRecipient(IdlTestServiceProxy& client) : client_(client) {} + ~IdlTestServiceRecipient() override = default; + void OnRemoteDied(const wptr& remote) override + { + client_.OnRemoteDied(remote); + } + private: + IdlTestServiceProxy& client_; + }; + + void RemoveDeathRecipient(); + void OnRemoteDied(const wptr& remote); + static inline BrokerDelegator delegator_; + sptr remote_; + sptr deathRecipient_; + OnRemoteDiedCallback remoteDiedCallback_; + std::mutex mutex_; }; } // namespace OHOS #endif // OHOS_IDLTESTSERVICEPROXY_H diff --git a/test/sa_test/in_use_idl/target_cpp/iesim_service.h.txt b/test/sa_test/in_use_idl/target_cpp/iesim_service.h.txt index ab955f7..f0ce99e 100644 --- a/test/sa_test/in_use_idl/target_cpp/iesim_service.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/iesim_service.h.txt @@ -39,6 +39,7 @@ using OHOS::Telephony::ResponseEsimResult; namespace OHOS { namespace Telephony { + enum class IEsimServiceIpcCode { COMMAND_GET_EID = MIN_TRANSACTION_ID, COMMAND_GET_OSU_STATUS, @@ -59,10 +60,14 @@ enum class IEsimServiceIpcCode { COMMAND_IS_ESIM_SUPPORTED, }; +using OnRemoteDiedCallback = std::function&)>; + class IEsimService : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Telephony.IEsimService"); + virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} + virtual ErrCode GetEid( int32_t slotId, std::string& eId) = 0; diff --git a/test/sa_test/in_use_idl/target_cpp/iidl_test_service.h.txt b/test/sa_test/in_use_idl/target_cpp/iidl_test_service.h.txt index 9bc066b..545159e 100644 --- a/test/sa_test/in_use_idl/target_cpp/iidl_test_service.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/iidl_test_service.h.txt @@ -21,15 +21,20 @@ #include namespace OHOS { + enum class IIdlTestServiceIpcCode { COMMAND_TEST_INT_TRANSACTION = MIN_TRANSACTION_ID, COMMAND_TEST_STRING_TRANSACTION, }; +using OnRemoteDiedCallback = std::function&)>; + class IIdlTestService : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IIdlTestService"); + virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} + virtual ErrCode TestIntTransaction( int32_t val) = 0; diff --git a/test/sa_test/in_use_idl/target_cpp/iquick_fix_manager.h.txt b/test/sa_test/in_use_idl/target_cpp/iquick_fix_manager.h.txt index bbb2e8f..fc68a40 100644 --- a/test/sa_test/in_use_idl/target_cpp/iquick_fix_manager.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/iquick_fix_manager.h.txt @@ -26,16 +26,21 @@ using OHOS::AAFwk::ApplicationQuickFixInfo; namespace OHOS { namespace AAFwk { + enum class IQuickFixManagerIpcCode { COMMAND_APPLY_QUICK_FIX = MIN_TRANSACTION_ID, COMMAND_GET_APPLYED_QUICK_FIX_INFO, COMMAND_REVOKE_QUICK_FIX, }; +using OnRemoteDiedCallback = std::function&)>; + class IQuickFixManager : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.AAFwk.IQuickFixManager"); + virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} + virtual ErrCode ApplyQuickFix( const std::vector& quickFixFiles, bool isDebug) = 0; diff --git a/test/sa_test/in_use_idl/target_cpp/itest_server_interface.h.txt b/test/sa_test/in_use_idl/target_cpp/itest_server_interface.h.txt index 51f8894..acfa5de 100644 --- a/test/sa_test/in_use_idl/target_cpp/itest_server_interface.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/itest_server_interface.h.txt @@ -27,16 +27,21 @@ using OHOS::EventFwk::CommonEventData; namespace OHOS { namespace testserver { + enum class ITestServerInterfaceIpcCode { COMMAND_CREATE_SESSION = MIN_TRANSACTION_ID, COMMAND_SET_PASTE_DATA, COMMAND_PUBLISH_COMMON_EVENT, }; +using OnRemoteDiedCallback = std::function&)>; + class ITestServerInterface : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.testserver.ITestServerInterface"); + virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} + virtual ErrCode CreateSession( const SessionToken& sessionToken) = 0; diff --git a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.cpp.txt index 28e873b..f0d4ba5 100644 --- a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.cpp.txt @@ -17,6 +17,52 @@ namespace OHOS { namespace AAFwk { +QuickFixManagerProxy::QuickFixManagerProxy(const sptr& remote) : IRemoteProxy(remote) +{ + std::lock_guard lock(mutex_); + if (remote_ && remote_ != remote) { + RemoveDeathRecipient(); + } + if (remote) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) QuickFixManagerRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } +} + +QuickFixManagerProxy::~QuickFixManagerProxy() +{ + RemoveDeathRecipient(); +} + +void QuickFixManagerProxy::RemoveDeathRecipient() +{ + std::lock_guard lock(mutex_); + if (!remote_ || !deathRecipient_) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + deathRecipient_ = nullptr; + remoteDiedCallback_ = nullptr; +} + +void QuickFixManagerProxy::OnRemoteDied(const wptr& remote) +{ + if (remoteDiedCallback_) { + remoteDiedCallback_(remote); + } + RemoveDeathRecipient(); +} + ErrCode QuickFixManagerProxy::ApplyQuickFix( const std::vector& quickFixFiles, bool isDebug) @@ -43,10 +89,11 @@ ErrCode QuickFixManagerProxy::ApplyQuickFix( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IQuickFixManagerIpcCode::COMMAND_APPLY_QUICK_FIX), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IQuickFixManagerIpcCode::COMMAND_APPLY_QUICK_FIX), data, reply, option); if (FAILED(result)) { return result; } @@ -76,10 +123,11 @@ ErrCode QuickFixManagerProxy::GetApplyedQuickFixInfo( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IQuickFixManagerIpcCode::COMMAND_GET_APPLYED_QUICK_FIX_INFO), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IQuickFixManagerIpcCode::COMMAND_GET_APPLYED_QUICK_FIX_INFO), data, reply, option); if (FAILED(result)) { return result; } @@ -113,10 +161,11 @@ ErrCode QuickFixManagerProxy::RevokeQuickFix( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IQuickFixManagerIpcCode::COMMAND_REVOKE_QUICK_FIX), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IQuickFixManagerIpcCode::COMMAND_REVOKE_QUICK_FIX), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.h.txt index 4497777..aade00b 100644 --- a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.h.txt @@ -16,20 +16,22 @@ #ifndef OHOS_AAFWK_QUICKFIXMANAGERPROXY_H #define OHOS_AAFWK_QUICKFIXMANAGERPROXY_H -#include "iquick_fix_manager.h" +#include #include +#include "iquick_fix_manager.h" namespace OHOS { namespace AAFwk { class QuickFixManagerProxy : public IRemoteProxy { public: - explicit QuickFixManagerProxy( - const sptr& remote) - : IRemoteProxy(remote) - {} + explicit QuickFixManagerProxy(const sptr& remote); + + ~QuickFixManagerProxy() override; - virtual ~QuickFixManagerProxy() - {} + void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override + { + remoteDiedCallback_ = callback; + } ErrCode ApplyQuickFix( const std::vector& quickFixFiles, @@ -43,7 +45,26 @@ public: const std::string& bundleName) override; private: + class QuickFixManagerRecipient : public IRemoteObject::DeathRecipient { + public: + explicit QuickFixManagerRecipient(QuickFixManagerProxy& client) : client_(client) {} + ~QuickFixManagerRecipient() override = default; + void OnRemoteDied(const wptr& remote) override + { + client_.OnRemoteDied(remote); + } + private: + QuickFixManagerProxy& client_; + }; + + void RemoveDeathRecipient(); + void OnRemoteDied(const wptr& remote); + static inline BrokerDelegator delegator_; + sptr remote_; + sptr deathRecipient_; + OnRemoteDiedCallback remoteDiedCallback_; + std::mutex mutex_; }; } // namespace AAFwk } // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.cpp.txt index bf3a9e7..42130db 100644 --- a/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.cpp.txt @@ -17,6 +17,52 @@ namespace OHOS { namespace testserver { +TestServerInterfaceProxy::TestServerInterfaceProxy(const sptr& remote) : IRemoteProxy(remote) +{ + std::lock_guard lock(mutex_); + if (remote_ && remote_ != remote) { + RemoveDeathRecipient(); + } + if (remote) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) TestServerInterfaceRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } +} + +TestServerInterfaceProxy::~TestServerInterfaceProxy() +{ + RemoveDeathRecipient(); +} + +void TestServerInterfaceProxy::RemoveDeathRecipient() +{ + std::lock_guard lock(mutex_); + if (!remote_ || !deathRecipient_) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + deathRecipient_ = nullptr; + remoteDiedCallback_ = nullptr; +} + +void TestServerInterfaceProxy::OnRemoteDied(const wptr& remote) +{ + if (remoteDiedCallback_) { + remoteDiedCallback_(remote); + } + RemoveDeathRecipient(); +} + ErrCode TestServerInterfaceProxy::CreateSession( const SessionToken& sessionToken) { @@ -33,10 +79,11 @@ ErrCode TestServerInterfaceProxy::CreateSession( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(ITestServerInterfaceIpcCode::COMMAND_CREATE_SESSION), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(ITestServerInterfaceIpcCode::COMMAND_CREATE_SESSION), data, reply, option); if (FAILED(result)) { return result; } @@ -65,10 +112,11 @@ ErrCode TestServerInterfaceProxy::SetPasteData( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(ITestServerInterfaceIpcCode::COMMAND_SET_PASTE_DATA), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(ITestServerInterfaceIpcCode::COMMAND_SET_PASTE_DATA), data, reply, option); if (FAILED(result)) { return result; } @@ -98,10 +146,11 @@ ErrCode TestServerInterfaceProxy::PublishCommonEvent( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(ITestServerInterfaceIpcCode::COMMAND_PUBLISH_COMMON_EVENT), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(ITestServerInterfaceIpcCode::COMMAND_PUBLISH_COMMON_EVENT), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.h.txt index b5e2d80..d46226c 100644 --- a/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.h.txt @@ -16,20 +16,22 @@ #ifndef OHOS_TESTSERVER_TESTSERVERINTERFACEPROXY_H #define OHOS_TESTSERVER_TESTSERVERINTERFACEPROXY_H -#include "itest_server_interface.h" +#include #include +#include "itest_server_interface.h" namespace OHOS { namespace testserver { class TestServerInterfaceProxy : public IRemoteProxy { public: - explicit TestServerInterfaceProxy( - const sptr& remote) - : IRemoteProxy(remote) - {} + explicit TestServerInterfaceProxy(const sptr& remote); + + ~TestServerInterfaceProxy() override; - virtual ~TestServerInterfaceProxy() - {} + void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override + { + remoteDiedCallback_ = callback; + } ErrCode CreateSession( const SessionToken& sessionToken) override; @@ -42,7 +44,26 @@ public: bool& re) override; private: + class TestServerInterfaceRecipient : public IRemoteObject::DeathRecipient { + public: + explicit TestServerInterfaceRecipient(TestServerInterfaceProxy& client) : client_(client) {} + ~TestServerInterfaceRecipient() override = default; + void OnRemoteDied(const wptr& remote) override + { + client_.OnRemoteDied(remote); + } + private: + TestServerInterfaceProxy& client_; + }; + + void RemoveDeathRecipient(); + void OnRemoteDied(const wptr& remote); + static inline BrokerDelegator delegator_; + sptr remote_; + sptr deathRecipient_; + OnRemoteDiedCallback remoteDiedCallback_; + std::mutex mutex_; }; } // namespace testserver } // namespace OHOS diff --git a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.cpp.txt b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.cpp.txt index a7b9e30..a3d6550 100644 --- a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.cpp.txt @@ -17,6 +17,76 @@ namespace idl { namespace OHOS { +FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) +{ + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST001), 100000); + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST002), 0); + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST003), 0); + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST004), 200000); + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST005), 2147483647000); + + std::lock_guard lock(mutex_); + if (remote_ && remote_ != remote) { + RemoveDeathRecipient(); + } + if (remote) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) FooRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } +} + +FooProxy::~FooProxy() +{ + RemoveDeathRecipient(); + + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST001)); + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST002)); + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST003)); + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST004)); + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST005)); +} + +void FooProxy::RemoveDeathRecipient() +{ + std::lock_guard lock(mutex_); + if (!remote_ || !deathRecipient_) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + deathRecipient_ = nullptr; + remoteDiedCallback_ = nullptr; +} + +void FooProxy::OnRemoteDied(const wptr& remote) +{ + if (remoteDiedCallback_) { + remoteDiedCallback_(remote); + } + RemoveDeathRecipient(); + + ApiCacheManager::GetInstance().ClearCache(GetDescriptor()); +} + ErrCode FooProxy::test001( short param1, int32_t& funcResult) @@ -33,8 +103,9 @@ ErrCode FooProxy::test001( return ERR_INVALID_DATA; } - bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST001), data, reply); - if (hitCache == true) { + bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST001), data, reply); + if (hitCache) { ErrCode errCode = reply.ReadInt32(); if (FAILED(errCode)) { return errCode; @@ -44,10 +115,11 @@ ErrCode FooProxy::test001( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_TEST001), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_TEST001), data, reply, option); if (FAILED(result)) { return result; } @@ -57,7 +129,8 @@ ErrCode FooProxy::test001( return errCode; } - ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST001), data, reply); + ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST001), data, reply); funcResult = reply.ReadInt32(); return ERR_OK; } @@ -77,8 +150,9 @@ ErrCode FooProxy::test002( return ERR_INVALID_DATA; } - bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST002), data, reply); - if (hitCache == true) { + bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST002), data, reply); + if (hitCache) { ErrCode errCode = reply.ReadInt32(); if (FAILED(errCode)) { return errCode; @@ -87,10 +161,11 @@ ErrCode FooProxy::test002( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_TEST002), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_TEST002), data, reply, option); if (FAILED(result)) { return result; } @@ -100,7 +175,8 @@ ErrCode FooProxy::test002( return errCode; } - ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST002), data, reply); + ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST002), data, reply); return ERR_OK; } @@ -120,8 +196,9 @@ ErrCode FooProxy::test003( return ERR_INVALID_DATA; } - bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST003), data, reply); - if (hitCache == true) { + bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST003), data, reply); + if (hitCache) { ErrCode errCode = reply.ReadInt32(); if (FAILED(errCode)) { return errCode; @@ -131,10 +208,11 @@ ErrCode FooProxy::test003( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_TEST003), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_TEST003), data, reply, option); if (FAILED(result)) { return result; } @@ -144,7 +222,8 @@ ErrCode FooProxy::test003( return errCode; } - ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST003), data, reply); + ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST003), data, reply); param2 = reply.ReadInt32(); return ERR_OK; } @@ -175,8 +254,9 @@ ErrCode FooProxy::test004( } } - bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST004), data, reply); - if (hitCache == true) { + bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST004), data, reply); + if (hitCache) { ErrCode errCode = reply.ReadInt32(); if (FAILED(errCode)) { return errCode; @@ -191,10 +271,11 @@ ErrCode FooProxy::test004( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_TEST004), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_TEST004), data, reply, option); if (FAILED(result)) { return result; } @@ -204,7 +285,8 @@ ErrCode FooProxy::test004( return errCode; } - ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST004), data, reply); + ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST004), data, reply); int32_t outParamSize = reply.ReadInt32(); for (int32_t i = 0; i < outParamSize; ++i) { int64_t key = reply.ReadInt64(); @@ -230,8 +312,9 @@ ErrCode FooProxy::test005( return ERR_INVALID_DATA; } - bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005), data, reply); - if (hitCache == true) { + bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST005), data, reply); + if (hitCache) { ErrCode errCode = reply.ReadInt32(); if (FAILED(errCode)) { return errCode; @@ -241,10 +324,11 @@ ErrCode FooProxy::test005( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_TEST005), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_TEST005), data, reply, option); if (FAILED(result)) { return result; } @@ -254,7 +338,8 @@ ErrCode FooProxy::test005( return errCode; } - ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005), data, reply); + ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST005), data, reply); param2 = reply.ReadDouble(); return ERR_OK; } diff --git a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.h.txt b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.h.txt index 3b67fc9..87c7605 100644 --- a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.h.txt @@ -16,55 +16,22 @@ #ifndef IDL_OHOS_FOOPROXY_H #define IDL_OHOS_FOOPROXY_H -#include "ifoo.h" +#include #include +#include "ifoo.h" #include "api_cache_manager.h" namespace idl { namespace OHOS { class FooProxy : public IRemoteProxy { public: - explicit FooProxy( - const sptr& remote) - : IRemoteProxy(remote) - { - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST001), 100000); - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST002), 0); - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST003), 0); - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST004), 200000); - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005), 2147483647000); + explicit FooProxy(const sptr& remote); - if (remote != nullptr) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) FooRecipient(*this); - if (deathRecipient_ == nullptr) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } - } + ~FooProxy() override; - virtual ~FooProxy() + void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override { - if (remote_ == nullptr) { - return; - } - if (deathRecipient_ == nullptr) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST001)); - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST002)); - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST003)); - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST004)); - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005)); + remoteDiedCallback_ = callback; } ErrCode test001( @@ -89,24 +56,24 @@ public: private: class FooRecipient : public IRemoteObject::DeathRecipient { public: - explicit FooRecipient(FooProxy &client) : client_(client) {} + explicit FooRecipient(FooProxy& client) : client_(client) {} ~FooRecipient() override = default; - void OnRemoteDied(const wptr &remote) override + void OnRemoteDied(const wptr& remote) override { client_.OnRemoteDied(remote); } private: - FooProxy &client_; + FooProxy& client_; }; - void OnRemoteDied(const wptr &remoteObject) - { - (void)remoteObject; - ApiCacheManager::GetInstance().ClearCache(GetDescriptor()); - } - sptr remote_ = nullptr; - sptr deathRecipient_ = nullptr; + void RemoveDeathRecipient(); + void OnRemoteDied(const wptr& remote); + static inline BrokerDelegator delegator_; + sptr remote_; + sptr deathRecipient_; + OnRemoteDiedCallback remoteDiedCallback_; + std::mutex mutex_; }; } // namespace OHOS } // namespace idl diff --git a/test/sa_test/keyword_cacheable_test_001/target_cpp/ifoo.h.txt b/test/sa_test/keyword_cacheable_test_001/target_cpp/ifoo.h.txt index f47d3c9..6ffaa87 100644 --- a/test/sa_test/keyword_cacheable_test_001/target_cpp/ifoo.h.txt +++ b/test/sa_test/keyword_cacheable_test_001/target_cpp/ifoo.h.txt @@ -23,6 +23,7 @@ namespace idl { namespace OHOS { + enum class IFooIpcCode { COMMAND_TEST001 = MIN_TRANSACTION_ID, COMMAND_TEST002, @@ -31,10 +32,14 @@ enum class IFooIpcCode { COMMAND_TEST005, }; +using OnRemoteDiedCallback = std::function&)>; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"idl.OHOS.IFoo"); + virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} + virtual ErrCode test001( short param1, int32_t& funcResult) = 0; diff --git a/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.cpp.txt b/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.cpp.txt index 84946f5..fd6c6d8 100644 --- a/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.cpp.txt @@ -17,6 +17,64 @@ namespace idl { namespace OHOS { +FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) +{ + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST005), 0); + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST005), 2000); + + std::lock_guard lock(mutex_); + if (remote_ && remote_ != remote) { + RemoveDeathRecipient(); + } + if (remote) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) FooRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } +} + +FooProxy::~FooProxy() +{ + RemoveDeathRecipient(); + + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST005)); + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST005)); +} + +void FooProxy::RemoveDeathRecipient() +{ + std::lock_guard lock(mutex_); + if (!remote_ || !deathRecipient_) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + deathRecipient_ = nullptr; + remoteDiedCallback_ = nullptr; +} + +void FooProxy::OnRemoteDied(const wptr& remote) +{ + if (remoteDiedCallback_) { + remoteDiedCallback_(remote); + } + RemoveDeathRecipient(); + + ApiCacheManager::GetInstance().ClearCache(GetDescriptor()); +} + ErrCode FooProxy::test001( int32_t param1) { @@ -33,10 +91,11 @@ ErrCode FooProxy::test001( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_TEST001), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_TEST001), data, reply, option); if (FAILED(result)) { return result; } @@ -59,10 +118,11 @@ ErrCode FooProxy::test002( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_TEST002), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_TEST002), data, reply, option); if (FAILED(result)) { return result; } @@ -85,8 +145,9 @@ ErrCode FooProxy::test005( return ERR_INVALID_DATA; } - bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005), data, reply); - if (hitCache == true) { + bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST005), data, reply); + if (hitCache) { ErrCode errCode = reply.ReadInt32(); if (FAILED(errCode)) { return errCode; @@ -96,10 +157,11 @@ ErrCode FooProxy::test005( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_TEST005), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_TEST005), data, reply, option); if (FAILED(result)) { return result; } @@ -109,7 +171,8 @@ ErrCode FooProxy::test005( return errCode; } - ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005), data, reply); + ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST005), data, reply); param2 = reply.ReadDouble(); return ERR_OK; } @@ -130,8 +193,9 @@ ErrCode FooProxy::test005( return ERR_INVALID_DATA; } - bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005), data, reply); - if (hitCache == true) { + bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST005), data, reply); + if (hitCache) { ErrCode errCode = reply.ReadInt32(); if (FAILED(errCode)) { return errCode; @@ -141,10 +205,11 @@ ErrCode FooProxy::test005( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_TEST005), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_TEST005), data, reply, option); if (FAILED(result)) { return result; } @@ -154,7 +219,8 @@ ErrCode FooProxy::test005( return errCode; } - ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005), data, reply); + ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST005), data, reply); param2 = reply.ReadInt32(); return ERR_OK; } diff --git a/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.h.txt b/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.h.txt index 40f60c7..586a621 100644 --- a/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.h.txt @@ -16,49 +16,22 @@ #ifndef IDL_OHOS_FOOPROXY_H #define IDL_OHOS_FOOPROXY_H -#include "ifoo.h" +#include #include +#include "ifoo.h" #include "api_cache_manager.h" namespace idl { namespace OHOS { class FooProxy : public IRemoteProxy { public: - explicit FooProxy( - const sptr& remote) - : IRemoteProxy(remote) - { - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005), 0); - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005), 2000); + explicit FooProxy(const sptr& remote); - if (remote != nullptr) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) FooRecipient(*this); - if (deathRecipient_ == nullptr) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } - } + ~FooProxy() override; - virtual ~FooProxy() + void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override { - if (remote_ == nullptr) { - return; - } - if (deathRecipient_ == nullptr) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005)); - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_TEST005)); + remoteDiedCallback_ = callback; } ErrCode test001( @@ -78,24 +51,24 @@ public: private: class FooRecipient : public IRemoteObject::DeathRecipient { public: - explicit FooRecipient(FooProxy &client) : client_(client) {} + explicit FooRecipient(FooProxy& client) : client_(client) {} ~FooRecipient() override = default; - void OnRemoteDied(const wptr &remote) override + void OnRemoteDied(const wptr& remote) override { client_.OnRemoteDied(remote); } private: - FooProxy &client_; + FooProxy& client_; }; - void OnRemoteDied(const wptr &remoteObject) - { - (void)remoteObject; - ApiCacheManager::GetInstance().ClearCache(GetDescriptor()); - } - sptr remote_ = nullptr; - sptr deathRecipient_ = nullptr; + void RemoveDeathRecipient(); + void OnRemoteDied(const wptr& remote); + static inline BrokerDelegator delegator_; + sptr remote_; + sptr deathRecipient_; + OnRemoteDiedCallback remoteDiedCallback_; + std::mutex mutex_; }; } // namespace OHOS } // namespace idl diff --git a/test/sa_test/keyword_cacheable_test_002/target_cpp/ifoo.h.txt b/test/sa_test/keyword_cacheable_test_002/target_cpp/ifoo.h.txt index 9a1e224..a4946ac 100644 --- a/test/sa_test/keyword_cacheable_test_002/target_cpp/ifoo.h.txt +++ b/test/sa_test/keyword_cacheable_test_002/target_cpp/ifoo.h.txt @@ -22,6 +22,7 @@ namespace idl { namespace OHOS { + enum class IFooIpcCode { COMMAND_TEST001 = MIN_TRANSACTION_ID, COMMAND_TEST002, @@ -29,10 +30,14 @@ enum class IFooIpcCode { COMMAND_TEST005, }; +using OnRemoteDiedCallback = std::function&)>; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"idl.OHOS.IFoo"); + virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} + virtual ErrCode test001( int32_t param1) = 0; diff --git a/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.cpp.txt b/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.cpp.txt index ef08645..ccc55a3 100644 --- a/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.cpp.txt @@ -16,6 +16,52 @@ #include "foo_proxy.h" namespace test { +FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) +{ + std::lock_guard lock(mutex_); + if (remote_ && remote_ != remote) { + RemoveDeathRecipient(); + } + if (remote) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) FooRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } +} + +FooProxy::~FooProxy() +{ + RemoveDeathRecipient(); +} + +void FooProxy::RemoveDeathRecipient() +{ + std::lock_guard lock(mutex_); + if (!remote_ || !deathRecipient_) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + deathRecipient_ = nullptr; + remoteDiedCallback_ = nullptr; +} + +void FooProxy::OnRemoteDied(const wptr& remote) +{ + if (remoteDiedCallback_) { + remoteDiedCallback_(remote); + } + RemoveDeathRecipient(); +} + ErrCode FooProxy::seq_test_func( const myseq& inParam, myseq& outParam, @@ -37,10 +83,11 @@ ErrCode FooProxy::seq_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -84,10 +131,11 @@ ErrCode FooProxy::seq_test_func2( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC2), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC2), data, reply, option); if (FAILED(result)) { return result; } @@ -137,10 +185,11 @@ ErrCode FooProxy::interface_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -182,10 +231,11 @@ ErrCode FooProxy::interface_test_func2( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC2), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC2), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.h.txt b/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.h.txt index 51b1f0c..ca238a0 100644 --- a/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.h.txt @@ -16,19 +16,21 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include "ifoo.h" +#include #include +#include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy( - const sptr& remote) - : IRemoteProxy(remote) - {} + explicit FooProxy(const sptr& remote); + + ~FooProxy() override; - virtual ~FooProxy() - {} + void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override + { + remoteDiedCallback_ = callback; + } ErrCode seq_test_func( const myseq& inParam, @@ -51,7 +53,26 @@ public: const sptr& inoutParam) override; private: + class FooRecipient : public IRemoteObject::DeathRecipient { + public: + explicit FooRecipient(FooProxy& client) : client_(client) {} + ~FooRecipient() override = default; + void OnRemoteDied(const wptr& remote) override + { + client_.OnRemoteDied(remote); + } + private: + FooProxy& client_; + }; + + void RemoveDeathRecipient(); + void OnRemoteDied(const wptr& remote); + static inline BrokerDelegator delegator_; + sptr remote_; + sptr deathRecipient_; + OnRemoteDiedCallback remoteDiedCallback_; + std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/keyword_import_dir/target_cpp/ifoo.h.txt b/test/sa_test/keyword_import_dir/target_cpp/ifoo.h.txt index 765ffd9..19b34cb 100644 --- a/test/sa_test/keyword_import_dir/target_cpp/ifoo.h.txt +++ b/test/sa_test/keyword_import_dir/target_cpp/ifoo.h.txt @@ -30,6 +30,7 @@ using test::myinterface; using ::myinterface2; namespace test { + enum class IFooIpcCode { COMMAND_SEQ_TEST_FUNC = MIN_TRANSACTION_ID, COMMAND_SEQ_TEST_FUNC2, @@ -37,10 +38,14 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC2, }; +using OnRemoteDiedCallback = std::function&)>; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); + virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} + virtual ErrCode seq_test_func( const myseq& inParam, myseq& outParam, diff --git a/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.cpp.txt b/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.cpp.txt index caa597e..5033f8a 100644 --- a/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.cpp.txt @@ -16,6 +16,52 @@ #include "foo_proxy.h" namespace test { +FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) +{ + std::lock_guard lock(mutex_); + if (remote_ && remote_ != remote) { + RemoveDeathRecipient(); + } + if (remote) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) FooRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } +} + +FooProxy::~FooProxy() +{ + RemoveDeathRecipient(); +} + +void FooProxy::RemoveDeathRecipient() +{ + std::lock_guard lock(mutex_); + if (!remote_ || !deathRecipient_) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + deathRecipient_ = nullptr; + remoteDiedCallback_ = nullptr; +} + +void FooProxy::OnRemoteDied(const wptr& remote) +{ + if (remoteDiedCallback_) { + remoteDiedCallback_(remote); + } + RemoveDeathRecipient(); +} + ErrCode FooProxy::void_test_func() { MessageParcel data; @@ -26,12 +72,12 @@ ErrCode FooProxy::void_test_func() return ERR_INVALID_VALUE; } - sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -65,10 +111,11 @@ ErrCode FooProxy::bool_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -104,10 +151,11 @@ ErrCode FooProxy::byte_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -142,8 +190,9 @@ ErrCode FooProxy::short_test_func( return ERR_INVALID_DATA; } - bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply); - if (hitCache == true) { + bool hitCache = ApiCacheManager::GetInstance().PreSendRequest(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply); + if (hitCache) { ErrCode errCode = reply.ReadInt32(); if (FAILED(errCode)) { return errCode; @@ -154,10 +203,11 @@ ErrCode FooProxy::short_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -167,7 +217,8 @@ ErrCode FooProxy::short_test_func( return errCode; } - ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply); + ApiCacheManager::GetInstance().PostSendRequest(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply); outParam = (short)reply.ReadInt32(); inoutParam = (short)reply.ReadInt32(); return ERR_OK; @@ -194,10 +245,11 @@ ErrCode FooProxy::int_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -233,10 +285,11 @@ ErrCode FooProxy::long_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -275,10 +328,11 @@ ErrCode FooProxy::string_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -309,10 +363,11 @@ ErrCode FooProxy::float_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -340,10 +395,11 @@ ErrCode FooProxy::double_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -379,10 +435,11 @@ ErrCode FooProxy::seq_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -432,10 +489,11 @@ ErrCode FooProxy::interface_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.h.txt b/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.h.txt index 8fe1620..7ce8042 100644 --- a/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.h.txt @@ -16,19 +16,21 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include "ifoo.h" +#include #include +#include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy( - const sptr& remote) - : IRemoteProxy(remote) - {} + explicit FooProxy(const sptr& remote); - virtual ~FooProxy() - {} + ~FooProxy() override; + + void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override + { + remoteDiedCallback_ = callback; + } ErrCode void_test_func() override; @@ -83,7 +85,26 @@ public: const sptr& inoutParam) override; private: + class FooRecipient : public IRemoteObject::DeathRecipient { + public: + explicit FooRecipient(FooProxy& client) : client_(client) {} + ~FooRecipient() override = default; + void OnRemoteDied(const wptr& remote) override + { + client_.OnRemoteDied(remote); + } + private: + FooProxy& client_; + }; + + void RemoveDeathRecipient(); + void OnRemoteDied(const wptr& remote); + static inline BrokerDelegator delegator_; + sptr remote_; + sptr deathRecipient_; + OnRemoteDiedCallback remoteDiedCallback_; + std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/keyword_ipccode_test_001/target_cpp/ifoo.h.txt b/test/sa_test/keyword_ipccode_test_001/target_cpp/ifoo.h.txt index 90e0f58..308da2e 100644 --- a/test/sa_test/keyword_ipccode_test_001/target_cpp/ifoo.h.txt +++ b/test/sa_test/keyword_ipccode_test_001/target_cpp/ifoo.h.txt @@ -26,6 +26,7 @@ using test::myseq; using test::myinterface; namespace test { + enum class IFooIpcCode { COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID, COMMAND_BOOL_TEST_FUNC = 20, @@ -40,10 +41,14 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC, }; +using OnRemoteDiedCallback = std::function&)>; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); + virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} + virtual ErrCode void_test_func() = 0; virtual ErrCode bool_test_func( diff --git a/test/sa_test/keyword_oneway/target_cpp/foo_proxy.cpp.txt.txt b/test/sa_test/keyword_oneway/target_cpp/foo_proxy.cpp.txt similarity index 69% rename from test/sa_test/keyword_oneway/target_cpp/foo_proxy.cpp.txt.txt rename to test/sa_test/keyword_oneway/target_cpp/foo_proxy.cpp.txt index 617cb40..5f9a7df 100644 --- a/test/sa_test/keyword_oneway/target_cpp/foo_proxy.cpp.txt.txt +++ b/test/sa_test/keyword_oneway/target_cpp/foo_proxy.cpp.txt @@ -16,6 +16,52 @@ #include "foo_proxy.h" namespace test { +FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) +{ + std::lock_guard lock(mutex_); + if (remote_ && remote_ != remote) { + RemoveDeathRecipient(); + } + if (remote) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) FooRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } +} + +FooProxy::~FooProxy() +{ + RemoveDeathRecipient(); +} + +void FooProxy::RemoveDeathRecipient() +{ + std::lock_guard lock(mutex_); + if (!remote_ || !deathRecipient_) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + deathRecipient_ = nullptr; + remoteDiedCallback_ = nullptr; +} + +void FooProxy::OnRemoteDied(const wptr& remote) +{ + if (remoteDiedCallback_) { + remoteDiedCallback_(remote); + } + RemoveDeathRecipient(); +} + ErrCode FooProxy::void_test_func() { MessageParcel data; @@ -26,12 +72,12 @@ ErrCode FooProxy::void_test_func() return ERR_INVALID_VALUE; } - sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -54,10 +100,11 @@ ErrCode FooProxy::bool_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -80,10 +127,11 @@ ErrCode FooProxy::byte_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -106,10 +154,11 @@ ErrCode FooProxy::short_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -132,10 +181,11 @@ ErrCode FooProxy::int_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -158,10 +208,11 @@ ErrCode FooProxy::long_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -184,10 +235,11 @@ ErrCode FooProxy::string_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -210,10 +262,11 @@ ErrCode FooProxy::float_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -236,10 +289,11 @@ ErrCode FooProxy::double_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -262,10 +316,11 @@ ErrCode FooProxy::char_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -288,10 +343,11 @@ ErrCode FooProxy::seq_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -317,10 +373,11 @@ ErrCode FooProxy::interface_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/keyword_oneway/target_cpp/foo_proxy.h.txt.txt b/test/sa_test/keyword_oneway/target_cpp/foo_proxy.h.txt similarity index 65% rename from test/sa_test/keyword_oneway/target_cpp/foo_proxy.h.txt.txt rename to test/sa_test/keyword_oneway/target_cpp/foo_proxy.h.txt index 94963ea..298b4ac 100644 --- a/test/sa_test/keyword_oneway/target_cpp/foo_proxy.h.txt.txt +++ b/test/sa_test/keyword_oneway/target_cpp/foo_proxy.h.txt @@ -16,19 +16,21 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include "ifoo.h" +#include #include +#include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy( - const sptr& remote) - : IRemoteProxy(remote) - {} + explicit FooProxy(const sptr& remote); - virtual ~FooProxy() - {} + ~FooProxy() override; + + void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override + { + remoteDiedCallback_ = callback; + } ErrCode void_test_func() override; @@ -66,7 +68,26 @@ public: const sptr& inParam) override; private: + class FooRecipient : public IRemoteObject::DeathRecipient { + public: + explicit FooRecipient(FooProxy& client) : client_(client) {} + ~FooRecipient() override = default; + void OnRemoteDied(const wptr& remote) override + { + client_.OnRemoteDied(remote); + } + private: + FooProxy& client_; + }; + + void RemoveDeathRecipient(); + void OnRemoteDied(const wptr& remote); + static inline BrokerDelegator delegator_; + sptr remote_; + sptr deathRecipient_; + OnRemoteDiedCallback remoteDiedCallback_; + std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/keyword_oneway/target_cpp/foo_stub.cpp.txt.txt b/test/sa_test/keyword_oneway/target_cpp/foo_stub.cpp.txt similarity index 100% rename from test/sa_test/keyword_oneway/target_cpp/foo_stub.cpp.txt.txt rename to test/sa_test/keyword_oneway/target_cpp/foo_stub.cpp.txt diff --git a/test/sa_test/keyword_oneway/target_cpp/foo_stub.h.txt.txt b/test/sa_test/keyword_oneway/target_cpp/foo_stub.h.txt similarity index 100% rename from test/sa_test/keyword_oneway/target_cpp/foo_stub.h.txt.txt rename to test/sa_test/keyword_oneway/target_cpp/foo_stub.h.txt diff --git a/test/sa_test/keyword_oneway/target_cpp/ifoo.h.txt.txt b/test/sa_test/keyword_oneway/target_cpp/ifoo.h.txt similarity index 92% rename from test/sa_test/keyword_oneway/target_cpp/ifoo.h.txt.txt rename to test/sa_test/keyword_oneway/target_cpp/ifoo.h.txt index c4d2e10..3aa42e5 100644 --- a/test/sa_test/keyword_oneway/target_cpp/ifoo.h.txt.txt +++ b/test/sa_test/keyword_oneway/target_cpp/ifoo.h.txt @@ -26,6 +26,7 @@ using test::myseq; using test::myinterface; namespace test { + enum class IFooIpcCode { COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID, COMMAND_BOOL_TEST_FUNC, @@ -41,10 +42,14 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC, }; +using OnRemoteDiedCallback = std::function&)>; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); + virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} + virtual ErrCode void_test_func() = 0; virtual ErrCode bool_test_func( diff --git a/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt index 666bb49..5b07e0c 100644 --- a/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt @@ -16,6 +16,52 @@ #include "foo_proxy.h" namespace test { +FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) +{ + std::lock_guard lock(mutex_); + if (remote_ && remote_ != remote) { + RemoveDeathRecipient(); + } + if (remote) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) FooRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } +} + +FooProxy::~FooProxy() +{ + RemoveDeathRecipient(); +} + +void FooProxy::RemoveDeathRecipient() +{ + std::lock_guard lock(mutex_); + if (!remote_ || !deathRecipient_) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + deathRecipient_ = nullptr; + remoteDiedCallback_ = nullptr; +} + +void FooProxy::OnRemoteDied(const wptr& remote) +{ + if (remoteDiedCallback_) { + remoteDiedCallback_(remote); + } + RemoveDeathRecipient(); +} + ErrCode FooProxy::void_test_func() { MessageParcel data; @@ -26,12 +72,12 @@ ErrCode FooProxy::void_test_func() return ERR_INVALID_VALUE; } - sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -78,10 +124,11 @@ ErrCode FooProxy::bool_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -152,10 +199,11 @@ ErrCode FooProxy::byte_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -226,10 +274,11 @@ ErrCode FooProxy::short_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -300,10 +349,11 @@ ErrCode FooProxy::int_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -374,10 +424,11 @@ ErrCode FooProxy::long_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -448,10 +499,11 @@ ErrCode FooProxy::string_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -522,10 +574,11 @@ ErrCode FooProxy::float_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -596,10 +649,11 @@ ErrCode FooProxy::double_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -670,10 +724,11 @@ ErrCode FooProxy::char_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -744,10 +799,11 @@ ErrCode FooProxy::seq_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -836,10 +892,11 @@ ErrCode FooProxy::interface_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/type_array/target_cpp/foo_proxy.h.txt b/test/sa_test/type_array/target_cpp/foo_proxy.h.txt index eff3259..457b9d4 100644 --- a/test/sa_test/type_array/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_array/target_cpp/foo_proxy.h.txt @@ -16,19 +16,21 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include "ifoo.h" +#include #include +#include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy( - const sptr& remote) - : IRemoteProxy(remote) - {} + explicit FooProxy(const sptr& remote); - virtual ~FooProxy() - {} + ~FooProxy() override; + + void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override + { + remoteDiedCallback_ = callback; + } ErrCode void_test_func() override; @@ -99,7 +101,26 @@ public: std::vector>& funcResult) override; private: + class FooRecipient : public IRemoteObject::DeathRecipient { + public: + explicit FooRecipient(FooProxy& client) : client_(client) {} + ~FooRecipient() override = default; + void OnRemoteDied(const wptr& remote) override + { + client_.OnRemoteDied(remote); + } + private: + FooProxy& client_; + }; + + void RemoveDeathRecipient(); + void OnRemoteDied(const wptr& remote); + static inline BrokerDelegator delegator_; + sptr remote_; + sptr deathRecipient_; + OnRemoteDiedCallback remoteDiedCallback_; + std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/type_array/target_cpp/ifoo.h.txt b/test/sa_test/type_array/target_cpp/ifoo.h.txt index dcbf6d4..a7a41bc 100644 --- a/test/sa_test/type_array/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_array/target_cpp/ifoo.h.txt @@ -27,6 +27,7 @@ using test::myseq; using test::myinterface; namespace test { + enum class IFooIpcCode { COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID, COMMAND_BOOL_TEST_FUNC, @@ -42,10 +43,14 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC, }; +using OnRemoteDiedCallback = std::function&)>; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); + virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} + virtual ErrCode void_test_func() = 0; virtual ErrCode bool_test_func( diff --git a/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt index 5483302..75cd232 100644 --- a/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt @@ -16,6 +16,52 @@ #include "foo_proxy.h" namespace test { +FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) +{ + std::lock_guard lock(mutex_); + if (remote_ && remote_ != remote) { + RemoveDeathRecipient(); + } + if (remote) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) FooRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } +} + +FooProxy::~FooProxy() +{ + RemoveDeathRecipient(); +} + +void FooProxy::RemoveDeathRecipient() +{ + std::lock_guard lock(mutex_); + if (!remote_ || !deathRecipient_) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + deathRecipient_ = nullptr; + remoteDiedCallback_ = nullptr; +} + +void FooProxy::OnRemoteDied(const wptr& remote) +{ + if (remoteDiedCallback_) { + remoteDiedCallback_(remote); + } + RemoveDeathRecipient(); +} + ErrCode FooProxy::bool_test_func( const std::vector& inParam, std::vector& outParam, @@ -50,10 +96,11 @@ ErrCode FooProxy::bool_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -124,10 +171,11 @@ ErrCode FooProxy::byte_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -198,10 +246,11 @@ ErrCode FooProxy::short_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -272,10 +321,11 @@ ErrCode FooProxy::int_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -346,10 +396,11 @@ ErrCode FooProxy::long_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -420,10 +471,11 @@ ErrCode FooProxy::string_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -494,10 +546,11 @@ ErrCode FooProxy::float_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -568,10 +621,11 @@ ErrCode FooProxy::double_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -642,10 +696,11 @@ ErrCode FooProxy::char_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -716,10 +771,11 @@ ErrCode FooProxy::seq_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -808,10 +864,11 @@ ErrCode FooProxy::interface_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/type_list/target_cpp/foo_proxy.h.txt b/test/sa_test/type_list/target_cpp/foo_proxy.h.txt index 5d882af..8d5e82d 100644 --- a/test/sa_test/type_list/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_list/target_cpp/foo_proxy.h.txt @@ -16,19 +16,21 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include "ifoo.h" +#include #include +#include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy( - const sptr& remote) - : IRemoteProxy(remote) - {} + explicit FooProxy(const sptr& remote); - virtual ~FooProxy() - {} + ~FooProxy() override; + + void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override + { + remoteDiedCallback_ = callback; + } ErrCode bool_test_func( const std::vector& inParam, @@ -97,7 +99,26 @@ public: std::vector>& funcResult) override; private: + class FooRecipient : public IRemoteObject::DeathRecipient { + public: + explicit FooRecipient(FooProxy& client) : client_(client) {} + ~FooRecipient() override = default; + void OnRemoteDied(const wptr& remote) override + { + client_.OnRemoteDied(remote); + } + private: + FooProxy& client_; + }; + + void RemoveDeathRecipient(); + void OnRemoteDied(const wptr& remote); + static inline BrokerDelegator delegator_; + sptr remote_; + sptr deathRecipient_; + OnRemoteDiedCallback remoteDiedCallback_; + std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/type_list/target_cpp/ifoo.h.txt b/test/sa_test/type_list/target_cpp/ifoo.h.txt index a4c98d2..b9c064f 100644 --- a/test/sa_test/type_list/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_list/target_cpp/ifoo.h.txt @@ -27,6 +27,7 @@ using test::myseq; using test::myinterface; namespace test { + enum class IFooIpcCode { COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID, COMMAND_BYTE_TEST_FUNC, @@ -41,10 +42,14 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC, }; +using OnRemoteDiedCallback = std::function&)>; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); + virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} + virtual ErrCode bool_test_func( const std::vector& inParam, std::vector& outParam, diff --git a/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt index a382704..5888d66 100644 --- a/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt @@ -16,6 +16,52 @@ #include "foo_proxy.h" namespace test { +FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) +{ + std::lock_guard lock(mutex_); + if (remote_ && remote_ != remote) { + RemoveDeathRecipient(); + } + if (remote) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) FooRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } +} + +FooProxy::~FooProxy() +{ + RemoveDeathRecipient(); +} + +void FooProxy::RemoveDeathRecipient() +{ + std::lock_guard lock(mutex_); + if (!remote_ || !deathRecipient_) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + deathRecipient_ = nullptr; + remoteDiedCallback_ = nullptr; +} + +void FooProxy::OnRemoteDied(const wptr& remote) +{ + if (remoteDiedCallback_) { + remoteDiedCallback_(remote); + } + RemoveDeathRecipient(); +} + ErrCode FooProxy::void_test_func() { MessageParcel data; @@ -26,12 +72,12 @@ ErrCode FooProxy::void_test_func() return ERR_INVALID_VALUE; } - sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -86,10 +132,11 @@ ErrCode FooProxy::bool_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -162,10 +209,11 @@ ErrCode FooProxy::byte_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -238,10 +286,11 @@ ErrCode FooProxy::short_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -314,10 +363,11 @@ ErrCode FooProxy::int_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -390,10 +440,11 @@ ErrCode FooProxy::long_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -466,10 +517,11 @@ ErrCode FooProxy::string_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -542,10 +594,11 @@ ErrCode FooProxy::float_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -618,10 +671,11 @@ ErrCode FooProxy::double_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -694,10 +748,11 @@ ErrCode FooProxy::char_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -770,10 +825,11 @@ ErrCode FooProxy::seq_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -882,10 +938,11 @@ ErrCode FooProxy::interface_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/type_map/target_cpp/foo_proxy.h.txt b/test/sa_test/type_map/target_cpp/foo_proxy.h.txt index ffefacb..c8a2f0d 100644 --- a/test/sa_test/type_map/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_map/target_cpp/foo_proxy.h.txt @@ -16,19 +16,21 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include "ifoo.h" +#include #include +#include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy( - const sptr& remote) - : IRemoteProxy(remote) - {} + explicit FooProxy(const sptr& remote); - virtual ~FooProxy() - {} + ~FooProxy() override; + + void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override + { + remoteDiedCallback_ = callback; + } ErrCode void_test_func() override; @@ -99,7 +101,26 @@ public: std::unordered_map, sptr>& funcResult) override; private: + class FooRecipient : public IRemoteObject::DeathRecipient { + public: + explicit FooRecipient(FooProxy& client) : client_(client) {} + ~FooRecipient() override = default; + void OnRemoteDied(const wptr& remote) override + { + client_.OnRemoteDied(remote); + } + private: + FooProxy& client_; + }; + + void RemoveDeathRecipient(); + void OnRemoteDied(const wptr& remote); + static inline BrokerDelegator delegator_; + sptr remote_; + sptr deathRecipient_; + OnRemoteDiedCallback remoteDiedCallback_; + std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/type_map/target_cpp/ifoo.h.txt b/test/sa_test/type_map/target_cpp/ifoo.h.txt index de740a7..fb9e6c2 100644 --- a/test/sa_test/type_map/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_map/target_cpp/ifoo.h.txt @@ -27,6 +27,7 @@ using test::myseq; using test::myinterface; namespace test { + enum class IFooIpcCode { COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID, COMMAND_BOOL_TEST_FUNC, @@ -42,10 +43,14 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC, }; +using OnRemoteDiedCallback = std::function&)>; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); + virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} + virtual ErrCode void_test_func() = 0; virtual ErrCode bool_test_func( diff --git a/test/sa_test/type_single/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_single/target_cpp/foo_proxy.cpp.txt index ecf12f4..89baf17 100644 --- a/test/sa_test/type_single/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_single/target_cpp/foo_proxy.cpp.txt @@ -16,6 +16,52 @@ #include "foo_proxy.h" namespace test { +FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) +{ + std::lock_guard lock(mutex_); + if (remote_ && remote_ != remote) { + RemoveDeathRecipient(); + } + if (remote) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) FooRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } +} + +FooProxy::~FooProxy() +{ + RemoveDeathRecipient(); +} + +void FooProxy::RemoveDeathRecipient() +{ + std::lock_guard lock(mutex_); + if (!remote_ || !deathRecipient_) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + deathRecipient_ = nullptr; + remoteDiedCallback_ = nullptr; +} + +void FooProxy::OnRemoteDied(const wptr& remote) +{ + if (remoteDiedCallback_) { + remoteDiedCallback_(remote); + } + RemoveDeathRecipient(); +} + ErrCode FooProxy::void_test_func() { MessageParcel data; @@ -26,12 +72,12 @@ ErrCode FooProxy::void_test_func() return ERR_INVALID_VALUE; } - sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_VOID_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -66,10 +112,11 @@ ErrCode FooProxy::bool_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -107,10 +154,11 @@ ErrCode FooProxy::byte_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -148,10 +196,11 @@ ErrCode FooProxy::short_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -189,10 +238,11 @@ ErrCode FooProxy::int_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -230,10 +280,11 @@ ErrCode FooProxy::long_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -271,10 +322,11 @@ ErrCode FooProxy::string_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -312,10 +364,11 @@ ErrCode FooProxy::float_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -353,10 +406,11 @@ ErrCode FooProxy::double_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -394,10 +448,11 @@ ErrCode FooProxy::char_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -435,10 +490,11 @@ ErrCode FooProxy::seq_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SEQ_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -494,10 +550,11 @@ ErrCode FooProxy::interface_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -541,10 +598,11 @@ ErrCode FooProxy::interface_test_func2( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC2), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INTERFACE_TEST_FUNC2), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/type_single/target_cpp/foo_proxy.h.txt b/test/sa_test/type_single/target_cpp/foo_proxy.h.txt index 0476b81..2dcbd01 100644 --- a/test/sa_test/type_single/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_single/target_cpp/foo_proxy.h.txt @@ -16,19 +16,21 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include "ifoo.h" +#include #include +#include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy( - const sptr& remote) - : IRemoteProxy(remote) - {} + explicit FooProxy(const sptr& remote); - virtual ~FooProxy() - {} + ~FooProxy() override; + + void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override + { + remoteDiedCallback_ = callback; + } ErrCode void_test_func() override; @@ -105,7 +107,26 @@ public: sptr& funcResult) override; private: + class FooRecipient : public IRemoteObject::DeathRecipient { + public: + explicit FooRecipient(FooProxy& client) : client_(client) {} + ~FooRecipient() override = default; + void OnRemoteDied(const wptr& remote) override + { + client_.OnRemoteDied(remote); + } + private: + FooProxy& client_; + }; + + void RemoveDeathRecipient(); + void OnRemoteDied(const wptr& remote); + static inline BrokerDelegator delegator_; + sptr remote_; + sptr deathRecipient_; + OnRemoteDiedCallback remoteDiedCallback_; + std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/type_single/target_cpp/ifoo.h.txt b/test/sa_test/type_single/target_cpp/ifoo.h.txt index 92b1885..36aa091 100644 --- a/test/sa_test/type_single/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_single/target_cpp/ifoo.h.txt @@ -28,6 +28,7 @@ using test::myinterface; using test::myinterface2; namespace test { + enum class IFooIpcCode { COMMAND_VOID_TEST_FUNC = MIN_TRANSACTION_ID, COMMAND_BOOL_TEST_FUNC, @@ -44,10 +45,14 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC2, }; +using OnRemoteDiedCallback = std::function&)>; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); + virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} + virtual ErrCode void_test_func() = 0; virtual ErrCode bool_test_func( diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt index 789ca15..9759a8d 100644 --- a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt @@ -16,6 +16,52 @@ #include "foo_proxy.h" namespace test { +FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) +{ + std::lock_guard lock(mutex_); + if (remote_ && remote_ != remote) { + RemoveDeathRecipient(); + } + if (remote) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) FooRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } +} + +FooProxy::~FooProxy() +{ + RemoveDeathRecipient(); +} + +void FooProxy::RemoveDeathRecipient() +{ + std::lock_guard lock(mutex_); + if (!remote_ || !deathRecipient_) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + deathRecipient_ = nullptr; + remoteDiedCallback_ = nullptr; +} + +void FooProxy::OnRemoteDied(const wptr& remote) +{ + if (remoteDiedCallback_) { + remoteDiedCallback_(remote); + } + RemoveDeathRecipient(); +} + ErrCode FooProxy::uchar_test_func( uint8_t inParam, uint8_t& outParam, @@ -38,10 +84,11 @@ ErrCode FooProxy::uchar_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_UCHAR_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_UCHAR_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -79,10 +126,11 @@ ErrCode FooProxy::ushort_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_USHORT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_USHORT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -120,10 +168,11 @@ ErrCode FooProxy::uint_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_UINT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_UINT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -161,10 +210,11 @@ ErrCode FooProxy::ulong_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_ULONG_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_ULONG_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -202,10 +252,11 @@ ErrCode FooProxy::fd_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_FD_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_FD_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } @@ -243,10 +294,11 @@ ErrCode FooProxy::remote_object_test_func( } sptr remote = Remote(); - if (remote == nullptr) { + if (!remote) { return ERR_INVALID_DATA; } - int32_t result = remote->SendRequest(static_cast(IFooIpcCode::COMMAND_REMOTE_OBJECT_TEST_FUNC), data, reply, option); + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_REMOTE_OBJECT_TEST_FUNC), data, reply, option); if (FAILED(result)) { return result; } diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt index 24c0f24..70b5186 100644 --- a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt @@ -16,19 +16,21 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include "ifoo.h" +#include #include +#include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy( - const sptr& remote) - : IRemoteProxy(remote) - {} + explicit FooProxy(const sptr& remote); + + ~FooProxy() override; - virtual ~FooProxy() - {} + void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override + { + remoteDiedCallback_ = callback; + } ErrCode uchar_test_func( uint8_t inParam, @@ -67,7 +69,26 @@ public: sptr& funcResult) override; private: + class FooRecipient : public IRemoteObject::DeathRecipient { + public: + explicit FooRecipient(FooProxy& client) : client_(client) {} + ~FooRecipient() override = default; + void OnRemoteDied(const wptr& remote) override + { + client_.OnRemoteDied(remote); + } + private: + FooProxy& client_; + }; + + void RemoveDeathRecipient(); + void OnRemoteDied(const wptr& remote); + static inline BrokerDelegator delegator_; + sptr remote_; + sptr deathRecipient_; + OnRemoteDiedCallback remoteDiedCallback_; + std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt index 9e8495d..82e152d 100644 --- a/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt @@ -21,6 +21,7 @@ #include namespace test { + enum class IFooIpcCode { COMMAND_UCHAR_TEST_FUNC = MIN_TRANSACTION_ID, COMMAND_USHORT_TEST_FUNC, @@ -30,10 +31,14 @@ enum class IFooIpcCode { COMMAND_REMOTE_OBJECT_TEST_FUNC, }; +using OnRemoteDiedCallback = std::function&)>; + class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); + virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} + virtual ErrCode uchar_test_func( uint8_t inParam, uint8_t& outParam, -- Gitee From 3591b91945956ea8da940820d8231eea14c9b905 Mon Sep 17 00:00:00 2001 From: wenyu Date: Sat, 7 Dec 2024 18:11:25 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89ipc=E5=AE=B9=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wenyu --- idl_tool_2/ast/ast_attribute.h | 24 + idl_tool_2/ast/ast_method.h | 57 ++- .../cpp/sa_cpp_client_proxy_code_emitter.cpp | 39 +- .../SA/cpp/sa_cpp_client_proxy_code_emitter.h | 4 + .../SA/cpp/sa_cpp_interface_code_emitter.cpp | 1 - .../cpp/sa_cpp_service_stub_code_emitter.cpp | 42 +- .../SA/cpp/sa_cpp_service_stub_code_emitter.h | 8 +- idl_tool_2/lexer/lexer.cpp | 2 + idl_tool_2/lexer/token.h | 2 + idl_tool_2/parser/intf_type_check.cpp | 7 +- idl_tool_2/parser/parser.cpp | 149 +++--- idl_tool_2/parser/parser.h | 46 +- test/sa_test/keyword_ipccapacity_test_001.py | 34 ++ .../keyword_ipccapacity_test_001/foo/IFoo.idl | 30 ++ .../target_cpp/foo_proxy.cpp.txt | 483 ++++++++++++++++++ .../target_cpp/foo_proxy.h.txt | 119 +++++ .../target_cpp/foo_stub.cpp.txt | 222 ++++++++ .../target_cpp/foo_stub.h.txt | 42 ++ .../target_cpp/ifoo.h.txt | 104 ++++ test/sa_test/keyword_ipccapacity_test_002.py | 34 ++ .../keyword_ipccapacity_test_002/foo/IFoo.idl | 34 ++ .../target_cpp/fail_output.txt | 33 ++ .../target_cpp/fail_output.txt | 69 +-- 23 files changed, 1462 insertions(+), 123 deletions(-) create mode 100644 test/sa_test/keyword_ipccapacity_test_001.py create mode 100644 test/sa_test/keyword_ipccapacity_test_001/foo/IFoo.idl create mode 100644 test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_proxy.cpp.txt create mode 100644 test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_proxy.h.txt create mode 100644 test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_stub.cpp.txt create mode 100644 test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_stub.h.txt create mode 100644 test/sa_test/keyword_ipccapacity_test_001/target_cpp/ifoo.h.txt create mode 100644 test/sa_test/keyword_ipccapacity_test_002.py create mode 100644 test/sa_test/keyword_ipccapacity_test_002/foo/IFoo.idl create mode 100644 test/sa_test/keyword_ipccapacity_test_002/target_cpp/fail_output.txt diff --git a/idl_tool_2/ast/ast_attribute.h b/idl_tool_2/ast/ast_attribute.h index b1305bf..7d61922 100644 --- a/idl_tool_2/ast/ast_attribute.h +++ b/idl_tool_2/ast/ast_attribute.h @@ -32,6 +32,8 @@ public: static constexpr Attribute CACHEABLE = 0x1U << 5; static constexpr Attribute FREEZECONTROL = 0x1U << 6; static constexpr Attribute IPCCODE = 0x1U << 7; + static constexpr Attribute IPC_IN_CAPACITY = 0x1U << 8; + static constexpr Attribute IPC_OUT_CAPACITY = 0x1U << 9; explicit ASTAttr(Attribute value = ASTAttr::NONE) : value_(value) {} @@ -88,11 +90,33 @@ public: ipcCodeStr_ = ipcCodeStr; } + std::string &GetIpcInCapacity() + { + return ipcInCapacity_; + } + + void SetIpcInCapacity(const std::string &capacity) + { + ipcInCapacity_ = capacity; + } + + std::string &GetIpcOutCapacity() + { + return ipcOutCapacity_; + } + + void SetIpcOutCapacity(const std::string &capacity) + { + ipcOutCapacity_ = capacity; + } + private: Attribute value_; int32_t cacheableTime_ = 0; std::string cacheableTimeString_; std::string ipcCodeStr_; + std::string ipcInCapacity_; + std::string ipcOutCapacity_; }; class ASTParamAttr : public ASTNode { diff --git a/idl_tool_2/ast/ast_method.h b/idl_tool_2/ast/ast_method.h index 37e2c6e..3317c3f 100644 --- a/idl_tool_2/ast/ast_method.h +++ b/idl_tool_2/ast/ast_method.h @@ -38,7 +38,7 @@ public: std::string GetSignature(); - inline void SetAttribute(AutoPtr attr) + inline void SetAttribute(const AutoPtr& attr) { if (attr_ != nullptr && attr != nullptr) { attr_->SetValue(attr->GetValue()); @@ -101,19 +101,19 @@ public: cmdId_ = cmdId; } - inline size_t GetCmdId() + inline size_t GetCmdId() const { return cmdId_; } - inline std::string GetMethodIdentifier() + inline std::string GetMethodIdentifier() const { return isOverload_ ? "_" + std::to_string(cmdId_) : ""; } std::string Dump(const std::string &prefix) override; - void SetCacheable(AutoPtr attr) + void SetCacheable(const AutoPtr& attr) { if (attr->HasValue(ASTAttr::CACHEABLE)) { attr_->SetValue(ASTAttr::CACHEABLE); @@ -168,6 +168,50 @@ public: } } + bool HasIpcInCapacity() + { + return attr_->HasValue(ASTAttr::IPC_IN_CAPACITY); + } + + std::string &GetIpcInCapacity() + { + return attr_->GetIpcInCapacity(); + } + + void SetIpcInCapacity(const AutoPtr &attr) + { + if (attr->HasValue(ASTAttr::IPC_IN_CAPACITY)) { + attr_->SetIpcInCapacity(attr->GetIpcInCapacity()); + } + } + + bool HasIpcOutCapacity() + { + return attr_->HasValue(ASTAttr::IPC_OUT_CAPACITY); + } + + std::string &GetIpcOutCapacity() + { + return attr_->GetIpcOutCapacity(); + } + + void SetIpcOutCapacity(const AutoPtr &attr) + { + if (attr->HasValue(ASTAttr::IPC_OUT_CAPACITY)) { + attr_->SetIpcOutCapacity(attr->GetIpcOutCapacity()); + } + } + + void SetIpcCode(int32_t ipc_code) + { + this->ipcCode_ = ipc_code; + } + + int32_t GetIpcCode() const + { + return this->ipcCode_; + } + private: void BuildSignature(); @@ -176,8 +220,9 @@ private: AutoPtr attr_ = new ASTAttr(); AutoPtr returnType_; std::vector> parameters_; - bool isOverload_ = false; // used to identify if method is overload - size_t cmdId_; // used to identify same name method + bool isOverload_ = false; // used to identify if method is overload + size_t cmdId_ = 0; // used to identify same name method + int32_t ipcCode_ = 0; std::string freezeControlReason; }; } // namespace Idl diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp b/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp index 38c0276..b6432ef 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp @@ -15,7 +15,6 @@ #include "sa_cpp_client_proxy_code_emitter.h" #include "util/file.h" -#include "util/logger.h" #include "util/string_helper.h" namespace OHOS { @@ -190,11 +189,26 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyDeathRecipient(StringBuilder void SaCppClientProxyCodeEmitter::EmitInterfaceProxyConstants(StringBuilder &sb, const std::string &prefix) { EmitInterfaceProxyDeathRecipient(sb, prefix); + sb.Append(prefix).AppendFormat("static inline BrokerDelegator<%s> delegator_;\n", proxyName_.c_str()) .Append(prefix + "sptr remote_;\n") .Append(prefix + "sptr deathRecipient_;\n") .Append(prefix + "OnRemoteDiedCallback remoteDiedCallback_;\n") .Append(prefix + "std::mutex mutex_;\n"); + + EmitInterfaceProxyIpcCapacityValues(sb, prefix); +} + +void SaCppClientProxyCodeEmitter::EmitInterfaceProxyIpcCapacityValues(StringBuilder &sb, const std::string &prefix) +{ + size_t methodNumber = interface_->GetMethodNumber(); + for (size_t i = 0; i < methodNumber; i++) { + AutoPtr method = interface_->GetMethod(i); + if (method->HasIpcInCapacity()) { + sb.Append(prefix).AppendFormat("static constexpr size_t CAPACITY_%s_%d = %s << 10;\n", + ConstantName(method->GetName()).c_str(), method->GetIpcCode(), method->GetIpcInCapacity().c_str()); + } + } } void SaCppClientProxyCodeEmitter::EmitInterfaceProxyCppFile() @@ -329,6 +343,21 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodPostSendRequest(AutoPt interface_->GetName().c_str(), ConstantName(method->GetName()).c_str()); } +void SaCppClientProxyCodeEmitter::EmitInterfaceSetIpcCapacity(AutoPtr &method, StringBuilder &sb, + const std::string &prefix) const +{ + std::string capacity = StringHelper::Format("CAPACITY_%s_%d", ConstantName(method->GetName()).c_str(), + method->GetIpcCode()); + sb.Append(prefix).AppendFormat("if (!data.SetMaxCapacity(%s)) {\n", capacity.c_str()); + if (logOn_) { + sb.Append(prefix + TAB).AppendFormat( + "HiLog::Error(LABEL, \"Failed to set maximum capacity to %%zu\", %s);\n", + capacity.c_str()); + } + sb.Append(prefix + TAB).Append("return ERR_INVALID_VALUE;\n"); + sb.Append(prefix).Append("}\n\n"); +} + void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodBody(AutoPtr &method, StringBuilder &sb, const std::string &prefix) const { @@ -339,9 +368,13 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodBody(AutoPtrIsOneWay() ? "MessageOption::TF_ASYNC" : "MessageOption::TF_SYNC"); - sb.Append("\n"); + + if (method->HasIpcInCapacity()) { + EmitInterfaceSetIpcCapacity(method, sb, prefix + TAB); + } + sb.Append(prefix + TAB).Append("if (!data.WriteInterfaceToken(GetDescriptor())) {\n"); if (logOn_) { sb.Append(prefix + TAB + TAB).Append("HiLog::Error(LABEL, \"Write interface token failed!\");\n"); diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.h b/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.h index f99f7fe..fd3ae06 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.h +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.h @@ -78,6 +78,10 @@ private: void EmitInterfaceProxyMethodRetValue(AutoPtr &method, StringBuilder &sb, const std::string &prefix) const; + + void EmitInterfaceProxyIpcCapacityValues(StringBuilder &sb, const std::string &prefix); + + void EmitInterfaceSetIpcCapacity(AutoPtr &method, StringBuilder &sb, const std::string &prefix) const; }; } // namespace SA } // namespace OHOS diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp b/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp index d91917d..e55c715 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp @@ -15,7 +15,6 @@ #include "sa_cpp_interface_code_emitter.h" #include "util/file.h" -#include "util/logger.h" namespace OHOS { namespace Idl { diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp b/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp index 11f8e4e..97f43ad 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp @@ -15,7 +15,6 @@ #include "sa_cpp_service_stub_code_emitter.h" #include "util/file.h" -#include "util/logger.h" namespace OHOS { namespace Idl { @@ -53,11 +52,30 @@ void SaCppServiceStubCodeEmitter::EmitInterfaceStubInHeaderFile(StringBuilder &s sb.AppendFormat("class %s : public IRemoteStub<%s> {\n", stubName_.c_str(), interfaceName_.c_str()); sb.Append("public:\n"); EmitInterfaceStubMethodDecls(sb, TAB); + EmitInterfaceProxyIpcCapacityValues(sb, TAB); sb.Append("};\n"); EmitEndNamespace(sb); } -void SaCppServiceStubCodeEmitter::EmitInterfaceStubMethodDecls(StringBuilder &sb, const std::string &prefix) const +void SaCppServiceStubCodeEmitter::EmitInterfaceProxyIpcCapacityValues(StringBuilder &sb, const std::string &prefix) +{ + StringBuilder values; + size_t methodNumber = interface_->GetMethodNumber(); + for (size_t i = 0; i < methodNumber; i++) { + AutoPtr method = interface_->GetMethod(i); + if (method->HasIpcOutCapacity()) { + values.Append(prefix).AppendFormat("static constexpr size_t CAPACITY_%s_%d = %s << 10;\n", + ConstantName(method->GetName()).c_str(), method->GetIpcCode(), method->GetIpcOutCapacity().c_str()); + } + } + + std::string valuesStr = values.ToString(); + if (!valuesStr.empty()) { + sb.Append("private:\n").Append(valuesStr); + } +} + +void SaCppServiceStubCodeEmitter::EmitInterfaceStubMethodDecls(StringBuilder &sb, const std::string &prefix) { sb.Append(prefix).Append("int32_t OnRemoteRequest(\n"); sb.Append(prefix + TAB).Append("uint32_t code,\n"); @@ -126,6 +144,21 @@ void SaCppServiceStubCodeEmitter::EmitInterfaceStubMethodImpls(StringBuilder &sb sb.Append(prefix).Append("}\n"); } +void SaCppServiceStubCodeEmitter::EmitInterfaceSetIpcCapacity(AutoPtr &method, StringBuilder &sb, + const std::string &prefix) const +{ + std::string capacity = StringHelper::Format("CAPACITY_%s_%d", ConstantName(method->GetName()).c_str(), + method->GetIpcCode()); + sb.Append(prefix).AppendFormat("if (!reply.SetMaxCapacity(%s)) {\n", capacity.c_str()); + if (logOn_) { + sb.Append(prefix + TAB).AppendFormat( + "HiLog::Error(LABEL, \"Failed to set maximum capacity to %%zu\", %s);\n", + capacity.c_str()); + } + sb.Append(prefix + TAB).Append("return ERR_INVALID_VALUE;\n"); + sb.Append(prefix).Append("}\n"); +} + void SaCppServiceStubCodeEmitter::EmitInterfaceStubMethodImpl(AutoPtr &method, StringBuilder &sb, const std::string &prefix) const { @@ -151,6 +184,9 @@ void SaCppServiceStubCodeEmitter::EmitInterfaceStubMethodImpl(AutoPtr TypeKind retTypeKind = returnType->GetTypeKind(); if (hasOutParameter || (retTypeKind != TypeKind::TYPE_VOID)) { sb.Append(prefix + TAB).Append("if (SUCCEEDED(errCode)) {\n"); + if (method->HasIpcOutCapacity()) { + EmitInterfaceSetIpcCapacity(method, sb, prefix + TAB + TAB); + } for (int i = 0; i < paramNumber; i++) { AutoPtr param = method->GetParameter(i); if (param->GetAttribute() & ASTParamAttr::PARAM_OUT) { @@ -224,7 +260,7 @@ void SaCppServiceStubCodeEmitter::EmitLocalVariable(const AutoPtr } void SaCppServiceStubCodeEmitter::EmitSaReturnParameter(const std::string &name, const TypeKind kind, - StringBuilder &sb) const + StringBuilder &sb) { switch (kind) { case TypeKind::TYPE_CHAR: diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.h b/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.h index b13a1f7..244de81 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.h +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.h @@ -34,7 +34,7 @@ private: void EmitInterfaceStubInHeaderFile(StringBuilder &sb); - void EmitInterfaceStubMethodDecls(StringBuilder &sb, const std::string &prefix) const; + static void EmitInterfaceStubMethodDecls(StringBuilder &sb, const std::string &prefix); void EmitStubSourceFile(); @@ -46,7 +46,11 @@ private: void EmitLocalVariable(const AutoPtr ¶m, StringBuilder &sb, const std::string &prefix) const; - void EmitSaReturnParameter(const std::string &name, const TypeKind kind, StringBuilder &sb) const; + static void EmitSaReturnParameter(const std::string &name, TypeKind kind, StringBuilder &sb); + + void EmitInterfaceProxyIpcCapacityValues(StringBuilder &sb, const std::string &prefix); + + void EmitInterfaceSetIpcCapacity(AutoPtr &method, StringBuilder &sb, const std::string &prefix) const; }; } // namespace Idl } // namespace OHOS diff --git a/idl_tool_2/lexer/lexer.cpp b/idl_tool_2/lexer/lexer.cpp index cd019e0..1648ff0 100644 --- a/idl_tool_2/lexer/lexer.cpp +++ b/idl_tool_2/lexer/lexer.cpp @@ -58,6 +58,8 @@ Lexer::StrTokenTypeMap Lexer::keyWords_ = { {"mini", TokenType::MINI }, {"cacheable", TokenType::CACHEABLE }, {"ipccode", TokenType::IPCCODE }, + {"ipcincapacity", TokenType::IPC_IN_CAPACITY }, + {"ipcoutcapacity", TokenType::IPC_OUT_CAPACITY }, {"in", TokenType::IN }, {"out", TokenType::OUT }, {"inout", TokenType::INOUT }, diff --git a/idl_tool_2/lexer/token.h b/idl_tool_2/lexer/token.h index 247b531..c1e3766 100644 --- a/idl_tool_2/lexer/token.h +++ b/idl_tool_2/lexer/token.h @@ -63,6 +63,8 @@ enum class TokenType { MINI, // "mini" CACHEABLE, // "cacheable" IPCCODE, // "ipccode" + IPC_IN_CAPACITY, // "ipcincapacity" + IPC_OUT_CAPACITY, // "ipcoutcapacity" IN, // "in" OUT, // "out" INOUT, // "inout" diff --git a/idl_tool_2/parser/intf_type_check.cpp b/idl_tool_2/parser/intf_type_check.cpp index bb07acf..3153a87 100644 --- a/idl_tool_2/parser/intf_type_check.cpp +++ b/idl_tool_2/parser/intf_type_check.cpp @@ -122,9 +122,10 @@ bool IntfTypeChecker::CheckIntfSaAstMethods() for (size_t i = 0; i < interfaceType->GetMethodNumber(); i++) { AutoPtr method = interfaceType->GetMethod(i); if (((method->GetAttribute()->GetValue()) & - (~(ASTAttr::ONEWAY | ASTAttr::CACHEABLE | ASTAttr::IPCCODE))) != 0) { - Logger::E(TAG, StringHelper::Format("[%s:%d] error:intf sa: method attr support oneway or cacheable or " - "ipccode", __func__, __LINE__).c_str()); + (~(ASTAttr::ONEWAY | ASTAttr::CACHEABLE | ASTAttr::IPCCODE | + ASTAttr::IPC_IN_CAPACITY | ASTAttr::IPC_OUT_CAPACITY))) != 0) { + Logger::E(TAG, StringHelper::Format("[%s:%d] error:intf sa: method attr support oneway, cacheable, " + "ipccode, ipcincapacity, ipcoutcapacity", __func__, __LINE__).c_str()); return false; } if (method->GetAttribute()->HasValue(ASTAttr::CACHEABLE) && diff --git a/idl_tool_2/parser/parser.cpp b/idl_tool_2/parser/parser.cpp index 12088d1..b9aadc7 100644 --- a/idl_tool_2/parser/parser.cpp +++ b/idl_tool_2/parser/parser.cpp @@ -14,49 +14,12 @@ */ #include "parser/parser.h" - -#include -#include - -#include "ast/ast_array_type.h" -#include "ast/ast_enum_type.h" -#include "ast/ast_map_type.h" -#include "ast/ast_parameter.h" -#include "ast/ast_sequenceable_type.h" -#include "ast/ast_smq_type.h" -#include "ast/ast_struct_type.h" -#include "ast/ast_union_type.h" #include "util/logger.h" -#include "util/string_builder.h" +#include "parser/intf_type_check.h" namespace OHOS { namespace Idl { -static constexpr const char *RE_BIN_DIGIT = "0[b][0|1]+"; // binary digit -static constexpr const char *RE_OCT_DIGIT = "0[0-7]+"; // octal digit -static constexpr const char *RE_DEC_DIGIT = "[0-9]+"; // decimal digit -static constexpr const char *RE_HEX_DIFIT = "0[xX][0-9a-fA-F]+"; // hexadecimal digit -static constexpr const char *RE_DIGIT_SUFFIX = "(u|l|ll|ul|ull|)$"; -static constexpr const char *RE_IDENTIFIER = "[a-zA-Z_][a-zA-Z0-9_]*"; - -static constexpr unsigned int RE_PACKAGE_NUM = 3; -static constexpr unsigned int RE_PACKAGE_INDEX = 0; -static constexpr unsigned int RE_PACKAGE_MAJOR_VER_INDEX = 1; -static constexpr unsigned int RE_PACKAGE_MINOR_VER_INDEX = 2; - -static const std::regex RE_PACKAGE(std::string(RE_IDENTIFIER) + "(?:\\." + std::string(RE_IDENTIFIER) + ")*\\.[V|v]" + - "(" + std::string(RE_DEC_DIGIT) + ")_(" + std::string(RE_DEC_DIGIT) + ")"); -static const std::regex RE_PACKAGE_OR_IMPORT_SM(std::string(RE_IDENTIFIER) + - "(?:\\." + std::string(RE_IDENTIFIER) + ")*"); -static const std::regex RE_IMPORT(std::string(RE_IDENTIFIER) + "(?:\\." + std::string(RE_IDENTIFIER) + ")*\\.[V|v]" + - std::string(RE_DEC_DIGIT) + "_" + std::string(RE_DEC_DIGIT) + "." + std::string(RE_IDENTIFIER)); -static const std::regex RE_BIN_NUM(std::string(RE_BIN_DIGIT) + std::string(RE_DIGIT_SUFFIX), - std::regex_constants::icase); -static const std::regex RE_OCT_NUM(std::string(RE_OCT_DIGIT) + std::string(RE_DIGIT_SUFFIX), - std::regex_constants::icase); -static const std::regex RE_DEC_NUM(std::string(RE_DEC_DIGIT) + std::string(RE_DIGIT_SUFFIX), - std::regex_constants::icase); -static const std::regex RE_HEX_NUM(std::string(RE_HEX_DIFIT) + std::string(RE_DIGIT_SUFFIX), - std::regex_constants::icase); + AutoPtr g_currentEnum = nullptr; bool Parser::Parse(const std::vector &fileDetails) @@ -198,7 +161,7 @@ bool Parser::ParserPackageInfo(const std::string &packageName) return false; } - ast_->SetPackageName(result.str(RE_PACKAGE_INDEX).c_str()); + ast_->SetPackageName(result.str(RE_PACKAGE_INDEX)); size_t majorVersion = std::stoul(result.str(RE_PACKAGE_MAJOR_VER_INDEX)); size_t minorVersion = std::stoul(result.str(RE_PACKAGE_MINOR_VER_INDEX)); ast_->SetVersion(majorVersion, minorVersion); @@ -206,7 +169,7 @@ bool Parser::ParserPackageInfo(const std::string &packageName) if (!std::regex_match(packageName.c_str(), result, RE_PACKAGE_OR_IMPORT_SM)) { return false; } - ast_->SetPackageName(result.str(RE_PACKAGE_INDEX).c_str()); + ast_->SetPackageName(result.str(RE_PACKAGE_INDEX)); } return true; } @@ -444,6 +407,13 @@ AttrSet Parser::ParseAttributeInfo() // attrunit token = lexer_.PeekToken(); while (token.kind != TokenType::BRACKETS_RIGHT && token.kind != TokenType::END_OF_FILE) { + token = lexer_.PeekToken(); + if (attrs.find(token) != attrs.end()) { + LogError(__func__, __LINE__, token, StringHelper::Format("Duplicate declared attributes '%s'", + token.value.c_str())); + return attrs; + } + if (!ParseAttrUnit(attrs)) { return attrs; } @@ -476,24 +446,15 @@ bool Parser::ParseAttrUnit(AttrSet &attrs) case TokenType::MINI: case TokenType::CALLBACK: case TokenType::ONEWAY: { - if (attrs.find(token) != attrs.end()) { - LogError(__func__, __LINE__, token, StringHelper::Format("Duplicate declared attributes '%s'", - token.value.c_str())); - } else { - attrs.insert(token); - } + attrs.insert(token); lexer_.GetToken(); return true; } case TokenType::CACHEABLE: { - if (attrs.find(token) != attrs.end()) { - LogError(__func__, __LINE__, token, StringHelper::Format("Duplicate declared attributes cacheable")); - } else { - if (!lexer_.ReadCacheableTime(token)) { - LogError(__func__, __LINE__, token, StringHelper::Format("Cacheable time parse failed")); - } - attrs.insert(token); + if (!lexer_.ReadCacheableTime(token)) { + LogError(__func__, __LINE__, token, StringHelper::Format("Cacheable time parse failed")); } + attrs.insert(token); lexer_.GetToken(); return true; } @@ -505,6 +466,11 @@ bool Parser::ParseAttrUnit(AttrSet &attrs) ParseAttrUnitIpccode(attrs, token); return true; } + case TokenType::IPC_IN_CAPACITY: + case TokenType::IPC_OUT_CAPACITY: { + ParseAttrUnitIpcCapacity(attrs, token); + return true; + } default: LogError(__func__, __LINE__, token, StringHelper::Format("'%s' is a illegal attribute", token.value.c_str())); @@ -515,17 +481,13 @@ bool Parser::ParseAttrUnit(AttrSet &attrs) void Parser::ParseAttrUnitFreezecontrol(AttrSet &attrs, Token &token) { - if (attrs.find(token) != attrs.end()) { - LogError(__func__, __LINE__, token, StringHelper::Format("Duplicate declared attr freezecontrol")); - } else { - attrs.insert(token); - lexer_.GetToken(); - token = lexer_.PeekToken(); - if (token.value == "]") { - LogError(__func__, __LINE__, token, StringHelper::Format("freezecontrol attr cannot be empty")); - } else if (token.kind == TokenType::ID) { - freezecontrolAttr_ = token.value; - } + attrs.insert(token); + lexer_.GetToken(); + token = lexer_.PeekToken(); + if (token.value == "]") { + LogError(__func__, __LINE__, token, StringHelper::Format("freezecontrol attr cannot be empty")); + } else if (token.kind == TokenType::ID) { + freezecontrolAttr_ = token.value; } lexer_.GetToken(); } @@ -538,11 +500,6 @@ void Parser::ParseAttrUnitIpccode(AttrSet &attrs, Token &token) lexer_.GetToken(); return; } - if (attrs.find(token) != attrs.end()) { - LogError(__func__, __LINE__, token, StringHelper::Format("Duplicate declared attr ipc code")); - lexer_.GetToken(); - return; - } Token tokenTmp = token; lexer_.GetToken(); @@ -577,6 +534,45 @@ void Parser::ParseAttrUnitIpccode(AttrSet &attrs, Token &token) lexer_.GetToken(); } +void Parser::ParseAttrUnitIpcCapacity(AttrSet &attrs, Token &token) +{ + Options &options = Options::GetInstance(); + if (options.GetInterfaceType() != InterfaceType::SA || options.GetLanguage() != Language::CPP) { + LogError(__func__, __LINE__, token, StringHelper::Format("Not support ipc capacity")); + lexer_.GetToken(); + return; + } + + Token tokenTmp = token; + lexer_.GetToken(); + token = lexer_.PeekToken(); + if (token.value == "]" || token.value == "," || token.value.empty()) { + LogError(__func__, __LINE__, token, StringHelper::Format("ipc capacity attr cannot be empty")); + return; + } + + size_t end = 0; + int capacity = 0; + try { + capacity = std::stoi(token.value, &end); + } catch (...) { + end = 0; + } + if (end != token.value.size()) { + LogError(__func__, __LINE__, token, + StringHelper::Format("%s is illegal ipc capacity value", token.value.c_str())); + } else { + if (capacity < MIN_IPC_CAPACITY || capacity > MAX_IPC_CAPACITY) { + LogError(__func__, __LINE__, token, StringHelper::Format("ipc capacity %d is out of range [%d, %d]", + capacity, MIN_IPC_CAPACITY, MAX_IPC_CAPACITY)); + } else { + tokenTmp.value = std::to_string(capacity); + attrs.insert(tokenTmp); + } + } + lexer_.GetToken(); +} + void Parser::ParseInterface(const AttrSet &attrs) { AutoPtr interfaceType = new ASTInterfaceType; @@ -697,6 +693,7 @@ void Parser::CheckIpcCodeValue( } else { ipcCodeSet.insert(ipcCodeValue); } + method->SetIpcCode(ipcCodeValue); ipcCodeValue++; } @@ -757,6 +754,8 @@ AutoPtr Parser::ParseMethod(const AutoPtr &interfac method->SetAttribute(methodAttr); method->SetCacheable(methodAttr); method->SetIpcCode(methodAttr); + method->SetIpcInCapacity(methodAttr); + method->SetIpcOutCapacity(methodAttr); method->SetReturnType(ParseMethodReturnType()); // parser method name @@ -847,6 +846,14 @@ AutoPtr Parser::ParseMethodAttr() methodAttr->SetValue(ASTAttr::IPCCODE); methodAttr->SetIpcCodeStr(attr.value); break; + case TokenType::IPC_IN_CAPACITY: + methodAttr->SetValue(ASTAttr::IPC_IN_CAPACITY); + methodAttr->SetIpcInCapacity(attr.value); + break; + case TokenType::IPC_OUT_CAPACITY: + methodAttr->SetValue(ASTAttr::IPC_OUT_CAPACITY); + methodAttr->SetIpcOutCapacity(attr.value); + break; default: LogError(__func__, __LINE__, attr, std::string("illegal attribute of interface")); break; @@ -951,7 +958,7 @@ AutoPtr Parser::ParseParam() { AutoPtr paramAttr = ParseParamAttr(); AutoPtr paramType = ParseType(); - std::string paramName = ""; + std::string paramName; // param name Token token = lexer_.PeekToken(); diff --git a/idl_tool_2/parser/parser.h b/idl_tool_2/parser/parser.h index 5a29180..e156e9c 100644 --- a/idl_tool_2/parser/parser.h +++ b/idl_tool_2/parser/parser.h @@ -19,29 +19,63 @@ #include #include #include - +#include +#include #include "ast/ast.h" #include "ast/ast_attribute.h" #include "ast/ast_interface_type.h" #include "ast/ast_method.h" #include "ast/ast_type.h" +#include "ast/ast_enum_type.h" +#include "ast/ast_parameter.h" +#include "ast/ast_struct_type.h" +#include "ast/ast_union_type.h" #include "lexer/lexer.h" #include "preprocessor/preprocessor.h" #include "util/autoptr.h" #include "util/light_refcount_base.h" -#include "util/options.h" -#include "parser/intf_type_check.h" namespace OHOS { namespace Idl { -using AttrSet = std::set; + +static constexpr const char *RE_BIN_DIGIT = "0[b][0|1]+"; // binary digit +static constexpr const char *RE_OCT_DIGIT = "0[0-7]+"; // octal digit +static constexpr const char *RE_DEC_DIGIT = "[0-9]+"; // decimal digit +static constexpr const char *RE_HEX_DIFIT = "0[xX][0-9a-fA-F]+"; // hexadecimal digit +static constexpr const char *RE_DIGIT_SUFFIX = "(u|l|ll|ul|ull|)$"; +static constexpr const char *RE_IDENTIFIER = "[a-zA-Z_][a-zA-Z0-9_]*"; + +static constexpr unsigned int RE_PACKAGE_NUM = 3; +static constexpr unsigned int RE_PACKAGE_INDEX = 0; +static constexpr unsigned int RE_PACKAGE_MAJOR_VER_INDEX = 1; +static constexpr unsigned int RE_PACKAGE_MINOR_VER_INDEX = 2; + +static const std::regex RE_PACKAGE(std::string(RE_IDENTIFIER) + "(?:\\." + std::string(RE_IDENTIFIER) + ")*\\.[V|v]" + + "(" + std::string(RE_DEC_DIGIT) + ")_(" + std::string(RE_DEC_DIGIT) + ")"); +static const std::regex RE_PACKAGE_OR_IMPORT_SM(std::string(RE_IDENTIFIER) + + "(?:\\." + std::string(RE_IDENTIFIER) + ")*"); +static const std::regex RE_IMPORT(std::string(RE_IDENTIFIER) + "(?:\\." + std::string(RE_IDENTIFIER) + ")*\\.[V|v]" + + std::string(RE_DEC_DIGIT) + "_" + std::string(RE_DEC_DIGIT) + "." + std::string(RE_IDENTIFIER)); +static const std::regex RE_BIN_NUM(std::string(RE_BIN_DIGIT) + std::string(RE_DIGIT_SUFFIX), + std::regex_constants::icase); +static const std::regex RE_OCT_NUM(std::string(RE_OCT_DIGIT) + std::string(RE_DIGIT_SUFFIX), + std::regex_constants::icase); +static const std::regex RE_DEC_NUM(std::string(RE_DEC_DIGIT) + std::string(RE_DIGIT_SUFFIX), + std::regex_constants::icase); +static const std::regex RE_HEX_NUM(std::string(RE_HEX_DIFIT) + std::string(RE_DIGIT_SUFFIX), + std::regex_constants::icase); + struct AstCompare { bool operator()(const AutoPtr &lhs, const AutoPtr &rhs) const { return lhs->GetMinorVer() < rhs->GetMinorVer(); } }; + +using AttrSet = std::set; + using AstMergeMap = std::map, AstCompare>>; + class Parser { public: Parser() = default; @@ -59,6 +93,8 @@ public: private: static constexpr int MIN_TRANSACTION_ID = 0x01; static constexpr int MAX_TRANSACTION_ID = 0x00ffffff; + static constexpr int MIN_IPC_CAPACITY = 1; + static constexpr int MAX_IPC_CAPACITY = 0x0001ffff; class Attribute : public LightRefCountBase { public: @@ -103,6 +139,8 @@ private: void ParseAttrUnitIpccode(AttrSet &attrs, Token &token); + void ParseAttrUnitIpcCapacity(AttrSet &attrs, Token &token); + // parse interface type void ParseInterface(const AttrSet &attrs = {}); diff --git a/test/sa_test/keyword_ipccapacity_test_001.py b/test/sa_test/keyword_ipccapacity_test_001.py new file mode 100644 index 0000000..ad1a376 --- /dev/null +++ b/test/sa_test/keyword_ipccapacity_test_001.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from test_base import Test + + +class KeywordIpcCapacityTest001(Test): + def get_file_name(self): + return __file__ + + def run_cpp(self): + self.set_gen_cpp_env() + return self.run_choose(True) + + def run(self): + return self.run_cpp() + +if __name__ == "__main__": + KeywordIpcCapacityTest001().test() \ No newline at end of file diff --git a/test/sa_test/keyword_ipccapacity_test_001/foo/IFoo.idl b/test/sa_test/keyword_ipccapacity_test_001/foo/IFoo.idl new file mode 100644 index 0000000..7def329 --- /dev/null +++ b/test/sa_test/keyword_ipccapacity_test_001/foo/IFoo.idl @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +interface test.IFoo { + // 有返回值 + [ipcincapacity 1] boolean bool_test_func([in] boolean inParam, [out] boolean outParam, [inout] boolean inoutParam); + [ipcoutcapacity 1] byte byte_test_func([in] byte inParam, [out] byte outParam, [inout] byte inoutParam); + [ipcincapacity 131071, ipcoutcapacity 131071] short short_test_func([in] short inParam, [out] short outParam, [inout] short inoutParam); + [ipcoutcapacity 131071, ipcincapacity 131071] char char_test_func([in] char inParam, [out] char outParam, [inout] char inoutParam); + [cacheable 100, oneway, ipccode 10, ipcincapacity 1, ipcoutcapacity 2] int int_test_func([in] int inParam); + + // 没返回值 + [ipcincapacity 1] void long_test_func([in] long inParam, [out] long outParam, [inout] long inoutParam); + [ipcoutcapacity 1] void string_test_func([in] String inParam, [in] String outParam, [in] String inoutParam); + [ipcincapacity 131071, ipcoutcapacity 131071] void float_test_func([in] float inParam, [in] float outParam, [in] float inoutParam); + [ipcoutcapacity 131071, ipcincapacity 131071] FileDescriptor fd_test_func([in] FileDescriptor inParam, [out] FileDescriptor outParam, [inout] FileDescriptor inoutParam); + [cacheable 200, oneway, ipccode 0x00ffffff, ipcincapacity 1, ipcoutcapacity 2] void double_test_func([in] double inParam); +} diff --git a/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_proxy.cpp.txt b/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_proxy.cpp.txt new file mode 100644 index 0000000..df94678 --- /dev/null +++ b/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_proxy.cpp.txt @@ -0,0 +1,483 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "foo_proxy.h" + +namespace test { +FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) +{ + std::lock_guard lock(mutex_); + if (remote_ && remote_ != remote) { + RemoveDeathRecipient(); + } + if (remote) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) FooRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } +} + +FooProxy::~FooProxy() +{ + RemoveDeathRecipient(); +} + +void FooProxy::RemoveDeathRecipient() +{ + std::lock_guard lock(mutex_); + if (!remote_ || !deathRecipient_) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + deathRecipient_ = nullptr; + remoteDiedCallback_ = nullptr; +} + +void FooProxy::OnRemoteDied(const wptr& remote) +{ + if (remoteDiedCallback_) { + remoteDiedCallback_(remote); + } + RemoveDeathRecipient(); +} + +ErrCode FooProxy::bool_test_func( + bool inParam, + bool& outParam, + bool inoutParam, + bool& funcResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.SetMaxCapacity(CAPACITY_BOOL_TEST_FUNC_1)) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(inParam ? 1 : 0)) { + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(inoutParam ? 1 : 0)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BOOL_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = reply.ReadInt32() == 1 ? true : false; + inoutParam = reply.ReadInt32() == 1 ? true : false; + funcResult = reply.ReadInt32() == 1 ? true : false; + return ERR_OK; +} + +ErrCode FooProxy::byte_test_func( + int8_t inParam, + int8_t& outParam, + int8_t inoutParam, + int8_t& funcResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_BYTE_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = (int8_t)reply.ReadInt32(); + inoutParam = (int8_t)reply.ReadInt32(); + funcResult = (int8_t)reply.ReadInt32(); + return ERR_OK; +} + +ErrCode FooProxy::short_test_func( + short inParam, + short& outParam, + short inoutParam, + short& funcResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.SetMaxCapacity(CAPACITY_SHORT_TEST_FUNC_3)) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_SHORT_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = (short)reply.ReadInt32(); + inoutParam = (short)reply.ReadInt32(); + funcResult = (short)reply.ReadInt32(); + return ERR_OK; +} + +ErrCode FooProxy::char_test_func( + zchar inParam, + zchar& outParam, + zchar inoutParam, + zchar& funcResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.SetMaxCapacity(CAPACITY_CHAR_TEST_FUNC_4)) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_CHAR_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = (zchar)reply.ReadInt32(); + inoutParam = (zchar)reply.ReadInt32(); + funcResult = (zchar)reply.ReadInt32(); + return ERR_OK; +} + +ErrCode FooProxy::int_test_func( + int32_t inParam, + int32_t& funcResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + if (!data.SetMaxCapacity(CAPACITY_INT_TEST_FUNC_10)) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(inParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_INT_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + return ERR_OK; +} + +ErrCode FooProxy::long_test_func( + int64_t inParam, + int64_t& outParam, + int64_t inoutParam) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.SetMaxCapacity(CAPACITY_LONG_TEST_FUNC_11)) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt64(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteInt64(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_LONG_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = reply.ReadInt64(); + inoutParam = reply.ReadInt64(); + return ERR_OK; +} + +ErrCode FooProxy::string_test_func( + const std::string& inParam, + const std::string& outParam, + const std::string& inoutParam) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(inParam))) { + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(outParam))) { + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(inoutParam))) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_STRING_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + return ERR_OK; +} + +ErrCode FooProxy::float_test_func( + float inParam, + float outParam, + float inoutParam) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.SetMaxCapacity(CAPACITY_FLOAT_TEST_FUNC_13)) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteFloat(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteFloat(outParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteFloat(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_FLOAT_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + return ERR_OK; +} + +ErrCode FooProxy::fd_test_func( + int inParam, + int& outParam, + int inoutParam, + int& funcResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.SetMaxCapacity(CAPACITY_FD_TEST_FUNC_14)) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteFileDescriptor(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteFileDescriptor(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_FD_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = reply.ReadFileDescriptor(); + inoutParam = reply.ReadFileDescriptor(); + funcResult = reply.ReadFileDescriptor(); + return ERR_OK; +} + +ErrCode FooProxy::double_test_func( + double inParam) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + if (!data.SetMaxCapacity(CAPACITY_DOUBLE_TEST_FUNC_16777215)) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteDouble(inParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC), data, reply, option); + if (FAILED(result)) { + return result; + } + return ERR_OK; +} +} // namespace test diff --git a/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_proxy.h.txt b/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_proxy.h.txt new file mode 100644 index 0000000..752dec2 --- /dev/null +++ b/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_proxy.h.txt @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FOOPROXY_H +#define TEST_FOOPROXY_H + +#include +#include +#include "ifoo.h" + +namespace test { +class FooProxy : public IRemoteProxy { +public: + explicit FooProxy(const sptr& remote); + + ~FooProxy() override; + + void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override + { + remoteDiedCallback_ = callback; + } + + ErrCode bool_test_func( + bool inParam, + bool& outParam, + bool inoutParam, + bool& funcResult) override; + + ErrCode byte_test_func( + int8_t inParam, + int8_t& outParam, + int8_t inoutParam, + int8_t& funcResult) override; + + ErrCode short_test_func( + short inParam, + short& outParam, + short inoutParam, + short& funcResult) override; + + ErrCode char_test_func( + zchar inParam, + zchar& outParam, + zchar inoutParam, + zchar& funcResult) override; + + ErrCode int_test_func( + int32_t inParam, + int32_t& funcResult) override; + + ErrCode long_test_func( + int64_t inParam, + int64_t& outParam, + int64_t inoutParam) override; + + ErrCode string_test_func( + const std::string& inParam, + const std::string& outParam, + const std::string& inoutParam) override; + + ErrCode float_test_func( + float inParam, + float outParam, + float inoutParam) override; + + ErrCode fd_test_func( + int inParam, + int& outParam, + int inoutParam, + int& funcResult) override; + + ErrCode double_test_func( + double inParam) override; + +private: + class FooRecipient : public IRemoteObject::DeathRecipient { + public: + explicit FooRecipient(FooProxy& client) : client_(client) {} + ~FooRecipient() override = default; + void OnRemoteDied(const wptr& remote) override + { + client_.OnRemoteDied(remote); + } + private: + FooProxy& client_; + }; + + void RemoveDeathRecipient(); + void OnRemoteDied(const wptr& remote); + + static inline BrokerDelegator delegator_; + sptr remote_; + sptr deathRecipient_; + OnRemoteDiedCallback remoteDiedCallback_; + std::mutex mutex_; + static constexpr size_t CAPACITY_BOOL_TEST_FUNC_1 = 1 << 10; + static constexpr size_t CAPACITY_SHORT_TEST_FUNC_3 = 131071 << 10; + static constexpr size_t CAPACITY_CHAR_TEST_FUNC_4 = 131071 << 10; + static constexpr size_t CAPACITY_INT_TEST_FUNC_10 = 1 << 10; + static constexpr size_t CAPACITY_LONG_TEST_FUNC_11 = 1 << 10; + static constexpr size_t CAPACITY_FLOAT_TEST_FUNC_13 = 131071 << 10; + static constexpr size_t CAPACITY_FD_TEST_FUNC_14 = 131071 << 10; + static constexpr size_t CAPACITY_DOUBLE_TEST_FUNC_16777215 = 1 << 10; +}; +} // namespace test +#endif // TEST_FOOPROXY_H + diff --git a/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_stub.cpp.txt b/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_stub.cpp.txt new file mode 100644 index 0000000..c397527 --- /dev/null +++ b/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_stub.cpp.txt @@ -0,0 +1,222 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "foo_stub.h" + +namespace test { +int32_t FooStub::OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) +{ + std::u16string localDescriptor = GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (localDescriptor != remoteDescriptor) { + return ERR_TRANSACTION_FAILED; + } + switch (static_cast(code)) { + case IFooIpcCode::COMMAND_BOOL_TEST_FUNC: { + bool inParam = data.ReadInt32() == 1 ? true : false; + bool outParam; + bool inoutParam = data.ReadInt32() == 1 ? true : false; + bool result; + ErrCode errCode = bool_test_func(inParam, outParam, inoutParam, result); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt32(outParam ? 1 : 0)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(inoutParam ? 1 : 0)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(result ? 1 : 0)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IFooIpcCode::COMMAND_BYTE_TEST_FUNC: { + int8_t inParam = (int8_t)data.ReadInt32(); + int8_t outParam; + int8_t inoutParam = (int8_t)data.ReadInt32(); + int8_t result; + ErrCode errCode = byte_test_func(inParam, outParam, inoutParam, result); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.SetMaxCapacity(CAPACITY_BYTE_TEST_FUNC_2)) { + return ERR_INVALID_VALUE; + } + if (!reply.WriteInt32(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(inoutParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(result)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IFooIpcCode::COMMAND_SHORT_TEST_FUNC: { + short inParam = (short)data.ReadInt32(); + short outParam; + short inoutParam = (short)data.ReadInt32(); + short result; + ErrCode errCode = short_test_func(inParam, outParam, inoutParam, result); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.SetMaxCapacity(CAPACITY_SHORT_TEST_FUNC_3)) { + return ERR_INVALID_VALUE; + } + if (!reply.WriteInt32(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(inoutParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(result)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IFooIpcCode::COMMAND_CHAR_TEST_FUNC: { + zchar inParam = (zchar)data.ReadInt32(); + zchar outParam; + zchar inoutParam = (zchar)data.ReadInt32(); + zchar result; + ErrCode errCode = char_test_func(inParam, outParam, inoutParam, result); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.SetMaxCapacity(CAPACITY_CHAR_TEST_FUNC_4)) { + return ERR_INVALID_VALUE; + } + if (!reply.WriteInt32(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(inoutParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(result)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IFooIpcCode::COMMAND_INT_TEST_FUNC: { + int32_t inParam = data.ReadInt32(); + int32_t result; + ErrCode errCode = int_test_func(inParam, result); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.SetMaxCapacity(CAPACITY_INT_TEST_FUNC_10)) { + return ERR_INVALID_VALUE; + } + if (!reply.WriteInt32(result)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IFooIpcCode::COMMAND_LONG_TEST_FUNC: { + int64_t inParam = data.ReadInt64(); + int64_t outParam; + int64_t inoutParam = data.ReadInt64(); + ErrCode errCode = long_test_func(inParam, outParam, inoutParam); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteInt64(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteInt64(inoutParam)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IFooIpcCode::COMMAND_STRING_TEST_FUNC: { + std::string inParam = Str16ToStr8(data.ReadString16()); + std::string outParam = Str16ToStr8(data.ReadString16()); + std::string inoutParam = Str16ToStr8(data.ReadString16()); + ErrCode errCode = string_test_func(inParam, outParam, inoutParam); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IFooIpcCode::COMMAND_FLOAT_TEST_FUNC: { + float inParam = data.ReadFloat(); + float outParam = data.ReadFloat(); + float inoutParam = data.ReadFloat(); + ErrCode errCode = float_test_func(inParam, outParam, inoutParam); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + case IFooIpcCode::COMMAND_FD_TEST_FUNC: { + int inParam = data.ReadFileDescriptor(); + int outParam; + int inoutParam = data.ReadFileDescriptor(); + int result; + ErrCode errCode = fd_test_func(inParam, outParam, inoutParam, result); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.SetMaxCapacity(CAPACITY_FD_TEST_FUNC_14)) { + return ERR_INVALID_VALUE; + } + if (!reply.WriteFileDescriptor(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteFileDescriptor(inoutParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteFileDescriptor(result)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case IFooIpcCode::COMMAND_DOUBLE_TEST_FUNC: { + double inParam = data.ReadDouble(); + ErrCode errCode = double_test_func(inParam); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + return ERR_NONE; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + + return ERR_TRANSACTION_FAILED; +} +} // namespace test diff --git a/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_stub.h.txt b/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_stub.h.txt new file mode 100644 index 0000000..50caf13 --- /dev/null +++ b/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_stub.h.txt @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FOOSTUB_H +#define TEST_FOOSTUB_H + +#include "ifoo.h" +#include + +namespace test { +class FooStub : public IRemoteStub { +public: + int32_t OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) override; +private: + static constexpr size_t CAPACITY_BYTE_TEST_FUNC_2 = 1 << 10; + static constexpr size_t CAPACITY_SHORT_TEST_FUNC_3 = 131071 << 10; + static constexpr size_t CAPACITY_CHAR_TEST_FUNC_4 = 131071 << 10; + static constexpr size_t CAPACITY_INT_TEST_FUNC_10 = 2 << 10; + static constexpr size_t CAPACITY_STRING_TEST_FUNC_12 = 1 << 10; + static constexpr size_t CAPACITY_FLOAT_TEST_FUNC_13 = 131071 << 10; + static constexpr size_t CAPACITY_FD_TEST_FUNC_14 = 131071 << 10; + static constexpr size_t CAPACITY_DOUBLE_TEST_FUNC_16777215 = 2 << 10; +}; +} // namespace test +#endif // TEST_FOOSTUB_H + diff --git a/test/sa_test/keyword_ipccapacity_test_001/target_cpp/ifoo.h.txt b/test/sa_test/keyword_ipccapacity_test_001/target_cpp/ifoo.h.txt new file mode 100644 index 0000000..2047de1 --- /dev/null +++ b/test/sa_test/keyword_ipccapacity_test_001/target_cpp/ifoo.h.txt @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_IFOO_H +#define TEST_IFOO_H + +#include +#include +#include + +namespace test { + +enum class IFooIpcCode { + COMMAND_BOOL_TEST_FUNC = MIN_TRANSACTION_ID, + COMMAND_BYTE_TEST_FUNC, + COMMAND_SHORT_TEST_FUNC, + COMMAND_CHAR_TEST_FUNC, + COMMAND_INT_TEST_FUNC = 10, + COMMAND_LONG_TEST_FUNC, + COMMAND_STRING_TEST_FUNC, + COMMAND_FLOAT_TEST_FUNC, + COMMAND_FD_TEST_FUNC, + COMMAND_DOUBLE_TEST_FUNC = 16777215, +}; + +using OnRemoteDiedCallback = std::function&)>; + +class IFoo : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); + + virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} + + virtual ErrCode bool_test_func( + bool inParam, + bool& outParam, + bool inoutParam, + bool& funcResult) = 0; + + virtual ErrCode byte_test_func( + int8_t inParam, + int8_t& outParam, + int8_t inoutParam, + int8_t& funcResult) = 0; + + virtual ErrCode short_test_func( + short inParam, + short& outParam, + short inoutParam, + short& funcResult) = 0; + + virtual ErrCode char_test_func( + zchar inParam, + zchar& outParam, + zchar inoutParam, + zchar& funcResult) = 0; + + virtual ErrCode int_test_func( + int32_t inParam, + int32_t& funcResult) = 0; + + virtual ErrCode long_test_func( + int64_t inParam, + int64_t& outParam, + int64_t inoutParam) = 0; + + virtual ErrCode string_test_func( + const std::string& inParam, + const std::string& outParam, + const std::string& inoutParam) = 0; + + virtual ErrCode float_test_func( + float inParam, + float outParam, + float inoutParam) = 0; + + virtual ErrCode fd_test_func( + int inParam, + int& outParam, + int inoutParam, + int& funcResult) = 0; + + virtual ErrCode double_test_func( + double inParam) = 0; +protected: + const int VECTOR_MAX_SIZE = 102400; + const int LIST_MAX_SIZE = 102400; + const int MAP_MAX_SIZE = 102400; +}; +} // namespace test +#endif // TEST_IFOO_H + diff --git a/test/sa_test/keyword_ipccapacity_test_002.py b/test/sa_test/keyword_ipccapacity_test_002.py new file mode 100644 index 0000000..cdd503b --- /dev/null +++ b/test/sa_test/keyword_ipccapacity_test_002.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from test_base import Test + + +class KeywordIpcCapacityTest002(Test): + def get_file_name(self): + return __file__ + + def run_cpp(self): + self.set_gen_cpp_env() + return self.run_choose(False) + + def run(self): + return self.run_cpp() + +if __name__ == "__main__": + KeywordIpcCapacityTest002().test() \ No newline at end of file diff --git a/test/sa_test/keyword_ipccapacity_test_002/foo/IFoo.idl b/test/sa_test/keyword_ipccapacity_test_002/foo/IFoo.idl new file mode 100644 index 0000000..27b8956 --- /dev/null +++ b/test/sa_test/keyword_ipccapacity_test_002/foo/IFoo.idl @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +interface test.IFoo { + [ipcincapacity 0] void func1(); + [ipcoutcapacity 0] void func2(); + [ipcincapacity 131072] void func3(); + [ipcoutcapacity 131072] void func4(); + [ipcincapacity 0, ipcoutcapacity 0] void func5(); + [ipcincapacity 131072, ipcoutcapacity 131072] void func6(); + [ipcincapacity 131071, ipcoutcapacity 131072] void func7(); + [ipcincapacity 131072, ipcoutcapacity 131071] void func8(); + [cacheable 100, oneway, ipccode 10, ipcincapacity 262144, ipcoutcapacity 1048576] void func9(); + [ipcincapacity] void func10(); + [ipcoutcapacity ] void func11(); + [ipcincapacity , ipcoutcapacity] void func12(); + [ipcincapacity abc123] void func13(); + [ipcoutcapacity a456bc] void func14(); + [ipcincapacity abc, ipcoutcapacity 0x1234] void func15(); + [ipcincapacity 1, ipcincapacity 2] void func16(); + [ipcoutcapacity 1, ipcoutcapacity 2] void func17(); +} diff --git a/test/sa_test/keyword_ipccapacity_test_002/target_cpp/fail_output.txt b/test/sa_test/keyword_ipccapacity_test_002/target_cpp/fail_output.txt new file mode 100644 index 0000000..6f654e7 --- /dev/null +++ b/test/sa_test/keyword_ipccapacity_test_002/target_cpp/fail_output.txt @@ -0,0 +1,33 @@ +[IDL-GEN]: [ParseAttrUnitIpcCapacity:602] [IFoo.idl:17:20] error:ipc capacity 0 is out of range [1, 131071] +[IDL-GEN]: [ParseAttrUnitIpcCapacity:602] [IFoo.idl:18:21] error:ipc capacity 0 is out of range [1, 131071] +[IDL-GEN]: [ParseAttrUnitIpcCapacity:602] [IFoo.idl:19:20] error:ipc capacity 131072 is out of range [1, 131071] +[IDL-GEN]: [ParseAttrUnitIpcCapacity:602] [IFoo.idl:20:21] error:ipc capacity 131072 is out of range [1, 131071] +[IDL-GEN]: [ParseAttrUnitIpcCapacity:602] [IFoo.idl:21:20] error:ipc capacity 0 is out of range [1, 131071] +[IDL-GEN]: [ParseAttrUnitIpcCapacity:602] [IFoo.idl:21:38] error:ipc capacity 0 is out of range [1, 131071] +[IDL-GEN]: [ParseAttrUnitIpcCapacity:602] [IFoo.idl:22:20] error:ipc capacity 131072 is out of range [1, 131071] +[IDL-GEN]: [ParseAttrUnitIpcCapacity:602] [IFoo.idl:22:43] error:ipc capacity 131072 is out of range [1, 131071] +[IDL-GEN]: [ParseAttrUnitIpcCapacity:602] [IFoo.idl:23:43] error:ipc capacity 131072 is out of range [1, 131071] +[IDL-GEN]: [ParseAttrUnitIpcCapacity:602] [IFoo.idl:24:20] error:ipc capacity 131072 is out of range [1, 131071] +[IDL-GEN]: [ParseAttrUnitIpcCapacity:602] [IFoo.idl:25:55] error:ipc capacity 262144 is out of range [1, 131071] +[IDL-GEN]: [ParseAttrUnitIpcCapacity:602] [IFoo.idl:25:78] error:ipc capacity 1048576 is out of range [1, 131071] +[IDL-GEN]: [ParseAttrUnitIpcCapacity:586] [IFoo.idl:26:19] error:ipc capacity attr cannot be empty +[IDL-GEN]: [ParseAttrUnitIpcCapacity:586] [IFoo.idl:27:21] error:ipc capacity attr cannot be empty +[IDL-GEN]: [ParseAttrUnitIpcCapacity:586] [IFoo.idl:28:20] error:ipc capacity attr cannot be empty +[IDL-GEN]: [ParseAttrUnitIpcCapacity:586] [IFoo.idl:28:36] error:ipc capacity attr cannot be empty +[IDL-GEN]: [ParseAttrUnitIpcCapacity:598] [IFoo.idl:29:20] error:abc123 is illegal ipc capacity value +[IDL-GEN]: [ParseAttrUnitIpcCapacity:598] [IFoo.idl:30:21] error:a456bc is illegal ipc capacity value +[IDL-GEN]: [ParseAttrUnitIpcCapacity:598] [IFoo.idl:31:20] error:abc is illegal ipc capacity value +[IDL-GEN]: [ParseAttrUnitIpcCapacity:598] [IFoo.idl:31:40] error:0x1234 is illegal ipc capacity value +[IDL-GEN]: [ParseAttributeInfo:448] [IFoo.idl:32:23] error:Duplicate declared attributes 'ipcincapacity' +[IDL-GEN]: [ParseMethod:800] [IFoo.idl:32:23] error:expected method name before 'ipcincapacity' token +[IDL-GEN]: [ParseMethodParamList:950] [IFoo.idl:32:23] error:expected '(' before 'ipcincapacity' token +[IDL-GEN]: [CheckParamAttr:1062] [IFoo.idl:32:23] error:expected '[' before 'ipcincapacity' token +[IDL-GEN]: [ParseType:1114] [IFoo.idl:32:52] error:')' of type is illegal +[IDL-GEN]: [ParseParam:1002] [IFoo.idl:32:52] error:expected param name before ')' token +[IDL-GEN]: [ParseAttributeInfo:448] [IFoo.idl:33:24] error:Duplicate declared attributes 'ipcoutcapacity' +[IDL-GEN]: [ParseMethod:800] [IFoo.idl:33:24] error:expected method name before 'ipcoutcapacity' token +[IDL-GEN]: [ParseMethodParamList:950] [IFoo.idl:33:24] error:expected '(' before 'ipcoutcapacity' token +[IDL-GEN]: [CheckParamAttr:1062] [IFoo.idl:33:24] error:expected '[' before 'ipcoutcapacity' token +[IDL-GEN]: [ParseType:1114] [IFoo.idl:33:54] error:')' of type is illegal +[IDL-GEN]: [ParseParam:1002] [IFoo.idl:33:54] error:expected param name before ')' token +[IDL-GEN]: failed to parse file \ No newline at end of file diff --git a/test/sa_test/keyword_ipccode_test_002/target_cpp/fail_output.txt b/test/sa_test/keyword_ipccode_test_002/target_cpp/fail_output.txt index c8d43fb..f495605 100644 --- a/test/sa_test/keyword_ipccode_test_002/target_cpp/fail_output.txt +++ b/test/sa_test/keyword_ipccode_test_002/target_cpp/fail_output.txt @@ -1,31 +1,40 @@ -[IDL-GEN]: [ParseAttrUnitIpccode:551] [IFoo.idl:18:13] error:Ipccode attr cannot be empty -[IDL-GEN]: [ParseAttrUnitIpccode:570] [IFoo.idl:20:14] error:ipccode 0 is out of range [1, 16777215] -[IDL-GEN]: [ParseAttrUnitIpccode:570] [IFoo.idl:22:14] error:ipccode 100000000 is out of range [1, 16777215] -[IDL-GEN]: [ParseAttrUnitIpccode:567] [IFoo.idl:24:14] error:100000000000000 is illegal ipccode value -[IDL-GEN]: [CheckIpcCodeValue:696] error:the ipccode 1 is duplicated -[IDL-GEN]: [CheckIpcCodeValue:696] error:the ipccode 2 is duplicated -[IDL-GEN]: [ParseAttrUnitIpccode:551] [IFoo.idl:28:28] error:Ipccode attr cannot be empty -[IDL-GEN]: [CheckIpcCodeValue:696] error:the ipccode 3 is duplicated -[IDL-GEN]: [CheckIpcCodeValue:696] error:the ipccode 4 is duplicated -[IDL-GEN]: [ParseAttrUnitIpccode:551] [IFoo.idl:30:13] error:Ipccode attr cannot be empty -[IDL-GEN]: [CheckIpcCodeValue:696] error:the ipccode 5 is duplicated -[IDL-GEN]: [CheckIpcCodeValue:696] error:the ipccode 6 is duplicated -[IDL-GEN]: [CheckIpcCodeValue:696] error:the ipccode 1 is duplicated -[IDL-GEN]: [CheckIpcCodeValue:696] error:the ipccode 2 is duplicated -[IDL-GEN]: [ParseAttrUnitIpccode:567] [IFoo.idl:40:14] error:10a is illegal ipccode value -[IDL-GEN]: [ParseAttrUnitIpccode:567] [IFoo.idl:41:14] error:10.1 is illegal ipccode value -[IDL-GEN]: [ParseAttrUnitIpccode:567] [IFoo.idl:43:14] error:0x is illegal ipccode value -[IDL-GEN]: [CheckIpcCodeValue:693] error:the ipccode 16777216 is out of range [1, 16777215] -[IDL-GEN]: [ParseAttrUnitIpccode:551] [IFoo.idl:46:13] error:Ipccode attr cannot be empty -[IDL-GEN]: [CheckIpcCodeValue:693] error:the ipccode 16777217 is out of range [1, 16777215] -[IDL-GEN]: [ParseAttrUnitIpccode:542] [IFoo.idl:47:19] error:Duplicate declared attr ipc code -[IDL-GEN]: [ParseAttrUnitIpccode:542] [IFoo.idl:48:19] error:Duplicate declared attr ipc code -[IDL-GEN]: [ParseAttributeInfo:461] [IFoo.idl:48:27] error:expected ',' or ']' before '1' token -[IDL-GEN]: [ParseAttrUnitIpccode:551] [IFoo.idl:49:13] error:Ipccode attr cannot be empty -[IDL-GEN]: [ParseAttrUnitIpccode:551] [IFoo.idl:50:6] error:Ipccode attr cannot be empty -[IDL-GEN]: [ParseAttributeInfo:461] [IFoo.idl:50:6] error:expected ',' or ']' before '' token -[IDL-GEN]: [ParseMethod:765] [IFoo.idl:50:6] error:expected method name before '' token -[IDL-GEN]: [ParseMethodParamList:907] [IFoo.idl:50:6] error:expected '(' before '' token -[IDL-GEN]: [ParseMethod:778] [IFoo.idl:50:6] error:expected ';' before '' token -[IDL-GEN]: [ParseInterfaceBody:738] [IFoo.idl:50:6] error:expected '}' before '' token +[IDL-GEN]: [ParseAttrUnitIpccode:544] [IFoo.idl:18:13] error:Ipccode attr cannot be empty +[IDL-GEN]: [ParseAttrUnitIpccode:563] [IFoo.idl:20:14] error:ipccode 0 is out of range [1, 16777215] +[IDL-GEN]: [ParseAttrUnitIpccode:563] [IFoo.idl:22:14] error:ipccode 100000000 is out of range [1, 16777215] +[IDL-GEN]: [ParseAttrUnitIpccode:560] [IFoo.idl:24:14] error:100000000000000 is illegal ipccode value +[IDL-GEN]: [CheckIpcCodeValue:728] error:the ipccode 1 is duplicated +[IDL-GEN]: [CheckIpcCodeValue:728] error:the ipccode 2 is duplicated +[IDL-GEN]: [ParseAttrUnitIpccode:544] [IFoo.idl:28:28] error:Ipccode attr cannot be empty +[IDL-GEN]: [CheckIpcCodeValue:728] error:the ipccode 3 is duplicated +[IDL-GEN]: [CheckIpcCodeValue:728] error:the ipccode 4 is duplicated +[IDL-GEN]: [ParseAttrUnitIpccode:544] [IFoo.idl:30:13] error:Ipccode attr cannot be empty +[IDL-GEN]: [CheckIpcCodeValue:728] error:the ipccode 5 is duplicated +[IDL-GEN]: [CheckIpcCodeValue:728] error:the ipccode 6 is duplicated +[IDL-GEN]: [CheckIpcCodeValue:728] error:the ipccode 1 is duplicated +[IDL-GEN]: [CheckIpcCodeValue:728] error:the ipccode 2 is duplicated +[IDL-GEN]: [ParseAttrUnitIpccode:560] [IFoo.idl:40:14] error:10a is illegal ipccode value +[IDL-GEN]: [ParseAttrUnitIpccode:560] [IFoo.idl:41:14] error:10.1 is illegal ipccode value +[IDL-GEN]: [ParseAttrUnitIpccode:560] [IFoo.idl:43:14] error:0x is illegal ipccode value +[IDL-GEN]: [CheckIpcCodeValue:725] error:the ipccode 16777216 is out of range [1, 16777215] +[IDL-GEN]: [ParseAttrUnitIpccode:544] [IFoo.idl:46:13] error:Ipccode attr cannot be empty +[IDL-GEN]: [CheckIpcCodeValue:725] error:the ipccode 16777217 is out of range [1, 16777215] +[IDL-GEN]: [ParseAttributeInfo:448] [IFoo.idl:47:19] error:Duplicate declared attributes 'ipccode' +[IDL-GEN]: [ParseMethod:800] [IFoo.idl:47:19] error:expected method name before 'ipccode' token +[IDL-GEN]: [ParseMethodParamList:950] [IFoo.idl:47:19] error:expected '(' before 'ipccode' token +[IDL-GEN]: [CheckParamAttr:1062] [IFoo.idl:47:19] error:expected '[' before 'ipccode' token +[IDL-GEN]: [ParseType:1114] [IFoo.idl:47:45] error:')' of type is illegal +[IDL-GEN]: [ParseParam:1002] [IFoo.idl:47:45] error:expected param name before ')' token +[IDL-GEN]: [ParseAttributeInfo:448] [IFoo.idl:48:19] error:Duplicate declared attributes 'ipccode' +[IDL-GEN]: [ParseMethod:800] [IFoo.idl:48:19] error:expected method name before 'ipccode' token +[IDL-GEN]: [ParseMethodParamList:950] [IFoo.idl:48:19] error:expected '(' before 'ipccode' token +[IDL-GEN]: [CheckParamAttr:1062] [IFoo.idl:48:19] error:expected '[' before 'ipccode' token +[IDL-GEN]: [ParseType:1114] [IFoo.idl:48:47] error:')' of type is illegal +[IDL-GEN]: [ParseParam:1002] [IFoo.idl:48:47] error:expected param name before ')' token +[IDL-GEN]: [ParseAttrUnitIpccode:544] [IFoo.idl:49:13] error:Ipccode attr cannot be empty +[IDL-GEN]: [ParseAttrUnitIpccode:544] [IFoo.idl:50:6] error:Ipccode attr cannot be empty +[IDL-GEN]: [ParseAttributeInfo:467] [IFoo.idl:50:6] error:expected ',' or ']' before '' token +[IDL-GEN]: [ParseMethod:800] [IFoo.idl:50:6] error:expected method name before '' token +[IDL-GEN]: [ParseMethodParamList:950] [IFoo.idl:50:6] error:expected '(' before '' token +[IDL-GEN]: [ParseMethod:813] [IFoo.idl:50:6] error:expected ';' before '' token +[IDL-GEN]: [ParseInterfaceBody:771] [IFoo.idl:50:6] error:expected '}' before '' token [IDL-GEN]: failed to parse file \ No newline at end of file -- Gitee From e627c75ee7619e9a61e79bcc63e939f1b19f921d Mon Sep 17 00:00:00 2001 From: wenyu Date: Fri, 13 Dec 2024 14:53:51 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E5=9B=9E=E9=80=80=E6=AD=BB=E4=BA=A1?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wenyu --- .../cpp/sa_cpp_client_proxy_code_emitter.cpp | 147 +++++++----------- .../SA/cpp/sa_cpp_client_proxy_code_emitter.h | 12 +- .../SA/cpp/sa_cpp_interface_code_emitter.cpp | 12 +- .../SA/cpp/sa_cpp_interface_code_emitter.h | 2 - .../cmd_hitrace_tag/target/foo_proxy.cpp.txt | 46 ------ .../cmd_hitrace_tag/target/foo_proxy.h.txt | 33 +--- .../sa_test/cmd_hitrace_tag/target/ifoo.h.txt | 4 - .../target/foo_proxy.cpp.txt | 51 ------ .../target/foo_proxy.h.txt | 33 +--- .../cmd_log_tag_domainid/target/ifoo.h.txt | 4 - .../target/foo_proxy.cpp.txt | 46 ------ .../cmd_save_metadata/target/foo_proxy.h.txt | 33 +--- .../cmd_save_metadata/target/ifoo.h.txt | 4 - .../app_fwk_update_service_proxy.cpp.txt | 46 ------ .../app_fwk_update_service_proxy.h.txt | 33 +--- .../target_cpp/esim_service_proxy.cpp.txt | 46 ------ .../target_cpp/esim_service_proxy.h.txt | 33 +--- .../target_cpp/iapp_fwk_update_service.h.txt | 4 - .../target_cpp/idl_test_service_proxy.cpp.txt | 46 ------ .../target_cpp/idl_test_service_proxy.h.txt | 33 +--- .../in_use_idl/target_cpp/iesim_service.h.txt | 4 - .../target_cpp/iidl_test_service.h.txt | 4 - .../target_cpp/iquick_fix_manager.h.txt | 4 - .../target_cpp/itest_server_interface.h.txt | 4 - .../quick_fix_manager_proxy.cpp.txt | 46 ------ .../target_cpp/quick_fix_manager_proxy.h.txt | 33 +--- .../test_server_interface_proxy.cpp.txt | 46 ------ .../test_server_interface_proxy.h.txt | 33 +--- .../target_cpp/foo_proxy.cpp.txt | 70 --------- .../target_cpp/foo_proxy.h.txt | 72 +++++++-- .../target_cpp/ifoo.h.txt | 4 - .../target_cpp/foo_proxy.cpp.txt | 58 ------- .../target_cpp/foo_proxy.h.txt | 60 +++++-- .../target_cpp/ifoo.h.txt | 4 - .../target_cpp/foo_proxy.cpp.txt | 46 ------ .../target_cpp/foo_proxy.h.txt | 33 +--- .../keyword_import_dir/target_cpp/ifoo.h.txt | 4 - .../target_cpp/foo_proxy.cpp.txt | 46 ------ .../target_cpp/foo_proxy.h.txt | 33 +--- .../target_cpp/ifoo.h.txt | 4 - .../target_cpp/foo_proxy.cpp.txt | 46 ------ .../target_cpp/foo_proxy.h.txt | 33 +--- .../target_cpp/ifoo.h.txt | 4 - .../target_cpp/foo_proxy.cpp.txt | 46 ------ .../keyword_oneway/target_cpp/foo_proxy.h.txt | 33 +--- .../keyword_oneway/target_cpp/ifoo.h.txt | 4 - .../type_array/target_cpp/foo_proxy.cpp.txt | 46 ------ .../type_array/target_cpp/foo_proxy.h.txt | 33 +--- test/sa_test/type_array/target_cpp/ifoo.h.txt | 4 - .../type_list/target_cpp/foo_proxy.cpp.txt | 46 ------ .../type_list/target_cpp/foo_proxy.h.txt | 33 +--- test/sa_test/type_list/target_cpp/ifoo.h.txt | 4 - .../type_map/target_cpp/foo_proxy.cpp.txt | 46 ------ .../type_map/target_cpp/foo_proxy.h.txt | 33 +--- test/sa_test/type_map/target_cpp/ifoo.h.txt | 4 - .../type_single/target_cpp/foo_proxy.cpp.txt | 46 ------ .../type_single/target_cpp/foo_proxy.h.txt | 33 +--- .../sa_test/type_single/target_cpp/ifoo.h.txt | 4 - .../target_cpp/foo_proxy.cpp.txt | 46 ------ .../target_cpp/foo_proxy.h.txt | 33 +--- .../target_cpp/ifoo.h.txt | 4 - 61 files changed, 261 insertions(+), 1596 deletions(-) diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp b/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp index b6432ef..85de530 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp @@ -34,8 +34,7 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyHeaderFile() EmitLicense(sb); EmitHeadMacro(sb, proxyFullName_); - sb.Append("\n").Append("#include \n") - .Append("#include \n") + sb.Append("\n").Append("#include \n") .AppendFormat("#include \"%s.h\"\n", FileName(interfaceName_).c_str()); if (ast_ != nullptr && ast_->GetHasCacheableProxyMethods()) { sb.Append("#include \"api_cache_manager.h\"\n"); @@ -54,15 +53,13 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyInHeaderFile(StringBuilder & { EmitBeginNamespace(sb); sb.AppendFormat("class %s : public IRemoteProxy<%s> {\n", proxyName_.c_str(), interfaceName_.c_str()); - sb.Append("public:\n"); - EmitInterfaceProxyConstructorDecl(sb, TAB); - EmitInterfaceProxyRemoteDiedCallback(sb, TAB); + EmitInterfaceProxyConstructor(sb, TAB); + sb.Append("\n"); EmitInterfaceProxyMethodDecls(sb, TAB); - + sb.Append("\n"); sb.Append("private:\n"); EmitInterfaceProxyConstants(sb, TAB); - sb.Append("};\n"); EmitEndNamespace(sb); } @@ -70,11 +67,8 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyInHeaderFile(StringBuilder & void SaCppClientProxyCodeEmitter::EmitInterfaceProxyRegisterDeathRecipient(StringBuilder &sb, const std::string &prefix) const { - sb.Append(prefix).Append("if (remote_ && remote_ != remote) {\n") - .Append(prefix + TAB).Append("RemoveDeathRecipient();\n") - .Append(prefix).Append("}\n") - .Append(prefix).Append("if (remote) {\n") - .Append(prefix + TAB).Append("if (!remote->IsProxyObject()) {\n"); + sb.Append(prefix).Append("if (remote_) {\n"); + sb.Append(prefix + TAB).Append("if (!remote->IsProxyObject()) {\n"); if (logOn_) { sb.Append(prefix + TAB + TAB).Append("HiLog::Error(LABEL, \"remote is not proxy object!\");\n"); } @@ -118,10 +112,22 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyAddCacheApi(StringBuilder &s } } sb.Append("\n"); + EmitInterfaceProxyRegisterDeathRecipient(sb, prefix + TAB); + sb.Append(prefix).Append("}\n"); } -void SaCppClientProxyCodeEmitter::EmitInterfaceProxyDelCacheApi(StringBuilder &sb, const std::string &prefix) const +void SaCppClientProxyCodeEmitter::EmitInterfaceProxyUnRegisterDeathRecipient(StringBuilder &sb, + const std::string &prefix) const { + sb.Append(prefix).Append("{\n"); + sb.Append(prefix + TAB).Append("if (remote_ == nullptr) {\n"); + sb.Append(prefix + TAB).Append(TAB).Append("return;\n"); + sb.Append(prefix + TAB).Append("}\n"); + sb.Append(prefix + TAB).Append("if (deathRecipient_ == nullptr) {\n"); + sb.Append(prefix + TAB).Append(TAB).Append("return;\n"); + sb.Append(prefix + TAB).Append("}\n"); + sb.Append(prefix + TAB).Append("remote_->RemoveDeathRecipient(deathRecipient_);\n"); + sb.Append(prefix + TAB).Append("remote_ = nullptr;\n"); size_t methodNumber = interface_->GetMethodNumber(); if (methodNumber > 0) { sb.Append("\n"); @@ -134,12 +140,26 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyDelCacheApi(StringBuilder &s } } } + sb.Append(prefix).Append("}\n"); } -void SaCppClientProxyCodeEmitter::EmitInterfaceProxyConstructorDecl(StringBuilder &sb, const std::string &prefix) const +void SaCppClientProxyCodeEmitter::EmitInterfaceProxyConstructor(StringBuilder &sb, const std::string &prefix) const { - sb.Append(prefix).AppendFormat("explicit %s(const sptr& remote);\n\n", proxyName_.c_str()) - .Append(prefix).AppendFormat("~%s() override;\n\n", proxyName_.c_str()); + sb.Append(prefix).AppendFormat("explicit %s(\n", proxyName_.c_str()); + sb.Append(prefix + TAB).Append("const sptr& remote)\n"); + sb.Append(prefix + TAB).AppendFormat(": IRemoteProxy<%s>(remote)\n", interfaceName_.c_str()); + if (ast_->GetHasCacheableProxyMethods()) { + EmitInterfaceProxyAddCacheApi(sb, prefix); + } else { + sb.Append(prefix).Append("{}\n"); + } + sb.Append("\n"); + sb.Append(prefix).AppendFormat("virtual ~%s()\n", proxyName_.c_str()); + if (ast_->GetHasCacheableProxyMethods()) { + EmitInterfaceProxyUnRegisterDeathRecipient(sb, prefix); + } else { + sb.Append(prefix).Append("{}\n"); + } } void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodDecls(StringBuilder &sb, const std::string &prefix) const @@ -148,18 +168,12 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodDecls(StringBuilder &s for (size_t i = 0; i < methodNumber; i++) { AutoPtr method = interface_->GetMethod(i); EmitInterfaceProxyMethodDecl(method, sb, prefix); - sb.Append("\n"); + if (i != methodNumber - 1) { + sb.Append("\n"); + } } } -void SaCppClientProxyCodeEmitter::EmitInterfaceProxyRemoteDiedCallback(StringBuilder &sb, const std::string &prefix) -{ - sb.Append(prefix).Append("void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override\n") - .Append(prefix).Append("{\n") - .Append(prefix + TAB).Append("remoteDiedCallback_ = callback;\n") - .Append(prefix).Append("}\n\n"); -} - void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodDecl(AutoPtr &method, StringBuilder &sb, const std::string &prefix) const { @@ -172,29 +186,32 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyDeathRecipient(StringBuilder { sb.Append(prefix).AppendFormat("class %s : public IRemoteObject::DeathRecipient {\n", deathRecipientName_.c_str()); sb.Append(prefix).Append("public:\n"); - sb.Append(prefix + TAB).AppendFormat("explicit %s(%s& client) : client_(client) {}\n", deathRecipientName_.c_str(), + sb.Append(prefix + TAB).AppendFormat("explicit %s(%s &client) : client_(client) {}\n", deathRecipientName_.c_str(), proxyName_.c_str()); sb.Append(prefix + TAB).AppendFormat("~%s() override = default;\n", deathRecipientName_.c_str()); - sb.Append(prefix + TAB).Append("void OnRemoteDied(const wptr& remote) override\n"); + sb.Append(prefix + TAB).Append("void OnRemoteDied(const wptr &remote) override\n"); sb.Append(prefix + TAB).Append("{\n"); sb.Append(prefix + TAB + TAB).Append("client_.OnRemoteDied(remote);\n"); sb.Append(prefix + TAB).Append("}\n"); sb.Append(prefix).Append("private:\n"); - sb.Append(prefix + TAB).AppendFormat("%s& client_;\n", proxyName_.c_str()); + sb.Append(prefix + TAB).AppendFormat("%s &client_;\n", proxyName_.c_str()); sb.Append(prefix).Append("};\n\n"); - sb.Append(prefix).Append("void RemoveDeathRecipient();\n"); - sb.Append(prefix).Append("void OnRemoteDied(const wptr& remote);\n\n"); + + sb.Append(prefix).Append("void OnRemoteDied(const wptr &remoteObject)\n"); + sb.Append(prefix).Append("{\n"); + sb.Append(prefix + TAB).Append("(void)remoteObject;\n"); + sb.Append(prefix + TAB).Append("ApiCacheManager::GetInstance().ClearCache(GetDescriptor());\n"); + sb.Append(prefix).Append("}\n"); + sb.Append(prefix).Append("sptr remote_ = nullptr;\n"); + sb.Append(prefix).Append("sptr deathRecipient_ = nullptr;\n"); } void SaCppClientProxyCodeEmitter::EmitInterfaceProxyConstants(StringBuilder &sb, const std::string &prefix) { - EmitInterfaceProxyDeathRecipient(sb, prefix); + if (ast_->GetHasCacheableProxyMethods()) {EmitInterfaceProxyDeathRecipient(sb, prefix); - sb.Append(prefix).AppendFormat("static inline BrokerDelegator<%s> delegator_;\n", proxyName_.c_str()) - .Append(prefix + "sptr remote_;\n") - .Append(prefix + "sptr deathRecipient_;\n") - .Append(prefix + "OnRemoteDiedCallback remoteDiedCallback_;\n") - .Append(prefix + "std::mutex mutex_;\n"); +} + sb.Append(prefix).AppendFormat("static inline BrokerDelegator<%s> delegator_;\n", proxyName_.c_str()); EmitInterfaceProxyIpcCapacityValues(sb, prefix); } @@ -231,9 +248,6 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyCppFile() sb.Append("using OHOS::HiviewDFX::HiLog;\n\n"); } EmitBeginNamespace(sb); - EmitInterfaceProxyConstructorImpl(sb); - EmitInterfaceProxyRemoveDeathRecipient(sb); - EmitInterfaceProxyOnRemoteDied(sb); EmitInterfaceProxyMethodImpls(sb, ""); EmitEndNamespace(sb); @@ -243,61 +257,6 @@ void SaCppClientProxyCodeEmitter::EmitInterfaceProxyCppFile() file.Close(); } -void SaCppClientProxyCodeEmitter::EmitInterfaceProxyConstructorImpl(StringBuilder &sb) const -{ - sb.AppendFormat("%s::%s(const sptr& remote) : IRemoteProxy<%s>(remote)\n{\n", - proxyName_.c_str(), proxyName_.c_str(), interfaceName_.c_str()); - if (ast_->GetHasCacheableProxyMethods()) { - EmitInterfaceProxyAddCacheApi(sb, TAB); - } - sb.Append(TAB).Append("std::lock_guard lock(mutex_);\n"); - EmitInterfaceProxyRegisterDeathRecipient(sb, TAB); - sb.Append("}\n\n"); - - sb.AppendFormat("%s::~%s()\n", proxyName_.c_str(), proxyName_.c_str()) - .Append("{\n") - .Append(TAB).Append("RemoveDeathRecipient();\n"); - if (ast_->GetHasCacheableProxyMethods()) { - EmitInterfaceProxyDelCacheApi(sb, TAB); - } - sb.Append("}\n\n"); -} - -void SaCppClientProxyCodeEmitter::EmitInterfaceProxyRemoveDeathRecipient(StringBuilder &sb) const -{ - sb.AppendFormat("void %s::RemoveDeathRecipient()\n", proxyName_.c_str()) - .Append("{\n") - .Append(TAB).Append("std::lock_guard lock(mutex_);\n"); - if (logOn_) { - sb.Append(TAB).Append("HiLog::Info(LABEL, \"Remove death recipient\");\n"); - } - sb.Append(TAB).Append("if (!remote_ || !deathRecipient_) {\n") - .Append(TAB).Append(TAB).Append("return;\n") - .Append(TAB).Append("}\n") - .Append(TAB).Append("remote_->RemoveDeathRecipient(deathRecipient_);\n") - .Append(TAB).Append("remote_ = nullptr;\n") - .Append(TAB).Append("deathRecipient_ = nullptr;\n") - .Append(TAB).Append("remoteDiedCallback_ = nullptr;\n") - .Append("}\n\n"); -} - -void SaCppClientProxyCodeEmitter::EmitInterfaceProxyOnRemoteDied(StringBuilder &sb) const -{ - sb.AppendFormat("void %s::OnRemoteDied(const wptr& remote)\n{\n", proxyName_.c_str()); - if (logOn_) { - sb.Append(TAB).Append("HiLog::Info(LABEL, \"On remote died\");\n"); - } - sb.Append(TAB).Append("if (remoteDiedCallback_) {\n") - .Append(TAB).Append(TAB).Append("remoteDiedCallback_(remote);\n") - .Append(TAB).Append("}\n") - .Append(TAB).Append("RemoveDeathRecipient();\n"); - - if (ast_->GetHasCacheableProxyMethods()) { - sb.Append("\n").Append(TAB).Append("ApiCacheManager::GetInstance().ClearCache(GetDescriptor());\n"); - } - sb.Append("}\n\n"); -} - void SaCppClientProxyCodeEmitter::EmitInterfaceProxyMethodImpls(StringBuilder &sb, const std::string &prefix) const { size_t methodNumber = interface_->GetMethodNumber(); diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.h b/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.h index fd3ae06..29b59ab 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.h +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.h @@ -37,11 +37,9 @@ private: void EmitInterfaceProxyAddCacheApi(StringBuilder &sb, const std::string &prefix) const; - void EmitInterfaceProxyDelCacheApi(StringBuilder &sb, const std::string &prefix) const; + void EmitInterfaceProxyUnRegisterDeathRecipient(StringBuilder &sb, const std::string &prefix) const; - void EmitInterfaceProxyConstructorDecl(StringBuilder &sb, const std::string &prefix) const; - - static void EmitInterfaceProxyRemoteDiedCallback(StringBuilder &sb, const std::string &prefix); + void EmitInterfaceProxyConstructor(StringBuilder &sb, const std::string &prefix) const; void EmitInterfaceProxyMethodDecls(StringBuilder &sb, const std::string &prefix) const; @@ -53,12 +51,6 @@ private: void EmitInterfaceProxyCppFile(); - void EmitInterfaceProxyRemoveDeathRecipient(StringBuilder &sb) const; - - void EmitInterfaceProxyOnRemoteDied(StringBuilder &sb) const; - - void EmitInterfaceProxyConstructorImpl(StringBuilder &sb) const; - void EmitInterfaceProxyMethodImpls(StringBuilder &sb, const std::string &prefix) const; void EmitInterfaceProxyMethodImpl(AutoPtr &method, StringBuilder &sb, const std::string &prefix) const; diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp b/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp index e55c715..cdf1ddb 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp @@ -167,7 +167,6 @@ void SaCppInterfaceCodeEmitter::EmitInterfaceDefinition(StringBuilder &sb) { EmitBeginNamespace(sb); EmitInterfaceMethodCommands(sb, TAB); - EmitCallbackDecl(sb); sb.AppendFormat("class %s : public IRemoteBroker {\n", interface_->GetName().c_str()); sb.Append("public:\n"); EmitInterfaceBody(sb, TAB); @@ -176,18 +175,11 @@ void SaCppInterfaceCodeEmitter::EmitInterfaceDefinition(StringBuilder &sb) EmitEndNamespace(sb); } -void SaCppInterfaceCodeEmitter::EmitCallbackDecl(StringBuilder &sb) -{ - sb.Append("using OnRemoteDiedCallback = std::function&)>;\n\n"); -} - void SaCppInterfaceCodeEmitter::EmitInterfaceBody(StringBuilder &sb, const std::string &prefix) const { std::string nameWithoutPath = GetNamespace(interfaceFullName_); - sb.Append(prefix).AppendFormat("DECLARE_INTERFACE_DESCRIPTOR(u\"%s\");\n\n", nameWithoutPath.c_str()) - .Append(prefix) - .Append("virtual void RegisterOnRemoteDiedCallback(" - "[[maybe_unused]] const OnRemoteDiedCallback& callback) {}\n\n"); + sb.Append(prefix).AppendFormat("DECLARE_INTERFACE_DESCRIPTOR(u\"%s\");\n", nameWithoutPath.c_str()); + sb.Append("\n"); int methodNumber = static_cast(interface_->GetMethodNumber()); for (int i = 0; i < methodNumber; i++) { diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.h b/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.h index 33ed166..e2d4de3 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.h +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.h @@ -52,8 +52,6 @@ private: void EmitInterfaceMethod(AutoPtr &method, StringBuilder &sb, const std::string &prefix) const; void EmitInterfaceMemberVariables(StringBuilder &sb, const std::string &prefix) const; - - static void EmitCallbackDecl(StringBuilder &sb); }; } // namespace Idl } // namespace OHOS diff --git a/test/sa_test/cmd_hitrace_tag/target/foo_proxy.cpp.txt b/test/sa_test/cmd_hitrace_tag/target/foo_proxy.cpp.txt index c804b96..84620df 100644 --- a/test/sa_test/cmd_hitrace_tag/target/foo_proxy.cpp.txt +++ b/test/sa_test/cmd_hitrace_tag/target/foo_proxy.cpp.txt @@ -16,52 +16,6 @@ #include "foo_proxy.h" namespace test { -FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) -{ - std::lock_guard lock(mutex_); - if (remote_ && remote_ != remote) { - RemoveDeathRecipient(); - } - if (remote) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) FooRecipient(*this); - if (!deathRecipient_) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } -} - -FooProxy::~FooProxy() -{ - RemoveDeathRecipient(); -} - -void FooProxy::RemoveDeathRecipient() -{ - std::lock_guard lock(mutex_); - if (!remote_ || !deathRecipient_) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - deathRecipient_ = nullptr; - remoteDiedCallback_ = nullptr; -} - -void FooProxy::OnRemoteDied(const wptr& remote) -{ - if (remoteDiedCallback_) { - remoteDiedCallback_(remote); - } - RemoveDeathRecipient(); -} - ErrCode FooProxy::void_test_func() { MessageParcel data; diff --git a/test/sa_test/cmd_hitrace_tag/target/foo_proxy.h.txt b/test/sa_test/cmd_hitrace_tag/target/foo_proxy.h.txt index ad7e93d..bb7da5c 100644 --- a/test/sa_test/cmd_hitrace_tag/target/foo_proxy.h.txt +++ b/test/sa_test/cmd_hitrace_tag/target/foo_proxy.h.txt @@ -16,21 +16,19 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include #include #include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy(const sptr& remote); + explicit FooProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} - ~FooProxy() override; - - void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override - { - remoteDiedCallback_ = callback; - } + virtual ~FooProxy() + {} ErrCode void_test_func() override; @@ -101,26 +99,7 @@ public: sptr& funcResult) override; private: - class FooRecipient : public IRemoteObject::DeathRecipient { - public: - explicit FooRecipient(FooProxy& client) : client_(client) {} - ~FooRecipient() override = default; - void OnRemoteDied(const wptr& remote) override - { - client_.OnRemoteDied(remote); - } - private: - FooProxy& client_; - }; - - void RemoveDeathRecipient(); - void OnRemoteDied(const wptr& remote); - static inline BrokerDelegator delegator_; - sptr remote_; - sptr deathRecipient_; - OnRemoteDiedCallback remoteDiedCallback_; - std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/cmd_hitrace_tag/target/ifoo.h.txt b/test/sa_test/cmd_hitrace_tag/target/ifoo.h.txt index ee1e92e..52effa4 100644 --- a/test/sa_test/cmd_hitrace_tag/target/ifoo.h.txt +++ b/test/sa_test/cmd_hitrace_tag/target/ifoo.h.txt @@ -42,14 +42,10 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC, }; -using OnRemoteDiedCallback = std::function&)>; - class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); - virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} - virtual ErrCode void_test_func() = 0; virtual ErrCode bool_test_func( diff --git a/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.cpp.txt b/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.cpp.txt index 44e8420..f9e1eef 100644 --- a/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.cpp.txt +++ b/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.cpp.txt @@ -19,57 +19,6 @@ using OHOS::HiviewDFX::HiLog; namespace test { -FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) -{ - std::lock_guard lock(mutex_); - if (remote_ && remote_ != remote) { - RemoveDeathRecipient(); - } - if (remote) { - if (!remote->IsProxyObject()) { - HiLog::Error(LABEL, "remote is not proxy object!"); - return; - } - deathRecipient_ = new (std::nothrow) FooRecipient(*this); - if (!deathRecipient_) { - HiLog::Error(LABEL, "deathRecipient_ is nullptr!"); - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - HiLog::Error(LABEL, "AddDeathRecipient failed!"); - return; - } - remote_ = remote; - } -} - -FooProxy::~FooProxy() -{ - RemoveDeathRecipient(); -} - -void FooProxy::RemoveDeathRecipient() -{ - std::lock_guard lock(mutex_); - HiLog::Info(LABEL, "Remove death recipient"); - if (!remote_ || !deathRecipient_) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - deathRecipient_ = nullptr; - remoteDiedCallback_ = nullptr; -} - -void FooProxy::OnRemoteDied(const wptr& remote) -{ - HiLog::Info(LABEL, "On remote died"); - if (remoteDiedCallback_) { - remoteDiedCallback_(remote); - } - RemoveDeathRecipient(); -} - ErrCode FooProxy::void_test_func() { MessageParcel data; diff --git a/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.h.txt b/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.h.txt index ad7e93d..bb7da5c 100644 --- a/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.h.txt +++ b/test/sa_test/cmd_log_tag_domainid/target/foo_proxy.h.txt @@ -16,21 +16,19 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include #include #include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy(const sptr& remote); + explicit FooProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} - ~FooProxy() override; - - void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override - { - remoteDiedCallback_ = callback; - } + virtual ~FooProxy() + {} ErrCode void_test_func() override; @@ -101,26 +99,7 @@ public: sptr& funcResult) override; private: - class FooRecipient : public IRemoteObject::DeathRecipient { - public: - explicit FooRecipient(FooProxy& client) : client_(client) {} - ~FooRecipient() override = default; - void OnRemoteDied(const wptr& remote) override - { - client_.OnRemoteDied(remote); - } - private: - FooProxy& client_; - }; - - void RemoveDeathRecipient(); - void OnRemoteDied(const wptr& remote); - static inline BrokerDelegator delegator_; - sptr remote_; - sptr deathRecipient_; - OnRemoteDiedCallback remoteDiedCallback_; - std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/cmd_log_tag_domainid/target/ifoo.h.txt b/test/sa_test/cmd_log_tag_domainid/target/ifoo.h.txt index b2aaf9c..19c8d9c 100644 --- a/test/sa_test/cmd_log_tag_domainid/target/ifoo.h.txt +++ b/test/sa_test/cmd_log_tag_domainid/target/ifoo.h.txt @@ -43,14 +43,10 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC, }; -using OnRemoteDiedCallback = std::function&)>; - class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); - virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} - virtual ErrCode void_test_func() = 0; virtual ErrCode bool_test_func( diff --git a/test/sa_test/cmd_save_metadata/target/foo_proxy.cpp.txt b/test/sa_test/cmd_save_metadata/target/foo_proxy.cpp.txt index c804b96..84620df 100644 --- a/test/sa_test/cmd_save_metadata/target/foo_proxy.cpp.txt +++ b/test/sa_test/cmd_save_metadata/target/foo_proxy.cpp.txt @@ -16,52 +16,6 @@ #include "foo_proxy.h" namespace test { -FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) -{ - std::lock_guard lock(mutex_); - if (remote_ && remote_ != remote) { - RemoveDeathRecipient(); - } - if (remote) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) FooRecipient(*this); - if (!deathRecipient_) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } -} - -FooProxy::~FooProxy() -{ - RemoveDeathRecipient(); -} - -void FooProxy::RemoveDeathRecipient() -{ - std::lock_guard lock(mutex_); - if (!remote_ || !deathRecipient_) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - deathRecipient_ = nullptr; - remoteDiedCallback_ = nullptr; -} - -void FooProxy::OnRemoteDied(const wptr& remote) -{ - if (remoteDiedCallback_) { - remoteDiedCallback_(remote); - } - RemoveDeathRecipient(); -} - ErrCode FooProxy::void_test_func() { MessageParcel data; diff --git a/test/sa_test/cmd_save_metadata/target/foo_proxy.h.txt b/test/sa_test/cmd_save_metadata/target/foo_proxy.h.txt index ad7e93d..bb7da5c 100644 --- a/test/sa_test/cmd_save_metadata/target/foo_proxy.h.txt +++ b/test/sa_test/cmd_save_metadata/target/foo_proxy.h.txt @@ -16,21 +16,19 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include #include #include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy(const sptr& remote); + explicit FooProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} - ~FooProxy() override; - - void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override - { - remoteDiedCallback_ = callback; - } + virtual ~FooProxy() + {} ErrCode void_test_func() override; @@ -101,26 +99,7 @@ public: sptr& funcResult) override; private: - class FooRecipient : public IRemoteObject::DeathRecipient { - public: - explicit FooRecipient(FooProxy& client) : client_(client) {} - ~FooRecipient() override = default; - void OnRemoteDied(const wptr& remote) override - { - client_.OnRemoteDied(remote); - } - private: - FooProxy& client_; - }; - - void RemoveDeathRecipient(); - void OnRemoteDied(const wptr& remote); - static inline BrokerDelegator delegator_; - sptr remote_; - sptr deathRecipient_; - OnRemoteDiedCallback remoteDiedCallback_; - std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/cmd_save_metadata/target/ifoo.h.txt b/test/sa_test/cmd_save_metadata/target/ifoo.h.txt index ee1e92e..52effa4 100644 --- a/test/sa_test/cmd_save_metadata/target/ifoo.h.txt +++ b/test/sa_test/cmd_save_metadata/target/ifoo.h.txt @@ -42,14 +42,10 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC, }; -using OnRemoteDiedCallback = std::function&)>; - class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); - virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} - virtual ErrCode void_test_func() = 0; virtual ErrCode bool_test_func( diff --git a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.cpp.txt index c936c61..75f9e0d 100644 --- a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.cpp.txt @@ -17,52 +17,6 @@ namespace OHOS { namespace NWeb { -AppFwkUpdateServiceProxy::AppFwkUpdateServiceProxy(const sptr& remote) : IRemoteProxy(remote) -{ - std::lock_guard lock(mutex_); - if (remote_ && remote_ != remote) { - RemoveDeathRecipient(); - } - if (remote) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) AppFwkUpdateServiceRecipient(*this); - if (!deathRecipient_) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } -} - -AppFwkUpdateServiceProxy::~AppFwkUpdateServiceProxy() -{ - RemoveDeathRecipient(); -} - -void AppFwkUpdateServiceProxy::RemoveDeathRecipient() -{ - std::lock_guard lock(mutex_); - if (!remote_ || !deathRecipient_) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - deathRecipient_ = nullptr; - remoteDiedCallback_ = nullptr; -} - -void AppFwkUpdateServiceProxy::OnRemoteDied(const wptr& remote) -{ - if (remoteDiedCallback_) { - remoteDiedCallback_(remote); - } - RemoveDeathRecipient(); -} - ErrCode AppFwkUpdateServiceProxy::VerifyPackageInstall( const std::string& bundleName, const std::string& hapPath, diff --git a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.h.txt index 146b100..073f536 100644 --- a/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/app_fwk_update_service_proxy.h.txt @@ -16,7 +16,6 @@ #ifndef OHOS_NWEB_APPFWKUPDATESERVICEPROXY_H #define OHOS_NWEB_APPFWKUPDATESERVICEPROXY_H -#include #include #include "iapp_fwk_update_service.h" @@ -24,14 +23,13 @@ namespace OHOS { namespace NWeb { class AppFwkUpdateServiceProxy : public IRemoteProxy { public: - explicit AppFwkUpdateServiceProxy(const sptr& remote); + explicit AppFwkUpdateServiceProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} - ~AppFwkUpdateServiceProxy() override; - - void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override - { - remoteDiedCallback_ = callback; - } + virtual ~AppFwkUpdateServiceProxy() + {} ErrCode VerifyPackageInstall( const std::string& bundleName, @@ -39,26 +37,7 @@ public: int32_t& success) override; private: - class AppFwkUpdateServiceRecipient : public IRemoteObject::DeathRecipient { - public: - explicit AppFwkUpdateServiceRecipient(AppFwkUpdateServiceProxy& client) : client_(client) {} - ~AppFwkUpdateServiceRecipient() override = default; - void OnRemoteDied(const wptr& remote) override - { - client_.OnRemoteDied(remote); - } - private: - AppFwkUpdateServiceProxy& client_; - }; - - void RemoveDeathRecipient(); - void OnRemoteDied(const wptr& remote); - static inline BrokerDelegator delegator_; - sptr remote_; - sptr deathRecipient_; - OnRemoteDiedCallback remoteDiedCallback_; - std::mutex mutex_; }; } // namespace NWeb } // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.cpp.txt index 0505883..d7b2eb9 100644 --- a/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.cpp.txt @@ -17,52 +17,6 @@ namespace OHOS { namespace Telephony { -EsimServiceProxy::EsimServiceProxy(const sptr& remote) : IRemoteProxy(remote) -{ - std::lock_guard lock(mutex_); - if (remote_ && remote_ != remote) { - RemoveDeathRecipient(); - } - if (remote) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) EsimServiceRecipient(*this); - if (!deathRecipient_) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } -} - -EsimServiceProxy::~EsimServiceProxy() -{ - RemoveDeathRecipient(); -} - -void EsimServiceProxy::RemoveDeathRecipient() -{ - std::lock_guard lock(mutex_); - if (!remote_ || !deathRecipient_) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - deathRecipient_ = nullptr; - remoteDiedCallback_ = nullptr; -} - -void EsimServiceProxy::OnRemoteDied(const wptr& remote) -{ - if (remoteDiedCallback_) { - remoteDiedCallback_(remote); - } - RemoveDeathRecipient(); -} - ErrCode EsimServiceProxy::GetEid( int32_t slotId, std::string& eId) diff --git a/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.h.txt index 73b9e86..9da426e 100644 --- a/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/esim_service_proxy.h.txt @@ -16,7 +16,6 @@ #ifndef OHOS_TELEPHONY_ESIMSERVICEPROXY_H #define OHOS_TELEPHONY_ESIMSERVICEPROXY_H -#include #include #include "iesim_service.h" @@ -24,14 +23,13 @@ namespace OHOS { namespace Telephony { class EsimServiceProxy : public IRemoteProxy { public: - explicit EsimServiceProxy(const sptr& remote); + explicit EsimServiceProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} - ~EsimServiceProxy() override; - - void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override - { - remoteDiedCallback_ = callback; - } + virtual ~EsimServiceProxy() + {} ErrCode GetEid( int32_t slotId, @@ -118,26 +116,7 @@ public: int32_t slotId) override; private: - class EsimServiceRecipient : public IRemoteObject::DeathRecipient { - public: - explicit EsimServiceRecipient(EsimServiceProxy& client) : client_(client) {} - ~EsimServiceRecipient() override = default; - void OnRemoteDied(const wptr& remote) override - { - client_.OnRemoteDied(remote); - } - private: - EsimServiceProxy& client_; - }; - - void RemoveDeathRecipient(); - void OnRemoteDied(const wptr& remote); - static inline BrokerDelegator delegator_; - sptr remote_; - sptr deathRecipient_; - OnRemoteDiedCallback remoteDiedCallback_; - std::mutex mutex_; }; } // namespace Telephony } // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/iapp_fwk_update_service.h.txt b/test/sa_test/in_use_idl/target_cpp/iapp_fwk_update_service.h.txt index 88b8029..8eb1f12 100644 --- a/test/sa_test/in_use_idl/target_cpp/iapp_fwk_update_service.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/iapp_fwk_update_service.h.txt @@ -27,14 +27,10 @@ enum class IAppFwkUpdateServiceIpcCode { COMMAND_VERIFY_PACKAGE_INSTALL = MIN_TRANSACTION_ID, }; -using OnRemoteDiedCallback = std::function&)>; - class IAppFwkUpdateService : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.NWeb.IAppFwkUpdateService"); - virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} - virtual ErrCode VerifyPackageInstall( const std::string& bundleName, const std::string& hapPath, diff --git a/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.cpp.txt index 6138c02..e250517 100644 --- a/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.cpp.txt @@ -16,52 +16,6 @@ #include "idl_test_service_proxy.h" namespace OHOS { -IdlTestServiceProxy::IdlTestServiceProxy(const sptr& remote) : IRemoteProxy(remote) -{ - std::lock_guard lock(mutex_); - if (remote_ && remote_ != remote) { - RemoveDeathRecipient(); - } - if (remote) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) IdlTestServiceRecipient(*this); - if (!deathRecipient_) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } -} - -IdlTestServiceProxy::~IdlTestServiceProxy() -{ - RemoveDeathRecipient(); -} - -void IdlTestServiceProxy::RemoveDeathRecipient() -{ - std::lock_guard lock(mutex_); - if (!remote_ || !deathRecipient_) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - deathRecipient_ = nullptr; - remoteDiedCallback_ = nullptr; -} - -void IdlTestServiceProxy::OnRemoteDied(const wptr& remote) -{ - if (remoteDiedCallback_) { - remoteDiedCallback_(remote); - } - RemoveDeathRecipient(); -} - ErrCode IdlTestServiceProxy::TestIntTransaction( int32_t val) { diff --git a/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.h.txt index c30c57a..e8b94b3 100644 --- a/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/idl_test_service_proxy.h.txt @@ -16,21 +16,19 @@ #ifndef OHOS_IDLTESTSERVICEPROXY_H #define OHOS_IDLTESTSERVICEPROXY_H -#include #include #include "iidl_test_service.h" namespace OHOS { class IdlTestServiceProxy : public IRemoteProxy { public: - explicit IdlTestServiceProxy(const sptr& remote); + explicit IdlTestServiceProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} - ~IdlTestServiceProxy() override; - - void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override - { - remoteDiedCallback_ = callback; - } + virtual ~IdlTestServiceProxy() + {} ErrCode TestIntTransaction( int32_t val) override; @@ -39,26 +37,7 @@ public: const std::string& val) override; private: - class IdlTestServiceRecipient : public IRemoteObject::DeathRecipient { - public: - explicit IdlTestServiceRecipient(IdlTestServiceProxy& client) : client_(client) {} - ~IdlTestServiceRecipient() override = default; - void OnRemoteDied(const wptr& remote) override - { - client_.OnRemoteDied(remote); - } - private: - IdlTestServiceProxy& client_; - }; - - void RemoveDeathRecipient(); - void OnRemoteDied(const wptr& remote); - static inline BrokerDelegator delegator_; - sptr remote_; - sptr deathRecipient_; - OnRemoteDiedCallback remoteDiedCallback_; - std::mutex mutex_; }; } // namespace OHOS #endif // OHOS_IDLTESTSERVICEPROXY_H diff --git a/test/sa_test/in_use_idl/target_cpp/iesim_service.h.txt b/test/sa_test/in_use_idl/target_cpp/iesim_service.h.txt index f0ce99e..58e45a8 100644 --- a/test/sa_test/in_use_idl/target_cpp/iesim_service.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/iesim_service.h.txt @@ -60,14 +60,10 @@ enum class IEsimServiceIpcCode { COMMAND_IS_ESIM_SUPPORTED, }; -using OnRemoteDiedCallback = std::function&)>; - class IEsimService : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Telephony.IEsimService"); - virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} - virtual ErrCode GetEid( int32_t slotId, std::string& eId) = 0; diff --git a/test/sa_test/in_use_idl/target_cpp/iidl_test_service.h.txt b/test/sa_test/in_use_idl/target_cpp/iidl_test_service.h.txt index 545159e..3f88d26 100644 --- a/test/sa_test/in_use_idl/target_cpp/iidl_test_service.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/iidl_test_service.h.txt @@ -27,14 +27,10 @@ enum class IIdlTestServiceIpcCode { COMMAND_TEST_STRING_TRANSACTION, }; -using OnRemoteDiedCallback = std::function&)>; - class IIdlTestService : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IIdlTestService"); - virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} - virtual ErrCode TestIntTransaction( int32_t val) = 0; diff --git a/test/sa_test/in_use_idl/target_cpp/iquick_fix_manager.h.txt b/test/sa_test/in_use_idl/target_cpp/iquick_fix_manager.h.txt index fc68a40..8353c38 100644 --- a/test/sa_test/in_use_idl/target_cpp/iquick_fix_manager.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/iquick_fix_manager.h.txt @@ -33,14 +33,10 @@ enum class IQuickFixManagerIpcCode { COMMAND_REVOKE_QUICK_FIX, }; -using OnRemoteDiedCallback = std::function&)>; - class IQuickFixManager : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.AAFwk.IQuickFixManager"); - virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} - virtual ErrCode ApplyQuickFix( const std::vector& quickFixFiles, bool isDebug) = 0; diff --git a/test/sa_test/in_use_idl/target_cpp/itest_server_interface.h.txt b/test/sa_test/in_use_idl/target_cpp/itest_server_interface.h.txt index acfa5de..db596f4 100644 --- a/test/sa_test/in_use_idl/target_cpp/itest_server_interface.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/itest_server_interface.h.txt @@ -34,14 +34,10 @@ enum class ITestServerInterfaceIpcCode { COMMAND_PUBLISH_COMMON_EVENT, }; -using OnRemoteDiedCallback = std::function&)>; - class ITestServerInterface : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.testserver.ITestServerInterface"); - virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} - virtual ErrCode CreateSession( const SessionToken& sessionToken) = 0; diff --git a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.cpp.txt index f0d4ba5..9272693 100644 --- a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.cpp.txt @@ -17,52 +17,6 @@ namespace OHOS { namespace AAFwk { -QuickFixManagerProxy::QuickFixManagerProxy(const sptr& remote) : IRemoteProxy(remote) -{ - std::lock_guard lock(mutex_); - if (remote_ && remote_ != remote) { - RemoveDeathRecipient(); - } - if (remote) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) QuickFixManagerRecipient(*this); - if (!deathRecipient_) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } -} - -QuickFixManagerProxy::~QuickFixManagerProxy() -{ - RemoveDeathRecipient(); -} - -void QuickFixManagerProxy::RemoveDeathRecipient() -{ - std::lock_guard lock(mutex_); - if (!remote_ || !deathRecipient_) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - deathRecipient_ = nullptr; - remoteDiedCallback_ = nullptr; -} - -void QuickFixManagerProxy::OnRemoteDied(const wptr& remote) -{ - if (remoteDiedCallback_) { - remoteDiedCallback_(remote); - } - RemoveDeathRecipient(); -} - ErrCode QuickFixManagerProxy::ApplyQuickFix( const std::vector& quickFixFiles, bool isDebug) diff --git a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.h.txt index aade00b..c00e702 100644 --- a/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/quick_fix_manager_proxy.h.txt @@ -16,7 +16,6 @@ #ifndef OHOS_AAFWK_QUICKFIXMANAGERPROXY_H #define OHOS_AAFWK_QUICKFIXMANAGERPROXY_H -#include #include #include "iquick_fix_manager.h" @@ -24,14 +23,13 @@ namespace OHOS { namespace AAFwk { class QuickFixManagerProxy : public IRemoteProxy { public: - explicit QuickFixManagerProxy(const sptr& remote); + explicit QuickFixManagerProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} - ~QuickFixManagerProxy() override; - - void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override - { - remoteDiedCallback_ = callback; - } + virtual ~QuickFixManagerProxy() + {} ErrCode ApplyQuickFix( const std::vector& quickFixFiles, @@ -45,26 +43,7 @@ public: const std::string& bundleName) override; private: - class QuickFixManagerRecipient : public IRemoteObject::DeathRecipient { - public: - explicit QuickFixManagerRecipient(QuickFixManagerProxy& client) : client_(client) {} - ~QuickFixManagerRecipient() override = default; - void OnRemoteDied(const wptr& remote) override - { - client_.OnRemoteDied(remote); - } - private: - QuickFixManagerProxy& client_; - }; - - void RemoveDeathRecipient(); - void OnRemoteDied(const wptr& remote); - static inline BrokerDelegator delegator_; - sptr remote_; - sptr deathRecipient_; - OnRemoteDiedCallback remoteDiedCallback_; - std::mutex mutex_; }; } // namespace AAFwk } // namespace OHOS diff --git a/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.cpp.txt b/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.cpp.txt index 42130db..59683d0 100644 --- a/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.cpp.txt +++ b/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.cpp.txt @@ -17,52 +17,6 @@ namespace OHOS { namespace testserver { -TestServerInterfaceProxy::TestServerInterfaceProxy(const sptr& remote) : IRemoteProxy(remote) -{ - std::lock_guard lock(mutex_); - if (remote_ && remote_ != remote) { - RemoveDeathRecipient(); - } - if (remote) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) TestServerInterfaceRecipient(*this); - if (!deathRecipient_) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } -} - -TestServerInterfaceProxy::~TestServerInterfaceProxy() -{ - RemoveDeathRecipient(); -} - -void TestServerInterfaceProxy::RemoveDeathRecipient() -{ - std::lock_guard lock(mutex_); - if (!remote_ || !deathRecipient_) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - deathRecipient_ = nullptr; - remoteDiedCallback_ = nullptr; -} - -void TestServerInterfaceProxy::OnRemoteDied(const wptr& remote) -{ - if (remoteDiedCallback_) { - remoteDiedCallback_(remote); - } - RemoveDeathRecipient(); -} - ErrCode TestServerInterfaceProxy::CreateSession( const SessionToken& sessionToken) { diff --git a/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.h.txt b/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.h.txt index d46226c..2d82f1c 100644 --- a/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.h.txt +++ b/test/sa_test/in_use_idl/target_cpp/test_server_interface_proxy.h.txt @@ -16,7 +16,6 @@ #ifndef OHOS_TESTSERVER_TESTSERVERINTERFACEPROXY_H #define OHOS_TESTSERVER_TESTSERVERINTERFACEPROXY_H -#include #include #include "itest_server_interface.h" @@ -24,14 +23,13 @@ namespace OHOS { namespace testserver { class TestServerInterfaceProxy : public IRemoteProxy { public: - explicit TestServerInterfaceProxy(const sptr& remote); + explicit TestServerInterfaceProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} - ~TestServerInterfaceProxy() override; - - void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override - { - remoteDiedCallback_ = callback; - } + virtual ~TestServerInterfaceProxy() + {} ErrCode CreateSession( const SessionToken& sessionToken) override; @@ -44,26 +42,7 @@ public: bool& re) override; private: - class TestServerInterfaceRecipient : public IRemoteObject::DeathRecipient { - public: - explicit TestServerInterfaceRecipient(TestServerInterfaceProxy& client) : client_(client) {} - ~TestServerInterfaceRecipient() override = default; - void OnRemoteDied(const wptr& remote) override - { - client_.OnRemoteDied(remote); - } - private: - TestServerInterfaceProxy& client_; - }; - - void RemoveDeathRecipient(); - void OnRemoteDied(const wptr& remote); - static inline BrokerDelegator delegator_; - sptr remote_; - sptr deathRecipient_; - OnRemoteDiedCallback remoteDiedCallback_; - std::mutex mutex_; }; } // namespace testserver } // namespace OHOS diff --git a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.cpp.txt b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.cpp.txt index a3d6550..bfe7d55 100644 --- a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.cpp.txt @@ -17,76 +17,6 @@ namespace idl { namespace OHOS { -FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) -{ - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), - static_cast(IFooIpcCode::COMMAND_TEST001), 100000); - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), - static_cast(IFooIpcCode::COMMAND_TEST002), 0); - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), - static_cast(IFooIpcCode::COMMAND_TEST003), 0); - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), - static_cast(IFooIpcCode::COMMAND_TEST004), 200000); - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), - static_cast(IFooIpcCode::COMMAND_TEST005), 2147483647000); - - std::lock_guard lock(mutex_); - if (remote_ && remote_ != remote) { - RemoveDeathRecipient(); - } - if (remote) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) FooRecipient(*this); - if (!deathRecipient_) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } -} - -FooProxy::~FooProxy() -{ - RemoveDeathRecipient(); - - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), - static_cast(IFooIpcCode::COMMAND_TEST001)); - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), - static_cast(IFooIpcCode::COMMAND_TEST002)); - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), - static_cast(IFooIpcCode::COMMAND_TEST003)); - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), - static_cast(IFooIpcCode::COMMAND_TEST004)); - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), - static_cast(IFooIpcCode::COMMAND_TEST005)); -} - -void FooProxy::RemoveDeathRecipient() -{ - std::lock_guard lock(mutex_); - if (!remote_ || !deathRecipient_) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - deathRecipient_ = nullptr; - remoteDiedCallback_ = nullptr; -} - -void FooProxy::OnRemoteDied(const wptr& remote) -{ - if (remoteDiedCallback_) { - remoteDiedCallback_(remote); - } - RemoveDeathRecipient(); - - ApiCacheManager::GetInstance().ClearCache(GetDescriptor()); -} - ErrCode FooProxy::test001( short param1, int32_t& funcResult) diff --git a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.h.txt b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.h.txt index 87c7605..5433377 100644 --- a/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/keyword_cacheable_test_001/target_cpp/foo_proxy.h.txt @@ -16,7 +16,6 @@ #ifndef IDL_OHOS_FOOPROXY_H #define IDL_OHOS_FOOPROXY_H -#include #include #include "ifoo.h" #include "api_cache_manager.h" @@ -25,13 +24,56 @@ namespace idl { namespace OHOS { class FooProxy : public IRemoteProxy { public: - explicit FooProxy(const sptr& remote); + explicit FooProxy( + const sptr& remote) + : IRemoteProxy(remote) + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST001), 100000); + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST002), 0); + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST003), 0); + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST004), 200000); + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST005), 2147483647000); - ~FooProxy() override; + if (remote_) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) FooRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } + } - void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override + virtual ~FooProxy() { - remoteDiedCallback_ = callback; + if (remote_ == nullptr) { + return; + } + if (deathRecipient_ == nullptr) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST001)); + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST002)); + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST003)); + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST004)); + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST005)); } ErrCode test001( @@ -56,24 +98,24 @@ public: private: class FooRecipient : public IRemoteObject::DeathRecipient { public: - explicit FooRecipient(FooProxy& client) : client_(client) {} + explicit FooRecipient(FooProxy &client) : client_(client) {} ~FooRecipient() override = default; - void OnRemoteDied(const wptr& remote) override + void OnRemoteDied(const wptr &remote) override { client_.OnRemoteDied(remote); } private: - FooProxy& client_; + FooProxy &client_; }; - void RemoveDeathRecipient(); - void OnRemoteDied(const wptr& remote); - + void OnRemoteDied(const wptr &remoteObject) + { + (void)remoteObject; + ApiCacheManager::GetInstance().ClearCache(GetDescriptor()); + } + sptr remote_ = nullptr; + sptr deathRecipient_ = nullptr; static inline BrokerDelegator delegator_; - sptr remote_; - sptr deathRecipient_; - OnRemoteDiedCallback remoteDiedCallback_; - std::mutex mutex_; }; } // namespace OHOS } // namespace idl diff --git a/test/sa_test/keyword_cacheable_test_001/target_cpp/ifoo.h.txt b/test/sa_test/keyword_cacheable_test_001/target_cpp/ifoo.h.txt index 6ffaa87..44d9b6b 100644 --- a/test/sa_test/keyword_cacheable_test_001/target_cpp/ifoo.h.txt +++ b/test/sa_test/keyword_cacheable_test_001/target_cpp/ifoo.h.txt @@ -32,14 +32,10 @@ enum class IFooIpcCode { COMMAND_TEST005, }; -using OnRemoteDiedCallback = std::function&)>; - class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"idl.OHOS.IFoo"); - virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} - virtual ErrCode test001( short param1, int32_t& funcResult) = 0; diff --git a/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.cpp.txt b/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.cpp.txt index fd6c6d8..ccb925e 100644 --- a/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.cpp.txt @@ -17,64 +17,6 @@ namespace idl { namespace OHOS { -FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) -{ - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), - static_cast(IFooIpcCode::COMMAND_TEST005), 0); - ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), - static_cast(IFooIpcCode::COMMAND_TEST005), 2000); - - std::lock_guard lock(mutex_); - if (remote_ && remote_ != remote) { - RemoveDeathRecipient(); - } - if (remote) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) FooRecipient(*this); - if (!deathRecipient_) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } -} - -FooProxy::~FooProxy() -{ - RemoveDeathRecipient(); - - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), - static_cast(IFooIpcCode::COMMAND_TEST005)); - ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), - static_cast(IFooIpcCode::COMMAND_TEST005)); -} - -void FooProxy::RemoveDeathRecipient() -{ - std::lock_guard lock(mutex_); - if (!remote_ || !deathRecipient_) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - deathRecipient_ = nullptr; - remoteDiedCallback_ = nullptr; -} - -void FooProxy::OnRemoteDied(const wptr& remote) -{ - if (remoteDiedCallback_) { - remoteDiedCallback_(remote); - } - RemoveDeathRecipient(); - - ApiCacheManager::GetInstance().ClearCache(GetDescriptor()); -} - ErrCode FooProxy::test001( int32_t param1) { diff --git a/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.h.txt b/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.h.txt index 586a621..cfdaa85 100644 --- a/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/keyword_cacheable_test_002/target_cpp/foo_proxy.h.txt @@ -16,7 +16,6 @@ #ifndef IDL_OHOS_FOOPROXY_H #define IDL_OHOS_FOOPROXY_H -#include #include #include "ifoo.h" #include "api_cache_manager.h" @@ -25,13 +24,44 @@ namespace idl { namespace OHOS { class FooProxy : public IRemoteProxy { public: - explicit FooProxy(const sptr& remote); + explicit FooProxy( + const sptr& remote) + : IRemoteProxy(remote) + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST005), 0); + ApiCacheManager::GetInstance().AddCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST005), 2000); - ~FooProxy() override; + if (remote_) { + if (!remote->IsProxyObject()) { + return; + } + deathRecipient_ = new (std::nothrow) FooRecipient(*this); + if (!deathRecipient_) { + return; + } + if (!remote->AddDeathRecipient(deathRecipient_)) { + return; + } + remote_ = remote; + } + } - void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override + virtual ~FooProxy() { - remoteDiedCallback_ = callback; + if (remote_ == nullptr) { + return; + } + if (deathRecipient_ == nullptr) { + return; + } + remote_->RemoveDeathRecipient(deathRecipient_); + remote_ = nullptr; + + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST005)); + ApiCacheManager::GetInstance().DelCacheApi(GetDescriptor(), + static_cast(IFooIpcCode::COMMAND_TEST005)); } ErrCode test001( @@ -51,24 +81,24 @@ public: private: class FooRecipient : public IRemoteObject::DeathRecipient { public: - explicit FooRecipient(FooProxy& client) : client_(client) {} + explicit FooRecipient(FooProxy &client) : client_(client) {} ~FooRecipient() override = default; - void OnRemoteDied(const wptr& remote) override + void OnRemoteDied(const wptr &remote) override { client_.OnRemoteDied(remote); } private: - FooProxy& client_; + FooProxy &client_; }; - void RemoveDeathRecipient(); - void OnRemoteDied(const wptr& remote); - + void OnRemoteDied(const wptr &remoteObject) + { + (void)remoteObject; + ApiCacheManager::GetInstance().ClearCache(GetDescriptor()); + } + sptr remote_ = nullptr; + sptr deathRecipient_ = nullptr; static inline BrokerDelegator delegator_; - sptr remote_; - sptr deathRecipient_; - OnRemoteDiedCallback remoteDiedCallback_; - std::mutex mutex_; }; } // namespace OHOS } // namespace idl diff --git a/test/sa_test/keyword_cacheable_test_002/target_cpp/ifoo.h.txt b/test/sa_test/keyword_cacheable_test_002/target_cpp/ifoo.h.txt index a4946ac..b0e70b6 100644 --- a/test/sa_test/keyword_cacheable_test_002/target_cpp/ifoo.h.txt +++ b/test/sa_test/keyword_cacheable_test_002/target_cpp/ifoo.h.txt @@ -30,14 +30,10 @@ enum class IFooIpcCode { COMMAND_TEST005, }; -using OnRemoteDiedCallback = std::function&)>; - class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"idl.OHOS.IFoo"); - virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} - virtual ErrCode test001( int32_t param1) = 0; diff --git a/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.cpp.txt b/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.cpp.txt index ccc55a3..6c1528e 100644 --- a/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.cpp.txt @@ -16,52 +16,6 @@ #include "foo_proxy.h" namespace test { -FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) -{ - std::lock_guard lock(mutex_); - if (remote_ && remote_ != remote) { - RemoveDeathRecipient(); - } - if (remote) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) FooRecipient(*this); - if (!deathRecipient_) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } -} - -FooProxy::~FooProxy() -{ - RemoveDeathRecipient(); -} - -void FooProxy::RemoveDeathRecipient() -{ - std::lock_guard lock(mutex_); - if (!remote_ || !deathRecipient_) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - deathRecipient_ = nullptr; - remoteDiedCallback_ = nullptr; -} - -void FooProxy::OnRemoteDied(const wptr& remote) -{ - if (remoteDiedCallback_) { - remoteDiedCallback_(remote); - } - RemoveDeathRecipient(); -} - ErrCode FooProxy::seq_test_func( const myseq& inParam, myseq& outParam, diff --git a/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.h.txt b/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.h.txt index ca238a0..b1acc52 100644 --- a/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/keyword_import_dir/target_cpp/foo_proxy.h.txt @@ -16,21 +16,19 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include #include #include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy(const sptr& remote); + explicit FooProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} - ~FooProxy() override; - - void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override - { - remoteDiedCallback_ = callback; - } + virtual ~FooProxy() + {} ErrCode seq_test_func( const myseq& inParam, @@ -53,26 +51,7 @@ public: const sptr& inoutParam) override; private: - class FooRecipient : public IRemoteObject::DeathRecipient { - public: - explicit FooRecipient(FooProxy& client) : client_(client) {} - ~FooRecipient() override = default; - void OnRemoteDied(const wptr& remote) override - { - client_.OnRemoteDied(remote); - } - private: - FooProxy& client_; - }; - - void RemoveDeathRecipient(); - void OnRemoteDied(const wptr& remote); - static inline BrokerDelegator delegator_; - sptr remote_; - sptr deathRecipient_; - OnRemoteDiedCallback remoteDiedCallback_; - std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/keyword_import_dir/target_cpp/ifoo.h.txt b/test/sa_test/keyword_import_dir/target_cpp/ifoo.h.txt index 19b34cb..6d3217f 100644 --- a/test/sa_test/keyword_import_dir/target_cpp/ifoo.h.txt +++ b/test/sa_test/keyword_import_dir/target_cpp/ifoo.h.txt @@ -38,14 +38,10 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC2, }; -using OnRemoteDiedCallback = std::function&)>; - class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); - virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} - virtual ErrCode seq_test_func( const myseq& inParam, myseq& outParam, diff --git a/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_proxy.cpp.txt b/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_proxy.cpp.txt index df94678..872bcd9 100644 --- a/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_proxy.cpp.txt @@ -16,52 +16,6 @@ #include "foo_proxy.h" namespace test { -FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) -{ - std::lock_guard lock(mutex_); - if (remote_ && remote_ != remote) { - RemoveDeathRecipient(); - } - if (remote) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) FooRecipient(*this); - if (!deathRecipient_) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } -} - -FooProxy::~FooProxy() -{ - RemoveDeathRecipient(); -} - -void FooProxy::RemoveDeathRecipient() -{ - std::lock_guard lock(mutex_); - if (!remote_ || !deathRecipient_) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - deathRecipient_ = nullptr; - remoteDiedCallback_ = nullptr; -} - -void FooProxy::OnRemoteDied(const wptr& remote) -{ - if (remoteDiedCallback_) { - remoteDiedCallback_(remote); - } - RemoveDeathRecipient(); -} - ErrCode FooProxy::bool_test_func( bool inParam, bool& outParam, diff --git a/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_proxy.h.txt b/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_proxy.h.txt index 752dec2..f23c996 100644 --- a/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/keyword_ipccapacity_test_001/target_cpp/foo_proxy.h.txt @@ -16,21 +16,19 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include #include #include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy(const sptr& remote); + explicit FooProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} - ~FooProxy() override; - - void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override - { - remoteDiedCallback_ = callback; - } + virtual ~FooProxy() + {} ErrCode bool_test_func( bool inParam, @@ -85,26 +83,7 @@ public: double inParam) override; private: - class FooRecipient : public IRemoteObject::DeathRecipient { - public: - explicit FooRecipient(FooProxy& client) : client_(client) {} - ~FooRecipient() override = default; - void OnRemoteDied(const wptr& remote) override - { - client_.OnRemoteDied(remote); - } - private: - FooProxy& client_; - }; - - void RemoveDeathRecipient(); - void OnRemoteDied(const wptr& remote); - static inline BrokerDelegator delegator_; - sptr remote_; - sptr deathRecipient_; - OnRemoteDiedCallback remoteDiedCallback_; - std::mutex mutex_; static constexpr size_t CAPACITY_BOOL_TEST_FUNC_1 = 1 << 10; static constexpr size_t CAPACITY_SHORT_TEST_FUNC_3 = 131071 << 10; static constexpr size_t CAPACITY_CHAR_TEST_FUNC_4 = 131071 << 10; diff --git a/test/sa_test/keyword_ipccapacity_test_001/target_cpp/ifoo.h.txt b/test/sa_test/keyword_ipccapacity_test_001/target_cpp/ifoo.h.txt index 2047de1..8964929 100644 --- a/test/sa_test/keyword_ipccapacity_test_001/target_cpp/ifoo.h.txt +++ b/test/sa_test/keyword_ipccapacity_test_001/target_cpp/ifoo.h.txt @@ -35,14 +35,10 @@ enum class IFooIpcCode { COMMAND_DOUBLE_TEST_FUNC = 16777215, }; -using OnRemoteDiedCallback = std::function&)>; - class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); - virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} - virtual ErrCode bool_test_func( bool inParam, bool& outParam, diff --git a/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.cpp.txt b/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.cpp.txt index 5033f8a..b62490c 100644 --- a/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.cpp.txt @@ -16,52 +16,6 @@ #include "foo_proxy.h" namespace test { -FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) -{ - std::lock_guard lock(mutex_); - if (remote_ && remote_ != remote) { - RemoveDeathRecipient(); - } - if (remote) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) FooRecipient(*this); - if (!deathRecipient_) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } -} - -FooProxy::~FooProxy() -{ - RemoveDeathRecipient(); -} - -void FooProxy::RemoveDeathRecipient() -{ - std::lock_guard lock(mutex_); - if (!remote_ || !deathRecipient_) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - deathRecipient_ = nullptr; - remoteDiedCallback_ = nullptr; -} - -void FooProxy::OnRemoteDied(const wptr& remote) -{ - if (remoteDiedCallback_) { - remoteDiedCallback_(remote); - } - RemoveDeathRecipient(); -} - ErrCode FooProxy::void_test_func() { MessageParcel data; diff --git a/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.h.txt b/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.h.txt index 7ce8042..8238fa1 100644 --- a/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/keyword_ipccode_test_001/target_cpp/foo_proxy.h.txt @@ -16,21 +16,19 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include #include #include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy(const sptr& remote); + explicit FooProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} - ~FooProxy() override; - - void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override - { - remoteDiedCallback_ = callback; - } + virtual ~FooProxy() + {} ErrCode void_test_func() override; @@ -85,26 +83,7 @@ public: const sptr& inoutParam) override; private: - class FooRecipient : public IRemoteObject::DeathRecipient { - public: - explicit FooRecipient(FooProxy& client) : client_(client) {} - ~FooRecipient() override = default; - void OnRemoteDied(const wptr& remote) override - { - client_.OnRemoteDied(remote); - } - private: - FooProxy& client_; - }; - - void RemoveDeathRecipient(); - void OnRemoteDied(const wptr& remote); - static inline BrokerDelegator delegator_; - sptr remote_; - sptr deathRecipient_; - OnRemoteDiedCallback remoteDiedCallback_; - std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/keyword_ipccode_test_001/target_cpp/ifoo.h.txt b/test/sa_test/keyword_ipccode_test_001/target_cpp/ifoo.h.txt index 308da2e..db36b35 100644 --- a/test/sa_test/keyword_ipccode_test_001/target_cpp/ifoo.h.txt +++ b/test/sa_test/keyword_ipccode_test_001/target_cpp/ifoo.h.txt @@ -41,14 +41,10 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC, }; -using OnRemoteDiedCallback = std::function&)>; - class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); - virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} - virtual ErrCode void_test_func() = 0; virtual ErrCode bool_test_func( diff --git a/test/sa_test/keyword_oneway/target_cpp/foo_proxy.cpp.txt b/test/sa_test/keyword_oneway/target_cpp/foo_proxy.cpp.txt index 5f9a7df..c9bfb56 100644 --- a/test/sa_test/keyword_oneway/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/keyword_oneway/target_cpp/foo_proxy.cpp.txt @@ -16,52 +16,6 @@ #include "foo_proxy.h" namespace test { -FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) -{ - std::lock_guard lock(mutex_); - if (remote_ && remote_ != remote) { - RemoveDeathRecipient(); - } - if (remote) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) FooRecipient(*this); - if (!deathRecipient_) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } -} - -FooProxy::~FooProxy() -{ - RemoveDeathRecipient(); -} - -void FooProxy::RemoveDeathRecipient() -{ - std::lock_guard lock(mutex_); - if (!remote_ || !deathRecipient_) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - deathRecipient_ = nullptr; - remoteDiedCallback_ = nullptr; -} - -void FooProxy::OnRemoteDied(const wptr& remote) -{ - if (remoteDiedCallback_) { - remoteDiedCallback_(remote); - } - RemoveDeathRecipient(); -} - ErrCode FooProxy::void_test_func() { MessageParcel data; diff --git a/test/sa_test/keyword_oneway/target_cpp/foo_proxy.h.txt b/test/sa_test/keyword_oneway/target_cpp/foo_proxy.h.txt index 298b4ac..5cdd78a 100644 --- a/test/sa_test/keyword_oneway/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/keyword_oneway/target_cpp/foo_proxy.h.txt @@ -16,21 +16,19 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include #include #include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy(const sptr& remote); + explicit FooProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} - ~FooProxy() override; - - void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override - { - remoteDiedCallback_ = callback; - } + virtual ~FooProxy() + {} ErrCode void_test_func() override; @@ -68,26 +66,7 @@ public: const sptr& inParam) override; private: - class FooRecipient : public IRemoteObject::DeathRecipient { - public: - explicit FooRecipient(FooProxy& client) : client_(client) {} - ~FooRecipient() override = default; - void OnRemoteDied(const wptr& remote) override - { - client_.OnRemoteDied(remote); - } - private: - FooProxy& client_; - }; - - void RemoveDeathRecipient(); - void OnRemoteDied(const wptr& remote); - static inline BrokerDelegator delegator_; - sptr remote_; - sptr deathRecipient_; - OnRemoteDiedCallback remoteDiedCallback_; - std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/keyword_oneway/target_cpp/ifoo.h.txt b/test/sa_test/keyword_oneway/target_cpp/ifoo.h.txt index 3aa42e5..432d0bc 100644 --- a/test/sa_test/keyword_oneway/target_cpp/ifoo.h.txt +++ b/test/sa_test/keyword_oneway/target_cpp/ifoo.h.txt @@ -42,14 +42,10 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC, }; -using OnRemoteDiedCallback = std::function&)>; - class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); - virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} - virtual ErrCode void_test_func() = 0; virtual ErrCode bool_test_func( diff --git a/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt index 5b07e0c..1850316 100644 --- a/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_array/target_cpp/foo_proxy.cpp.txt @@ -16,52 +16,6 @@ #include "foo_proxy.h" namespace test { -FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) -{ - std::lock_guard lock(mutex_); - if (remote_ && remote_ != remote) { - RemoveDeathRecipient(); - } - if (remote) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) FooRecipient(*this); - if (!deathRecipient_) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } -} - -FooProxy::~FooProxy() -{ - RemoveDeathRecipient(); -} - -void FooProxy::RemoveDeathRecipient() -{ - std::lock_guard lock(mutex_); - if (!remote_ || !deathRecipient_) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - deathRecipient_ = nullptr; - remoteDiedCallback_ = nullptr; -} - -void FooProxy::OnRemoteDied(const wptr& remote) -{ - if (remoteDiedCallback_) { - remoteDiedCallback_(remote); - } - RemoveDeathRecipient(); -} - ErrCode FooProxy::void_test_func() { MessageParcel data; diff --git a/test/sa_test/type_array/target_cpp/foo_proxy.h.txt b/test/sa_test/type_array/target_cpp/foo_proxy.h.txt index 457b9d4..20eddbb 100644 --- a/test/sa_test/type_array/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_array/target_cpp/foo_proxy.h.txt @@ -16,21 +16,19 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include #include #include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy(const sptr& remote); + explicit FooProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} - ~FooProxy() override; - - void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override - { - remoteDiedCallback_ = callback; - } + virtual ~FooProxy() + {} ErrCode void_test_func() override; @@ -101,26 +99,7 @@ public: std::vector>& funcResult) override; private: - class FooRecipient : public IRemoteObject::DeathRecipient { - public: - explicit FooRecipient(FooProxy& client) : client_(client) {} - ~FooRecipient() override = default; - void OnRemoteDied(const wptr& remote) override - { - client_.OnRemoteDied(remote); - } - private: - FooProxy& client_; - }; - - void RemoveDeathRecipient(); - void OnRemoteDied(const wptr& remote); - static inline BrokerDelegator delegator_; - sptr remote_; - sptr deathRecipient_; - OnRemoteDiedCallback remoteDiedCallback_; - std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/type_array/target_cpp/ifoo.h.txt b/test/sa_test/type_array/target_cpp/ifoo.h.txt index a7a41bc..76621b2 100644 --- a/test/sa_test/type_array/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_array/target_cpp/ifoo.h.txt @@ -43,14 +43,10 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC, }; -using OnRemoteDiedCallback = std::function&)>; - class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); - virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} - virtual ErrCode void_test_func() = 0; virtual ErrCode bool_test_func( diff --git a/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt index 75cd232..a3514c2 100644 --- a/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_list/target_cpp/foo_proxy.cpp.txt @@ -16,52 +16,6 @@ #include "foo_proxy.h" namespace test { -FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) -{ - std::lock_guard lock(mutex_); - if (remote_ && remote_ != remote) { - RemoveDeathRecipient(); - } - if (remote) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) FooRecipient(*this); - if (!deathRecipient_) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } -} - -FooProxy::~FooProxy() -{ - RemoveDeathRecipient(); -} - -void FooProxy::RemoveDeathRecipient() -{ - std::lock_guard lock(mutex_); - if (!remote_ || !deathRecipient_) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - deathRecipient_ = nullptr; - remoteDiedCallback_ = nullptr; -} - -void FooProxy::OnRemoteDied(const wptr& remote) -{ - if (remoteDiedCallback_) { - remoteDiedCallback_(remote); - } - RemoveDeathRecipient(); -} - ErrCode FooProxy::bool_test_func( const std::vector& inParam, std::vector& outParam, diff --git a/test/sa_test/type_list/target_cpp/foo_proxy.h.txt b/test/sa_test/type_list/target_cpp/foo_proxy.h.txt index 8d5e82d..473a993 100644 --- a/test/sa_test/type_list/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_list/target_cpp/foo_proxy.h.txt @@ -16,21 +16,19 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include #include #include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy(const sptr& remote); + explicit FooProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} - ~FooProxy() override; - - void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override - { - remoteDiedCallback_ = callback; - } + virtual ~FooProxy() + {} ErrCode bool_test_func( const std::vector& inParam, @@ -99,26 +97,7 @@ public: std::vector>& funcResult) override; private: - class FooRecipient : public IRemoteObject::DeathRecipient { - public: - explicit FooRecipient(FooProxy& client) : client_(client) {} - ~FooRecipient() override = default; - void OnRemoteDied(const wptr& remote) override - { - client_.OnRemoteDied(remote); - } - private: - FooProxy& client_; - }; - - void RemoveDeathRecipient(); - void OnRemoteDied(const wptr& remote); - static inline BrokerDelegator delegator_; - sptr remote_; - sptr deathRecipient_; - OnRemoteDiedCallback remoteDiedCallback_; - std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/type_list/target_cpp/ifoo.h.txt b/test/sa_test/type_list/target_cpp/ifoo.h.txt index b9c064f..f7eafdf 100644 --- a/test/sa_test/type_list/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_list/target_cpp/ifoo.h.txt @@ -42,14 +42,10 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC, }; -using OnRemoteDiedCallback = std::function&)>; - class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); - virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} - virtual ErrCode bool_test_func( const std::vector& inParam, std::vector& outParam, diff --git a/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt index 5888d66..b879945 100644 --- a/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_map/target_cpp/foo_proxy.cpp.txt @@ -16,52 +16,6 @@ #include "foo_proxy.h" namespace test { -FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) -{ - std::lock_guard lock(mutex_); - if (remote_ && remote_ != remote) { - RemoveDeathRecipient(); - } - if (remote) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) FooRecipient(*this); - if (!deathRecipient_) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } -} - -FooProxy::~FooProxy() -{ - RemoveDeathRecipient(); -} - -void FooProxy::RemoveDeathRecipient() -{ - std::lock_guard lock(mutex_); - if (!remote_ || !deathRecipient_) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - deathRecipient_ = nullptr; - remoteDiedCallback_ = nullptr; -} - -void FooProxy::OnRemoteDied(const wptr& remote) -{ - if (remoteDiedCallback_) { - remoteDiedCallback_(remote); - } - RemoveDeathRecipient(); -} - ErrCode FooProxy::void_test_func() { MessageParcel data; diff --git a/test/sa_test/type_map/target_cpp/foo_proxy.h.txt b/test/sa_test/type_map/target_cpp/foo_proxy.h.txt index c8a2f0d..5217062 100644 --- a/test/sa_test/type_map/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_map/target_cpp/foo_proxy.h.txt @@ -16,21 +16,19 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include #include #include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy(const sptr& remote); + explicit FooProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} - ~FooProxy() override; - - void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override - { - remoteDiedCallback_ = callback; - } + virtual ~FooProxy() + {} ErrCode void_test_func() override; @@ -101,26 +99,7 @@ public: std::unordered_map, sptr>& funcResult) override; private: - class FooRecipient : public IRemoteObject::DeathRecipient { - public: - explicit FooRecipient(FooProxy& client) : client_(client) {} - ~FooRecipient() override = default; - void OnRemoteDied(const wptr& remote) override - { - client_.OnRemoteDied(remote); - } - private: - FooProxy& client_; - }; - - void RemoveDeathRecipient(); - void OnRemoteDied(const wptr& remote); - static inline BrokerDelegator delegator_; - sptr remote_; - sptr deathRecipient_; - OnRemoteDiedCallback remoteDiedCallback_; - std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/type_map/target_cpp/ifoo.h.txt b/test/sa_test/type_map/target_cpp/ifoo.h.txt index fb9e6c2..00d072d 100644 --- a/test/sa_test/type_map/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_map/target_cpp/ifoo.h.txt @@ -43,14 +43,10 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC, }; -using OnRemoteDiedCallback = std::function&)>; - class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); - virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} - virtual ErrCode void_test_func() = 0; virtual ErrCode bool_test_func( diff --git a/test/sa_test/type_single/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_single/target_cpp/foo_proxy.cpp.txt index 89baf17..5a1b617 100644 --- a/test/sa_test/type_single/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_single/target_cpp/foo_proxy.cpp.txt @@ -16,52 +16,6 @@ #include "foo_proxy.h" namespace test { -FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) -{ - std::lock_guard lock(mutex_); - if (remote_ && remote_ != remote) { - RemoveDeathRecipient(); - } - if (remote) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) FooRecipient(*this); - if (!deathRecipient_) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } -} - -FooProxy::~FooProxy() -{ - RemoveDeathRecipient(); -} - -void FooProxy::RemoveDeathRecipient() -{ - std::lock_guard lock(mutex_); - if (!remote_ || !deathRecipient_) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - deathRecipient_ = nullptr; - remoteDiedCallback_ = nullptr; -} - -void FooProxy::OnRemoteDied(const wptr& remote) -{ - if (remoteDiedCallback_) { - remoteDiedCallback_(remote); - } - RemoveDeathRecipient(); -} - ErrCode FooProxy::void_test_func() { MessageParcel data; diff --git a/test/sa_test/type_single/target_cpp/foo_proxy.h.txt b/test/sa_test/type_single/target_cpp/foo_proxy.h.txt index 2dcbd01..cd2eb91 100644 --- a/test/sa_test/type_single/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_single/target_cpp/foo_proxy.h.txt @@ -16,21 +16,19 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include #include #include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy(const sptr& remote); + explicit FooProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} - ~FooProxy() override; - - void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override - { - remoteDiedCallback_ = callback; - } + virtual ~FooProxy() + {} ErrCode void_test_func() override; @@ -107,26 +105,7 @@ public: sptr& funcResult) override; private: - class FooRecipient : public IRemoteObject::DeathRecipient { - public: - explicit FooRecipient(FooProxy& client) : client_(client) {} - ~FooRecipient() override = default; - void OnRemoteDied(const wptr& remote) override - { - client_.OnRemoteDied(remote); - } - private: - FooProxy& client_; - }; - - void RemoveDeathRecipient(); - void OnRemoteDied(const wptr& remote); - static inline BrokerDelegator delegator_; - sptr remote_; - sptr deathRecipient_; - OnRemoteDiedCallback remoteDiedCallback_; - std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/type_single/target_cpp/ifoo.h.txt b/test/sa_test/type_single/target_cpp/ifoo.h.txt index 36aa091..63a46ae 100644 --- a/test/sa_test/type_single/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_single/target_cpp/ifoo.h.txt @@ -45,14 +45,10 @@ enum class IFooIpcCode { COMMAND_INTERFACE_TEST_FUNC2, }; -using OnRemoteDiedCallback = std::function&)>; - class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); - virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} - virtual ErrCode void_test_func() = 0; virtual ErrCode bool_test_func( diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt index 9759a8d..6c7c62b 100644 --- a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt @@ -16,52 +16,6 @@ #include "foo_proxy.h" namespace test { -FooProxy::FooProxy(const sptr& remote) : IRemoteProxy(remote) -{ - std::lock_guard lock(mutex_); - if (remote_ && remote_ != remote) { - RemoveDeathRecipient(); - } - if (remote) { - if (!remote->IsProxyObject()) { - return; - } - deathRecipient_ = new (std::nothrow) FooRecipient(*this); - if (!deathRecipient_) { - return; - } - if (!remote->AddDeathRecipient(deathRecipient_)) { - return; - } - remote_ = remote; - } -} - -FooProxy::~FooProxy() -{ - RemoveDeathRecipient(); -} - -void FooProxy::RemoveDeathRecipient() -{ - std::lock_guard lock(mutex_); - if (!remote_ || !deathRecipient_) { - return; - } - remote_->RemoveDeathRecipient(deathRecipient_); - remote_ = nullptr; - deathRecipient_ = nullptr; - remoteDiedCallback_ = nullptr; -} - -void FooProxy::OnRemoteDied(const wptr& remote) -{ - if (remoteDiedCallback_) { - remoteDiedCallback_(remote); - } - RemoveDeathRecipient(); -} - ErrCode FooProxy::uchar_test_func( uint8_t inParam, uint8_t& outParam, diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt index 70b5186..78ac2a3 100644 --- a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt @@ -16,21 +16,19 @@ #ifndef TEST_FOOPROXY_H #define TEST_FOOPROXY_H -#include #include #include "ifoo.h" namespace test { class FooProxy : public IRemoteProxy { public: - explicit FooProxy(const sptr& remote); + explicit FooProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} - ~FooProxy() override; - - void RegisterOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override - { - remoteDiedCallback_ = callback; - } + virtual ~FooProxy() + {} ErrCode uchar_test_func( uint8_t inParam, @@ -69,26 +67,7 @@ public: sptr& funcResult) override; private: - class FooRecipient : public IRemoteObject::DeathRecipient { - public: - explicit FooRecipient(FooProxy& client) : client_(client) {} - ~FooRecipient() override = default; - void OnRemoteDied(const wptr& remote) override - { - client_.OnRemoteDied(remote); - } - private: - FooProxy& client_; - }; - - void RemoveDeathRecipient(); - void OnRemoteDied(const wptr& remote); - static inline BrokerDelegator delegator_; - sptr remote_; - sptr deathRecipient_; - OnRemoteDiedCallback remoteDiedCallback_; - std::mutex mutex_; }; } // namespace test #endif // TEST_FOOPROXY_H diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt index 82e152d..dd8d7c1 100644 --- a/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt @@ -31,14 +31,10 @@ enum class IFooIpcCode { COMMAND_REMOTE_OBJECT_TEST_FUNC, }; -using OnRemoteDiedCallback = std::function&)>; - class IFoo : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); - virtual void RegisterOnRemoteDiedCallback([[maybe_unused]] const OnRemoteDiedCallback& callback) {} - virtual ErrCode uchar_test_func( uint8_t inParam, uint8_t& outParam, -- Gitee