diff --git a/common/include/constants/distributed_camera_constants.h b/common/include/constants/distributed_camera_constants.h index ca57b9f6e0bbc2a126acf27c7ea151f7dfa37d6b..e1f3eb3e1a8323cf23e0b232fd1c2facc1fa80dd 100644 --- a/common/include/constants/distributed_camera_constants.h +++ b/common/include/constants/distributed_camera_constants.h @@ -83,6 +83,15 @@ const uint32_t DCAMERA_MAX_RECV_DATA_LEN = 104857600; const uint16_t DCAMERA_MAX_RECV_EXT_LEN = 65535; const uint32_t DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID = 4803; const uint32_t DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID = 4804; +const std::string SESSION_HEAD = "ohos.dhardware.dcamera_"; +const std::string DEVICE_ID_0 = "device/0"; +const std::string DEVICE_ID_1 = "device/1"; +const std::string SENDER_SESSION_NAME_CONTROL = "_control_sender"; +const std::string SENDER_SESSION_NAME_DATA_SNAPSHOT = "_dataSnapshot_sender"; +const std::string SENDER_SESSION_NAME_DATA_CONTINUE = "_dataContinue_sender"; +const std::string RECEIVER_SESSION_NAME_CONTROL = "_control_receiver"; +const std::string RECEIVER_SESSION_NAME_DATA_SNAPSHOT = "_dataSnapshot_receiver"; +const std::string RECEIVER_SESSION_NAME_DATA_CONTINUE = "_dataContinue_receiver"; const std::string DCAMERA_PKG_NAME = "ohos.dhardware.dcamera"; const std::string SNAP_SHOT_SESSION_FLAG = "dataSnapshot"; const std::string CONTINUE_SESSION_FLAG = "dataContinue"; diff --git a/interfaces/inner_kits/native_cpp/camera_sink/include/distributed_camera_sink_proxy.h b/interfaces/inner_kits/native_cpp/camera_sink/include/distributed_camera_sink_proxy.h index 498a105f1fe4d3f5d6abc5ce591f1488a4581fcc..cfd6e5d3f1580f195949ab011245ebaa1f1b292f 100644 --- a/interfaces/inner_kits/native_cpp/camera_sink/include/distributed_camera_sink_proxy.h +++ b/interfaces/inner_kits/native_cpp/camera_sink/include/distributed_camera_sink_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -36,11 +36,6 @@ public: int32_t ReleaseSink() override; int32_t SubscribeLocalHardware(const std::string& dhId, const std::string& parameters) override; int32_t UnsubscribeLocalHardware(const std::string& dhId) override; - int32_t StopCapture(const std::string& dhId) override; - int32_t ChannelNeg(const std::string& dhId, std::string& channelInfo) override; - int32_t GetCameraInfo(const std::string& dhId, std::string& cameraInfo) override; - int32_t OpenChannel(const std::string& dhId, std::string& openInfo) override; - int32_t CloseChannel(const std::string& dhId) override; int32_t PauseDistributedHardware(const std::string &networkId) override; int32_t ResumeDistributedHardware(const std::string &networkId) override; int32_t StopDistributedHardware(const std::string &networkId) override; diff --git a/interfaces/inner_kits/native_cpp/camera_sink/include/idistributed_camera_sink.h b/interfaces/inner_kits/native_cpp/camera_sink/include/idistributed_camera_sink.h index 34ad338983d98950b55ed327d8983f62edf4fa15..36b8e0fe66dffe274dbe2b4ccd10707fcd4a13df 100644 --- a/interfaces/inner_kits/native_cpp/camera_sink/include/idistributed_camera_sink.h +++ b/interfaces/inner_kits/native_cpp/camera_sink/include/idistributed_camera_sink.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -31,11 +31,6 @@ public: virtual int32_t ReleaseSink() = 0; virtual int32_t SubscribeLocalHardware(const std::string& dhId, const std::string& parameters) = 0; virtual int32_t UnsubscribeLocalHardware(const std::string& dhId) = 0; - virtual int32_t StopCapture(const std::string& dhId) = 0; - virtual int32_t ChannelNeg(const std::string& dhId, std::string& channelInfo) = 0; - virtual int32_t GetCameraInfo(const std::string& dhId, std::string& cameraInfo) = 0; - virtual int32_t OpenChannel(const std::string& dhId, std::string& openInfo) = 0; - virtual int32_t CloseChannel(const std::string& dhId) = 0; virtual int32_t PauseDistributedHardware(const std::string &networkId) = 0; virtual int32_t ResumeDistributedHardware(const std::string &networkId) = 0; virtual int32_t StopDistributedHardware(const std::string &networkId) = 0; diff --git a/interfaces/inner_kits/native_cpp/camera_sink/src/distributed_camera_sink_proxy.cpp b/interfaces/inner_kits/native_cpp/camera_sink/src/distributed_camera_sink_proxy.cpp index cb2ea35aa9fd89e63362122562ddeca5d6a09e1e..6792567f5ae9d0d64eef09c3e7a4ab03dde23bd6 100644 --- a/interfaces/inner_kits/native_cpp/camera_sink/src/distributed_camera_sink_proxy.cpp +++ b/interfaces/inner_kits/native_cpp/camera_sink/src/distributed_camera_sink_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -141,155 +141,6 @@ int32_t DistributedCameraSinkProxy::UnsubscribeLocalHardware(const std::string& return result; } -int32_t DistributedCameraSinkProxy::StopCapture(const std::string& dhId) -{ - DHLOGI("dhId: %{public}s", GetAnonyString(dhId).c_str()); - if (dhId.empty() || dhId.size() > DID_MAX_SIZE) { - DHLOGE("params is invalid"); - return DCAMERA_BAD_VALUE; - } - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null"); - return DCAMERA_BAD_VALUE; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option = { MessageOption::TF_ASYNC }; - if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) { - DHLOGE("write token failed"); - return DCAMERA_BAD_VALUE; - } - if (!data.WriteString(dhId)) { - DHLOGE("write params failed"); - return DCAMERA_BAD_VALUE; - } - remote->SendRequest(static_cast(IDCameraSinkInterfaceCode::STOP_CAPTURE), data, reply, option); - int32_t result = reply.ReadInt32(); - DHLOGI("async dhId: %{public}s", GetAnonyString(dhId).c_str()); - return result; -} - -int32_t DistributedCameraSinkProxy::ChannelNeg(const std::string& dhId, std::string& channelInfo) -{ - DHLOGI("dhId: %{public}s", GetAnonyString(dhId).c_str()); - if (dhId.empty() || dhId.size() > DID_MAX_SIZE || channelInfo.empty() || - channelInfo.size() > PARAM_MAX_SIZE) { - DHLOGE("params is invalid"); - return DCAMERA_BAD_VALUE; - } - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null"); - return DCAMERA_BAD_VALUE; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) { - DHLOGE("write token failed"); - return DCAMERA_BAD_VALUE; - } - if (!data.WriteString(dhId) || !data.WriteString(channelInfo)) { - DHLOGE("write params failed"); - return DCAMERA_BAD_VALUE; - } - remote->SendRequest(static_cast(IDCameraSinkInterfaceCode::CHANNEL_NEG), data, reply, option); - int32_t result = reply.ReadInt32(); - return result; -} - -int32_t DistributedCameraSinkProxy::GetCameraInfo(const std::string& dhId, std::string& cameraInfo) -{ - DHLOGI("dhId: %{public}s", GetAnonyString(dhId).c_str()); - if (dhId.empty() || dhId.size() > DID_MAX_SIZE) { - DHLOGE("parmas is invalid"); - return DCAMERA_BAD_VALUE; - } - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null"); - return DCAMERA_BAD_VALUE; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) { - DHLOGE("write token failed"); - return DCAMERA_BAD_VALUE; - } - if (!data.WriteString(dhId) || !data.WriteString(cameraInfo)) { - DHLOGE("write params failed"); - return DCAMERA_BAD_VALUE; - } - remote->SendRequest(static_cast(IDCameraSinkInterfaceCode::GET_CAMERA_INFO), data, reply, option); - int32_t result = reply.ReadInt32(); - return result; -} - -int32_t DistributedCameraSinkProxy::OpenChannel(const std::string& dhId, std::string& openInfo) -{ - DHLOGI("DistributedCameraSinkProxy OpenChannel Begin,dhId: %{public}s", GetAnonyString(dhId).c_str()); - if (dhId.empty() || dhId.size() > DID_MAX_SIZE || openInfo.empty() || - openInfo.size() > PARAM_MAX_SIZE) { - DHLOGE("params is invalid"); - return DCAMERA_BAD_VALUE; - } - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null"); - return DCAMERA_BAD_VALUE; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) { - DHLOGE("write token failed"); - return DCAMERA_BAD_VALUE; - } - if (!data.WriteString(dhId) || !data.WriteString(openInfo)) { - DHLOGE("write params failed"); - return DCAMERA_BAD_VALUE; - } - remote->SendRequest(static_cast(IDCameraSinkInterfaceCode::OPEN_CHANNEL), data, reply, option); - int32_t result = reply.ReadInt32(); - DHLOGI("DistributedCameraSinkProxy OpenChannel End,result: %{public}d", result); - return result; -} - -int32_t DistributedCameraSinkProxy::CloseChannel(const std::string& dhId) -{ - DHLOGI("dhId: %{public}s", GetAnonyString(dhId).c_str()); - if (dhId.empty() || dhId.size() > DID_MAX_SIZE) { - DHLOGE("params is invalid"); - return DCAMERA_BAD_VALUE; - } - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("remote service is null"); - return DCAMERA_BAD_VALUE; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) { - DHLOGE("write token failed"); - return DCAMERA_BAD_VALUE; - } - if (!data.WriteString(dhId)) { - DHLOGE("write params failed"); - return DCAMERA_BAD_VALUE; - } - remote->SendRequest(static_cast(IDCameraSinkInterfaceCode::CLOSE_CHANNEL), data, reply, option); - int32_t result = reply.ReadInt32(); - return result; -} - int32_t DistributedCameraSinkProxy::PauseDistributedHardware(const std::string &networkId) { DHLOGI("networkId: %{public}s", GetAnonyString(networkId).c_str()); diff --git a/interfaces/inner_kits/native_cpp/camera_source/include/distributed_camera_source_proxy.h b/interfaces/inner_kits/native_cpp/camera_source/include/distributed_camera_source_proxy.h index 356735e031cf24d333d00a76d4fa8814a010b97f..a6585895e34cd752df67df59b265725b9fec9635 100644 --- a/interfaces/inner_kits/native_cpp/camera_source/include/distributed_camera_source_proxy.h +++ b/interfaces/inner_kits/native_cpp/camera_source/include/distributed_camera_source_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -40,7 +40,6 @@ public: const std::string& reqId, const EnableParam& param) override; int32_t UnregisterDistributedHardware(const std::string& devId, const std::string& dhId, const std::string& reqId) override; - int32_t DCameraNotify(const std::string& devId, const std::string& dhId, std::string& events) override; private: bool CheckRegParams(const std::string& devId, const std::string& dhId, diff --git a/interfaces/inner_kits/native_cpp/camera_source/include/idistributed_camera_source.h b/interfaces/inner_kits/native_cpp/camera_source/include/idistributed_camera_source.h index 8a36f3391255b8b9d1403170703440c840e141ee..116e1999ac98866e254464b166ecd35eb1194b5e 100644 --- a/interfaces/inner_kits/native_cpp/camera_source/include/idistributed_camera_source.h +++ b/interfaces/inner_kits/native_cpp/camera_source/include/idistributed_camera_source.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -34,7 +34,6 @@ public: const std::string& reqId, const EnableParam& param) = 0; virtual int32_t UnregisterDistributedHardware(const std::string& devId, const std::string& dhId, const std::string& reqId) = 0; - virtual int32_t DCameraNotify(const std::string& devId, const std::string& dhId, std::string& events) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/camera_source/src/distributed_camera_source_proxy.cpp b/interfaces/inner_kits/native_cpp/camera_source/src/distributed_camera_source_proxy.cpp index bcbc124a071b44c5bc35158c2f118d1202fe3ad4..bace57deea5564db9c2e7f3b9c664ae67192ea80 100644 --- a/interfaces/inner_kits/native_cpp/camera_source/src/distributed_camera_source_proxy.cpp +++ b/interfaces/inner_kits/native_cpp/camera_source/src/distributed_camera_source_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -180,38 +180,6 @@ bool DistributedCameraSourceProxy::CheckUnregParams(const std::string& devId, co return true; } -int32_t DistributedCameraSourceProxy::DCameraNotify(const std::string& devId, const std::string& dhId, - std::string& events) -{ - DHLOGI("DCameraNotify devId: %{public}s dhId: %{public}s events: %{public}s", - GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), events.c_str()); - if (!CheckNotifyParams(devId, dhId, events)) { - DHLOGE("input is invalid"); - return DCAMERA_BAD_VALUE; - } - sptr remote = Remote(); - if (remote == nullptr) { - DHLOGE("DistributedCameraSourceProxy remote service null"); - return DCAMERA_BAD_VALUE; - } - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(DistributedCameraSourceProxy::GetDescriptor())) { - DHLOGE("write token failed"); - return DCAMERA_BAD_VALUE; - } - - if (!data.WriteString(devId) || !data.WriteString(dhId) || !data.WriteString(events)) { - DHLOGE("write params failed"); - return DCAMERA_BAD_VALUE; - } - remote->SendRequest(static_cast(IDCameraSourceInterfaceCode::CAMERA_NOTIFY), - data, reply, option); - int32_t result = reply.ReadInt32(); - return result; -} - bool DistributedCameraSourceProxy::CheckNotifyParams(const std::string& devId, const std::string& dhId, std::string& events) { diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/BUILD.gn index aa4e576f09a28190bc878d4b50fb7c5df18b99b1..6bddf62116a8bd19f1f42d69fd1655dd9cbee1b1 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/BUILD.gn @@ -30,24 +30,15 @@ group("fuzztest") { "sinkhandlerunsubscribelocalhardware_fuzzer:fuzztest", "sinkonloadsystemabilityfail_fuzzer:fuzztest", "sinkonloadsystemabilitysuccess_fuzzer:fuzztest", - "sinkproxychannelneg_fuzzer:fuzztest", - "sinkproxyclosechannel_fuzzer:fuzztest", - "sinkproxygetcamerainfo_fuzzer:fuzztest", "sinkproxyinitsink_fuzzer:fuzztest", - "sinkproxyopenchannel_fuzzer:fuzztest", "sinkproxyreleasesink_fuzzer:fuzztest", - "sinkproxystopcapture_fuzzer:fuzztest", "sinkproxysubscribelocalhardware_fuzzer:fuzztest", "sinkproxyunsubscribelocalhardware_fuzzer:fuzztest", - "sinkservicechannelneg_fuzzer:fuzztest", - "sinkserviceclosechannel_fuzzer:fuzztest", "sinkservicegetcamerainfo_fuzzer:fuzztest", "sinkserviceinitsink_fuzzer:fuzztest", - "sinkserviceopenchannel_fuzzer:fuzztest", "sinkservicepausedistributedhardware_fuzzer:fuzztest", "sinkservicereleasesink_fuzzer:fuzztest", "sinkserviceresumedistributedhardware_fuzzer:fuzztest", - "sinkservicestopcapture_fuzzer:fuzztest", "sinkservicestopdistributedhardware_fuzzer:fuzztest", "sinkservicesubscribelocalhardware_fuzzer:fuzztest", "sinkserviceunsubscribelocalhardware_fuzzer:fuzztest", diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/BUILD.gn deleted file mode 100644 index bdabd840d9b72079b9ea2f1d20e0e238621c0813..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/BUILD.gn +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright (c) 2022-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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SinkProxyChannelNegFuzzTest") { - module_out_path = "${fuzz_test_output_path}/sinkproxychannelneg" - - fuzz_config_file = "${innerkits_path}/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer" - - include_dirs = [ - "include", - "${common_path}/include", - "${common_path}/include/constants", - "${innerkits_path}/native_cpp/camera_sink/include", - "${innerkits_path}/native_cpp/camera_sink/include/callback", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - sources = [ "sinkproxychannelneg_fuzzer.cpp" ] - - deps = [ - "${common_path}:distributed_camera_utils", - "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SinkProxyChannelNegFuzzTest\"", - "LOG_DOMAIN=0xD004150", - ] - - external_deps = [ - "c_utils:utils", - "distributed_hardware_fwk:distributedhardwareutils", - "hilog:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SinkProxyChannelNegFuzzTest" ] -} -############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/corpus/init deleted file mode 100644 index bc977bd9738ee9a70b362067f57a9c63d3adb801..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2022 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. - -FUZZ \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/project.xml deleted file mode 100644 index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/sinkproxychannelneg_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/sinkproxychannelneg_fuzzer.cpp deleted file mode 100644 index 453b1ac2d78951fc650d65b9c374682dd72496ad..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/sinkproxychannelneg_fuzzer.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022 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 "sinkproxychannelneg_fuzzer.h" - -#include -#include - -#include "distributed_camera_constants.h" -#include "distributed_camera_sink_proxy.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void SinkProxyChannelNegFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - - std::string dhId(reinterpret_cast(data), size); - std::string channelInfo(reinterpret_cast(data), size); - - sptr samgr = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID); - std::shared_ptr dCSinkProxy = - std::make_shared(remoteObject); - - dCSinkProxy->ChannelNeg(dhId, channelInfo); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SinkProxyChannelNegFuzzTest(data, size); - return 0; -} - diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/sinkproxychannelneg_fuzzer.h b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/sinkproxychannelneg_fuzzer.h deleted file mode 100644 index 296d13ab4cb7fbb84833d82acd4dde57bc2c5283..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/sinkproxychannelneg_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 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 SINKPROXYCHANNELNEG_FUZZER_H -#define SINKPROXYCHANNELNEG_FUZZER_H - -#define FUZZ_PROJECT_NAME "sinkproxychannelneg_fuzzer" - -#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/BUILD.gn deleted file mode 100644 index 8be84c8c5acf6ef304a3f0ff27ed039db5ac3987..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/BUILD.gn +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright (c) 2022-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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SinkProxyCloseChannelFuzzTest") { - module_out_path = "${fuzz_test_output_path}/sinkproxyclosechannel" - - fuzz_config_file = "${innerkits_path}/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer" - - include_dirs = [ - "include", - "${common_path}/include", - "${common_path}/include/constants", - "${innerkits_path}/native_cpp/camera_sink/include", - "${innerkits_path}/native_cpp/camera_sink/include/callback", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - sources = [ "sinkproxyclosechannel_fuzzer.cpp" ] - - deps = [ - "${common_path}:distributed_camera_utils", - "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SinkProxyCloseChannelFuzzTest\"", - "LOG_DOMAIN=0xD004150", - ] - - external_deps = [ - "c_utils:utils", - "distributed_hardware_fwk:distributedhardwareutils", - "hilog:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SinkProxyCloseChannelFuzzTest" ] -} -############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/corpus/init deleted file mode 100644 index bc977bd9738ee9a70b362067f57a9c63d3adb801..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2022 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. - -FUZZ \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/project.xml deleted file mode 100644 index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/sinkproxyclosechannel_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/sinkproxyclosechannel_fuzzer.cpp deleted file mode 100644 index 1bf7996ecd684ed334b5c63272824377bfb01a75..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/sinkproxyclosechannel_fuzzer.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2022 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 "sinkproxyclosechannel_fuzzer.h" - -#include -#include - -#include "distributed_camera_constants.h" -#include "distributed_camera_sink_proxy.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void SinkProxyCloseChannelFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - std::string dhId(reinterpret_cast(data), size); - - sptr samgr = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID); - std::shared_ptr dCSinkProxy = - std::make_shared(remoteObject); - - dCSinkProxy->CloseChannel(dhId); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SinkProxyCloseChannelFuzzTest(data, size); - return 0; -} - diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/sinkproxyclosechannel_fuzzer.h b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/sinkproxyclosechannel_fuzzer.h deleted file mode 100644 index b6380e00a3e3db27bff2636179cd9bc426efbc7d..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/sinkproxyclosechannel_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 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 SINKPROXYCLOSECHANNEL_FUZZER_H -#define SINKPROXYCLOSECHANNEL_FUZZER_H - -#define FUZZ_PROJECT_NAME "sinkproxyclosechannel_fuzzer" - -#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer/BUILD.gn deleted file mode 100644 index b2dcd5d8026b343d567e473da7a38a0406189db0..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer/BUILD.gn +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright (c) 2022-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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SinkProxyGetCameraInfoFuzzTest") { - module_out_path = "${fuzz_test_output_path}/sinkproxygetcamerainfo" - - fuzz_config_file = "${innerkits_path}/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer" - - include_dirs = [ - "include", - "${common_path}/include", - "${common_path}/include/constants", - "${innerkits_path}/native_cpp/camera_sink/include", - "${innerkits_path}/native_cpp/camera_sink/include/callback", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - sources = [ "sinkproxygetcamerainfo_fuzzer.cpp" ] - - deps = [ - "${common_path}:distributed_camera_utils", - "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SinkProxyGetCameraInfoFuzzTest\"", - "LOG_DOMAIN=0xD004150", - ] - - external_deps = [ - "c_utils:utils", - "distributed_hardware_fwk:distributedhardwareutils", - "hilog:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SinkProxyGetCameraInfoFuzzTest" ] -} -############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer/corpus/init deleted file mode 100644 index bc977bd9738ee9a70b362067f57a9c63d3adb801..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2022 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. - -FUZZ \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer/project.xml deleted file mode 100644 index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer/sinkproxygetcamerainfo_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer/sinkproxygetcamerainfo_fuzzer.cpp deleted file mode 100644 index 09766a4f71bd643116e1d8f1385817f462f4924d..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer/sinkproxygetcamerainfo_fuzzer.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022 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 "sinkproxygetcamerainfo_fuzzer.h" - -#include -#include - -#include "distributed_camera_constants.h" -#include "distributed_camera_sink_proxy.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void SinkProxyGetCameraInfoFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - - std::string dhId(reinterpret_cast(data), size); - std::string cameraInfo(reinterpret_cast(data), size); - - sptr samgr = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID); - std::shared_ptr dCSinkProxy = - std::make_shared(remoteObject); - - dCSinkProxy->GetCameraInfo(dhId, cameraInfo); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SinkProxyGetCameraInfoFuzzTest(data, size); - return 0; -} - diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer/sinkproxygetcamerainfo_fuzzer.h b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer/sinkproxygetcamerainfo_fuzzer.h deleted file mode 100644 index 3b3f4abdebad220a57323f8dde4beabd9c16ac30..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer/sinkproxygetcamerainfo_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 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 SINKPROXYGETCAMERAINFO_FUZZER_H -#define SINKPROXYGETCAMERAINFO_FUZZER_H - -#define FUZZ_PROJECT_NAME "sinkproxygetcamerainfo_fuzzer" - -#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/BUILD.gn deleted file mode 100644 index 390f70043cfa7b30324bd78cdb812029be93b5d6..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/BUILD.gn +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright (c) 2022-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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SinkProxyOpenChannelFuzzTest") { - module_out_path = "${fuzz_test_output_path}/sinkproxyopenchannel" - - fuzz_config_file = "${innerkits_path}/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer" - - include_dirs = [ - "include", - "${common_path}/include", - "${common_path}/include/constants", - "${innerkits_path}/native_cpp/camera_sink/include", - "${innerkits_path}/native_cpp/camera_sink/include/callback", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - sources = [ "sinkproxyopenchannel_fuzzer.cpp" ] - - deps = [ - "${common_path}:distributed_camera_utils", - "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SinkProxyOpenChannelFuzzTest\"", - "LOG_DOMAIN=0xD004150", - ] - - external_deps = [ - "c_utils:utils", - "distributed_hardware_fwk:distributedhardwareutils", - "hilog:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SinkProxyOpenChannelFuzzTest" ] -} -############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/corpus/init deleted file mode 100644 index bc977bd9738ee9a70b362067f57a9c63d3adb801..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2022 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. - -FUZZ \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/project.xml deleted file mode 100644 index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/sinkproxyopenchannel_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/sinkproxyopenchannel_fuzzer.cpp deleted file mode 100644 index 495126a7992934391af257925eeb15104fd6c711..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/sinkproxyopenchannel_fuzzer.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022 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 "sinkproxyopenchannel_fuzzer.h" - -#include -#include - -#include "distributed_camera_constants.h" -#include "distributed_camera_sink_proxy.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void SinkProxyOpenChannelFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - - std::string dhId(reinterpret_cast(data), size); - std::string openInfo(reinterpret_cast(data), size); - - sptr samgr = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID); - std::shared_ptr dCSinkProxy = - std::make_shared(remoteObject); - - dCSinkProxy->OpenChannel(dhId, openInfo); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SinkProxyOpenChannelFuzzTest(data, size); - return 0; -} - diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/sinkproxyopenchannel_fuzzer.h b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/sinkproxyopenchannel_fuzzer.h deleted file mode 100644 index 079473ae07eedc9fc641a7fb1c60d56d8da7dcd2..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/sinkproxyopenchannel_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 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 SINKPROXYOPENCHANNEL_FUZZER_H -#define SINKPROXYOPENCHANNEL_FUZZER_H - -#define FUZZ_PROJECT_NAME "sinkproxyopenchannel_fuzzer" - -#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer/BUILD.gn deleted file mode 100644 index 41d470c04b6513860dbbf4c837461c207061d86d..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer/BUILD.gn +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright (c) 2022-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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SinkProxyStopCaptureFuzzTest") { - module_out_path = "${fuzz_test_output_path}/sinkproxystopcapture" - - fuzz_config_file = "${innerkits_path}/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer" - - include_dirs = [ - "include", - "${common_path}/include", - "${common_path}/include/constants", - "${innerkits_path}/native_cpp/camera_sink/include", - "${innerkits_path}/native_cpp/camera_sink/include/callback", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - sources = [ "sinkproxystopcapture_fuzzer.cpp" ] - - deps = [ - "${common_path}:distributed_camera_utils", - "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SinkProxyStopCaptureFuzzTest\"", - "LOG_DOMAIN=0xD004150", - ] - - external_deps = [ - "c_utils:utils", - "distributed_hardware_fwk:distributedhardwareutils", - "hilog:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SinkProxyStopCaptureFuzzTest" ] -} -############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer/corpus/init deleted file mode 100644 index bc977bd9738ee9a70b362067f57a9c63d3adb801..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2022 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. - -FUZZ \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer/project.xml deleted file mode 100644 index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer/sinkproxystopcapture_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer/sinkproxystopcapture_fuzzer.cpp deleted file mode 100644 index 7a75bbb6fda6c0fb9932796d32867ba5addb2477..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer/sinkproxystopcapture_fuzzer.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2022 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 "sinkproxystopcapture_fuzzer.h" - -#include -#include - -#include "distributed_camera_constants.h" -#include "distributed_camera_sink_proxy.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void SinkProxyStopCaptureFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - - std::string dhId(reinterpret_cast(data), size); - - sptr samgr = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID); - std::shared_ptr dCSinkProxy = - std::make_shared(remoteObject); - - dCSinkProxy->StopCapture(dhId); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SinkProxyStopCaptureFuzzTest(data, size); - return 0; -} - diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer/sinkproxystopcapture_fuzzer.h b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer/sinkproxystopcapture_fuzzer.h deleted file mode 100644 index 67eff92da34c47927e8f35cb8732b8f93e1a7e24..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer/sinkproxystopcapture_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 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 SINKPROXYSTOPCAPTURE_FUZZER_H -#define SINKPROXYSTOPCAPTURE_FUZZER_H - -#define FUZZ_PROJECT_NAME "sinkproxystopcapture_fuzzer" - -#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/BUILD.gn deleted file mode 100644 index f0b888ed9592e3066bdd2f04aeb0364734aee098..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/BUILD.gn +++ /dev/null @@ -1,85 +0,0 @@ -# Copyright (c) 2023-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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SinkServiceChannelNegFuzzTest") { - module_out_path = "${fuzz_test_output_path}/sinkservicechannelneg" - - fuzz_config_file = "${innerkits_path}/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer" - - include_dirs = [ - "include", - "${common_path}/include/constants", - "${common_path}/include/utils", - "${innerkits_path}/native_cpp/camera_sink/include", - "${innerkits_path}/native_cpp/camera_sink/include/callback", - "${services_path}/cameraservice/base/include", - "${services_path}/cameraservice/cameraoperator/client/include", - "${services_path}/cameraservice/sinkservice/include/distributedcamera", - "${services_path}/cameraservice/sinkservice/include/distributedcameramgr", - "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/interface", - "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/eventbus", - "${services_path}/data_process/include/utils", - "${services_path}/channel/include", - "${feeding_smoother_path}/base", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "sinkservicechannelneg_fuzzer.cpp" ] - - deps = [ - "${common_path}:distributed_camera_utils", - "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", - "${services_path}/cameraservice/sinkservice:distributed_camera_sink", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SinkServiceChannelNegFuzzTest\"", - "LOG_DOMAIN=0xD004150", - ] - - external_deps = [ - "cJSON:cjson", - "c_utils:utils", - "device_manager:devicemanagersdk", - "distributed_hardware_fwk:distributedhardwareutils", - "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.1", - "graphic_surface:surface", - "hilog:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SinkServiceChannelNegFuzzTest" ] -} -############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/corpus/init deleted file mode 100644 index e4ceac1bcd4e3b3427eb63cea0c28304064333cc..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# 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. - -FUZZ \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/project.xml deleted file mode 100644 index 4fdbc407f205680885fa42663163b5c987f123a6..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/sinkservicechannelneg_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/sinkservicechannelneg_fuzzer.cpp deleted file mode 100644 index 0a5996df154835b562463aac79e823803d611069..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/sinkservicechannelneg_fuzzer.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 "sinkservicechannelneg_fuzzer.h" - -#include -#include - -#include "dcamera_sink_callback.h" -#include "distributed_camera_constants.h" -#include "distributed_camera_sink_service.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void SinkServiceChannelNegFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - - std::string dhId = "1"; - std::string channelInfo(reinterpret_cast(data), size); - - std::shared_ptr sinkService = - std::make_shared(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, true); - sptr sinkCallback(new DCameraSinkCallback()); - std::shared_ptr sinkDevice = std::make_shared(dhId, sinkCallback); - sinkService->camerasMap_.emplace(dhId, sinkDevice); - sinkService->ChannelNeg(dhId, channelInfo); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SinkServiceChannelNegFuzzTest(data, size); - return 0; -} - diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/sinkservicechannelneg_fuzzer.h b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/sinkservicechannelneg_fuzzer.h deleted file mode 100644 index a59143c1c68d3bcce5475fd94e45a840377afbbb..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/sinkservicechannelneg_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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. - */ - -#ifndef SINKSERVICECHANNELNEG_FUZZER_H -#define SINKSERVICECHANNELNEG_FUZZER_H - -#define FUZZ_PROJECT_NAME "sinkservicechannelneg_fuzzer" - -#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/BUILD.gn deleted file mode 100644 index 570fc458fcb62efd4c2d8a55d137ad7bd6c39b79..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/BUILD.gn +++ /dev/null @@ -1,87 +0,0 @@ -# Copyright (c) 2023-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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SinkServiceCloseChannelFuzzTest") { - module_out_path = "${fuzz_test_output_path}/sinkserviceclosechannel" - - fuzz_config_file = "${innerkits_path}/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer" - - include_dirs = [ - "include", - "${common_path}/include/constants", - "${common_path}/include/utils", - "${innerkits_path}/native_cpp/camera_sink/include", - "${innerkits_path}/native_cpp/camera_sink/include/callback", - "${innerkits_path}/native_cpp/test/include", - "${services_path}/cameraservice/base/include", - "${services_path}/cameraservice/cameraoperator/client/include", - "${services_path}/cameraservice/sinkservice/include/distributedcamera", - "${services_path}/cameraservice/sinkservice/include/distributedcameramgr", - "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/interface", - "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/eventbus", - "${services_path}/data_process/include/utils", - "${services_path}/channel/include", - "${feeding_smoother_path}/base", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "sinkserviceclosechannel_fuzzer.cpp" ] - - deps = [ - "${common_path}:distributed_camera_utils", - "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", - "${services_path}/cameraservice/sinkservice:distributed_camera_sink", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SinkServiceCloseChannelFuzzTest\"", - "LOG_DOMAIN=0xD004150", - ] - - external_deps = [ - "cJSON:cjson", - "c_utils:utils", - "device_manager:devicemanagersdk", - "distributed_hardware_fwk:distributedhardwareutils", - "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.1", - "eventhandler:libeventhandler", - "graphic_surface:surface", - "hilog:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SinkServiceCloseChannelFuzzTest" ] -} -############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/corpus/init deleted file mode 100644 index e4ceac1bcd4e3b3427eb63cea0c28304064333cc..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# 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. - -FUZZ \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/project.xml deleted file mode 100644 index 4fdbc407f205680885fa42663163b5c987f123a6..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/sinkserviceclosechannel_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/sinkserviceclosechannel_fuzzer.cpp deleted file mode 100644 index ddbccb8be967531145b41bb526c2a9826a903e11..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/sinkserviceclosechannel_fuzzer.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 "sinkserviceclosechannel_fuzzer.h" - -#include -#include - -#include "dcamera_sink_controller.h" -#include "dcamera_sink_access_control.h" -#include "dcamera_sink_callback.h" -#include "distributed_camera_constants.h" -#include "distributed_camera_sink_service.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void SinkServiceCloseChannelFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - std::string dhId = "1"; - - std::shared_ptr sinkService = - std::make_shared(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, true); - sptr sinkCallback(new DCameraSinkCallback()); - std::shared_ptr sinkDevice = std::make_shared(dhId, sinkCallback); - sinkDevice->accessControl_ = std::make_shared(); - sinkDevice->controller_ = std::make_shared(sinkDevice->accessControl_, sinkCallback); - sinkService->camerasMap_.emplace(dhId, sinkDevice); - sinkService->CloseChannel(dhId); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SinkServiceCloseChannelFuzzTest(data, size); - return 0; -} - diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/sinkserviceclosechannel_fuzzer.h b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/sinkserviceclosechannel_fuzzer.h deleted file mode 100644 index a07f6f62cb7711b15c4d8a1271863d7c97d50b7c..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/sinkserviceclosechannel_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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. - */ - -#ifndef SINKSERVICECLOSECHANNEL_FUZZER_H -#define SINKSERVICECLOSECHANNEL_FUZZER_H - -#define FUZZ_PROJECT_NAME "sinkserviceclosechannel_fuzzer" - -#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/BUILD.gn deleted file mode 100644 index c3cc220b6e3313ab105b061e399f848b0a94d01c..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/BUILD.gn +++ /dev/null @@ -1,85 +0,0 @@ -# Copyright (c) 2023-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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SinkServiceOpenChannelFuzzTest") { - module_out_path = "${fuzz_test_output_path}/sinkserviceopenchannel" - - fuzz_config_file = "${innerkits_path}/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer" - - include_dirs = [ - "include", - "${common_path}/include/constants", - "${common_path}/include/utils", - "${innerkits_path}/native_cpp/camera_sink/include", - "${innerkits_path}/native_cpp/camera_sink/include/callback", - "${services_path}/cameraservice/base/include", - "${services_path}/cameraservice/cameraoperator/client/include", - "${services_path}/cameraservice/sinkservice/include/distributedcamera", - "${services_path}/cameraservice/sinkservice/include/distributedcameramgr", - "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/interface", - "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/eventbus", - "${services_path}/data_process/include/utils", - "${services_path}/channel/include", - "${feeding_smoother_path}/base", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "sinkserviceopenchannel_fuzzer.cpp" ] - - deps = [ - "${common_path}:distributed_camera_utils", - "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", - "${services_path}/cameraservice/sinkservice:distributed_camera_sink", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SinkServiceOpenChannelFuzzTest\"", - "LOG_DOMAIN=0xD004150", - ] - - external_deps = [ - "cJSON:cjson", - "c_utils:utils", - "device_manager:devicemanagersdk", - "distributed_hardware_fwk:distributedhardwareutils", - "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.1", - "graphic_surface:surface", - "hilog:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SinkServiceOpenChannelFuzzTest" ] -} -############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/corpus/init deleted file mode 100644 index e4ceac1bcd4e3b3427eb63cea0c28304064333cc..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# 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. - -FUZZ \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/project.xml deleted file mode 100644 index 4fdbc407f205680885fa42663163b5c987f123a6..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/sinkserviceopenchannel_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/sinkserviceopenchannel_fuzzer.cpp deleted file mode 100644 index 9b4f62e8f261f237271c5d2463ebbb16c0a5f570..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/sinkserviceopenchannel_fuzzer.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 "sinkserviceopenchannel_fuzzer.h" - -#include -#include - -#include "dcamera_sink_callback.h" -#include "distributed_camera_constants.h" -#include "distributed_camera_sink_service.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void SinkServiceOpenChannelFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - - std::string dhId = "1"; - std::string openInfo(reinterpret_cast(data), size); - - std::shared_ptr sinkService = - std::make_shared(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, true); - sptr sinkCallback(new DCameraSinkCallback()); - std::shared_ptr sinkDevice = std::make_shared(dhId, sinkCallback); - sinkService->camerasMap_.emplace(dhId, sinkDevice); - sinkService->OpenChannel(dhId, openInfo); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SinkServiceOpenChannelFuzzTest(data, size); - return 0; -} - diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/sinkserviceopenchannel_fuzzer.h b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/sinkserviceopenchannel_fuzzer.h deleted file mode 100644 index e6a6554e39951d7cbe6be202817bbf5440d73f8c..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/sinkserviceopenchannel_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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. - */ - -#ifndef SINKSERVICEOPENCHANNEL_FUZZER_H -#define SINKSERVICEOPENCHANNEL_FUZZER_H - -#define FUZZ_PROJECT_NAME "sinkserviceopenchannel_fuzzer" - -#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/BUILD.gn deleted file mode 100644 index fbb0c15e4b1e2c44b1d9809191f486d09b66037b..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/BUILD.gn +++ /dev/null @@ -1,86 +0,0 @@ -# Copyright (c) 2023-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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SinkServiceStopCaptureFuzzTest") { - module_out_path = "${fuzz_test_output_path}/sinkservicestopcapture" - - fuzz_config_file = "${innerkits_path}/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer" - - include_dirs = [ - "include", - "${common_path}/include/constants", - "${common_path}/include/utils", - "${innerkits_path}/native_cpp/camera_sink/include", - "${innerkits_path}/native_cpp/camera_sink/include/callback", - "${services_path}/cameraservice/base/include", - "${services_path}/cameraservice/cameraoperator/client/include", - "${services_path}/cameraservice/sinkservice/include/distributedcamera", - "${services_path}/cameraservice/sinkservice/include/distributedcameramgr", - "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/interface", - "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/eventbus", - "${services_path}/data_process/include/utils", - "${services_path}/channel/include", - "${feeding_smoother_path}/base", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "sinkservicestopcapture_fuzzer.cpp" ] - - deps = [ - "${common_path}:distributed_camera_utils", - "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", - "${services_path}/cameraservice/sinkservice:distributed_camera_sink", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SinkServiceStopCaptureFuzzTest\"", - "LOG_DOMAIN=0xD004150", - ] - - external_deps = [ - "cJSON:cjson", - "c_utils:utils", - "device_manager:devicemanagersdk", - "distributed_hardware_fwk:distributedhardwareutils", - "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.1", - "eventhandler:libeventhandler", - "graphic_surface:surface", - "hilog:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SinkServiceStopCaptureFuzzTest" ] -} -############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/corpus/init deleted file mode 100644 index e4ceac1bcd4e3b3427eb63cea0c28304064333cc..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# 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. - -FUZZ \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/project.xml deleted file mode 100644 index 4fdbc407f205680885fa42663163b5c987f123a6..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/sinkservicestopcapture_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/sinkservicestopcapture_fuzzer.cpp deleted file mode 100644 index 5dce7311ae8c33c299da2cc2abcac0072a2e71f2..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/sinkservicestopcapture_fuzzer.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2022 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 "sinkservicestopcapture_fuzzer.h" - -#include -#include - -#include "dcamera_sink_controller.h" -#include "dcamera_sink_access_control.h" -#include "dcamera_sink_callback.h" -#include "distributed_camera_constants.h" -#include "distributed_camera_sink_service.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void SinkServiceStopCaptureFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - - std::string dhId = "1"; - std::shared_ptr sinkService = - std::make_shared(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, true); - sptr sinkCallback(new DCameraSinkCallback()); - std::shared_ptr sinkDevice = std::make_shared(dhId, sinkCallback); - sinkDevice->accessControl_ = std::make_shared(); - sinkDevice->controller_ = std::make_shared(sinkDevice->accessControl_, sinkCallback); - sinkService->camerasMap_.emplace(dhId, sinkDevice); - - sinkService->StopCapture(dhId); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SinkServiceStopCaptureFuzzTest(data, size); - return 0; -} - diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/sinkservicestopcapture_fuzzer.h b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/sinkservicestopcapture_fuzzer.h deleted file mode 100644 index 82092fe7e89f5587d5a53b2bcadcb20fc3ce2d70..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/sinkservicestopcapture_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 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 SINKSERVICESTOPCAPTURE_FUZZER_H -#define SINKSERVICESTOPCAPTURE_FUZZER_H - -#define FUZZ_PROJECT_NAME "sinkservicestopcapture_fuzzer" - -#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/BUILD.gn index 9f8b5cd8720c0c0077850613659e8aa4aab8a9fb..78d4da40daf71b9f97deff4794d4ecbe83ba346b 100644 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 - 2023 Huawei Device Co., Ltd. +# Copyright (c) 2022 - 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 @@ -33,11 +33,9 @@ group("fuzztest") { "sourcehandlerunregisterdistributedhardware_fuzzer:fuzztest", "sourceonloadsystemabilityfail_fuzzer:fuzztest", "sourceonloadsystemabilitysuccess_fuzzer:fuzztest", - "sourceproxydcameranotify_fuzzer:fuzztest", "sourceproxyinitsource_fuzzer:fuzztest", "sourceproxyregisterdistributedhardware_fuzzer:fuzztest", "sourceproxyunregisterdistributedhardware_fuzzer:fuzztest", - "sourceservicedcameranotify_fuzzer:fuzztest", "sourceserviceinitsource_fuzzer:fuzztest", "sourceserviceregisterdistributedhardware_fuzzer:fuzztest", "sourceservicereleasesource_fuzzer:fuzztest", diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer/BUILD.gn deleted file mode 100644 index 5d5e88ad451b743a8b1c37ceabb2893b2bec3e50..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer/BUILD.gn +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright (c) 2022-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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SourceProxyDCameraNotifyFuzzTest") { - module_out_path = "${fuzz_test_output_path}/sourceproxydcameranotify" - - fuzz_config_file = "${innerkits_path}/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer" - - include_dirs = - [ "${innerkits_path}/native_cpp/camera_source/include/callback" ] - - include_dirs += [ - "include", - "${common_path}/include", - "${common_path}/include/constants", - "${innerkits_path}/native_cpp/camera_source/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - sources = [ "sourceproxydcameranotify_fuzzer.cpp" ] - - deps = [ - "${common_path}:distributed_camera_utils", - "${innerkits_path}/native_cpp/camera_source:distributed_camera_source_sdk", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SourceProxyDCameraNotifyFuzzTest\"", - "LOG_DOMAIN=0xD004150", - ] - - external_deps = [ - "c_utils:utils", - "distributed_hardware_fwk:distributedhardwareutils", - "hilog:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SourceProxyDCameraNotifyFuzzTest" ] -} -############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer/corpus/init deleted file mode 100644 index bc977bd9738ee9a70b362067f57a9c63d3adb801..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2022 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. - -FUZZ \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer/project.xml deleted file mode 100644 index 6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_fuzzer.cpp deleted file mode 100644 index 3a943a543a681985e4b90851fbbfb45f4c0710ef..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_fuzzer.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2022 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 "sourceproxydcameranotify_fuzzer.h" - -#include "dcamera_source_callback.h" -#include "distributed_camera_constants.h" -#include "distributed_camera_source_proxy.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void SourceProxyDCameraNotifyFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - - std::string dhId(reinterpret_cast(data), size); - std::string devId(reinterpret_cast(data), size); - std::string events(reinterpret_cast(data), size); - - sptr samgr = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID); - std::shared_ptr dCSourceProxy = - std::make_shared(remoteObject); - - dCSourceProxy->DCameraNotify(devId, dhId, events); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SourceProxyDCameraNotifyFuzzTest(data, size); - return 0; -} - diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_fuzzer.h b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_fuzzer.h deleted file mode 100644 index 895451671df6542da888ead9e0556155f1b31afe..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 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 SOURCEPROXYDCAMERANOTIFY_FUZZER_H -#define SOURCEPROXYDCAMERANOTIFY_FUZZER_H - -#define FUZZ_PROJECT_NAME "sourceproxydcameranotify_fuzzer" - -#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/BUILD.gn deleted file mode 100644 index 782645acd31795bbcd97793879b3fbb93a4ae23e..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/BUILD.gn +++ /dev/null @@ -1,83 +0,0 @@ -# Copyright (c) 2023-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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import( - "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SourceServiceDCameraNotifyFuzzTest") { - module_out_path = "${fuzz_test_output_path}/sourceservicedcameranotify" - - fuzz_config_file = "${innerkits_path}/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer" - - include_dirs = - [ "${innerkits_path}/native_cpp/camera_source/include/callback" ] - - include_dirs += [ - "include", - "${common_path}/include/constants", - "${common_path}/include/utils", - "${innerkits_path}/native_cpp/camera_source/include", - "${innerkits_path}/native_cpp/camera_source/include/callback", - "${services_path}/cameraservice/base/include", - "${services_path}/cameraservice/sourceservice/include/distributedcamera", - "${services_path}/cameraservice/sourceservice/include/distributedcameramgr", - "${services_path}/cameraservice/sourceservice/include/distributedcameramgr/dcameracontrol", - "${services_path}/cameraservice/sourceservice/include/distributedcameramgr/dcameradata", - "${services_path}/cameraservice/sourceservice/include/distributedcameramgr/dcamerahdf", - "${services_path}/cameraservice/sourceservice/include/distributedcameramgr/dcamerainterface", - "${services_path}/cameraservice/sourceservice/include/distributedcameramgr/dcamerastate", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - sources = [ "sourceservicedcameranotify_fuzzer.cpp" ] - - deps = [ - "${common_path}:distributed_camera_utils", - "${services_path}/cameraservice/sourceservice:distributed_camera_source", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SourceServiceDCameraNotifyFuzzTest\"", - "LOG_DOMAIN=0xD004150", - ] - - external_deps = [ - "cJSON:cjson", - "c_utils:utils", - "distributed_hardware_fwk:distributedhardwareutils", - "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.1", - "eventhandler:libeventhandler", - "hilog:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SourceServiceDCameraNotifyFuzzTest" ] -} -############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/corpus/init deleted file mode 100644 index e4ceac1bcd4e3b3427eb63cea0c28304064333cc..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# 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. - -FUZZ \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/project.xml deleted file mode 100644 index 4fdbc407f205680885fa42663163b5c987f123a6..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/sourceservicedcameranotify_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/sourceservicedcameranotify_fuzzer.cpp deleted file mode 100644 index ac6a421ef5ee2b77c349cfe26c86aee5baf1f657..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/sourceservicedcameranotify_fuzzer.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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 "sourceservicedcameranotify_fuzzer.h" - -#include "dcamera_source_callback.h" -#include "distributed_camera_constants.h" -#include "distributed_camera_source_service.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace DistributedHardware { -void SourceServiceDCameraNotifyFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - - std::string dhId(reinterpret_cast(data), size); - std::string devId(reinterpret_cast(data), size); - std::string events(reinterpret_cast(data), size); - - std::shared_ptr sourceService = - std::make_shared(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID, true); - - sourceService->DCameraNotify(devId, dhId, events); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SourceServiceDCameraNotifyFuzzTest(data, size); - return 0; -} - diff --git a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/sourceservicedcameranotify_fuzzer.h b/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/sourceservicedcameranotify_fuzzer.h deleted file mode 100644 index 8e9bad691df731c3bbc681ca4cc21626576beb9a..0000000000000000000000000000000000000000 --- a/interfaces/inner_kits/native_cpp/test/sourcefuzztest/sourceservicedcameranotify_fuzzer/sourceservicedcameranotify_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 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 SOURCESERVICEDCAMERANOTIFY_FUZZER_H -#define SOURCESERVICEDCAMERANOTIFY_FUZZER_H - -#define FUZZ_PROJECT_NAME "sourceservicedcameranotify_fuzzer" - -#endif \ No newline at end of file diff --git a/services/cameraservice/base/include/dcamera_open_info_cmd.h b/services/cameraservice/base/include/dcamera_open_info_cmd.h index 1f22e22d953d1e9b695f326045a63b73241f0692..2b96dc0903b71c4d408c46636157a7c2a6c783d1 100644 --- a/services/cameraservice/base/include/dcamera_open_info_cmd.h +++ b/services/cameraservice/base/include/dcamera_open_info_cmd.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -29,18 +29,6 @@ public: ~DCameraOpenInfo() = default; std::string sourceDevId_; }; - -class DCameraOpenInfoCmd { -public: - std::string type_; - std::string dhId_; - std::string command_; - std::shared_ptr value_; - -public: - int32_t Marshal(std::string& jsonStr); - int32_t Unmarshal(const std::string& jsonStr); -}; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DCAMERA_OPEN_INFO_H diff --git a/services/cameraservice/base/src/dcamera_open_info_cmd.cpp b/services/cameraservice/base/src/dcamera_open_info_cmd.cpp deleted file mode 100644 index 92ce18a9073bd0de94d764ba57a43f67c96206c7..0000000000000000000000000000000000000000 --- a/services/cameraservice/base/src/dcamera_open_info_cmd.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2021-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 "dcamera_open_info_cmd.h" -#include "cJSON.h" - -#include "distributed_camera_constants.h" -#include "distributed_camera_errno.h" -#include "distributed_hardware_log.h" - -namespace OHOS { -namespace DistributedHardware { -int32_t DCameraOpenInfoCmd::Marshal(std::string& jsonStr) -{ - if (value_ == nullptr) { - return DCAMERA_BAD_VALUE; - } - cJSON *rootValue = cJSON_CreateObject(); - if (rootValue == nullptr) { - return DCAMERA_BAD_VALUE; - } - cJSON_AddStringToObject(rootValue, "Type", type_.c_str()); - cJSON_AddStringToObject(rootValue, "dhId", dhId_.c_str()); - cJSON_AddStringToObject(rootValue, "Command", command_.c_str()); - - cJSON *openInfo = cJSON_CreateObject(); - if (openInfo == nullptr) { - cJSON_Delete(rootValue); - return DCAMERA_BAD_VALUE; - } - cJSON_AddStringToObject(openInfo, "SourceDevId", value_->sourceDevId_.c_str()); - cJSON_AddItemToObject(rootValue, "Value", openInfo); - - char *data = cJSON_Print(rootValue); - if (data == nullptr) { - cJSON_Delete(rootValue); - return DCAMERA_BAD_VALUE; - } - jsonStr = std::string(data); - cJSON_Delete(rootValue); - cJSON_free(data); - return DCAMERA_OK; -} - -int32_t DCameraOpenInfoCmd::Unmarshal(const std::string& jsonStr) -{ - cJSON *rootValue = cJSON_Parse(jsonStr.c_str()); - if (rootValue == nullptr) { - return DCAMERA_BAD_VALUE; - } - cJSON *type = cJSON_GetObjectItemCaseSensitive(rootValue, "Type"); - if (type == nullptr || !cJSON_IsString(type) || (type->valuestring == nullptr)) { - cJSON_Delete(rootValue); - return DCAMERA_BAD_VALUE; - } - type_ = type->valuestring; - cJSON *dhId = cJSON_GetObjectItemCaseSensitive(rootValue, "dhId"); - if (dhId == nullptr || !cJSON_IsString(dhId) || (dhId->valuestring == nullptr)) { - cJSON_Delete(rootValue); - return DCAMERA_BAD_VALUE; - } - dhId_ = dhId->valuestring; - cJSON *command = cJSON_GetObjectItemCaseSensitive(rootValue, "Command"); - if (command == nullptr || !cJSON_IsString(command) || (command->valuestring == nullptr)) { - cJSON_Delete(rootValue); - return DCAMERA_BAD_VALUE; - } - command_ = command->valuestring; - cJSON *valueJson = cJSON_GetObjectItemCaseSensitive(rootValue, "Value"); - if (valueJson == nullptr || !cJSON_IsObject(valueJson)) { - cJSON_Delete(rootValue); - return DCAMERA_BAD_VALUE; - } - cJSON *sourceDevId = cJSON_GetObjectItemCaseSensitive(valueJson, "SourceDevId"); - if (sourceDevId == nullptr || !cJSON_IsString(sourceDevId) || (sourceDevId->valuestring == nullptr)) { - cJSON_Delete(rootValue); - return DCAMERA_BAD_VALUE; - } - std::shared_ptr openInfo = std::make_shared(); - openInfo->sourceDevId_ = sourceDevId->valuestring; - value_ = openInfo; - cJSON_Delete(rootValue); - return DCAMERA_OK; -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/cameraservice/base/test/unittest/common/base/BUILD.gn b/services/cameraservice/base/test/unittest/common/base/BUILD.gn index 5c824bffe4934402b8807414a3e070f4e2feb6ba..f1595c13bd3c39c6caa7755c315974fff79a6d0e 100755 --- a/services/cameraservice/base/test/unittest/common/base/BUILD.gn +++ b/services/cameraservice/base/test/unittest/common/base/BUILD.gn @@ -39,7 +39,6 @@ ohos_unittest("DCameraServicesBaseTest") { "dcamera_event_cmd_test.cpp", "dcamera_info_cmd_test.cpp", "dcamera_metadata_setting_cmd_test.cpp", - "dcamera_open_info_cmd_test.cpp", "dcamera_protocol_test.cpp", "dcamera_sink_frame_info_test.cpp", ] diff --git a/services/cameraservice/base/test/unittest/common/base/dcamera_open_info_cmd_test.cpp b/services/cameraservice/base/test/unittest/common/base/dcamera_open_info_cmd_test.cpp deleted file mode 100755 index e2245355319b083818ac07b320a16c6d0d4371fc..0000000000000000000000000000000000000000 --- a/services/cameraservice/base/test/unittest/common/base/dcamera_open_info_cmd_test.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2022 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 -#include - -#include "dcamera_open_info_cmd.h" -#include "distributed_camera_errno.h" - -using namespace testing::ext; - -namespace OHOS { -namespace DistributedHardware { -class DCameraOpenInfoCmdTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - - -void DCameraOpenInfoCmdTest::SetUpTestCase(void) -{ -} - -void DCameraOpenInfoCmdTest::TearDownTestCase(void) -{ -} - -void DCameraOpenInfoCmdTest::SetUp(void) -{ -} - -void DCameraOpenInfoCmdTest::TearDown(void) -{ -} - -static const std::string TEST_OPEN_INFO_CMD_JSON = R"({ - "Type": "OPERATION", - "dhId": "camrea_0", - "Command": "OPEN_CHANNEL", - "Value": {"SourceDevId": "TestDevId"} -})"; - -static const std::string TEST_OPEN_INFO_CMD_JSON_LACK_TYPE = R"({ - "dhId": "camrea_0", - "Command": "OPEN_CHANNEL", - "Value": {"SourceDevId": "TestDevId"} -})"; - -static const std::string TEST_OPEN_INFO_CMD_JSON_TYPE_EXCEPTION = R"({ - "Type": 0, - "dhId": "camrea_0", - "Command": "OPEN_CHANNEL", - "Value": {"SourceDevId": "TestDevId"} -})"; - -static const std::string TEST_OPEN_INFO_CMD_JSON_LACK_DHID = R"({ - "Type": "OPERATION", - "Command": "OPEN_CHANNEL", - "Value": {"SourceDevId": "TestDevId"} -})"; - -static const std::string TEST_OPEN_INFO_CMD_JSON_DHID_EXCEPTION = R"({ - "Type": "OPERATION", - "dhId": 0, - "Command": "OPEN_CHANNEL", - "Value": {"SourceDevId": "TestDevId"} -})"; - -static const std::string TEST_OPEN_INFO_CMD_JSON_LACK_COMMAND = R"({ - "Type": "OPERATION", - "dhId": "camrea_0", - "Value": {"SourceDevId": "TestDevId"} -})"; - -static const std::string TEST_OPEN_INFO_CMD_JSON_COMMAND_EXCEPTION = R"({ - "Type": "OPERATION", - "dhId": "camrea_0", - "Command": 0, - "Value": {"SourceDevId": "TestDevId"} -})"; - -static const std::string TEST_OPEN_INFO_CMD_JSON_LACK_VALUE = R"({ - "Type": "OPERATION", - "dhId": "camrea_0", - "Command": "OPEN_CHANNEL" -})"; - -static const std::string TEST_OPEN_INFO_CMD_JSON_LACK_VALUE_BODY_DEVID = R"({ - "Type": "OPERATION", - "dhId": "camrea_0", - "Command": "OPEN_CHANNEL", - "Value": {} -})"; - -static const std::string TEST_OPEN_INFO_CMD_JSON_VALUE_BODY_DEVID_EXCEPTION = R"({ - "Type": "OPERATION", - "dhId": "camrea_0", - "Command": "OPEN_CHANNEL", - "Value": {"SourceDevId": 0} -})"; - -/** - * @tc.name: dcamera_open_info_cmd_001. - * @tc.desc: Verify OpenInfoCmd Json. - * @tc.type: FUNC - * @tc.require: Issue Number - */ -HWTEST_F(DCameraOpenInfoCmdTest, dcamera_open_info_cmd_001, TestSize.Level1) -{ - DCameraOpenInfoCmd cmd; - int32_t ret = cmd.Unmarshal(TEST_OPEN_INFO_CMD_JSON); - EXPECT_EQ(DCAMERA_OK, ret); - - std::string jsonStr; - ret = cmd.Marshal(jsonStr); - EXPECT_EQ(DCAMERA_OK, ret); - - std::string str = "0"; - ret = cmd.Unmarshal(str); - EXPECT_EQ(DCAMERA_BAD_VALUE, ret); - - ret = cmd.Unmarshal(TEST_OPEN_INFO_CMD_JSON_LACK_TYPE); - EXPECT_EQ(DCAMERA_BAD_VALUE, ret); - - ret = cmd.Unmarshal(TEST_OPEN_INFO_CMD_JSON_TYPE_EXCEPTION); - EXPECT_EQ(DCAMERA_BAD_VALUE, ret); - - ret = cmd.Unmarshal(TEST_OPEN_INFO_CMD_JSON_LACK_DHID); - EXPECT_EQ(DCAMERA_BAD_VALUE, ret); - - ret = cmd.Unmarshal(TEST_OPEN_INFO_CMD_JSON_DHID_EXCEPTION); - EXPECT_EQ(DCAMERA_BAD_VALUE, ret); - - ret = cmd.Unmarshal(TEST_OPEN_INFO_CMD_JSON_LACK_COMMAND); - EXPECT_EQ(DCAMERA_BAD_VALUE, ret); - - ret = cmd.Unmarshal(TEST_OPEN_INFO_CMD_JSON_COMMAND_EXCEPTION); - EXPECT_EQ(DCAMERA_BAD_VALUE, ret); - - ret = cmd.Unmarshal(TEST_OPEN_INFO_CMD_JSON_LACK_VALUE); - EXPECT_EQ(DCAMERA_BAD_VALUE, ret); - - ret = cmd.Unmarshal(TEST_OPEN_INFO_CMD_JSON_LACK_VALUE_BODY_DEVID); - EXPECT_EQ(DCAMERA_BAD_VALUE, ret); - - ret = cmd.Unmarshal(TEST_OPEN_INFO_CMD_JSON_VALUE_BODY_DEVID_EXCEPTION); - EXPECT_EQ(DCAMERA_BAD_VALUE, ret); -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sinkservice/BUILD.gn b/services/cameraservice/sinkservice/BUILD.gn index c2731760cd0986f8f464f4b603a8b7e011f30b79..af32e17286799b47469fc71037d3a5645206e44e 100644 --- a/services/cameraservice/sinkservice/BUILD.gn +++ b/services/cameraservice/sinkservice/BUILD.gn @@ -63,7 +63,6 @@ ohos_shared_library("distributed_camera_sink") { "${services_path}/cameraservice/base/src/dcamera_event_cmd.cpp", "${services_path}/cameraservice/base/src/dcamera_info_cmd.cpp", "${services_path}/cameraservice/base/src/dcamera_metadata_setting_cmd.cpp", - "${services_path}/cameraservice/base/src/dcamera_open_info_cmd.cpp", "src/distributedcamera/dcamera_sink_callback_proxy.cpp", "src/distributedcamera/dcamera_sink_hidumper.cpp", "src/distributedcamera/distributed_camera_sink_service.cpp", @@ -75,7 +74,6 @@ ohos_shared_library("distributed_camera_sink") { "src/distributedcameramgr/dcamera_sink_data_process.cpp", "src/distributedcameramgr/dcamera_sink_dev.cpp", "src/distributedcameramgr/dcamera_sink_output.cpp", - "src/distributedcameramgr/dcamera_sink_service_ipc.cpp", "src/distributedcameramgr/listener/dcamera_sink_controller_channel_listener.cpp", "src/distributedcameramgr/listener/dcamera_sink_data_process_listener.cpp", "src/distributedcameramgr/listener/dcamera_sink_output_channel_listener.cpp", diff --git a/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h b/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h index 601ef5befbae066d69f77ac4740b61f9e1b20ae7..e386e7215e6278508d1152b656e6b8a1167982a7 100644 --- a/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h +++ b/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -38,11 +38,7 @@ public: int32_t ReleaseSink() override; int32_t SubscribeLocalHardware(const std::string& dhId, const std::string& parameters) override; int32_t UnsubscribeLocalHardware(const std::string& dhId) override; - int32_t StopCapture(const std::string& dhId) override; - int32_t ChannelNeg(const std::string& dhId, std::string& channelInfo) override; - int32_t GetCameraInfo(const std::string& dhId, std::string& cameraInfo) override; - int32_t OpenChannel(const std::string& dhId, std::string& openInfo) override; - int32_t CloseChannel(const std::string& dhId) override; + int32_t GetCameraInfo(const std::string& dhId, std::string& cameraInfo); int Dump(int32_t fd, const std::vector& args) override; static void GetCamDumpInfo(CameraDumpInfo& camDump); int32_t PauseDistributedHardware(const std::string &networkId) override; diff --git a/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_stub.h b/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_stub.h index 3ec0f8208973496206177421ef4aad8f1e85a4cb..8c95000f2271950df787bcf551caa0bdab71d9fa 100644 --- a/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_stub.h +++ b/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -34,11 +34,6 @@ private: int32_t ReleaseSinkInner(MessageParcel &data, MessageParcel &reply); int32_t SubscribeLocalHardwareInner(MessageParcel &data, MessageParcel &reply); int32_t UnsubscribeLocalHardwareInner(MessageParcel &data, MessageParcel &reply); - int32_t StopCaptureInner(MessageParcel &data, MessageParcel &reply); - int32_t ChannelNegInner(MessageParcel &data, MessageParcel &reply); - int32_t GetCameraInfoInner(MessageParcel &data, MessageParcel &reply); - int32_t OpenChannelInner(MessageParcel &data, MessageParcel &reply); - int32_t CloseChannelInner(MessageParcel &data, MessageParcel &reply); bool HasEnableDHPermission(); int32_t PauseDistributedHardwareInner(MessageParcel &data, MessageParcel &reply); int32_t ResumeDistributedHardwareInner(MessageParcel &data, MessageParcel &reply); diff --git a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_controller.h b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_controller.h index efd2c765f34d51de6f5ecf406150a22cac561732..fce0e08627f5b38020dfaae4c6195527f05188f8 100644 --- a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_controller.h +++ b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_controller.h @@ -57,7 +57,7 @@ public: void OnStateChanged(std::shared_ptr& event); void OnMetadataResult(std::vector>& settings); - void OnSessionState(int32_t state); + void OnSessionState(int32_t state, std::string networkId); void OnSessionError(int32_t eventType, int32_t eventReason, std::string detail); void OnDataReceived(std::vector>& buffers); diff --git a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_dev.h b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_dev.h index 8d6c15fd6b02173dac9389f17f960f58069658a1..5bc63103d7376c62897af3f97578380ad7c51962 100644 --- a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_dev.h +++ b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_dev.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -35,11 +35,7 @@ public: int32_t UnInit(); int32_t SubscribeLocalHardware(const std::string& parameters); int32_t UnsubscribeLocalHardware(); - int32_t StopCapture(); - int32_t ChannelNeg(std::string& channelInfo); int32_t GetCameraInfo(std::string& cameraInfo); - int32_t OpenChannel(std::string& openInfo); - int32_t CloseChannel(); std::string GetDhid(); int32_t PauseDistributedHardware(const std::string &networkId); int32_t ResumeDistributedHardware(const std::string &networkId); diff --git a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_service_ipc.h b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_service_ipc.h deleted file mode 100644 index 8838c26697904f562896bdfd4e6b32d3e0ce28d5..0000000000000000000000000000000000000000 --- a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_service_ipc.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2021-2022 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_DCAMERA_SINK_SERVICE_IPC_H -#define OHOS_DCAMERA_SINK_SERVICE_IPC_H - -#include "idistributed_camera_source.h" - -#include - -#include "single_instance.h" - -namespace OHOS { -namespace DistributedHardware { -class DCameraSinkServiceIpc { -DECLARE_SINGLE_INSTANCE_BASE(DCameraSinkServiceIpc); - -public: - void Init(); - void UnInit(); - sptr GetSourceRemoteCamSrv(const std::string& deviceId); - void OnSourceRemoteCamSrvDied(const wptr& remote); - void DeleteSourceRemoteCamSrv(const std::string& deviceId); - -private: - DCameraSinkServiceIpc(); - ~DCameraSinkServiceIpc(); - void ClearSourceRemoteCamSrv(); - - class SourceRemoteRecipient : public IRemoteObject::DeathRecipient { - public: - void OnRemoteDied(const wptr& remote) override; - }; - sptr sourceRemoteRecipient_; - std::map> remoteSources_; - std::mutex sourceRemoteCamSrvLock_; - - bool isInit_; - std::mutex initCamSrvLock_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DCAMERA_SINK_SERVICE_IPC_H diff --git a/services/cameraservice/sinkservice/include/distributedcameramgr/listener/dcamera_sink_controller_channel_listener.h b/services/cameraservice/sinkservice/include/distributedcameramgr/listener/dcamera_sink_controller_channel_listener.h index 18c8f33acc59f2197351421026d709f24f7fab1e..55ebaa626d111fc79ecc9e363ff7f388ac6caabc 100644 --- a/services/cameraservice/sinkservice/include/distributedcameramgr/listener/dcamera_sink_controller_channel_listener.h +++ b/services/cameraservice/sinkservice/include/distributedcameramgr/listener/dcamera_sink_controller_channel_listener.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -27,7 +27,7 @@ public: explicit DCameraSinkControllerChannelListener(std::shared_ptr& controller); ~DCameraSinkControllerChannelListener() override = default; - void OnSessionState(int32_t state) override; + void OnSessionState(int32_t state, std::string networkId) override; void OnSessionError(int32_t eventType, int32_t eventReason, std::string detail) override; void OnDataReceived(std::vector>& buffers) override; diff --git a/services/cameraservice/sinkservice/include/distributedcameramgr/listener/dcamera_sink_output_channel_listener.h b/services/cameraservice/sinkservice/include/distributedcameramgr/listener/dcamera_sink_output_channel_listener.h index c390a4578608edcf6337657054f1239641229531..48f2ced9d2cea85e87716b86c97ee5862d525291 100644 --- a/services/cameraservice/sinkservice/include/distributedcameramgr/listener/dcamera_sink_output_channel_listener.h +++ b/services/cameraservice/sinkservice/include/distributedcameramgr/listener/dcamera_sink_output_channel_listener.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -27,7 +27,7 @@ public: DCameraSinkOutputChannelListener(DCStreamType type, std::shared_ptr& output); ~DCameraSinkOutputChannelListener() override = default; - void OnSessionState(int32_t state) override; + void OnSessionState(int32_t state, std::string networkId) override; void OnSessionError(int32_t eventType, int32_t eventReason, std::string detail) override; void OnDataReceived(std::vector>& buffers) override; diff --git a/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp b/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp index 8f97f2acb3646e8e7fe9cd5f72582380b99ecb21..7d1e2bd5173e8073c484ed0f7e615e14f3280a11 100644 --- a/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp +++ b/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp @@ -26,7 +26,6 @@ #include "anonymous_string.h" #include "dcamera_handler.h" #include "dcamera_hisysevent_adapter.h" -#include "dcamera_sink_service_ipc.h" #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" @@ -59,7 +58,6 @@ void DistributedCameraSinkService::OnStart() bool DistributedCameraSinkService::Init() { DHLOGI("DistributedCameraSinkService start init"); - DCameraSinkServiceIpc::GetInstance().Init(); if (!registerToService_) { bool ret = Publish(this); CHECK_AND_RETURN_RET_LOG(!ret, false, "Publish service failed"); @@ -74,7 +72,6 @@ void DistributedCameraSinkService::OnStop() DHLOGI("DistributedCameraSinkService OnStop service"); state_ = DCameraServiceState::DCAMERA_SRV_STATE_NOT_START; registerToService_ = false; - DCameraSinkServiceIpc::GetInstance().UnInit(); } int32_t DistributedCameraSinkService::InitSink(const std::string& params, @@ -164,46 +161,6 @@ int32_t DistributedCameraSinkService::UnsubscribeLocalHardware(const std::string return DCAMERA_OK; } -int32_t DistributedCameraSinkService::StopCapture(const std::string& dhId) -{ - DHLOGI("dhId: %{public}s", GetAnonyString(dhId).c_str()); - std::shared_ptr sinkDevice = nullptr; - { - std::lock_guard lock(mapMutex_); - auto iter = camerasMap_.find(dhId); - if (iter == camerasMap_.end()) { - DHLOGE("device not found"); - return DCAMERA_NOT_FOUND; - } - sinkDevice = iter->second; - } - - int32_t ret = sinkDevice->StopCapture(); - CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK, ret, "StopCapture failed, ret: %{public}d", ret); - DHLOGI("StopCapture success"); - return DCAMERA_OK; -} - -int32_t DistributedCameraSinkService::ChannelNeg(const std::string& dhId, std::string& channelInfo) -{ - DHLOGI("dhId: %{public}s", GetAnonyString(dhId).c_str()); - std::shared_ptr sinkDevice = nullptr; - { - std::lock_guard lock(mapMutex_); - auto iter = camerasMap_.find(dhId); - if (iter == camerasMap_.end()) { - DHLOGE("device not found"); - return DCAMERA_NOT_FOUND; - } - sinkDevice = iter->second; - } - - int32_t ret = sinkDevice->ChannelNeg(channelInfo); - CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK, ret, "ChannelNeg failed, ret: %{public}d", ret); - DHLOGI("ChannelNeg success"); - return DCAMERA_OK; -} - int32_t DistributedCameraSinkService::GetCameraInfo(const std::string& dhId, std::string& cameraInfo) { DHLOGI("dhId: %{public}s", GetAnonyString(dhId).c_str()); @@ -224,51 +181,6 @@ int32_t DistributedCameraSinkService::GetCameraInfo(const std::string& dhId, std return DCAMERA_OK; } -int32_t DistributedCameraSinkService::OpenChannel(const std::string& dhId, std::string& openInfo) -{ - DHLOGI("DistributedCameraSinkService OpenChannel Begin, dhId: %{public}s", GetAnonyString(dhId).c_str()); - std::shared_ptr sinkDevice = nullptr; - { - std::lock_guard lock(mapMutex_); - auto iter = camerasMap_.find(dhId); - if (iter == camerasMap_.end()) { - DHLOGE("device not found"); - return DCAMERA_NOT_FOUND; - } - sinkDevice = iter->second; - } - - int32_t ret = sinkDevice->OpenChannel(openInfo); - if (ret != DCAMERA_OK) { - DHLOGE("OpenChannel failed, ret: %{public}d", ret); - ReportDcamerOptFail(DCAMERA_OPT_FAIL, DCAMERA_SINK_OPEN_CAM_ERROR, - CreateMsg("sink service open channel failed, dhId: %s", GetAnonyString(dhId).c_str())); - return ret; - } - DHLOGI("DistributedCameraSinkService OpenChannel success"); - return DCAMERA_OK; -} - -int32_t DistributedCameraSinkService::CloseChannel(const std::string& dhId) -{ - DHLOGI("dhId: %{public}s", GetAnonyString(dhId).c_str()); - std::shared_ptr sinkDevice = nullptr; - { - std::lock_guard lock(mapMutex_); - auto iter = camerasMap_.find(dhId); - if (iter == camerasMap_.end()) { - DHLOGE("device not found"); - return DCAMERA_NOT_FOUND; - } - sinkDevice = iter->second; - } - - int32_t ret = sinkDevice->CloseChannel(); - CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK, ret, "CloseChannel failed, ret: %{public}d", ret); - DHLOGI("CloseChannel success"); - return DCAMERA_OK; -} - int DistributedCameraSinkService::Dump(int32_t fd, const std::vector& args) { DHLOGI("DistributedCameraSinkService Dump."); diff --git a/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_stub.cpp b/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_stub.cpp index be87cebdfc9482517e8027b525e8073eacfcb88b..0c8120341819e2f8351d1be09a459e4d9515fc89 100644 --- a/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_stub.cpp +++ b/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -33,16 +33,6 @@ DistributedCameraSinkStub::DistributedCameraSinkStub() : IRemoteStub(true) &DistributedCameraSinkStub::SubscribeLocalHardwareInner; memberFuncMap_[static_cast(IDCameraSinkInterfaceCode::UNSUBSCRIBE_LOCAL_HARDWARE)] = &DistributedCameraSinkStub::UnsubscribeLocalHardwareInner; - memberFuncMap_[static_cast(IDCameraSinkInterfaceCode::STOP_CAPTURE)] = - &DistributedCameraSinkStub::StopCaptureInner; - memberFuncMap_[static_cast(IDCameraSinkInterfaceCode::CHANNEL_NEG)] = - &DistributedCameraSinkStub::ChannelNegInner; - memberFuncMap_[static_cast(IDCameraSinkInterfaceCode::GET_CAMERA_INFO)] = - &DistributedCameraSinkStub::GetCameraInfoInner; - memberFuncMap_[static_cast(IDCameraSinkInterfaceCode::OPEN_CHANNEL)] = - &DistributedCameraSinkStub::OpenChannelInner; - memberFuncMap_[static_cast(IDCameraSinkInterfaceCode::CLOSE_CHANNEL)] = - &DistributedCameraSinkStub::CloseChannelInner; memberFuncMap_[static_cast(IDCameraSinkInterfaceCode::PAUSE_DISTRIBUTED_HARDWARE)] = &DistributedCameraSinkStub::PauseDistributedHardwareInner; memberFuncMap_[static_cast(IDCameraSinkInterfaceCode::RESUME_DISTRIBUTED_HARDWARE)] = @@ -83,16 +73,6 @@ int32_t DistributedCameraSinkStub::OnRemoteRequest(uint32_t code, MessageParcel return SubscribeLocalHardwareInner(data, reply); case static_cast(IDCameraSinkInterfaceCode::UNSUBSCRIBE_LOCAL_HARDWARE): return UnsubscribeLocalHardwareInner(data, reply); - case static_cast(IDCameraSinkInterfaceCode::STOP_CAPTURE): - return StopCaptureInner(data, reply); - case static_cast(IDCameraSinkInterfaceCode::CHANNEL_NEG): - return ChannelNegInner(data, reply); - case static_cast(IDCameraSinkInterfaceCode::GET_CAMERA_INFO): - return GetCameraInfoInner(data, reply); - case static_cast(IDCameraSinkInterfaceCode::OPEN_CHANNEL): - return OpenChannelInner(data, reply); - case static_cast(IDCameraSinkInterfaceCode::CLOSE_CHANNEL): - return CloseChannelInner(data, reply); case static_cast(IDCameraSinkInterfaceCode::PAUSE_DISTRIBUTED_HARDWARE): return PauseDistributedHardwareInner(data, reply); case static_cast(IDCameraSinkInterfaceCode::RESUME_DISTRIBUTED_HARDWARE): @@ -188,97 +168,6 @@ int32_t DistributedCameraSinkStub::UnsubscribeLocalHardwareInner(MessageParcel & return DCAMERA_OK; } -int32_t DistributedCameraSinkStub::StopCaptureInner(MessageParcel &data, MessageParcel &reply) -{ - DHLOGD("enter"); - int32_t ret = DCAMERA_OK; - do { - std::string dhId = data.ReadString(); - if (dhId.empty() || dhId.size() > DID_MAX_SIZE) { - DHLOGE("params is invalid"); - ret = DCAMERA_BAD_VALUE; - break; - } - ret = StopCapture(dhId); - } while (0); - reply.WriteInt32(ret); - return DCAMERA_OK; -} - -int32_t DistributedCameraSinkStub::ChannelNegInner(MessageParcel &data, MessageParcel &reply) -{ - DHLOGD("enter"); - int32_t ret = DCAMERA_OK; - do { - std::string dhId = data.ReadString(); - std::string channelInfo = data.ReadString(); - if (dhId.empty() || dhId.size() > DID_MAX_SIZE || channelInfo.empty() || - channelInfo.size() > PARAM_MAX_SIZE) { - DHLOGE("params is invalid"); - ret = DCAMERA_BAD_VALUE; - break; - } - ret = ChannelNeg(dhId, channelInfo); - } while (0); - reply.WriteInt32(ret); - return DCAMERA_OK; -} - -int32_t DistributedCameraSinkStub::GetCameraInfoInner(MessageParcel &data, MessageParcel &reply) -{ - DHLOGD("enter"); - int32_t ret = DCAMERA_OK; - do { - std::string dhId = data.ReadString(); - std::string cameraInfo = data.ReadString(); - if (dhId.empty() || dhId.size() > DID_MAX_SIZE) { - DHLOGE("params is invalid"); - ret = DCAMERA_BAD_VALUE; - break; - } - ret = GetCameraInfo(dhId, cameraInfo); - } while (0); - reply.WriteInt32(ret); - return DCAMERA_OK; -} - -int32_t DistributedCameraSinkStub::OpenChannelInner(MessageParcel &data, MessageParcel &reply) -{ - DHLOGD("DistributedCameraSinkStub OpenChannelInner Begin"); - int32_t ret = DCAMERA_OK; - do { - std::string dhId = data.ReadString(); - std::string openInfo = data.ReadString(); - if (dhId.empty() || dhId.size() > DID_MAX_SIZE || openInfo.empty()|| - openInfo.size() > PARAM_MAX_SIZE) { - DHLOGE("params is invalid"); - ret = DCAMERA_BAD_VALUE; - break; - } - ret = OpenChannel(dhId, openInfo); - } while (0); - reply.WriteInt32(ret); - DHLOGD("DistributedCameraSinkStub OpenChannelInner End"); - return DCAMERA_OK; -} - -int32_t DistributedCameraSinkStub::CloseChannelInner(MessageParcel &data, MessageParcel &reply) -{ - DHLOGD("enter"); - int32_t ret = DCAMERA_OK; - do { - std::string dhId = data.ReadString(); - if (dhId.empty() || dhId.size() > DID_MAX_SIZE) { - DHLOGE("params is invalid"); - ret = DCAMERA_BAD_VALUE; - break; - } - ret = CloseChannel(dhId); - } while (0); - reply.WriteInt32(ret); - return DCAMERA_OK; -} - bool DistributedCameraSinkStub::HasAccessDHPermission() { Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp index bf0f0d146d5ac1d66bccd7dc37f604cebd63afce..90133cafca2a20b46f4472e4a448832d96d04f4c 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp @@ -29,7 +29,6 @@ #include "dcamera_sink_controller_channel_listener.h" #include "dcamera_sink_controller_state_callback.h" #include "dcamera_sink_output.h" -#include "dcamera_sink_service_ipc.h" #include "distributed_camera_constants.h" #include "distributed_camera_errno.h" @@ -140,12 +139,6 @@ int32_t DCameraSinkController::DCameraNotify(std::shared_ptr& even return DCAMERA_BAD_VALUE; } - sptr sourceSA = DCameraSinkServiceIpc::GetInstance().GetSourceRemoteCamSrv(srcDevId_); - if (sourceSA == nullptr) { - DHLOGE("sourceSA is null"); - return DCAMERA_BAD_VALUE; - } - DCameraEventCmd eventCmd; std::string jsonStr = ""; eventCmd.type_ = DCAMERA_PROTOCOL_TYPE_MESSAGE; @@ -159,20 +152,18 @@ int32_t DCameraSinkController::DCameraNotify(std::shared_ptr& even return ret; } - std::string sinkDevId; - ret = GetLocalDeviceNetworkId(sinkDevId); - if (ret != DCAMERA_OK) { - DHLOGE("GetLocalDeviceNetworkId failed, devId: %{public}s, dhId: %{public}s, ret: %{public}d", - GetAnonyString(sinkDevId).c_str(), GetAnonyString(dhId_).c_str(), ret); - return ret; + std::shared_ptr buffer = std::make_shared(jsonStr.length() + 1); + ret = memcpy_s(buffer->Data(), buffer->Capacity(), reinterpret_cast(const_cast(jsonStr.c_str())), + jsonStr.length()); + if (ret != EOK) { + DHLOGE("DCameraNotify memcpy_s failed, dhId: %{public}s ret: %{public}d", GetAnonyString(dhId_).c_str(), ret); + return DCAMERA_BAD_VALUE; } - - ret = sourceSA->DCameraNotify(sinkDevId, dhId_, jsonStr); + ret = channel_->SendData(buffer); if (ret != DCAMERA_OK) { - DHLOGE("SourceSA notify failed, srcId: %{public}s, sinkId: %{public}s, dhId: %{public}s, ret: %{public}d", - GetAnonyString(srcDevId_).c_str(), GetAnonyString(sinkDevId).c_str(), - GetAnonyString(dhId_).c_str(), ret); - return ret; + DHLOGE("DCameraNotify channel send data failed, dhId: %{public}s ret: %{public}d", + GetAnonyString(dhId_).c_str(), ret); + return DCAMERA_BAD_VALUE; } DHLOGI("DCameraNotify %{public}s success", GetAnonyString(dhId_).c_str()); @@ -233,33 +224,21 @@ int32_t DCameraSinkController::CheckSensitive() int32_t DCameraSinkController::OpenChannel(std::shared_ptr& openInfo) { DHLOGI("DCameraSinkController OpenChannel Start, dhId: %{public}s", GetAnonyString(dhId_).c_str()); - if (!CheckPermission()) { - DHLOGE("DCameraSinkController OpenChannel fail, CheckPermission fail"); - return DCAMERA_WRONG_STATE; - } if (sessionState_ != DCAMERA_CHANNEL_STATE_DISCONNECTED) { DHLOGE("wrong state, dhId: %{public}s, sessionState: %{public}d", GetAnonyString(dhId_).c_str(), sessionState_); return DCAMERA_WRONG_STATE; } - srcDevId_ = openInfo->sourceDevId_; - int32_t ret = CheckSensitive(); - if (ret != DCAMERA_OK) { - DHLOGE("Check sensitive error. ret %{public}d.", ret); - return ret; - } DCameraLowLatency::GetInstance().EnableLowLatency(); std::vector indexs; - indexs.push_back(DCameraIndex(srcDevId_, dhId_)); + indexs.push_back(DCameraIndex("", dhId_)); auto controller = std::shared_ptr(shared_from_this()); std::shared_ptr listener = std::make_shared(controller); - ret = channel_->CreateSession(indexs, SESSION_FLAG, DCAMERA_SESSION_MODE_CTRL, listener); + int32_t ret = channel_->CreateSession(indexs, SESSION_FLAG, DCAMERA_SESSION_MODE_CTRL, listener); if (ret != DCAMERA_OK) { DHLOGE("channel create session failed, dhId: %{public}s, ret: %{public}d", GetAnonyString(dhId_).c_str(), ret); return ret; } - ret = PullUpPage(); - CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK, ret, "PullUpPage failed"); DHLOGI("DCameraSinkController OpenChannel %{public}s success", GetAnonyString(dhId_).c_str()); return DCAMERA_OK; } @@ -284,29 +263,13 @@ int32_t DCameraSinkController::CloseChannel() { DHLOGI("DCameraSinkController CloseChannel Start, dhId: %{public}s", GetAnonyString(dhId_).c_str()); std::lock_guard autoLock(channelLock_); - DCameraLowLatency::GetInstance().DisableLowLatency(); - DCameraSinkServiceIpc::GetInstance().DeleteSourceRemoteCamSrv(srcDevId_); srcDevId_.clear(); - if (channel_ == nullptr) { - return DCAMERA_BAD_VALUE; - } - int32_t ret = channel_->ReleaseSession(); - if (ret != DCAMERA_OK) { - DHLOGE("DCameraSinkController release channel failed, dhId: %{public}s, ret: %{public}d", - GetAnonyString(dhId_).c_str(), ret); - } - - ret = output_->CloseChannel(); - if (ret != DCAMERA_OK) { - DHLOGE("DCameraSinkController CloseChannel failed, dhId: %{public}s, ret: %{public}d", - GetAnonyString(dhId_).c_str(), ret); - } sessionState_ = DCAMERA_CHANNEL_STATE_DISCONNECTED; if (isPageStatus_.load()) { bool isSensitive = false; bool isSameAccout = false; - ret = sinkCallback_->OnNotifyResourceInfo(ResourceEventType::EVENT_TYPE_CLOSE_PAGE, PAGE_SUBTYPE, srcDevId_, - isSensitive, isSameAccout); + int32_t ret = sinkCallback_->OnNotifyResourceInfo(ResourceEventType::EVENT_TYPE_CLOSE_PAGE, PAGE_SUBTYPE, + srcDevId_, isSensitive, isSameAccout); if (ret != DCAMERA_OK) { DHLOGE("close page failed, ret: %{public}d", ret); } @@ -343,6 +306,24 @@ int32_t DCameraSinkController::Init(std::vector& indexs) std::make_shared(runner, shared_from_this()); isInit_ = true; initCallback_ = std::make_shared(); + std::shared_ptr openInfo = std::make_shared(); + openInfo->sourceDevId_ = ""; + ret = OpenChannel(openInfo); + if (ret != DCAMERA_OK) { + DHLOGE("OpenChannel init failed, dhId: %{public}s, ret: %{public}d", GetAnonyString(dhId_).c_str(), ret); + return ret; + } + std::shared_ptr info = std::make_shared(); + info->sourceDevId_ = ""; + DCameraChannelDetail continueChInfo(CONTINUE_SESSION_FLAG, CONTINUOUS_FRAME); + DCameraChannelDetail snapShotChInfo(SNAP_SHOT_SESSION_FLAG, SNAPSHOT_FRAME); + info->detail_.push_back(continueChInfo); + info->detail_.push_back(snapShotChInfo); + ret = ChannelNeg(info); + if (ret != DCAMERA_OK) { + DHLOGE("ChannelNeg init failed, dhId: %{public}s, ret: %{public}d", GetAnonyString(dhId_).c_str(), ret); + return ret; + } DHLOGI("DCameraSinkController Init %{public}s success", GetAnonyString(dhId_).c_str()); return DCAMERA_OK; } @@ -363,7 +344,21 @@ int32_t DCameraSinkController::UnInit() GetAnonyString(dhId_).c_str(), ret); } + DCameraLowLatency::GetInstance().DisableLowLatency(); + if (channel_ != nullptr) { + ret = channel_->ReleaseSession(); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraSinkController release channel failed, dhId: %{public}s, ret: %{public}d", + GetAnonyString(dhId_).c_str(), ret); + } + } + if (output_ != nullptr) { + ret = output_->CloseChannel(); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraSinkController output CloseChannel failed, dhId: %{public}s, ret: %{public}d", + GetAnonyString(dhId_).c_str(), ret); + } ret = output_->UnInit(); if (ret != DCAMERA_OK) { DHLOGE("DCameraSinkController release output failed, dhId: %{public}s, ret: %{public}d", @@ -475,7 +470,7 @@ void DCameraSinkController::OnMetadataResult(std::vector& d cJSON_Delete(rootValue); if ((!command.empty()) && (command.compare(DCAMERA_PROTOCOL_CMD_CAPTURE) == 0)) { DCameraCaptureInfoCmd captureInfoCmd; - int ret = captureInfoCmd.Unmarshal(jsonStr); + int32_t ret = captureInfoCmd.Unmarshal(jsonStr); if (ret != DCAMERA_OK) { DHLOGE("Capture Info Unmarshal failed, dhId: %{public}s ret: %{public}d", GetAnonyString(dhId_).c_str(), ret); @@ -612,13 +616,17 @@ int32_t DCameraSinkController::HandleReceivedData(std::shared_ptr& d return StartCapture(captureInfoCmd.value_, sceneMode_); } else if ((!command.empty()) && (command.compare(DCAMERA_PROTOCOL_CMD_UPDATE_METADATA) == 0)) { DCameraMetadataSettingCmd metadataSettingCmd; - int ret = metadataSettingCmd.Unmarshal(jsonStr); + int32_t ret = metadataSettingCmd.Unmarshal(jsonStr); if (ret != DCAMERA_OK) { DHLOGE("Metadata Setting Unmarshal failed, dhId: %{public}s ret: %{public}d", GetAnonyString(dhId_).c_str(), ret); return ret; } return UpdateSettings(metadataSettingCmd.value_); + } else if ((!command.empty()) && (command.compare(DCAMERA_PROTOCOL_CMD_STOP_CAPTURE) == 0)) { + return StopCapture(); + } else if ((!command.empty()) && (command.compare(DCAMERA_PROTOCOL_CMD_CLOSE_CHANNEL) == 0)) { + return CloseChannel(); } return DCAMERA_BAD_VALUE; } diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_dev.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_dev.cpp index b2581d87e5fbd8debdd96bf5824e9eedbfa09bea..a04de46d16aae6d73a750c27dc029d6a738462ff 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_dev.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_dev.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -85,32 +85,6 @@ int32_t DCameraSinkDev::UnsubscribeLocalHardware() return DCAMERA_OK; } -int32_t DCameraSinkDev::StopCapture() -{ - DHLOGI("StopCapture dhId: %{public}s", GetAnonyString(dhId_).c_str()); - CHECK_AND_RETURN_RET_LOG(controller_ == nullptr, DCAMERA_BAD_VALUE, "controller_ is null."); - return controller_->StopCapture(); -} - -int32_t DCameraSinkDev::ChannelNeg(std::string& channelInfo) -{ - DHLOGI("ChannelNeg dhId: %{public}s", GetAnonyString(dhId_).c_str()); - if (channelInfo.empty()) { - DHLOGE("channelInfo is empty"); - return DCAMERA_BAD_VALUE; - } - - DCameraChannelInfoCmd channelInfoCmd; - int32_t ret = channelInfoCmd.Unmarshal(channelInfo); - if (ret != DCAMERA_OK) { - DHLOGE("channelInfo unmarshal failed, dhId: %{public}s, ret: %{public}d", - GetAnonyString(dhId_).c_str(), ret); - return ret; - } - CHECK_AND_RETURN_RET_LOG(controller_ == nullptr, DCAMERA_BAD_VALUE, "controller_ is null."); - return controller_->ChannelNeg(channelInfoCmd.value_); -} - int32_t DCameraSinkDev::GetCameraInfo(std::string& cameraInfo) { DHLOGI("GetCameraInfo dhId: %{public}s", GetAnonyString(dhId_).c_str()); @@ -136,31 +110,6 @@ int32_t DCameraSinkDev::GetCameraInfo(std::string& cameraInfo) return DCAMERA_OK; } -int32_t DCameraSinkDev::OpenChannel(std::string& openInfo) -{ - DHLOGI("DCameraSinkDev OpenChannel Begin, dhId: %{public}s", GetAnonyString(dhId_).c_str()); - if (openInfo.empty()) { - DHLOGE("openInfo is empty"); - return DCAMERA_BAD_VALUE; - } - - DCameraOpenInfoCmd cmd; - int32_t ret = cmd.Unmarshal(openInfo); - if (ret != DCAMERA_OK) { - DHLOGE("openInfo unmarshal failed, dhId: %{public}s, ret: %{public}d", GetAnonyString(dhId_).c_str(), ret); - return ret; - } - CHECK_AND_RETURN_RET_LOG(controller_ == nullptr, DCAMERA_BAD_VALUE, "controller_ is null."); - return controller_->OpenChannel(cmd.value_); -} - -int32_t DCameraSinkDev::CloseChannel() -{ - DHLOGI("CloseChannel dhId: %{public}s", GetAnonyString(dhId_).c_str()); - CHECK_AND_RETURN_RET_LOG(controller_ == nullptr, DCAMERA_BAD_VALUE, "controller_ is null."); - return controller_->CloseChannel(); -} - std::string DCameraSinkDev::GetDhid() { return GetAnonyString(dhId_); diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_service_ipc.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_service_ipc.cpp deleted file mode 100644 index 25a286f9564ee84c9ada04af85c12edd703f713a..0000000000000000000000000000000000000000 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_service_ipc.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 "dcamera_sink_service_ipc.h" - -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -#include "anonymous_string.h" -#include "distributed_camera_constants.h" -#include "distributed_camera_errno.h" -#include "distributed_hardware_log.h" - -namespace OHOS { -namespace DistributedHardware { -DCameraSinkServiceIpc::DCameraSinkServiceIpc() : isInit_(false) -{ - DHLOGI("DCameraSinkServiceIpc Create"); -} - -DCameraSinkServiceIpc::~DCameraSinkServiceIpc() -{ - DHLOGI("DCameraSinkServiceIpc Delete"); - UnInit(); -} - -IMPLEMENT_SINGLE_INSTANCE(DCameraSinkServiceIpc); - -void DCameraSinkServiceIpc::Init() -{ - std::lock_guard autoLock(initCamSrvLock_); - DHLOGI("DCameraSinkServiceIpc Init Start"); - if (isInit_) { - DHLOGI("DCameraSinkServiceIpc has already init"); - return; - } - sourceRemoteRecipient_ = sptr(new SourceRemoteRecipient()); - isInit_ = true; - DHLOGI("DCameraSinkServiceIpc Init End"); -} - -void DCameraSinkServiceIpc::UnInit() -{ - std::lock_guard autoLock(initCamSrvLock_); - DHLOGI("DCameraSinkServiceIpc UnInit Start"); - if (!isInit_) { - DHLOGI("DCameraSinkServiceIpc has already UnInit"); - return; - } - ClearSourceRemoteCamSrv(); - DHLOGI("DCameraSinkServiceIpc Start free recipient"); - sourceRemoteRecipient_ = nullptr; - isInit_ = false; - DHLOGI("DCameraSinkServiceIpc UnInit End"); -} - -sptr DCameraSinkServiceIpc::GetSourceRemoteCamSrv(const std::string& deviceId) -{ - if (deviceId.empty()) { - DHLOGE("GetSourceRemoteCamSrv deviceId is empty"); - return nullptr; - } - { - std::lock_guard autoLock(sourceRemoteCamSrvLock_); - auto iter = remoteSources_.find(deviceId); - if (iter != remoteSources_.end()) { - auto object = iter->second; - if (object != nullptr) { - DHLOGI("DCameraSinkServiceIpc GetSourceRemoteCamSrv from cache devId: %{public}s", - GetAnonyString(deviceId).c_str()); - return object; - } - } - } - DHLOGI("GetSourceRemoteCamSrv remote deviceid is %{public}s", GetAnonyString(deviceId).c_str()); - auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgr == nullptr) { - DHLOGE("GetSourceRemoteCamSrv failed to connect to systemAbilityMgr!"); - return nullptr; - } - - auto object = samgr->CheckSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID, deviceId); - if (object == nullptr) { - DHLOGE("GetSourceRemoteCamSrv failed get remote CamSrv %{public}s", GetAnonyString(deviceId).c_str()); - return nullptr; - } - int32_t ret = object->AddDeathRecipient(sourceRemoteRecipient_); - sptr remoteCamSrvObj = iface_cast(object); - if (remoteCamSrvObj == nullptr) { - DHLOGI("GetSourceRemoteCamSrv failed, remoteCamSrvObj is null ret: %{public}d", ret); - return nullptr; - } - { - std::lock_guard autoLock(sourceRemoteCamSrvLock_); - auto iter = remoteSources_.find(deviceId); - if (iter != remoteSources_.end()) { - iter->second->AsObject()->RemoveDeathRecipient(sourceRemoteRecipient_); - } - remoteSources_[deviceId] = remoteCamSrvObj; - } - DHLOGI("GetSourceRemoteCamSrv success, AddDeathRecipient ret: %{public}d", ret); - return remoteCamSrvObj; -} - -void DCameraSinkServiceIpc::DeleteSourceRemoteCamSrv(const std::string& deviceId) -{ - DHLOGI("DeleteSourceRemoteCamSrv devId: %{public}s", GetAnonyString(deviceId).c_str()); - std::lock_guard autoLock(sourceRemoteCamSrvLock_); - auto item = remoteSources_.find(deviceId); - if (item == remoteSources_.end()) { - DHLOGI("DeleteSourceRemoteCamSrv not found device: %{public}s", GetAnonyString(deviceId).c_str()); - return; - } - - if (item->second != nullptr) { - item->second->AsObject()->RemoveDeathRecipient(sourceRemoteRecipient_); - } - remoteSources_.erase(item); -} - -void DCameraSinkServiceIpc::ClearSourceRemoteCamSrv() -{ - DHLOGI("ClearSourceRemoteCamSrv Start"); - std::lock_guard autoLock(sourceRemoteCamSrvLock_); - for (auto iter = remoteSources_.begin(); iter != remoteSources_.end(); iter++) { - if (iter->second != nullptr) { - iter->second->AsObject()->RemoveDeathRecipient(sourceRemoteRecipient_); - } - } - remoteSources_.clear(); - DHLOGI("ClearSourceRemoteCamSrv end"); -} - -void DCameraSinkServiceIpc::SourceRemoteRecipient::OnRemoteDied(const wptr& remote) -{ - DHLOGI("SourceRemoteRecipient OnRemoteDied received died notify!"); - DCameraSinkServiceIpc::GetInstance().OnSourceRemoteCamSrvDied(remote); -} - -void DCameraSinkServiceIpc::OnSourceRemoteCamSrvDied(const wptr& remote) -{ - DHLOGI("OnSourceRemoteCamSrvDied delete diedRemoted"); - std::lock_guard autoLock(sourceRemoteCamSrvLock_); - sptr diedRemoted = remote.promote(); - if (diedRemoted == nullptr) { - DHLOGE("OnSourceRemoteCamSrvDied promote failed!"); - return; - } - auto iter = std::find_if(remoteSources_.begin(), remoteSources_.end(), [&]( - const std::pair> &item)->bool { - return item.second->AsObject() == diedRemoted; - }); - if (iter == remoteSources_.end()) { - DHLOGI("OnSourceRemoteCamSrvDied not found remote object"); - return; - } - DHLOGI("OnSourceRemoteCamSrvDied remote.devId: %{public}s", GetAnonyString(iter->first).c_str()); - if (iter->second != nullptr) { - iter->second->AsObject()->RemoveDeathRecipient(sourceRemoteRecipient_); - } - remoteSources_.erase(iter); -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/listener/dcamera_sink_controller_channel_listener.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/listener/dcamera_sink_controller_channel_listener.cpp index 4203ca5321148eb86d0bd66534d15b3619fc58be..30fd3d73c4f3c68430724c6ea638371d16d1415c 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/listener/dcamera_sink_controller_channel_listener.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/listener/dcamera_sink_controller_channel_listener.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -24,14 +24,14 @@ DCameraSinkControllerChannelListener::DCameraSinkControllerChannelListener( { } -void DCameraSinkControllerChannelListener::OnSessionState(int32_t state) +void DCameraSinkControllerChannelListener::OnSessionState(int32_t state, std::string networkId) { std::shared_ptr controller = controller_.lock(); if (controller == nullptr) { DHLOGE("DCameraSinkControllerChannelListener::OnSessionState controller is null"); return; } - controller->OnSessionState(state); + controller->OnSessionState(state, networkId); } void DCameraSinkControllerChannelListener::OnSessionError(int32_t eventType, int32_t eventReason, std::string detail) diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/listener/dcamera_sink_output_channel_listener.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/listener/dcamera_sink_output_channel_listener.cpp index d2649c20b078a72e813b0ba29b358f77f2de95b9..0ada4dc05cb7964667323784153712fb8e83bc41 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/listener/dcamera_sink_output_channel_listener.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/listener/dcamera_sink_output_channel_listener.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -24,7 +24,7 @@ DCameraSinkOutputChannelListener::DCameraSinkOutputChannelListener( { } -void DCameraSinkOutputChannelListener::OnSessionState(int32_t state) +void DCameraSinkOutputChannelListener::OnSessionState(int32_t state, std::string networkId) { std::shared_ptr output = output_.lock(); if (output == nullptr) { diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/distributed_camera_sink_service_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/distributed_camera_sink_service_test.cpp index bcf0efe0139e96621a02b3ab75a6ae738ec6a966..a248cdbad3fae78db809a52c656c0f89d82d2fce 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/distributed_camera_sink_service_test.cpp +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/distributed_camera_sink_service_test.cpp @@ -96,7 +96,7 @@ HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_001, TestSi EXPECT_EQ(sinkService_ == nullptr, false); int32_t ret = sinkService_->SubscribeLocalHardware(g_dhId, g_testParams); - EXPECT_EQ(DCAMERA_OK, ret); + EXPECT_EQ(DCAMERA_NOT_FOUND, ret); } /** @@ -111,37 +111,7 @@ HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_002, TestSi EXPECT_EQ(sinkService_ == nullptr, false); int32_t ret = sinkService_->UnsubscribeLocalHardware(g_dhId); - EXPECT_EQ(DCAMERA_OK, ret); -} - -/** - * @tc.name: dcamera_sink_service_test_003 - * @tc.desc: Verify the StopCapture function. - * @tc.type: FUNC - * @tc.require: AR000GK6N1 - */ -HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_003, TestSize.Level1) -{ - DHLOGI("dcamera_sink_service_test_003"); - EXPECT_EQ(sinkService_ == nullptr, false); - - int32_t ret = sinkService_->StopCapture(g_dhId); - EXPECT_EQ(DCAMERA_OK, ret); -} - -/** - * @tc.name: dcamera_sink_service_test_004 - * @tc.desc: Verify the ChannelNeg function. - * @tc.type: FUNC - * @tc.require: AR000GK6MT - */ -HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_004, TestSize.Level1) -{ - DHLOGI("dcamera_sink_service_test_004"); - EXPECT_EQ(sinkService_ == nullptr, false); - - int32_t ret = sinkService_->ChannelNeg(g_dhId, g_testChannelInfoContinue); - EXPECT_NE(DCAMERA_OK, ret); + EXPECT_EQ(DCAMERA_NOT_FOUND, ret); } /** @@ -156,28 +126,7 @@ HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_005, TestSi EXPECT_EQ(sinkService_ == nullptr, false); int32_t ret = sinkService_->GetCameraInfo(g_dhId, g_testCameraInfo); - EXPECT_EQ(DCAMERA_OK, ret); -} - -/** - * @tc.name: dcamera_sink_service_test_006 - * @tc.desc: Verify the OpenChannel and CloseChannel function. - * @tc.type: FUNC - * @tc.require: AR000GK6N1 - */ -HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_006, TestSize.Level1) -{ - DHLOGI("dcamera_sink_service_test_006"); - EXPECT_EQ(sinkService_ == nullptr, false); - - int32_t ret = sinkService_->OpenChannel(g_dhId, g_testOpenInfoService); - EXPECT_NE(DCAMERA_OK, ret); - - ret = sinkService_->ChannelNeg(g_dhId, g_testChannelInfoContinue); - EXPECT_NE(DCAMERA_OK, ret); - - ret = sinkService_->CloseChannel(g_dhId); - EXPECT_EQ(DCAMERA_OK, ret); + EXPECT_EQ(DCAMERA_NOT_FOUND, ret); } /** @@ -229,20 +178,6 @@ HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_009, TestSi EXPECT_EQ(DCAMERA_NOT_FOUND, ret); } -/** - * @tc.name: dcamera_sink_service_test_010 - * @tc.desc: Verify the ChannelNeg function can't find id. - * @tc.type: FUNC - */ -HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_010, TestSize.Level1) -{ - DHLOGI("dcamera_sink_service_test_010"); - EXPECT_EQ(sinkService_ == nullptr, false); - - int32_t ret = sinkService_->ChannelNeg("", g_testChannelInfoContinue); - EXPECT_EQ(DCAMERA_NOT_FOUND, ret); -} - /** * @tc.name: dcamera_sink_service_test_011 * @tc.desc: Verify the GetCameraInfo function can't find id. @@ -257,23 +192,6 @@ HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_011, TestSi EXPECT_EQ(DCAMERA_NOT_FOUND, ret); } -/** - * @tc.name: dcamera_sink_service_test_012 - * @tc.desc: Verify the OpenChannel and CloseChannel function can't find id. - * @tc.type: FUNC - */ -HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_012, TestSize.Level1) -{ - DHLOGI("dcamera_sink_service_test_012"); - EXPECT_EQ(sinkService_ == nullptr, false); - - int32_t ret = sinkService_->OpenChannel("", g_testOpenInfoService); - EXPECT_EQ(DCAMERA_NOT_FOUND, ret); - - ret = sinkService_->CloseChannel(""); - EXPECT_EQ(DCAMERA_NOT_FOUND, ret); -} - /** * @tc.name: dcamera_sink_service_test_013 * @tc.desc: Verify the Dump function with large arg. @@ -292,20 +210,6 @@ HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_013, TestSi EXPECT_EQ(DCAMERA_BAD_VALUE, ret); } -/** - * @tc.name: dcamera_sink_service_test_014 - * @tc.desc: Verify the StopCapture function can't find id. - * @tc.type: FUNC - */ -HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_014, TestSize.Level1) -{ - DHLOGI("dcamera_sink_service_test_014"); - EXPECT_EQ(sinkService_ == nullptr, false); - - int32_t ret = sinkService_->StopCapture(""); - EXPECT_EQ(DCAMERA_NOT_FOUND, ret); -} - /** * @tc.name: dcamera_sink_service_test_015 * @tc.desc: Verify the PauseDistributedHardware function. diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/distributed_camera_sink_stub_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/distributed_camera_sink_stub_test.cpp index 6f935d22bf1a882213234eef5e439e8e9e50441c..8ef77444bee30baa22a2429d3e2ece0b011c4425 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/distributed_camera_sink_stub_test.cpp +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/distributed_camera_sink_stub_test.cpp @@ -146,89 +146,6 @@ HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_004, TestSize.Level1) EXPECT_EQ(DCAMERA_OK, ret); } -/** - * @tc.name: dcamera_sink_stub_test_005 - * @tc.desc: Verify the StopCapture function. - * @tc.type: FUNC - * @tc.require: issue - */ -HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_005, TestSize.Level1) -{ - DHLOGI("dcamera_sink_stub_test_005"); - sptr sinkStubPtr(new MockDistributedCameraSinkStub()); - DistributedCameraSinkProxy sinkProxy(sinkStubPtr); - std::string dhId = "dhId000"; - int32_t ret = sinkProxy.StopCapture(dhId); - EXPECT_EQ(DCAMERA_OK, ret); -} - -/** - * @tc.name: dcamera_sink_stub_test_006 - * @tc.desc: Verify the ChannelNeg function. - * @tc.type: FUNC - * @tc.require: issue - */ -HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_006, TestSize.Level1) -{ - DHLOGI("dcamera_sink_stub_test_006"); - sptr sinkStubPtr(new MockDistributedCameraSinkStub()); - DistributedCameraSinkProxy sinkProxy(sinkStubPtr); - std::string dhId = "dhId000"; - std::string channelInfo = "channelInfo000"; - int32_t ret = sinkProxy.ChannelNeg(dhId, channelInfo); - EXPECT_EQ(DCAMERA_OK, ret); -} - -/** - * @tc.name: dcamera_sink_stub_test_007 - * @tc.desc: Verify the GetCameraInfo function. - * @tc.type: FUNC - * @tc.require: issue - */ -HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_007, TestSize.Level1) -{ - DHLOGI("dcamera_sink_stub_test_007"); - sptr sinkStubPtr(new MockDistributedCameraSinkStub()); - DistributedCameraSinkProxy sinkProxy(sinkStubPtr); - std::string dhId = "dhId000"; - std::string cameraInfo = "cameraInfo000"; - int32_t ret = sinkProxy.GetCameraInfo(dhId, cameraInfo); - EXPECT_EQ(DCAMERA_OK, ret); -} - -/** - * @tc.name: dcamera_sink_stub_test_008 - * @tc.desc: Verify the OpenChannel function. - * @tc.type: FUNC - * @tc.require: issue - */ -HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_008, TestSize.Level1) -{ - DHLOGI("dcamera_sink_stub_test_008"); - sptr sinkStubPtr(new MockDistributedCameraSinkStub()); - DistributedCameraSinkProxy sinkProxy(sinkStubPtr); - std::string dhId = "dhId000"; - std::string openInfo = "openInfo000"; - int32_t ret = sinkProxy.OpenChannel(dhId, openInfo); - EXPECT_EQ(DCAMERA_OK, ret); -} - -/** - * @tc.name: dcamera_sink_stub_test_009 - * @tc.desc: Verify the CloseChannel function. - * @tc.type: FUNC - * @tc.require: issue - */ -HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_009, TestSize.Level1) -{ - DHLOGI("dcamera_sink_stub_test_009"); - sptr sinkStubPtr(new MockDistributedCameraSinkStub()); - DistributedCameraSinkProxy sinkProxy(sinkStubPtr); - std::string dhId = "dhId000"; - int32_t ret = sinkProxy.CloseChannel(dhId); - EXPECT_EQ(DCAMERA_OK, ret); -} - /** * @tc.name: dcamera_sink_stub_test_010 * @tc.desc: Verify the PauseDistributedHardware function. diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/mock_distributed_camera_sink_stub.h b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/mock_distributed_camera_sink_stub.h index 3951fbed17a025efffb206ca763247b01ebcf80c..f75963a0cca8efffbb6abcfc2c32e572793884b0 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/mock_distributed_camera_sink_stub.h +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/mock_distributed_camera_sink_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -50,39 +50,6 @@ public: return DCAMERA_OK; } - int32_t StopCapture(const std::string &dhId) - { - (void)dhId; - return DCAMERA_OK; - } - - int32_t ChannelNeg(const std::string &dhId, std::string& channelInfo) - { - (void)dhId; - (void)channelInfo; - return DCAMERA_OK; - } - - int32_t GetCameraInfo(const std::string &dhId, std::string& cameraInfo) - { - (void)dhId; - (void)cameraInfo; - return DCAMERA_OK; - } - - int32_t OpenChannel(const std::string &dhId, std::string& openInfo) - { - (void)dhId; - (void)openInfo; - return DCAMERA_OK; - } - - int32_t CloseChannel(const std::string &dhId) - { - (void)dhId; - return DCAMERA_OK; - } - int32_t PauseDistributedHardware(const std::string &networkId) { (void)networkId; diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/BUILD.gn b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/BUILD.gn index 96f0d2cb1f9b5bf13246f13c221a09d2b862bf9c..a952275c5db591f514b1ac873c1b3578eb8e67f7 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/BUILD.gn +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/BUILD.gn @@ -57,7 +57,6 @@ ohos_unittest("DCameraSinkMgrTest") { "dcamera_sink_data_process_test.cpp", "dcamera_sink_dev_test.cpp", "dcamera_sink_output_test.cpp", - "dcamera_sink_service_ipc_test.cpp", ] cflags = [ diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_controller_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_controller_test.cpp index 16845901303d03472f65a6a198badd0f3b268bd1..1356576fe06c329c2d7ece20eccc856f3f71cfc8 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_controller_test.cpp +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_controller_test.cpp @@ -178,7 +178,7 @@ void DCameraSinkControllerTest::SetTokenID() HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_001, TestSize.Level1) { int32_t ret = controller_->Init(g_testCamIndex); - EXPECT_EQ(DCAMERA_OK, ret); + EXPECT_NE(DCAMERA_OK, ret); EXPECT_EQ(true, controller_->isInit_); ret = controller_->UnInit(); @@ -312,14 +312,14 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_008, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_009, TestSize.Level1) { - controller_->OnSessionState(DCAMERA_CHANNEL_STATE_CONNECTING); + controller_->OnSessionState(DCAMERA_CHANNEL_STATE_CONNECTING, ""); DCameraInfoCmd cmd; cmd.value_ = std::make_shared(); int32_t ret = controller_->GetCameraInfo(cmd.value_); EXPECT_EQ(DCAMERA_OK, ret); int32_t state = -1; - controller_->OnSessionState(state); + controller_->OnSessionState(state, ""); int32_t eventType = 1; int32_t eventReason = 0; @@ -336,7 +336,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_009, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_010, TestSize.Level1) { - controller_->OnSessionState(DCAMERA_CHANNEL_STATE_CONNECTED); + controller_->OnSessionState(DCAMERA_CHANNEL_STATE_CONNECTED, ""); DCameraInfoCmd cmd; cmd.value_ = std::make_shared(); @@ -364,7 +364,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_010, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_011, TestSize.Level1) { - controller_->OnSessionState(DCAMERA_CHANNEL_STATE_DISCONNECTED); + controller_->OnSessionState(DCAMERA_CHANNEL_STATE_DISCONNECTED, ""); std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); DCameraInfoCmd cmd; @@ -383,10 +383,10 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_011, TestSize.L HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_012, TestSize.Level1) { SetTokenID(); - DCameraOpenInfoCmd cmd; - cmd.Unmarshal(TEST_OPEN_INFO_CMD_JSON); - int32_t ret = controller_->OpenChannel(cmd.value_); - EXPECT_EQ(DCAMERA_WRONG_STATE, ret); + std::shared_ptr openInfo = std::make_shared(); + openInfo->sourceDevId_ = "test_012"; + int32_t ret = controller_->OpenChannel(openInfo); + EXPECT_EQ(DCAMERA_OK, ret); } /** @@ -397,7 +397,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_012, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_013, TestSize.Level1) { - controller_->OnSessionState(DCAMERA_CHANNEL_STATE_CONNECTED); + controller_->OnSessionState(DCAMERA_CHANNEL_STATE_CONNECTED, ""); DCameraInfoCmd cmd; cmd.value_ = std::make_shared(); @@ -405,9 +405,9 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_013, TestSize.L EXPECT_EQ(DCAMERA_OK, ret); EXPECT_EQ(DCAMERA_CHANNEL_STATE_CONNECTED, cmd.value_->state_); - DCameraOpenInfoCmd cmdOpenInfo; - cmdOpenInfo.Unmarshal(TEST_OPEN_INFO_CMD_JSON); - ret = controller_->OpenChannel(cmdOpenInfo.value_); + std::shared_ptr openInfo = std::make_shared(); + openInfo->sourceDevId_ = "test_013"; + ret = controller_->OpenChannel(openInfo); EXPECT_EQ(DCAMERA_WRONG_STATE, ret); } @@ -460,11 +460,11 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_015, TestSize.L HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_016, TestSize.Level1) { SetTokenID(); - DCameraOpenInfoCmd cmd; - cmd.Unmarshal(TEST_OPEN_INFO_CMD_JSON); + std::shared_ptr openInfo = std::make_shared(); + openInfo->sourceDevId_ = "test_016"; g_channelStr = "test016"; - int32_t ret = controller_->OpenChannel(cmd.value_); - EXPECT_EQ(DCAMERA_WRONG_STATE, ret); + int32_t ret = controller_->OpenChannel(openInfo); + EXPECT_EQ(DCAMERA_BAD_VALUE, ret); } /** diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_dev_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_dev_test.cpp index d112b225ced04b23a6f2346c25e96da8a6d7ceb5..cd6cde36378b4dff1611f6c5e2c745db88d54991 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_dev_test.cpp +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_dev_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -135,82 +135,6 @@ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_004, TestSize.Level1) EXPECT_EQ(DCAMERA_BAD_VALUE, ret); } -/** - * @tc.name: dcamera_sink_dev_test_005 - * @tc.desc: Verify the ChannelNeg function. - * @tc.type: FUNC - * @tc.require: AR000GK6MT - */ -HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_005, TestSize.Level1) -{ - int32_t ret = dev_->ChannelNeg(g_testChannelInfoDevEmpty); - EXPECT_EQ(DCAMERA_BAD_VALUE, ret); -} - -/** - * @tc.name: dcamera_sink_dev_test_006 - * @tc.desc: Verify the ChannelNeg function. - * @tc.type: FUNC - * @tc.require: AR000GK6MT - */ -HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_006, TestSize.Level1) -{ - int32_t ret = dev_->ChannelNeg(g_testChannelInfoDevContinue); - EXPECT_EQ(DCAMERA_OK, ret); - g_sinkCtrlStr = "test_006"; - ret = dev_->ChannelNeg(g_testChannelInfoDevContinue); - EXPECT_NE(DCAMERA_OK, ret); - g_sinkCtrlStr = ""; -} - -/** - * @tc.name: dcamera_sink_dev_test_007 - * @tc.desc: Verify the StopCapture function. - * @tc.type: FUNC - * @tc.require: AR000GK6N1 - */ -HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_007, TestSize.Level1) -{ - int32_t ret = dev_->StopCapture(); - EXPECT_EQ(DCAMERA_OK, ret); -} - -/** - * @tc.name: dcamera_sink_dev_test_008 - * @tc.desc: Verify the OpenChannel function. - * @tc.type: FUNC - * @tc.require: AR000GK6N1 - */ -HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_008, TestSize.Level1) -{ - int32_t ret = dev_->OpenChannel(g_testOpenInfoDevEmpty); - EXPECT_EQ(DCAMERA_BAD_VALUE, ret); -} - -/** - * @tc.name: dcamera_sink_dev_test_009 - * @tc.desc: Verify the OpenChannel function. - * @tc.type: FUNC - * @tc.require: AR000GK6N1 - */ -HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_009, TestSize.Level1) -{ - int32_t ret = dev_->OpenChannel(g_testOpenInfoDev); - EXPECT_EQ(DCAMERA_OK, ret); -} - -/** - * @tc.name: dcamera_sink_dev_test_010 - * @tc.desc: Verify the CloseChannel function. - * @tc.type: FUNC - * @tc.require: AR000GK6N1 - */ -HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_010, TestSize.Level1) -{ - int32_t ret = dev_->CloseChannel(); - EXPECT_EQ(DCAMERA_OK, ret); -} - /** * @tc.name: dcamera_sink_dev_test_011 * @tc.desc: Verify the GetDhid function. diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_service_ipc_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_service_ipc_test.cpp deleted file mode 100644 index 8b6c631338641afeeb08fd9492ba260dd26213aa..0000000000000000000000000000000000000000 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_service_ipc_test.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2022 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 - -#define private public -#include "dcamera_sink_service_ipc.h" -#undef private -#include "distributed_hardware_log.h" - -using namespace testing::ext; - -namespace OHOS { -namespace DistributedHardware { -class DCameraSinkServiceIpcTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - -void DCameraSinkServiceIpcTest::SetUpTestCase(void) -{ - DHLOGI("enter"); -} - -void DCameraSinkServiceIpcTest::TearDownTestCase(void) -{ - DHLOGI("enter"); -} - -void DCameraSinkServiceIpcTest::SetUp(void) -{ - DHLOGI("enter"); -} - -void DCameraSinkServiceIpcTest::TearDown(void) -{ - DHLOGI("enter"); -} - -/** - * @tc.name: dcamera_sink_service_ipc_test_001 - * @tc.desc: Verify the dcamera sink service ipc function. - * @tc.type: FUNC - * @tc.require: issue - */ -HWTEST_F(DCameraSinkServiceIpcTest, dcamera_sink_service_ipc_test_001, TestSize.Level1) -{ - DHLOGI("dcamera_sink_service_ipc_test_001"); - DCameraSinkServiceIpc::GetInstance().UnInit(); - DCameraSinkServiceIpc::GetInstance().Init(); - DCameraSinkServiceIpc::GetInstance().UnInit(); - DCameraSinkServiceIpc::GetInstance().isInit_ = true; - DCameraSinkServiceIpc::GetInstance().Init(); - DCameraSinkServiceIpc::GetInstance().UnInit(); - EXPECT_EQ(false, DCameraSinkServiceIpc::GetInstance().isInit_); -} - -/** - * @tc.name: dcamera_sink_service_ipc_test_002 - * @tc.desc: Verify the dcamera sink service ipc function. - * @tc.type: FUNC - * @tc.require: issue - */ -HWTEST_F(DCameraSinkServiceIpcTest, dcamera_sink_service_ipc_test_002, TestSize.Level1) -{ - DHLOGI("dcamera_sink_service_ipc_test_002"); - std::string devId = ""; - sptr sourceSA = DCameraSinkServiceIpc::GetInstance().GetSourceRemoteCamSrv(devId); - EXPECT_EQ(nullptr, sourceSA); - - devId = "devId000"; - sourceSA = DCameraSinkServiceIpc::GetInstance().GetSourceRemoteCamSrv(devId); - EXPECT_EQ(nullptr, sourceSA); - - DCameraSinkServiceIpc::GetInstance().DeleteSourceRemoteCamSrv(devId); - DCameraSinkServiceIpc::GetInstance().ClearSourceRemoteCamSrv(); - wptr remote; - DCameraSinkServiceIpc::GetInstance().OnSourceRemoteCamSrvDied(remote); - EXPECT_EQ(nullptr, sourceSA); -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index 5beae8280f1a0b5d5f55466485f59eb36cb44675..6af8a1da217858564e7e48ebc4737a1b62d59f41 100644 --- a/services/cameraservice/sourceservice/BUILD.gn +++ b/services/cameraservice/sourceservice/BUILD.gn @@ -61,7 +61,6 @@ ohos_shared_library("distributed_camera_source") { "${services_path}/cameraservice/base/src/dcamera_event_cmd.cpp", "${services_path}/cameraservice/base/src/dcamera_info_cmd.cpp", "${services_path}/cameraservice/base/src/dcamera_metadata_setting_cmd.cpp", - "${services_path}/cameraservice/base/src/dcamera_open_info_cmd.cpp", "src/distributedcamera/dcamera_service_state_listener.cpp", "src/distributedcamera/dcamera_source_callback_proxy.cpp", "src/distributedcamera/dcamera_source_hidumper.cpp", @@ -69,7 +68,6 @@ ohos_shared_library("distributed_camera_source") { "src/distributedcamera/distributed_camera_source_stub.cpp", "src/distributedcameramgr/dcamera_source_dev.cpp", "src/distributedcameramgr/dcamera_source_event.cpp", - "src/distributedcameramgr/dcamera_source_service_ipc.cpp", "src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp", "src/distributedcameramgr/dcameracontrol/dcamera_source_controller_channel_listener.cpp", "src/distributedcameramgr/dcameradata/dcamera_source_data_process.cpp", diff --git a/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h b/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h index fc341c5719d9cf99e526f5a371bb5d191be95a2b..13ad530938180e6d4e30ea64cbd5767c9f3b7739 100644 --- a/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h +++ b/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h @@ -47,7 +47,6 @@ public: const std::string& reqId, const EnableParam& param) override; int32_t UnregisterDistributedHardware(const std::string& devId, const std::string& dhId, const std::string& reqId) override; - int32_t DCameraNotify(const std::string& devId, const std::string& dhId, std::string& events) override; int Dump(int32_t fd, const std::vector& args) override; static void GetDumpInfo(CameraDumpInfo& camDump); diff --git a/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_stub.h b/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_stub.h index 99df7ea9bed8f300c7b1a78ba9127c0bf9374caa..c862c5c61b8a8649b9a5e48707d8fc45c1778739 100644 --- a/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_stub.h +++ b/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -34,11 +34,9 @@ private: int32_t ReleaseSourceInner(MessageParcel &data, MessageParcel &reply); int32_t RegisterDistributedHardwareInner(MessageParcel &data, MessageParcel &reply); int32_t UnregisterDistributedHardwareInner(MessageParcel &data, MessageParcel &reply); - int32_t DCameraNotifyInner(MessageParcel &data, MessageParcel &reply); bool CheckRegParams(const std::string& devId, const std::string& dhId, const std::string& reqId, const EnableParam& param); bool CheckUnregParams(const std::string& devId, const std::string& dhId, const std::string& reqId); - bool CheckNotifyParams(const std::string& devId, const std::string& dhId, std::string& events); bool HasEnableDHPermission(); using DCameraFunc = int32_t (DistributedCameraSourceStub::*)(MessageParcel &data, MessageParcel &reply); diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_service_ipc.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_service_ipc.h deleted file mode 100644 index 92ffac2e8f82f6797cbbd81d0fb4dbe33a65ac94..0000000000000000000000000000000000000000 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamera_source_service_ipc.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2021-2022 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_DCAMERA_SOURCE_SERVICE_IPC_H -#define OHOS_DCAMERA_SOURCE_SERVICE_IPC_H - -#include "idistributed_camera_sink.h" - -#include - -#include "single_instance.h" - -namespace OHOS { -namespace DistributedHardware { -class DCameraSourceServiceIpc { -DECLARE_SINGLE_INSTANCE_BASE(DCameraSourceServiceIpc); - -public: - void Init(); - void UnInit(); - sptr GetSinkRemoteCamSrv(const std::string& deviceId); - void OnSinkRemoteCamSrvDied(const wptr& remote); - void DeleteSinkRemoteCamSrv(const std::string& deviceId); - -private: - DCameraSourceServiceIpc(); - ~DCameraSourceServiceIpc(); - void ClearSinkRemoteCamSrv(); - - class SinkRemoteRecipient : public IRemoteObject::DeathRecipient { - public: - void OnRemoteDied(const wptr& remote) override; - }; - sptr sinkRemoteRecipient_; - std::map> remoteSinks_; - std::mutex sinkRemoteCamSrvLock_; - - bool isInit_; - std::mutex initCamSrvLock_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DCAMERA_SOURCE_SERVICE_IPC_H diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameracontrol/dcamera_source_controller.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameracontrol/dcamera_source_controller.h index 03d0120cdaee00c9f68218013b1ac9a369d8f8ed..4f50dcc3ba9ee718ac0303b1538a16128252ac7d 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameracontrol/dcamera_source_controller.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameracontrol/dcamera_source_controller.h @@ -49,7 +49,7 @@ public: int32_t ResumeDistributedHardware(const std::string &networkId) override; int32_t StopDistributedHardware(const std::string &networkId) override; - void OnSessionState(int32_t state); + void OnSessionState(int32_t state, std::string networKId); void OnSessionError(int32_t eventType, int32_t eventReason, std::string detail); void OnDataReceived(std::vector>& buffers); @@ -57,6 +57,7 @@ private: void HandleMetaDataResult(std::string& jsonStr); void PostChannelDisconnectedEvent(); int32_t PublishEnableLatencyMsg(const std::string& devId); + void HandleReceivedData(std::shared_ptr &dataBuffer); class DCameraHdiRecipient : public IRemoteObject::DeathRecipient { public: void OnRemoteDied(const wptr &remote) override; @@ -79,6 +80,7 @@ private: const std::string SESSION_FLAG = "control"; static constexpr uint8_t CHANNEL_REL_SECONDS = 5; + const size_t DATABUFF_MAX_SIZE = 100 * 1024 * 1024; std::atomic isChannelConnected_ = false; std::mutex channelMtx_; std::condition_variable channelCond_; diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameracontrol/dcamera_source_controller_channel_listener.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameracontrol/dcamera_source_controller_channel_listener.h index bf865e14338b0489f06c139cd916a3aa1e0b896f..0914ab1d06581bcc0440c5ebd8dc54f6fc823ee6 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameracontrol/dcamera_source_controller_channel_listener.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameracontrol/dcamera_source_controller_channel_listener.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -27,7 +27,7 @@ class DCameraSourceControllerChannelListener : public ICameraChannelListener { public: explicit DCameraSourceControllerChannelListener(std::shared_ptr& controller); ~DCameraSourceControllerChannelListener() override; - void OnSessionState(int32_t state) override; + void OnSessionState(int32_t state, std::string networKId) override; void OnSessionError(int32_t eventType, int32_t eventReason, std::string detail) override; void OnDataReceived(std::vector>& buffers) override; diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_source_input_channel_listener.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_source_input_channel_listener.h index 5c74d24f77eae0700b03ae131f2b7b9f54b49461..dc1fb1f1114dedd9486912cf166c7841b32831ba 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_source_input_channel_listener.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_source_input_channel_listener.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -29,7 +29,7 @@ class DCameraSourceInputChannelListener : public ICameraChannelListener { public: DCameraSourceInputChannelListener(std::shared_ptr& Input, DCStreamType streamType); ~DCameraSourceInputChannelListener() override; - void OnSessionState(int32_t state) override; + void OnSessionState(int32_t state, std::string networKId) override; void OnSessionError(int32_t eventType, int32_t eventReason, std::string detail) override; void OnDataReceived(std::vector>& buffers) override; diff --git a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp index b0bc57e4dd15ba7d67ca16ac8a3a5521789fb7e8..8a1f3d1f2c302eadbeea63a93366f95d0d18c055 100644 --- a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp +++ b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -30,7 +30,6 @@ #include "dcamera_hisysevent_adapter.h" #include "dcamera_hitrace_adapter.h" #include "dcamera_service_state_listener.h" -#include "dcamera_source_service_ipc.h" #include "dcamera_utils_tools.h" #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" @@ -70,7 +69,6 @@ void DistributedCameraSourceService::OnStart() bool DistributedCameraSourceService::Init() { DHLOGI("DistributedCameraSourceService start init"); - DCameraSourceServiceIpc::GetInstance().Init(); if (!registerToService_) { bool ret = Publish(this); if (!ret) { @@ -94,7 +92,6 @@ void DistributedCameraSourceService::OnStop() state_ = DCameraServiceState::DCAMERA_SRV_STATE_NOT_START; registerToService_ = false; listener_ = nullptr; - DCameraSourceServiceIpc::GetInstance().UnInit(); isHicollieRunning_.store(false); if (hicollieThread_.joinable()) { hicollieThread_.join(); @@ -246,25 +243,6 @@ int32_t DistributedCameraSourceService::UnregisterDistributedHardware(const std: return ret; } -int32_t DistributedCameraSourceService::DCameraNotify(const std::string& devId, const std::string& dhId, - std::string& events) -{ - DHLOGI("DCameraNotify devId: %{public}s, dhId: %{public}s", GetAnonyString(devId).c_str(), - GetAnonyString(dhId).c_str()); - DCameraIndex camIndex(devId, dhId); - std::shared_ptr camDev = GetCamDevByIndex(camIndex); - if (camDev == nullptr) { - DHLOGE("DistributedCameraSourceService DCameraNotify not found device"); - return DCAMERA_NOT_FOUND; - } - - int32_t ret = camDev->DCameraNotify(events); - if (ret != DCAMERA_OK) { - DHLOGE("DCameraNotify failed, ret: %{public}d", ret); - } - return ret; -} - int32_t DistributedCameraSourceService::LoadDCameraHDF() { DCAMERA_SYNC_TRACE(DCAMERA_LOAD_HDF); diff --git a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_stub.cpp b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_stub.cpp index 41b41e7a08718e1f02200baf5c3269e2034d75be..5889d415e4212d4cdf68a658b49d923ac1192342 100644 --- a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_stub.cpp +++ b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -34,8 +34,6 @@ DistributedCameraSourceStub::DistributedCameraSourceStub() : IRemoteStub(true) &DistributedCameraSourceStub::RegisterDistributedHardwareInner; memberFuncMap_[static_cast(IDCameraSourceInterfaceCode::UNREGISTER_DISTRIBUTED_HARDWARE)] = &DistributedCameraSourceStub::UnregisterDistributedHardwareInner; - memberFuncMap_[static_cast(IDCameraSourceInterfaceCode::CAMERA_NOTIFY)] = - &DistributedCameraSourceStub::DCameraNotifyInner; } DistributedCameraSourceStub::~DistributedCameraSourceStub() @@ -70,8 +68,6 @@ int32_t DistributedCameraSourceStub::OnRemoteRequest(uint32_t code, MessageParce return RegisterDistributedHardwareInner(data, reply); case static_cast(IDCameraSourceInterfaceCode::UNREGISTER_DISTRIBUTED_HARDWARE): return UnregisterDistributedHardwareInner(data, reply); - case static_cast(IDCameraSourceInterfaceCode::CAMERA_NOTIFY): - return DCameraNotifyInner(data, reply); default: DHLOGE("Invalid OnRemoteRequest code=%{public}d", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); @@ -219,38 +215,5 @@ bool DistributedCameraSourceStub::CheckUnregParams(const std::string& devId, con } return true; } - -int32_t DistributedCameraSourceStub::DCameraNotifyInner(MessageParcel &data, MessageParcel &reply) -{ - int32_t ret = DCAMERA_OK; - do { - std::string devId = data.ReadString(); - std::string dhId = data.ReadString(); - std::string events = data.ReadString(); - if (!CheckNotifyParams(devId, dhId, events)) { - DHLOGE("input is invalid"); - ret = DCAMERA_BAD_VALUE; - break; - } - ret = DCameraNotify(devId, dhId, events); - } while (0); - reply.WriteInt32(ret); - return DCAMERA_OK; -} - -bool DistributedCameraSourceStub::CheckNotifyParams(const std::string& devId, const std::string& dhId, - std::string& events) -{ - if (devId.empty() || devId.size() > DID_MAX_SIZE || dhId.empty() || dhId.size() > DID_MAX_SIZE) { - DHLOGE("devId or dhId is invalid"); - return false; - } - - if (events.empty() || events.size() > PARAM_MAX_SIZE) { - DHLOGE("events is invalid"); - return false; - } - return true; -} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_service_ipc.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_service_ipc.cpp deleted file mode 100644 index ad2aec0685e666ba827e2354a93c11a7fce8c3b5..0000000000000000000000000000000000000000 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_service_ipc.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 "dcamera_source_service_ipc.h" - -#include "if_system_ability_manager.h" -#include "iservice_registry.h" - -#include "anonymous_string.h" -#include "distributed_camera_constants.h" -#include "distributed_camera_errno.h" -#include "distributed_hardware_log.h" - -namespace OHOS { -namespace DistributedHardware { -DCameraSourceServiceIpc::DCameraSourceServiceIpc() : isInit_(false) -{ - DHLOGI("DCameraSourceServiceIpc Create"); -} - -DCameraSourceServiceIpc::~DCameraSourceServiceIpc() -{ - DHLOGI("DCameraSourceServiceIpc Delete"); - UnInit(); -} - -IMPLEMENT_SINGLE_INSTANCE(DCameraSourceServiceIpc); - -void DCameraSourceServiceIpc::Init() -{ - std::lock_guard autoLock(initCamSrvLock_); - DHLOGI("Start"); - if (isInit_) { - DHLOGI("DCameraSourceServiceIpc has already init"); - return; - } - sinkRemoteRecipient_ = sptr(new SinkRemoteRecipient()); - isInit_ = true; - DHLOGI("End"); -} - -void DCameraSourceServiceIpc::UnInit() -{ - std::lock_guard autoLock(initCamSrvLock_); - DHLOGI("Start"); - if (!isInit_) { - DHLOGI("DCameraSourceServiceIpc has already UnInit"); - return; - } - ClearSinkRemoteCamSrv(); - DHLOGI("Start free recipient"); - sinkRemoteRecipient_ = nullptr; - isInit_ = false; - DHLOGI("End"); -} - -sptr DCameraSourceServiceIpc::GetSinkRemoteCamSrv(const std::string& deviceId) -{ - if (deviceId.empty()) { - DHLOGE("GetSinkRemoteCamSrv deviceId is empty"); - return nullptr; - } - { - std::lock_guard autoLock(sinkRemoteCamSrvLock_); - auto iter = remoteSinks_.find(deviceId); - if (iter != remoteSinks_.end()) { - auto object = iter->second; - if (object != nullptr) { - DHLOGI("DCameraSourceServiceIpc GetSinkRemoteCamSrv from cache devId: %{public}s", - GetAnonyString(deviceId).c_str()); - return object; - } - } - } - DHLOGI("GetSinkRemoteCamSrv remote deviceid is %{public}s", GetAnonyString(deviceId).c_str()); - auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgr == nullptr) { - DHLOGE("GetSinkRemoteCamSrv failed to connect to systemAbilityMgr!"); - return nullptr; - } - - auto object = samgr->CheckSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, deviceId); - if (object == nullptr) { - DHLOGE("GetSinkRemoteCamSrv failed get remote CamSrv %{public}s", GetAnonyString(deviceId).c_str()); - return nullptr; - } - int32_t ret = object->AddDeathRecipient(sinkRemoteRecipient_); - sptr remoteCamSrvObj = iface_cast(object); - if (remoteCamSrvObj == nullptr) { - DHLOGI("GetSinkRemoteCamSrv failed, remoteCamSrvObj is null ret: %{public}d", ret); - return nullptr; - } - { - std::lock_guard autoLock(sinkRemoteCamSrvLock_); - auto iter = remoteSinks_.find(deviceId); - if (iter != remoteSinks_.end()) { - iter->second->AsObject()->RemoveDeathRecipient(sinkRemoteRecipient_); - } - remoteSinks_[deviceId] = remoteCamSrvObj; - } - DHLOGI("GetSinkRemoteCamSrv success, AddDeathRecipient ret: %{public}d", ret); - return remoteCamSrvObj; -} - -void DCameraSourceServiceIpc::DeleteSinkRemoteCamSrv(const std::string& deviceId) -{ - DHLOGI("DeleteSinkRemoteCamSrv devId: %{public}s", GetAnonyString(deviceId).c_str()); - std::lock_guard autoLock(sinkRemoteCamSrvLock_); - auto item = remoteSinks_.find(deviceId); - if (item == remoteSinks_.end()) { - DHLOGI("DeleteSinkRemoteCamSrv not found device: %{public}s", GetAnonyString(deviceId).c_str()); - return; - } - - if (item->second != nullptr) { - item->second->AsObject()->RemoveDeathRecipient(sinkRemoteRecipient_); - } - remoteSinks_.erase(item); -} - -void DCameraSourceServiceIpc::ClearSinkRemoteCamSrv() -{ - DHLOGI("ClearSinkRemoteCamSrv Start"); - std::lock_guard autoLock(sinkRemoteCamSrvLock_); - for (auto iter = remoteSinks_.begin(); iter != remoteSinks_.end(); iter++) { - if (iter->second != nullptr) { - iter->second->AsObject()->RemoveDeathRecipient(sinkRemoteRecipient_); - } - } - remoteSinks_.clear(); - DHLOGI("ClearSinkRemoteCamSrv end"); -} - -void DCameraSourceServiceIpc::SinkRemoteRecipient::OnRemoteDied(const wptr& remote) -{ - DHLOGI("SinkRemoteRecipient OnRemoteDied received died notify!"); - DCameraSourceServiceIpc::GetInstance().OnSinkRemoteCamSrvDied(remote); -} - -void DCameraSourceServiceIpc::OnSinkRemoteCamSrvDied(const wptr& remote) -{ - DHLOGI("OnSinkRemoteCamSrvDied delete diedRemoted"); - std::lock_guard autoLock(sinkRemoteCamSrvLock_); - sptr diedRemoted = remote.promote(); - if (diedRemoted == nullptr) { - DHLOGE("OnSinkRemoteCamSrvDied promote failed!"); - return; - } - auto iter = std::find_if(remoteSinks_.begin(), remoteSinks_.end(), [&]( - const std::pair> &item)->bool { - return item.second->AsObject() == diedRemoted; - }); - if (iter == remoteSinks_.end()) { - DHLOGI("OnSinkRemoteCamSrvDied not found remote object"); - return; - } - - DHLOGI("OnSinkRemoteCamSrvDied remote.devId: %{public}s", GetAnonyString(iter->first).c_str()); - if (iter->second != nullptr) { - iter->second->AsObject()->RemoveDeathRecipient(sinkRemoteRecipient_); - } - remoteSinks_.erase(iter); -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp index 65c6ee49e3cd86f4dff598d88001d785cddcafa3..d56cf733b834b631108a7d2516dcf3a512fae6e9 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp @@ -29,7 +29,6 @@ #include "dcamera_protocol.h" #include "dcamera_softbus_latency.h" #include "dcamera_source_controller_channel_listener.h" -#include "dcamera_source_service_ipc.h" #include "dcamera_utils_tools.h" #include "distributed_camera_constants.h" @@ -119,16 +118,33 @@ int32_t DCameraSourceController::StopCapture() std::string devId = indexs_.begin()->devId_; DHLOGI("StopCapture devId: %{public}s, dhId: %{public}s", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); - sptr camSinkSrv = DCameraSourceServiceIpc::GetInstance().GetSinkRemoteCamSrv(devId); - if (camSinkSrv == nullptr) { - DHLOGE("can not get service, devId: %{public}s", GetAnonyString(devId).c_str()); - return DCAMERA_BAD_OPERATE; + cJSON *rootValue = cJSON_CreateObject(); + if (rootValue == nullptr) { + return DCAMERA_BAD_VALUE; + } + cJSON_AddStringToObject(rootValue, "Command", DCAMERA_PROTOCOL_CMD_STOP_CAPTURE.c_str()); + char *data = cJSON_Print(rootValue); + if (data == nullptr) { + cJSON_Delete(rootValue); + return DCAMERA_BAD_VALUE; + } + std::string jsonStr = std::string(data); + cJSON_Delete(rootValue); + cJSON_free(data); + std::shared_ptr buffer = std::make_shared(jsonStr.length() + 1); + int32_t ret = memcpy_s(buffer->Data(), buffer->Capacity(), + reinterpret_cast(const_cast(jsonStr.c_str())), jsonStr.length()); + if (ret != EOK) { + DHLOGE("StopCapture memcpy_s failed %{public}d, devId: %{public}s, dhId: %{public}s", ret, + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); + return ret; } - int32_t ret = camSinkSrv->StopCapture(dhId); + CHECK_AND_RETURN_RET_LOG(channel_ == nullptr, DCAMERA_BAD_VALUE, "channel_ is null."); + ret = channel_->SendData(buffer); if (ret != DCAMERA_OK) { - DHLOGE("StopCapture failed: %{public}d, devId: %{public}s, dhId: %{public}s", ret, + DHLOGE("StopCapture SendData failed %{public}d, devId: %{public}s, dhId: %{public}s", ret, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); - return DCAMERA_BAD_OPERATE; + return ret; } DHLOGI("StopCapture devId: %{public}s, dhId: %{public}s success", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); @@ -137,42 +153,6 @@ int32_t DCameraSourceController::StopCapture() int32_t DCameraSourceController::ChannelNeg(std::shared_ptr& info) { - if (indexs_.size() > DCAMERA_MAX_NUM) { - DHLOGE("ChannelNeg not support operate %{public}zu camera", indexs_.size()); - return DCAMERA_BAD_OPERATE; - } - - std::string dhId = indexs_.begin()->dhId_; - std::string devId = indexs_.begin()->devId_; - DHLOGI("ChannelNeg devId: %{public}s, dhId: %{public}s", GetAnonyString(devId).c_str(), - GetAnonyString(dhId).c_str()); - sptr camSinkSrv = DCameraSourceServiceIpc::GetInstance().GetSinkRemoteCamSrv(devId); - if (camSinkSrv == nullptr) { - DHLOGE("can not get service, devId: %{public}s", GetAnonyString(devId).c_str()); - return DCAMERA_BAD_OPERATE; - } - DCameraChannelInfoCmd cmd; - cmd.type_ = DCAMERA_PROTOCOL_TYPE_MESSAGE; - cmd.dhId_ = dhId; - cmd.command_ = DCAMERA_PROTOCOL_CMD_CHAN_NEG; - cmd.value_ = info; - std::string jsonStr; - int32_t ret = cmd.Marshal(jsonStr); - if (ret != DCAMERA_OK) { - DHLOGE("Marshal failed ret: %{public}d, devId: %{public}s, dhId: %{public}s", ret, - GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); - return ret; - } - DHLOGD("devId: %{public}s, dhId: %{public}s channelNegCommand: %{public}s", - GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), cmd.command_.c_str()); - ret = camSinkSrv->ChannelNeg(dhId, jsonStr); - if (ret != DCAMERA_OK) { - DHLOGE("ChannelNeg rpc failed ret: %{public}d, devId: %{public}s, dhId: %{public}s", ret, - GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); - return ret; - } - DHLOGD("DCameraSourceController ChannelNeg devId: %{public}s, dhId: %{public}s success", - GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); return DCAMERA_OK; } @@ -253,34 +233,6 @@ int32_t DCameraSourceController::UpdateSettings(std::vector& camInfo) { - if (indexs_.size() > DCAMERA_MAX_NUM) { - DHLOGE("GetCameraInfo not support operate %{public}zu camera", indexs_.size()); - return DCAMERA_BAD_OPERATE; - } - - std::string dhId = indexs_.begin()->dhId_; - std::string devId = indexs_.begin()->devId_; - DHLOGI("GetCameraInfo devId: %{public}s, dhId: %{public}s", GetAnonyString(devId).c_str(), - GetAnonyString(dhId).c_str()); - sptr camSinkSrv = DCameraSourceServiceIpc::GetInstance().GetSinkRemoteCamSrv(devId); - if (camSinkSrv == nullptr) { - DHLOGE("can not get service, devId: %{public}s", GetAnonyString(devId).c_str()); - return DCAMERA_BAD_OPERATE; - } - std::string camInfoJson; - int32_t ret = camSinkSrv->GetCameraInfo(dhId, camInfoJson); - if (ret != DCAMERA_OK) { - DHLOGE("GetCameraInfo failed: %{public}d, devId: %{public}s, dhId: %{public}s", ret, - GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); - return ret; - } - DCameraInfoCmd cmd; - ret = cmd.Unmarshal(camInfoJson); - if (ret != DCAMERA_OK) { - DHLOGE("DCameraInfoCmd Unmarshal failed: %{public}d", ret); - return ret; - } - camInfo = cmd.value_; return DCAMERA_OK; } @@ -294,34 +246,11 @@ int32_t DCameraSourceController::OpenChannel(std::shared_ptr& o std::string devId = indexs_.begin()->devId_; DHLOGI("DCameraSourceController OpenChannel Start, devId: %{public}s, dhId: %{public}s", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); - sptr camSinkSrv = DCameraSourceServiceIpc::GetInstance().GetSinkRemoteCamSrv(devId); - if (camSinkSrv == nullptr) { - DHLOGE("DCameraSourceController can not get service, devId: %{public}s", GetAnonyString(devId).c_str()); - return DCAMERA_BAD_OPERATE; - } - std::string jsonStr; - DCameraOpenInfoCmd cmd; - cmd.type_ = DCAMERA_PROTOCOL_TYPE_MESSAGE; - cmd.dhId_ = dhId; - cmd.command_ = DCAMERA_PROTOCOL_CMD_OPEN_CHANNEL; - cmd.value_ = openInfo; - int32_t ret = cmd.Marshal(jsonStr); - if (ret != DCAMERA_OK) { - DHLOGE("DCameraSourceController Marshal OpenInfo failed %{public}d", ret); - return ret; - } - ret = camSinkSrv->OpenChannel(dhId, jsonStr); - if (ret != DCAMERA_OK) { - DHLOGE("DCameraSourceController SA OpenChannel failed %{public}d", ret); - return ret; - } - DHLOGD("DCameraSourceController OpenChannel devId: %{public}s, dhId: %{public}s success", - GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); std::vector indexs; indexs.push_back(DCameraIndex(devId, dhId)); CHECK_AND_RETURN_RET_LOG(channel_ == nullptr, DCAMERA_BAD_VALUE, "channel_ is null."); - ret = channel_->CreateSession(indexs, SESSION_FLAG, DCAMERA_SESSION_MODE_CTRL, listener_); + int32_t ret = channel_->CreateSession(indexs, SESSION_FLAG, DCAMERA_SESSION_MODE_CTRL, listener_); if (ret != DCAMERA_OK) { DHLOGE("DCameraSourceController Bind Socket failed, ret: %{public}d", ret); PostChannelDisconnectedEvent(); @@ -342,6 +271,7 @@ int32_t DCameraSourceController::CloseChannel() std::string devId = indexs_.begin()->devId_; DHLOGI("DCameraSourceController CloseChannel Start, devId: %{public}s, dhId: %{public}s", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); + CHECK_AND_RETURN_RET_LOG(channel_ == nullptr, DCAMERA_BAD_VALUE, "channel_ is null."); int32_t ret = channel_->CloseSession(); if (ret != DCAMERA_OK) { DHLOGE("CloseSession failed %{public}d", ret); @@ -353,13 +283,30 @@ int32_t DCameraSourceController::CloseChannel() if (ret != DCAMERA_OK) { DHLOGE("ReleaseSession failed %{public}d", ret); } - sptr camSinkSrv = DCameraSourceServiceIpc::GetInstance().GetSinkRemoteCamSrv(devId); - if (camSinkSrv != nullptr) { - ret = camSinkSrv->CloseChannel(dhId); - if (ret != DCAMERA_OK) { - DHLOGE("DCameraSourceController SA CloseChannel failed %{public}d", ret); - } - DCameraSourceServiceIpc::GetInstance().DeleteSinkRemoteCamSrv(devId); + cJSON *rootValue = cJSON_CreateObject(); + if (rootValue == nullptr) { + return DCAMERA_BAD_VALUE; + } + cJSON_AddStringToObject(rootValue, "Command", DCAMERA_PROTOCOL_CMD_CLOSE_CHANNEL.c_str()); + char *data = cJSON_Print(rootValue); + if (data == nullptr) { + cJSON_Delete(rootValue); + return DCAMERA_BAD_VALUE; + } + std::string jsonStr = std::string(data); + cJSON_Delete(rootValue); + cJSON_free(data); + std::shared_ptr buffer = std::make_shared(jsonStr.length() + 1); + ret = memcpy_s(buffer->Data(), buffer->Capacity(), + reinterpret_cast(const_cast(jsonStr.c_str())), jsonStr.length()); + if (ret != EOK) { + DHLOGE("CloseChannel memcpy_s failed %{public}d, devId: %{public}s, dhId: %{public}s", ret, + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); + } + ret = channel_->SendData(buffer); + if (ret != DCAMERA_OK) { + DHLOGE("StopCapture SendData failed %{public}d, devId: %{public}s, dhId: %{public}s", ret, + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); } return ret; } @@ -405,7 +352,7 @@ int32_t DCameraSourceController::UnInit() return DCAMERA_OK; } -void DCameraSourceController::OnSessionState(int32_t state) +void DCameraSourceController::OnSessionState(int32_t state, std::string networkId) { DHLOGI("DCameraSourceController OnSessionState state %{public}d", state); channelState_ = state; @@ -446,13 +393,20 @@ void DCameraSourceController::OnSessionError(int32_t eventType, int32_t eventRea void DCameraSourceController::OnDataReceived(std::vector>& buffers) { - if (buffers.empty()) { - DHLOGI("DCameraSourceController OnDataReceived empty, devId: %{public}s, dhId: %{public}s", - GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); - return; + for (auto& buffer : buffers) { + if (buffer->Size() <= 0 || buffer->Size() > DATABUFF_MAX_SIZE) { + DHLOGI("buffer is invalid"); + return; + } + HandleReceivedData(buffer); } - std::shared_ptr buffer = *(buffers.begin()); - std::string jsonStr(reinterpret_cast(buffer->Data())); +} + +void DCameraSourceController::HandleReceivedData(std::shared_ptr& dataBuffer) +{ + DHLOGI("DCameraSourceController::HandleReceivedData dhId: %{public}s", GetAnonyString(dhId_).c_str()); + uint8_t *data = dataBuffer->Data(); + std::string jsonStr(reinterpret_cast(data), dataBuffer->Capacity()); cJSON *rootValue = cJSON_Parse(jsonStr.c_str()); if (rootValue == nullptr) { return; @@ -460,14 +414,23 @@ void DCameraSourceController::OnDataReceived(std::vectorvaluestring == nullptr)) { cJSON_Delete(rootValue); + DHLOGE("parse command failed"); return; } std::string command = std::string(comvalue->valuestring); - if (command == DCAMERA_PROTOCOL_CMD_METADATA_RESULT) { + cJSON_Delete(rootValue); + if ((!command.empty()) && (command.compare(DCAMERA_PROTOCOL_CMD_METADATA_RESULT) == 0)) { HandleMetaDataResult(jsonStr); + } else if ((!command.empty()) && (command.compare(DCAMERA_PROTOCOL_CMD_STATE_NOTIFY) == 0)) { + DCameraEventCmd cmd; + int32_t ret = cmd.Unmarshal(jsonStr); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraSourceController Unmarshal failed, ret: %{public}d, devId: %{public}s, " + "dhId: %{public}s", ret, GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); + return; + } + DCameraNotify(cmd.value_); } - cJSON_Delete(rootValue); - return; } void DCameraSourceController::HandleMetaDataResult(std::string& jsonStr) diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller_channel_listener.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller_channel_listener.cpp index 289c6024e65db82c68e5524e2f41506b6c73ffce..635038668956547d29840810712d8d63e116eac8 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller_channel_listener.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller_channel_listener.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -31,7 +31,7 @@ DCameraSourceControllerChannelListener::~DCameraSourceControllerChannelListener( { } -void DCameraSourceControllerChannelListener::OnSessionState(int32_t state) +void DCameraSourceControllerChannelListener::OnSessionState(int32_t state, std::string networkId) { std::shared_ptr controller = controller_.lock(); if (controller == nullptr) { @@ -39,7 +39,7 @@ void DCameraSourceControllerChannelListener::OnSessionState(int32_t state) return; } - controller->OnSessionState(state); + controller->OnSessionState(state, networkId); } void DCameraSourceControllerChannelListener::OnSessionError(int32_t eventType, int32_t eventReason, std::string detail) diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input_channel_listener.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input_channel_listener.cpp index 1dfe66ef711facdf48ddf30ec891f1cb643e2137..037289df13d6a49c2563ca876c7f8bd1804f6314 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input_channel_listener.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input_channel_listener.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -31,7 +31,7 @@ DCameraSourceInputChannelListener::~DCameraSourceInputChannelListener() { } -void DCameraSourceInputChannelListener::OnSessionState(int32_t state) +void DCameraSourceInputChannelListener::OnSessionState(int32_t state, std::string networkId) { std::shared_ptr input = input_.lock(); if (input == nullptr) { diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/distributed_camera_source_service_test.cpp b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/distributed_camera_source_service_test.cpp index 57403d98dc047402302d8df0dd4f24852269b416..a139e85da905ad5b4f62ed7700a9d89467740b03 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/distributed_camera_source_service_test.cpp +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/distributed_camera_source_service_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -90,22 +90,6 @@ HWTEST_F(DistributedCameraSourceServiceTest, dcamera_source_service_test_001, Te EXPECT_EQ(DCAMERA_OK, ret); } -/** - * @tc.name: dcamera_source_service_test_002 - * @tc.desc: Verify the DCameraNotify function. - * @tc.type: FUNC - * @tc.require: issue - */ -HWTEST_F(DistributedCameraSourceServiceTest, dcamera_source_service_test_002, TestSize.Level1) -{ - DHLOGI("DistributedCameraSourceServiceTest::dcamera_source_service_test_002"); - EXPECT_EQ(false, testSrcService_ == nullptr); - - std::string events; - int32_t ret = testSrcService_->DCameraNotify(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, events); - EXPECT_EQ(DCAMERA_BAD_VALUE, ret); -} - /** * @tc.name: dcamera_source_service_test_003 * @tc.desc: Verify the Dump function. diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/distributed_camera_source_stub_test.cpp b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/distributed_camera_source_stub_test.cpp index a6cbf45191bcf21e0edccb2d70131c0b50711bee..18d8a77b997e68e0fa4457a8ea45ce7c5372553d 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/distributed_camera_source_stub_test.cpp +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcamera/distributed_camera_source_stub_test.cpp @@ -156,51 +156,6 @@ HWTEST_F(DcameraSourceStubTest, dcamera_source_stub_test_004, TestSize.Level1) EXPECT_EQ(DCAMERA_OK, ret); } -/** - * @tc.name: dcamera_source_stub_test_005 - * @tc.desc: Verify the DCameraNotify function. - * @tc.type: FUNC - * @tc.require: issue - */ -HWTEST_F(DcameraSourceStubTest, dcamera_source_stub_test_005, TestSize.Level1) -{ - DHLOGI("DcameraSourceStubTest::dcamera_source_stub_test_005"); - sptr sourceStubPtr(new MockDistributedCameraSourceStub()); - DistributedCameraSourceProxy sourceProxy(sourceStubPtr); - std::string devId = "devId000"; - std::string dhId = "dhId000"; - std::string events = "events000"; - int32_t ret = sourceProxy.DCameraNotify(devId, dhId, events); - EXPECT_EQ(DCAMERA_OK, ret); -} - -/** - * @tc.name: dcamera_source_stub_test_006 - * @tc.desc: Verify the DCameraNotify function. - * @tc.type: FUNC - * @tc.require: issue - */ -HWTEST_F(DcameraSourceStubTest, dcamera_source_stub_test_006, TestSize.Level1) -{ - DHLOGI("DcameraSourceStubTest::dcamera_source_stub_test_006"); - sptr sourceStubPtr(new MockDistributedCameraSourceStub()); - DistributedCameraSourceProxy sourceProxy(sourceStubPtr); - std::string devId = ""; - std::string dhId = "dhId000"; - std::string events = "events000"; - int32_t ret = sourceProxy.DCameraNotify(devId, dhId, events); - EXPECT_EQ(DCAMERA_BAD_VALUE, ret); - - devId = "devId000"; - events = ""; - ret = sourceProxy.DCameraNotify(devId, dhId, events); - EXPECT_EQ(DCAMERA_BAD_VALUE, ret); - - dhId = ""; - ret = sourceProxy.DCameraNotify(devId, dhId, events); - EXPECT_EQ(DCAMERA_BAD_VALUE, ret); -} - /** * @tc.name: dcamera_source_stub_test_007 * @tc.desc: Verify the UnregisterDistributedHardware function. diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn index 0a05c6ad0cc381d35e9167bc86666d4f6452485f..51694a09f7cfd13fb137f01b2261f5bddbc5fdb2 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn @@ -66,7 +66,6 @@ ohos_unittest("DCameraSourceMgrTest") { "dcamera_source_data_process_test.cpp", "dcamera_source_dev_test.cpp", "dcamera_source_input_test.cpp", - "dcamera_source_service_ipc_test.cpp", "dcamera_source_state_machine_test.cpp", "dcamera_stream_data_process_producer_test.cpp", "dcamera_stream_data_process_test.cpp", diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_controller_test.cpp b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_controller_test.cpp index f289abf00242eb602975418f200a4021ca72435a..730f15a49a183f95501304975cd85442a0173c86 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_controller_test.cpp +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_controller_test.cpp @@ -172,7 +172,7 @@ HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_004, TestSi ret = controller_->StopCapture(); controller_->UnInit(); - EXPECT_EQ(ret, DCAMERA_BAD_OPERATE); + EXPECT_EQ(ret, DCAMERA_OK); } /** @@ -198,7 +198,7 @@ HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_005, TestSi controller_->indexs_.push_back(index1); ret = controller_->ChannelNeg(chanInfo); controller_->UnInit(); - EXPECT_EQ(ret, DCAMERA_BAD_OPERATE); + EXPECT_EQ(ret, DCAMERA_OK); } /** @@ -247,7 +247,7 @@ HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_007, TestSi camInfo->state_ = 1; ret = controller_->GetCameraInfo(camInfo); controller_->UnInit(); - EXPECT_EQ(ret, DCAMERA_BAD_OPERATE); + EXPECT_EQ(ret, DCAMERA_OK); } /** @@ -268,7 +268,7 @@ HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_008, TestSi ret = GetLocalDeviceNetworkId(openInfo->sourceDevId_); ret = controller_->OpenChannel(openInfo); controller_->UnInit(); - EXPECT_EQ(ret, DCAMERA_BAD_OPERATE); + EXPECT_EQ(ret, DCAMERA_OK); } /** @@ -306,7 +306,7 @@ HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_010, TestSi std::shared_ptr listener = std::make_shared(controller_); int32_t state = 0; - listener->OnSessionState(state); + listener->OnSessionState(state, ""); int32_t eventType = 1; int32_t eventReason = 1; std::string detail = "OnSessionErrorTest"; @@ -343,7 +343,7 @@ HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_011, TestSi controller_->indexs_.push_back(index2); ret = controller_->ChannelNeg(chanInfo); controller_->UnInit(); - EXPECT_EQ(ret, DCAMERA_BAD_OPERATE); + EXPECT_EQ(ret, DCAMERA_OK); } /** @@ -412,7 +412,7 @@ HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_014, TestSi camInfo->state_ = 1; int32_t ret = controller_->GetCameraInfo(camInfo); controller_->UnInit(); - EXPECT_EQ(ret, DCAMERA_BAD_OPERATE); + EXPECT_EQ(ret, DCAMERA_OK); } /** @@ -503,7 +503,7 @@ HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_019, TestSi std::shared_ptr listener_ = std::make_shared(controller); int32_t state = 0; - listener_->OnSessionState(state); + listener_->OnSessionState(state, ""); int32_t eventType = 1; int32_t eventReason = 1; std::string detail = "OnSessionErrorTest"; diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_service_ipc_test.cpp b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_service_ipc_test.cpp deleted file mode 100644 index 0a22b70ce55557413680e02a971e6b37d67de90f..0000000000000000000000000000000000000000 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/dcamera_source_service_ipc_test.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2022 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 -#define private public -#include "dcamera_source_service_ipc.h" -#undef private - -#include "if_system_ability_manager.h" -#include "iservice_registry.h" -#include "anonymous_string.h" -#include "distributed_camera_constants.h" -#include "distributed_camera_errno.h" -#include "distributed_hardware_log.h" - -using namespace testing::ext; - -namespace OHOS { -namespace DistributedHardware { -class DCameraSourceServiceIpcTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - -void DCameraSourceServiceIpcTest::SetUpTestCase(void) -{ - DHLOGI("DCameraSourceServiceIpcTest::SetUpTestCase"); -} - -void DCameraSourceServiceIpcTest::TearDownTestCase(void) -{ - DHLOGI("DCameraSourceServiceIpcTest::TearDownTestCase"); -} - -void DCameraSourceServiceIpcTest::SetUp(void) -{ - DHLOGI("DCameraSourceServiceIpcTest::SetUp"); -} - -void DCameraSourceServiceIpcTest::TearDown(void) -{ - DHLOGI("DCameraSourceServiceIpcTest::TearDown"); -} - -/** - * @tc.name: dcamera_source_service_ipc_test_001 - * @tc.desc: Verify Init func. - * @tc.type: FUNC - * @tc.require: issue - */ -HWTEST_F(DCameraSourceServiceIpcTest, dcamera_source_service_ipc_test_001, TestSize.Level1) -{ - DHLOGI("DCameraSourceServiceIpcTest::dcamera_source_service_ipc_test_001"); - DCameraSourceServiceIpc::GetInstance().Init(); - EXPECT_EQ(DCameraSourceServiceIpc::GetInstance().isInit_, true); - DCameraSourceServiceIpc::GetInstance().Init(); - EXPECT_EQ(DCameraSourceServiceIpc::GetInstance().isInit_, true); -} - -/** - * @tc.name: dcamera_source_service_ipc_test_002 - * @tc.desc: Verify UnInit func. - * @tc.type: FUNC - * @tc.require: issue - */ -HWTEST_F(DCameraSourceServiceIpcTest, dcamera_source_service_ipc_test_002, TestSize.Level1) -{ - DHLOGI("DCameraSourceServiceIpcTest::dcamera_source_service_ipc_test_002"); - DCameraSourceServiceIpc::GetInstance().Init(); - EXPECT_EQ(DCameraSourceServiceIpc::GetInstance().isInit_, true); - DCameraSourceServiceIpc::GetInstance().UnInit(); - EXPECT_EQ(DCameraSourceServiceIpc::GetInstance().isInit_, false); - DCameraSourceServiceIpc::GetInstance().UnInit(); - EXPECT_EQ(DCameraSourceServiceIpc::GetInstance().isInit_, false); -} - -/** - * @tc.name: dcamera_source_service_ipc_test_003 - * @tc.desc: Verify GetSinkRemoteCamSrv func. - * @tc.type: FUNC - * @tc.require: issue - */ -HWTEST_F(DCameraSourceServiceIpcTest, dcamera_source_service_ipc_test_003, TestSize.Level1) -{ - DHLOGI("DCameraSourceServiceIpcTest::dcamera_source_service_ipc_test_003"); - std::string deviceId = ""; - DCameraSourceServiceIpc::GetInstance().Init(); - sptr camSinkSrv = DCameraSourceServiceIpc::GetInstance().GetSinkRemoteCamSrv(deviceId); - EXPECT_EQ(nullptr, camSinkSrv); - DCameraSourceServiceIpc::GetInstance().UnInit(); - EXPECT_EQ(DCameraSourceServiceIpc::GetInstance().isInit_, false); -} - -/** - * @tc.name: dcamera_source_service_ipc_test_004 - * @tc.desc: Verify DeleteSinkRemoteCamSrv func. - * @tc.type: FUNC - * @tc.require: issue - */ -HWTEST_F(DCameraSourceServiceIpcTest, dcamera_source_service_ipc_test_004, TestSize.Level1) -{ - DHLOGI("DCameraSourceServiceIpcTest::dcamera_source_service_ipc_test_004"); - std::string deviceId = "test004"; - DCameraSourceServiceIpc::GetInstance().Init(); - sptr camSinkSrv = DCameraSourceServiceIpc::GetInstance().GetSinkRemoteCamSrv(deviceId); - DCameraSourceServiceIpc::GetInstance().remoteSinks_.emplace(deviceId, camSinkSrv); - DCameraSourceServiceIpc::GetInstance().DeleteSinkRemoteCamSrv(deviceId); - deviceId = "test0004"; - DCameraSourceServiceIpc::GetInstance().DeleteSinkRemoteCamSrv(deviceId); - camSinkSrv = nullptr; - DCameraSourceServiceIpc::GetInstance().remoteSinks_.emplace(deviceId, camSinkSrv); - DCameraSourceServiceIpc::GetInstance().DeleteSinkRemoteCamSrv(deviceId); - DCameraSourceServiceIpc::GetInstance().UnInit(); - EXPECT_EQ(nullptr, camSinkSrv); -} - -/** - * @tc.name: dcamera_source_service_ipc_test_005 - * @tc.desc: Verify GetSinkRemoteCamSrv func. - * @tc.type: FUNC - * @tc.require: issue - */ -HWTEST_F(DCameraSourceServiceIpcTest, dcamera_source_service_ipc_test_005, TestSize.Level1) -{ - DHLOGI("DCameraSourceServiceIpcTest::dcamera_source_service_ipc_test_005"); - std::string deviceId = ""; - DCameraSourceServiceIpc::GetInstance().Init(); - sptr samgr = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - wptr remote = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID); - DCameraSourceServiceIpc::GetInstance().OnSinkRemoteCamSrvDied(remote); - DCameraSourceServiceIpc::GetInstance().UnInit(); - EXPECT_EQ(DCameraSourceServiceIpc::GetInstance().isInit_, false); -} -} -} \ No newline at end of file diff --git a/services/channel/include/dcamera_channel_sink_impl.h b/services/channel/include/dcamera_channel_sink_impl.h index 638d13ec0a053e23f552b6c41c31701a773a5f4c..441dab065f7f9e7a33310ab14753df7e0177078a 100644 --- a/services/channel/include/dcamera_channel_sink_impl.h +++ b/services/channel/include/dcamera_channel_sink_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -38,7 +38,6 @@ private: std::shared_ptr softbusSession_; std::string mySessionName_; DCameraSessionMode mode_ = DCAMERA_SESSION_MODE_CTRL; - const std::string SESSION_HEAD = "ohos.dhardware.dcamera_"; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/channel/include/dcamera_channel_source_impl.h b/services/channel/include/dcamera_channel_source_impl.h index 1d394ed7b9e83bd2a28325d18a28a3d1ca1c695a..4b545a50e1ada927afdad3afab96f8c1d9dac772 100644 --- a/services/channel/include/dcamera_channel_source_impl.h +++ b/services/channel/include/dcamera_channel_source_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -38,7 +38,6 @@ private: std::vector> softbusSessions_; std::string mySessionName_; DCameraSessionMode mode_ = DCAMERA_SESSION_MODE_CTRL; - const std::string SESSION_HEAD = "ohos.dhardware.dcamera_"; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/channel/include/dcamera_softbus_adapter.h b/services/channel/include/dcamera_softbus_adapter.h index 2af2bbd7eb84e9a70f7a89958f864e6f89752d14..3f99fc6eac4ca4c60642b32429d3d10923e2f332 100644 --- a/services/channel/include/dcamera_softbus_adapter.h +++ b/services/channel/include/dcamera_softbus_adapter.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -77,6 +77,7 @@ private: PeerSocketInfo info); int32_t DCameraSoftbusSourceGetSession(int32_t socket, std::shared_ptr& session); int32_t DCameraSoftbusSinkGetSession(int32_t socket, std::shared_ptr& session); + std::string FindSessNameByPeerSessName(const std::string peerSessionName); private: std::mutex optLock_; @@ -89,8 +90,6 @@ private: int32_t sourceSocketId_ = -1; std::map sessionModeAndDataTypeMap_; - std::mutex mySessionNamePeerDevIdLock_; - std::map peerDevIdMySessionNameMap_; std::mutex mySessionNameLock_; std::set mySessionNameSet_; diff --git a/services/channel/include/dcamera_softbus_session.h b/services/channel/include/dcamera_softbus_session.h index 13bdec34da0c3a146bf28ed63cf55bf41d35fe18..1ae110ac1330bf94cb23abc92c24b6e0106e4833 100644 --- a/services/channel/include/dcamera_softbus_session.h +++ b/services/channel/include/dcamera_softbus_session.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -37,7 +37,7 @@ public: std::string peerSessionName, std::shared_ptr listener, DCameraSessionMode mode); ~DCameraSoftbusSession(); int32_t CloseSession(); - int32_t OnSessionOpened(int32_t socket); + int32_t OnSessionOpened(int32_t socket, std::string networkId); int32_t OnSessionClose(int32_t sessionId); int32_t OnDataReceived(std::shared_ptr& buffer); int32_t SendData(DCameraSessionMode mode, std::shared_ptr& buffer); diff --git a/services/channel/include/icamera_channel_listener.h b/services/channel/include/icamera_channel_listener.h index 3fc269c8a2107afd02d314d9738b5648ffd55707..d0bba8bdbbd7f71965b413e855b5f95086389bf2 100644 --- a/services/channel/include/icamera_channel_listener.h +++ b/services/channel/include/icamera_channel_listener.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -34,7 +34,7 @@ class ICameraChannelListener { public: virtual ~ICameraChannelListener() = default; - virtual void OnSessionState(int32_t state) = 0; + virtual void OnSessionState(int32_t state, std::string networkId) = 0; virtual void OnSessionError(int32_t eventType, int32_t eventReason, std::string detail) = 0; virtual void OnDataReceived(std::vector>& buffers) = 0; }; diff --git a/services/channel/src/dcamera_channel_sink_impl.cpp b/services/channel/src/dcamera_channel_sink_impl.cpp index 6b277525aee41991dc1c6f61b92ace7b36362432..195492f1c4dfb2e6dad814a2d9f18414256afd0f 100644 --- a/services/channel/src/dcamera_channel_sink_impl.cpp +++ b/services/channel/src/dcamera_channel_sink_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -68,7 +68,7 @@ int32_t DCameraChannelSinkImpl::CreateSession(std::vector& camInde } camIndexs_.assign(camIndexs.begin(), camIndexs.end()); listener_ = listener; - mySessionName_ = SESSION_HEAD + camIndexs[0].dhId_ + std::string("_") + sessionFlag; + mySessionName_ = SESSION_HEAD + camIndexs[0].dhId_ + std::string("_") + sessionFlag + "_sender"; mode_ = sessionMode; std::string peerDevId = camIndexs[0].devId_; std::string peerSessionName = SESSION_HEAD + sessionFlag; diff --git a/services/channel/src/dcamera_channel_source_impl.cpp b/services/channel/src/dcamera_channel_source_impl.cpp index 4f955a1689148228db10303fb2c9127202aeec12..cbad0775c4cfd337aef681be4da057b496e383ce 100644 --- a/services/channel/src/dcamera_channel_source_impl.cpp +++ b/services/channel/src/dcamera_channel_source_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 diff --git a/services/channel/src/dcamera_softbus_adapter.cpp b/services/channel/src/dcamera_softbus_adapter.cpp index e84d04fa2343a654b4894067eac470325de1bf9f..d83d373102fc9f222c54e151f63d3eaa9f6ebf8f 100644 --- a/services/channel/src/dcamera_softbus_adapter.cpp +++ b/services/channel/src/dcamera_softbus_adapter.cpp @@ -36,6 +36,20 @@ static QosTV g_qosInfo[] = { { .qos = QOS_TYPE_MIN_LATENCY, .value = DCAMERA_QOS_TYPE_MIN_LATENCY} }; static uint32_t g_QosTV_Param_Index = static_cast(sizeof(g_qosInfo) / sizeof(QosTV)); +const static std::pair LOCAL_TO_PEER_SESS_NAME_MAP[] = { + {SESSION_HEAD + CAMERA_ID_PREFIX + DEVICE_ID_0 + RECEIVER_SESSION_NAME_CONTROL, + SESSION_HEAD + CAMERA_ID_PREFIX + DEVICE_ID_0 + SENDER_SESSION_NAME_CONTROL}, + {SESSION_HEAD + CAMERA_ID_PREFIX + DEVICE_ID_0 + RECEIVER_SESSION_NAME_DATA_SNAPSHOT, + SESSION_HEAD + CAMERA_ID_PREFIX + DEVICE_ID_0 + SENDER_SESSION_NAME_DATA_SNAPSHOT}, + {SESSION_HEAD + CAMERA_ID_PREFIX + DEVICE_ID_0 + RECEIVER_SESSION_NAME_DATA_CONTINUE, + SESSION_HEAD + CAMERA_ID_PREFIX + DEVICE_ID_0 + SENDER_SESSION_NAME_DATA_CONTINUE}, + {SESSION_HEAD + CAMERA_ID_PREFIX + DEVICE_ID_1 + RECEIVER_SESSION_NAME_CONTROL, + SESSION_HEAD + CAMERA_ID_PREFIX + DEVICE_ID_1 + SENDER_SESSION_NAME_CONTROL}, + {SESSION_HEAD + CAMERA_ID_PREFIX + DEVICE_ID_1 + RECEIVER_SESSION_NAME_DATA_SNAPSHOT, + SESSION_HEAD + CAMERA_ID_PREFIX + DEVICE_ID_1 + SENDER_SESSION_NAME_DATA_SNAPSHOT}, + {SESSION_HEAD + CAMERA_ID_PREFIX + DEVICE_ID_1 + RECEIVER_SESSION_NAME_DATA_CONTINUE, + SESSION_HEAD + CAMERA_ID_PREFIX + DEVICE_ID_1 + SENDER_SESSION_NAME_DATA_CONTINUE}, +}; } IMPLEMENT_SINGLE_INSTANCE(DCameraSoftbusAdapter); @@ -143,27 +157,20 @@ int32_t DCameraSoftbusAdapter::CreatSoftBusSinkSocketServer(std::string mySessio } SocketInfo serverSocketInfo = { .name = const_cast(mySessionName.c_str()), - .peerName = const_cast(peerSessionName.c_str()), - .peerNetworkId = const_cast(peerDevId.c_str()), .pkgName = const_cast(PKG_NAME.c_str()), .dataType = sessionModeAndDataTypeMap_[sessionMode], }; int socketId = Socket(serverSocketInfo); if (socketId < 0) { - DHLOGE("create socket server error, socket is invalid"); + DHLOGE("create socket server error, socket is invalid, socketId: %{public}d", socketId); return DCAMERA_BAD_VALUE; } int ret = Listen(socketId, g_qosInfo, g_QosTV_Param_Index, &sessListeners_[role]); if (ret != DCAMERA_OK) { - DHLOGE("create socket server error"); + DHLOGE("create socket server error, ret: %{public}d", ret); Shutdown(socketId); return DCAMERA_BAD_VALUE; } - { - std::lock_guard autoLock(mySessionNamePeerDevIdLock_); - std::string peerDevIdMySessionName = peerDevId + std::string("_") + mySessionName; - peerDevIdMySessionNameMap_[peerDevIdMySessionName] = mySessionName; - } DHLOGI("create socket server end, mySessionName: %{public}s, peerSessionName: %{public}s", GetAnonyString(mySessionName).c_str(), GetAnonyString(peerSessionName).c_str()); return DCAMERA_OK; @@ -174,9 +181,10 @@ int32_t DCameraSoftbusAdapter::CreateSoftBusSourceSocketClient(std::string myDev { DHLOGI("create socket client start, myDevId: %{public}s, peerSessionName: %{public}s", GetAnonyString(myDevId).c_str(), GetAnonyString(peerSessionName).c_str()); - std::string myDevIdPeerSessionName = myDevId + std::string("_") + peerSessionName; + std::string srcSessionName = peerSessionName + "_receiver"; + peerSessionName = peerSessionName + "_sender"; SocketInfo clientSocketInfo = { - .name = const_cast(myDevIdPeerSessionName.c_str()), + .name = const_cast(srcSessionName.c_str()), .peerName = const_cast(peerSessionName.c_str()), .peerNetworkId = const_cast(peerDevId.c_str()), .pkgName = const_cast(PKG_NAME.c_str()), @@ -305,7 +313,7 @@ int32_t DCameraSoftbusAdapter::SourceOnBind(int32_t socket, PeerSocketInfo info) DHLOGE("source bind socket can not find socket %{public}d", socket); return DCAMERA_NOT_FOUND; } - ret = session->OnSessionOpened(socket); + ret = session->OnSessionOpened(socket, info.networkId); if (ret != DCAMERA_OK) { DHLOGE("source bind socket failed, ret: %{public}d socket: %{public}d", ret, socket); } @@ -465,19 +473,24 @@ int32_t DCameraSoftbusAdapter::DCameraSoftbusSinkGetSession(int32_t socket, return DCAMERA_OK; } +std::string DCameraSoftbusAdapter::FindSessNameByPeerSessName(const std::string peerSessionName) +{ + auto foundItem = std::find_if(std::begin(LOCAL_TO_PEER_SESS_NAME_MAP), std::end(LOCAL_TO_PEER_SESS_NAME_MAP), + [&](const auto& item) { return item.first == peerSessionName; }); + if (foundItem != std::end(LOCAL_TO_PEER_SESS_NAME_MAP)) { + return foundItem->second; + } + return ""; +} + int32_t DCameraSoftbusAdapter::DCameraSoftBusGetSessionByPeerSocket(int32_t socket, std::shared_ptr &session, PeerSocketInfo info) { DHLOGI("find session by peer socket start, socket %{public}d", socket); - std::string mySessionName = ""; - { - std::lock_guard autoLock(mySessionNamePeerDevIdLock_); - auto sessionNameIter = peerDevIdMySessionNameMap_.find(info.name); - if (sessionNameIter == peerDevIdMySessionNameMap_.end()) { - DHLOGE("find session by peer socket error, socket %{public}d", socket); - return DCAMERA_NOT_FOUND; - } - mySessionName = sessionNameIter->second; + std::string mySessionName = FindSessNameByPeerSessName(info.name); + if (mySessionName.empty()) { + DHLOGE("find mySessionName is empty"); + return DCAMERA_BAD_VALUE; } auto iter = sinkSessions_.find(std::string(mySessionName)); if (iter == sinkSessions_.end()) { @@ -504,7 +517,7 @@ int32_t DCameraSoftbusAdapter::SinkOnBind(int32_t socket, PeerSocketInfo info) DHLOGE("sink bind socket error, can not find socket %{public}d", socket); return DCAMERA_NOT_FOUND; } - ret = session->OnSessionOpened(socket); + ret = session->OnSessionOpened(socket, info.networkId); if (ret != DCAMERA_OK) { DHLOGE("sink bind socket error, not find socket %{public}d", socket); } diff --git a/services/channel/src/dcamera_softbus_session.cpp b/services/channel/src/dcamera_softbus_session.cpp index ea26196669a08cb48d6dec1405bab2c8a18b03b5..76ae301359671925e4afc807ba372d6df65092e7 100644 --- a/services/channel/src/dcamera_softbus_session.cpp +++ b/services/channel/src/dcamera_softbus_session.cpp @@ -82,13 +82,13 @@ int32_t DCameraSoftbusSession::CloseSession() return DCAMERA_OK; } -int32_t DCameraSoftbusSession::OnSessionOpened(int32_t socket) +int32_t DCameraSoftbusSession::OnSessionOpened(int32_t socket, std::string networkId) { DHLOGI("open current session start, socket: %{public}d", socket); sessionId_ = socket; state_ = DCAMERA_SOFTBUS_STATE_OPENED; CHECK_AND_RETURN_RET_LOG(listener_ == nullptr, DCAMERA_BAD_VALUE, "listener_ is null."); - listener_->OnSessionState(DCAMERA_CHANNEL_STATE_CONNECTED); + listener_->OnSessionState(DCAMERA_CHANNEL_STATE_CONNECTED, networkId); DHLOGI("open current session end, socket: %{public}d", socket); return DCAMERA_OK; } @@ -100,7 +100,7 @@ int32_t DCameraSoftbusSession::OnSessionClose(int32_t sessionId) sessionId_ = -1; state_ = DCAMERA_SOFTBUS_STATE_CLOSED; CHECK_AND_RETURN_RET_LOG(listener_ == nullptr, DCAMERA_BAD_VALUE, "listener_ is null."); - listener_->OnSessionState(DCAMERA_CHANNEL_STATE_DISCONNECTED); + listener_->OnSessionState(DCAMERA_CHANNEL_STATE_DISCONNECTED, ""); return DCAMERA_OK; } @@ -342,7 +342,7 @@ int32_t DCameraSoftbusSession::BindSocketServer() DHLOGE("DCameraSoftbusSession BindSocketServer Error, socketId %{public}d", socketId); return socketId; } - OnSessionOpened(socketId); + OnSessionOpened(socketId, myDevId_); return socketId; } diff --git a/services/channel/test/unittest/common/channel/dcamera_channel_sink_impl_test.cpp b/services/channel/test/unittest/common/channel/dcamera_channel_sink_impl_test.cpp index c603d8e81227f55a156b05f74c913e290482cf4b..6437f793c4eef44ff9b9b180b78fb9c5e6dd5762 100644 --- a/services/channel/test/unittest/common/channel/dcamera_channel_sink_impl_test.cpp +++ b/services/channel/test/unittest/common/channel/dcamera_channel_sink_impl_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -259,7 +259,7 @@ HWTEST_F(DCameraChannelSinkImplTest, dcamera_channel_sink_impl_test_010, TestSiz int32_t eventType = 1; int32_t eventReason = 1; std::string detail = "test010"; - listener_->OnSessionState(state); + listener_->OnSessionState(state, ""); listener_->OnSessionError(eventType, eventReason, detail); size_t capacity = 1; std::shared_ptr dataBuffer = std::make_shared(capacity); diff --git a/services/channel/test/unittest/common/channel/dcamera_softbus_session_test.cpp b/services/channel/test/unittest/common/channel/dcamera_softbus_session_test.cpp index 89165202eae6fb9f4bc740a0e3a1fcc529968dc0..fe166a5562c7b2ede6d844616f028ee35f7e670b 100644 --- a/services/channel/test/unittest/common/channel/dcamera_softbus_session_test.cpp +++ b/services/channel/test/unittest/common/channel/dcamera_softbus_session_test.cpp @@ -114,7 +114,7 @@ HWTEST_F(DCameraSoftbusSessionTest, dcamera_softbus_session_test_002, TestSize.L std::string sessionName = "dcamera_softbus_session_test_002"; std::string pkgName = "ohos.dhardware.dcamera"; std::string networkId = "abcdefg123"; - int32_t ret = softbusSession_->OnSessionOpened(sessionId); + int32_t ret = softbusSession_->OnSessionOpened(sessionId, ""); EXPECT_EQ(DCAMERA_OK, ret); }