From 9d6acc313a1478ccc693080b1628196aa34d24c3 Mon Sep 17 00:00:00 2001 From: wangchaole Date: Thu, 5 May 2022 11:34:11 +0800 Subject: [PATCH 01/16] =?UTF-8?q?=E7=AD=89sink=E5=92=8Csource=E9=83=BDrele?= =?UTF-8?q?ase=E5=90=8E=EF=BC=8CSA=E5=86=8D=E8=BF=9B=E8=A1=8C=E9=80=80?= =?UTF-8?q?=E5=87=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- .../base/include/dcamera_sa_process_exit.h | 42 ++++++++++++++ .../base/src/dcamera_sa_process_exit.cpp | 56 +++++++++++++++++++ services/cameraservice/sinkservice/BUILD.gn | 1 + .../distributed_camera_sink_service.h | 1 + .../distributed_camera_sink_service.cpp | 5 +- services/cameraservice/sourceservice/BUILD.gn | 1 + .../distributed_camera_source_service.h | 1 + .../distributed_camera_source_service.cpp | 5 +- 8 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 services/cameraservice/base/include/dcamera_sa_process_exit.h create mode 100644 services/cameraservice/base/src/dcamera_sa_process_exit.cpp diff --git a/services/cameraservice/base/include/dcamera_sa_process_exit.h b/services/cameraservice/base/include/dcamera_sa_process_exit.h new file mode 100644 index 00000000..822b5f26 --- /dev/null +++ b/services/cameraservice/base/include/dcamera_sa_process_exit.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 DCAMERA_SA_PROCESS_EXIT_H +#define DCAMERA_SA_PROCESS_EXIT_H + +#include "single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +class DCameraSAExitState { +DECLARE_SINGLE_INSTANCE_BASE(DCameraSAExitState); + +public: + void checkSAProcessState(); + void setSinkProcessState(); + void setSourceProcessState(); +private: + typedef enum { + DCAMERA_SA_EXIT_STATE_START = 0, + DCAMERA_SA_EXIT_STATE_STOP = 1 + } DCameraSAProcessState; + DCameraSAExitState(); + ~DCameraSAExitState(); + DCameraSAProcessState sinkSAProcessState_ = DCAMERA_SA_EXIT_STATE_START; + DCameraSAProcessState sourceSAProcessState_ = DCAMERA_SA_EXIT_STATE_START; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // DCAMERA_SA_EXIT_STATE_H diff --git a/services/cameraservice/base/src/dcamera_sa_process_exit.cpp b/services/cameraservice/base/src/dcamera_sa_process_exit.cpp new file mode 100644 index 00000000..a46f1484 --- /dev/null +++ b/services/cameraservice/base/src/dcamera_sa_process_exit.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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_sa_process_exit.h" + +#include "distributed_hardware_log.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(DCameraSAProcessExit); +DCameraSAProcessExit::DCameraSAProcessExit() +{ + DHLOGI("DCameraSAProcessExit Create"); +} + +DCameraSAProcessExit::~DCameraSAProcessExit() +{ + DHLOGI("DCameraSAProcessExit Delete"); +} + +void DCameraSAProcessExit::setSinkProcessState() +{ + DHLOGI("release sink success."); + sourceSAProcessState_ = DCAMERA_SA_EXIT_STATE_STOP; +} + +void DCameraSAProcessExit::setSourceProcessState() +{ + DHLOGI("release source success."); + sinkSAProcessState_ = DCAMERA_SA_EXIT_STATE_STOP; +} + +void DCameraSAProcessExit::checkSAProcessState() +{ + if (sourceSAProcessState_ == DCAMERA_SA_EXIT_STATE_START || sinkSAProcessState_ == DCAMERA_SA_EXIT_STATE_START) { + return; + } + sourceSAProcessState_ = DCAMERA_SA_EXIT_STATE_STOP; + sinkSAProcessState_ = DCAMERA_SA_EXIT_STATE_STOP; + DHLOGI("exit sa process."); + exit(0); +} +} // 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 ca6b9c48..ff83f9b9 100644 --- a/services/cameraservice/sinkservice/BUILD.gn +++ b/services/cameraservice/sinkservice/BUILD.gn @@ -71,6 +71,7 @@ ohos_shared_library("distributed_camera_sink") { "${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", + "${services_path}/cameraservice/base/src/dcamera_sa_process_exit.cpp", "src/distributedcamera/distributed_camera_sink_service.cpp", "src/distributedcamera/distributed_camera_sink_stub.cpp", "src/distributedcameramgr/callback/dcamera_sink_controller_state_callback.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 48d13d92..2415c41d 100644 --- a/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h +++ b/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h @@ -54,6 +54,7 @@ private: std::string sinkVer_; std::map> camerasMap_; + std::mutex saProcessState_; }; } // namespace DistributedHardware } // namespace OHOS 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 a968898c..521e6bab 100644 --- a/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp +++ b/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp @@ -27,6 +27,7 @@ #include "dcamera_sink_service_ipc.h" #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" +#include "dcamera_sa_process_exit.h" namespace OHOS { namespace DistributedHardware { @@ -117,7 +118,9 @@ int32_t DistributedCameraSinkService::ReleaseSink() } camerasMap_.clear(); DHLOGI("exit sink sa process."); - exit(0); + std::lock_guard autoLock(saProcessState_); + DCameraSAProcessExit::GetInstance().setSinkProcessState(); + DCameraSAProcessExit::GetInstance().checkSAProcessState(); return DCAMERA_OK; } diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index 8f53c80d..95cc41fc 100644 --- a/services/cameraservice/sourceservice/BUILD.gn +++ b/services/cameraservice/sourceservice/BUILD.gn @@ -60,6 +60,7 @@ ohos_shared_library("distributed_camera_source") { "${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", + "${services_path}/cameraservice/base/src/dcamera_sa_exit_state.cpp", "src/distributedcamera/dcamera_service_state_listener.cpp", "src/distributedcamera/dcamera_source_callback_proxy.cpp", "src/distributedcamera/distributed_camera_source_service.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 11203067..df37b497 100644 --- a/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h +++ b/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h @@ -63,6 +63,7 @@ private: std::shared_ptr listener_; std::string sourceVer_; + std::mutex saProcessState_; }; } // namespace DistributedHardware } // namespace OHOS 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 3da2ed45..38c45782 100644 --- a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp +++ b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp @@ -27,6 +27,7 @@ #include "dcamera_source_service_ipc.h" #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" +#include "dcamera_sa_process_exit.h" namespace OHOS { namespace DistributedHardware { @@ -103,7 +104,9 @@ int32_t DistributedCameraSourceService::ReleaseSource() } listener_ = nullptr; DHLOGI("exit source sa process."); - exit(0); + std::lock_guard autoLock(saProcessState_); + DCameraSAProcessExit::GetInstance().setSourceProcessState(); + DCameraSAProcessExit::GetInstance().checkSAProcessState(); return DCAMERA_OK; } -- Gitee From d157ee5ddf006b0472e41499f4a3da359490bf44 Mon Sep 17 00:00:00 2001 From: wangchaole Date: Thu, 5 May 2022 12:47:02 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E7=AD=89sink=E5=92=8Csource=E9=83=BDrele?= =?UTF-8?q?ase=E5=90=8E=EF=BC=8CSA=E5=86=8D=E8=BF=9B=E8=A1=8C=E9=80=80?= =?UTF-8?q?=E5=87=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- .../cameraservice/base/include/dcamera_sa_process_exit.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/cameraservice/base/include/dcamera_sa_process_exit.h b/services/cameraservice/base/include/dcamera_sa_process_exit.h index 822b5f26..ed85760d 100644 --- a/services/cameraservice/base/include/dcamera_sa_process_exit.h +++ b/services/cameraservice/base/include/dcamera_sa_process_exit.h @@ -20,8 +20,8 @@ namespace OHOS { namespace DistributedHardware { -class DCameraSAExitState { -DECLARE_SINGLE_INSTANCE_BASE(DCameraSAExitState); +class DCameraSAProcessExit { +DECLARE_SINGLE_INSTANCE_BASE(DCameraSAProcessExit); public: void checkSAProcessState(); @@ -32,8 +32,8 @@ private: DCAMERA_SA_EXIT_STATE_START = 0, DCAMERA_SA_EXIT_STATE_STOP = 1 } DCameraSAProcessState; - DCameraSAExitState(); - ~DCameraSAExitState(); + DCameraSAProcessExit(); + ~DCameraSAProcessExit(); DCameraSAProcessState sinkSAProcessState_ = DCAMERA_SA_EXIT_STATE_START; DCameraSAProcessState sourceSAProcessState_ = DCAMERA_SA_EXIT_STATE_START; }; -- Gitee From a37fedbd814d44e38d0a13b201a5c54e0f05af4e Mon Sep 17 00:00:00 2001 From: wangchaole Date: Thu, 5 May 2022 14:08:56 +0800 Subject: [PATCH 03/16] =?UTF-8?q?=E7=AD=89sink=E5=92=8Csource=E9=83=BDrele?= =?UTF-8?q?ase=E5=90=8E=EF=BC=8CSA=E5=86=8D=E8=BF=9B=E8=A1=8C=E9=80=80?= =?UTF-8?q?=E5=87=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- services/cameraservice/sourceservice/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index 95cc41fc..f1fdcb2b 100644 --- a/services/cameraservice/sourceservice/BUILD.gn +++ b/services/cameraservice/sourceservice/BUILD.gn @@ -60,7 +60,7 @@ ohos_shared_library("distributed_camera_source") { "${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", - "${services_path}/cameraservice/base/src/dcamera_sa_exit_state.cpp", + "${services_path}/cameraservice/base/src/dcamera_sa_process_exit.cpp", "src/distributedcamera/dcamera_service_state_listener.cpp", "src/distributedcamera/dcamera_source_callback_proxy.cpp", "src/distributedcamera/distributed_camera_source_service.cpp", -- Gitee From adf0763d8076841113d0e82c537da70ba1085b3b Mon Sep 17 00:00:00 2001 From: wangchaole Date: Thu, 5 May 2022 15:22:30 +0800 Subject: [PATCH 04/16] =?UTF-8?q?=E7=AD=89sink=E5=92=8Csource=E9=83=BDrele?= =?UTF-8?q?ase=E5=90=8E=EF=BC=8CSA=E5=86=8D=E8=BF=9B=E8=A1=8C=E9=80=80?= =?UTF-8?q?=E5=87=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- .../cameraservice/base/include/dcamera_sa_process_exit.h | 2 +- .../cameraservice/base/src/dcamera_sa_process_exit.cpp | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/services/cameraservice/base/include/dcamera_sa_process_exit.h b/services/cameraservice/base/include/dcamera_sa_process_exit.h index ed85760d..c9274f02 100644 --- a/services/cameraservice/base/include/dcamera_sa_process_exit.h +++ b/services/cameraservice/base/include/dcamera_sa_process_exit.h @@ -32,7 +32,7 @@ private: DCAMERA_SA_EXIT_STATE_START = 0, DCAMERA_SA_EXIT_STATE_STOP = 1 } DCameraSAProcessState; - DCameraSAProcessExit(); + DCameraSAProcessExit() = default; ~DCameraSAProcessExit(); DCameraSAProcessState sinkSAProcessState_ = DCAMERA_SA_EXIT_STATE_START; DCameraSAProcessState sourceSAProcessState_ = DCAMERA_SA_EXIT_STATE_START; diff --git a/services/cameraservice/base/src/dcamera_sa_process_exit.cpp b/services/cameraservice/base/src/dcamera_sa_process_exit.cpp index a46f1484..5362c927 100644 --- a/services/cameraservice/base/src/dcamera_sa_process_exit.cpp +++ b/services/cameraservice/base/src/dcamera_sa_process_exit.cpp @@ -20,11 +20,6 @@ namespace OHOS { namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(DCameraSAProcessExit); -DCameraSAProcessExit::DCameraSAProcessExit() -{ - DHLOGI("DCameraSAProcessExit Create"); -} - DCameraSAProcessExit::~DCameraSAProcessExit() { DHLOGI("DCameraSAProcessExit Delete"); @@ -47,8 +42,8 @@ void DCameraSAProcessExit::checkSAProcessState() if (sourceSAProcessState_ == DCAMERA_SA_EXIT_STATE_START || sinkSAProcessState_ == DCAMERA_SA_EXIT_STATE_START) { return; } - sourceSAProcessState_ = DCAMERA_SA_EXIT_STATE_STOP; - sinkSAProcessState_ = DCAMERA_SA_EXIT_STATE_STOP; + sourceSAProcessState_ = DCAMERA_SA_EXIT_STATE_START; + sinkSAProcessState_ = DCAMERA_SA_EXIT_STATE_START; DHLOGI("exit sa process."); exit(0); } -- Gitee From e0d1121e391403c30745097029aec2b9f21bf96b Mon Sep 17 00:00:00 2001 From: wangchaole Date: Fri, 6 May 2022 09:46:55 +0800 Subject: [PATCH 05/16] =?UTF-8?q?=E7=AD=89sink=E5=92=8Csource=E9=83=BDrele?= =?UTF-8?q?ase=E5=90=8E=EF=BC=8CSA=E5=86=8D=E8=BF=9B=E8=A1=8C=E9=80=80?= =?UTF-8?q?=E5=87=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- services/cameraservice/base/src/dcamera_sa_process_exit.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/cameraservice/base/src/dcamera_sa_process_exit.cpp b/services/cameraservice/base/src/dcamera_sa_process_exit.cpp index 5362c927..55f0acf7 100644 --- a/services/cameraservice/base/src/dcamera_sa_process_exit.cpp +++ b/services/cameraservice/base/src/dcamera_sa_process_exit.cpp @@ -28,13 +28,13 @@ DCameraSAProcessExit::~DCameraSAProcessExit() void DCameraSAProcessExit::setSinkProcessState() { DHLOGI("release sink success."); - sourceSAProcessState_ = DCAMERA_SA_EXIT_STATE_STOP; + sinkSAProcessState_ = DCAMERA_SA_EXIT_STATE_STOP; } void DCameraSAProcessExit::setSourceProcessState() { DHLOGI("release source success."); - sinkSAProcessState_ = DCAMERA_SA_EXIT_STATE_STOP; + sourceSAProcessState_ = DCAMERA_SA_EXIT_STATE_STOP; } void DCameraSAProcessExit::checkSAProcessState() -- Gitee From e2142ec2f4cf9e9b1f1bd8f47bf76e08f5363813 Mon Sep 17 00:00:00 2001 From: wangchaole Date: Fri, 6 May 2022 16:45:55 +0800 Subject: [PATCH 06/16] =?UTF-8?q?=E7=AD=89sink=E5=92=8Csource=E9=83=BDrele?= =?UTF-8?q?ase=E5=90=8E=EF=BC=8CSA=E5=86=8D=E8=BF=9B=E8=A1=8C=E9=80=80?= =?UTF-8?q?=E5=87=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- ...cess_exit.h => dcamera_sa_process_state.h} | 27 +++++++------- ..._exit.cpp => dcamera_sa_process_state.cpp} | 35 +++++++++++-------- services/cameraservice/sinkservice/BUILD.gn | 2 +- .../distributed_camera_sink_service.h | 1 - .../distributed_camera_sink_service.cpp | 8 ++--- services/cameraservice/sourceservice/BUILD.gn | 2 +- .../distributed_camera_source_service.h | 1 - .../distributed_camera_source_service.cpp | 8 ++--- 8 files changed, 43 insertions(+), 41 deletions(-) rename services/cameraservice/base/include/{dcamera_sa_process_exit.h => dcamera_sa_process_state.h} (63%) rename services/cameraservice/base/src/{dcamera_sa_process_exit.cpp => dcamera_sa_process_state.cpp} (46%) diff --git a/services/cameraservice/base/include/dcamera_sa_process_exit.h b/services/cameraservice/base/include/dcamera_sa_process_state.h similarity index 63% rename from services/cameraservice/base/include/dcamera_sa_process_exit.h rename to services/cameraservice/base/include/dcamera_sa_process_state.h index c9274f02..442f7aea 100644 --- a/services/cameraservice/base/include/dcamera_sa_process_exit.h +++ b/services/cameraservice/base/include/dcamera_sa_process_state.h @@ -13,29 +13,32 @@ * limitations under the License. */ -#ifndef DCAMERA_SA_PROCESS_EXIT_H -#define DCAMERA_SA_PROCESS_EXIT_H +#ifndef DCAMERA_SA_PROCESS_STATE_H +#define DCAMERA_SA_PROCESS_STATE_H #include "single_instance.h" +#include + namespace OHOS { namespace DistributedHardware { -class DCameraSAProcessExit { -DECLARE_SINGLE_INSTANCE_BASE(DCameraSAProcessExit); +class DCameraSAProcessState { +DECLARE_SINGLE_INSTANCE_BASE(DCameraSAProcessState); public: - void checkSAProcessState(); - void setSinkProcessState(); - void setSourceProcessState(); + void SetSinkProcessExit(); + void SetSourceProcessExit(); private: typedef enum { DCAMERA_SA_EXIT_STATE_START = 0, DCAMERA_SA_EXIT_STATE_STOP = 1 - } DCameraSAProcessState; - DCameraSAProcessExit() = default; - ~DCameraSAProcessExit(); - DCameraSAProcessState sinkSAProcessState_ = DCAMERA_SA_EXIT_STATE_START; - DCameraSAProcessState sourceSAProcessState_ = DCAMERA_SA_EXIT_STATE_START; + } DCameraSAState; + DCameraSAProcessState() = default; + ~DCameraSAProcessState(); + void CheckSAProcessState(); + DCameraSAState sinkSAState_ = DCAMERA_SA_EXIT_STATE_START; + DCameraSAState sourceSAState_ = DCAMERA_SA_EXIT_STATE_START; + std::mutex saProcessState_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/base/src/dcamera_sa_process_exit.cpp b/services/cameraservice/base/src/dcamera_sa_process_state.cpp similarity index 46% rename from services/cameraservice/base/src/dcamera_sa_process_exit.cpp rename to services/cameraservice/base/src/dcamera_sa_process_state.cpp index 55f0acf7..4066ff73 100644 --- a/services/cameraservice/base/src/dcamera_sa_process_exit.cpp +++ b/services/cameraservice/base/src/dcamera_sa_process_state.cpp @@ -13,38 +13,43 @@ * limitations under the License. */ -#include "dcamera_sa_process_exit.h" +#include "dcamera_sa_process_state.h" #include "distributed_hardware_log.h" namespace OHOS { namespace DistributedHardware { -IMPLEMENT_SINGLE_INSTANCE(DCameraSAProcessExit); -DCameraSAProcessExit::~DCameraSAProcessExit() +IMPLEMENT_SINGLE_INSTANCE(DCameraSAProcessState); + +DCameraSAProcessState::~DCameraSAProcessState() { - DHLOGI("DCameraSAProcessExit Delete"); + DHLOGI("DCameraSAProcessState Delete"); } -void DCameraSAProcessExit::setSinkProcessState() +void DCameraSAProcessState::SetSinkProcessExit() { - DHLOGI("release sink success."); - sinkSAProcessState_ = DCAMERA_SA_EXIT_STATE_STOP; + DHLOGI("set sink process exit."); + std::lock_guard autoLock(saProcessState_); + sinkSAState_ = DCAMERA_SA_EXIT_STATE_STOP; + CheckSAProcessState(); } -void DCameraSAProcessExit::setSourceProcessState() +void DCameraSAProcessState::SetSourceProcessExit() { - DHLOGI("release source success."); - sourceSAProcessState_ = DCAMERA_SA_EXIT_STATE_STOP; + DHLOGI("set sources process exit."); + std::lock_guard autoLock(saProcessState_); + sourceSAState_ = DCAMERA_SA_EXIT_STATE_STOP; + CheckSAProcessState(); } -void DCameraSAProcessExit::checkSAProcessState() +void DCameraSAProcessState::CheckSAProcessState() { - if (sourceSAProcessState_ == DCAMERA_SA_EXIT_STATE_START || sinkSAProcessState_ == DCAMERA_SA_EXIT_STATE_START) { + DHLOGI("start exit sa process."); + if (sourceSAState_ == DCAMERA_SA_EXIT_STATE_START || sinkSAState_ == DCAMERA_SA_EXIT_STATE_START) { + DHLOGI("=============DCAMERA_SA_EXIT_STATE_START=============="); return; } - sourceSAProcessState_ = DCAMERA_SA_EXIT_STATE_START; - sinkSAProcessState_ = DCAMERA_SA_EXIT_STATE_START; - DHLOGI("exit sa process."); + DHLOGI("exit sa process success."); exit(0); } } // namespace DistributedHardware diff --git a/services/cameraservice/sinkservice/BUILD.gn b/services/cameraservice/sinkservice/BUILD.gn index ff83f9b9..6d3318ed 100644 --- a/services/cameraservice/sinkservice/BUILD.gn +++ b/services/cameraservice/sinkservice/BUILD.gn @@ -71,7 +71,7 @@ ohos_shared_library("distributed_camera_sink") { "${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", - "${services_path}/cameraservice/base/src/dcamera_sa_process_exit.cpp", + "${services_path}/cameraservice/base/src/dcamera_sa_process_state.cpp", "src/distributedcamera/distributed_camera_sink_service.cpp", "src/distributedcamera/distributed_camera_sink_stub.cpp", "src/distributedcameramgr/callback/dcamera_sink_controller_state_callback.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 2415c41d..48d13d92 100644 --- a/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h +++ b/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h @@ -54,7 +54,6 @@ private: std::string sinkVer_; std::map> camerasMap_; - std::mutex saProcessState_; }; } // namespace DistributedHardware } // namespace OHOS 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 521e6bab..3d3f23fa 100644 --- a/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp +++ b/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp @@ -27,7 +27,7 @@ #include "dcamera_sink_service_ipc.h" #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" -#include "dcamera_sa_process_exit.h" +#include "dcamera_sa_process_state.h" namespace OHOS { namespace DistributedHardware { @@ -117,10 +117,8 @@ int32_t DistributedCameraSinkService::ReleaseSink() } } camerasMap_.clear(); - DHLOGI("exit sink sa process."); - std::lock_guard autoLock(saProcessState_); - DCameraSAProcessExit::GetInstance().setSinkProcessState(); - DCameraSAProcessExit::GetInstance().checkSAProcessState(); + DHLOGI("check source sa state."); + DCameraSAProcessState::GetInstance().SetSinkProcessExit(); return DCAMERA_OK; } diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index f1fdcb2b..4724802d 100644 --- a/services/cameraservice/sourceservice/BUILD.gn +++ b/services/cameraservice/sourceservice/BUILD.gn @@ -60,7 +60,7 @@ ohos_shared_library("distributed_camera_source") { "${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", - "${services_path}/cameraservice/base/src/dcamera_sa_process_exit.cpp", + "${services_path}/cameraservice/base/src/dcamera_sa_process_state.cpp", "src/distributedcamera/dcamera_service_state_listener.cpp", "src/distributedcamera/dcamera_source_callback_proxy.cpp", "src/distributedcamera/distributed_camera_source_service.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 df37b497..11203067 100644 --- a/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h +++ b/services/cameraservice/sourceservice/include/distributedcamera/distributed_camera_source_service.h @@ -63,7 +63,6 @@ private: std::shared_ptr listener_; std::string sourceVer_; - std::mutex saProcessState_; }; } // namespace DistributedHardware } // namespace OHOS 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 38c45782..9ac40be4 100644 --- a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp +++ b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp @@ -27,7 +27,7 @@ #include "dcamera_source_service_ipc.h" #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" -#include "dcamera_sa_process_exit.h" +#include "dcamera_sa_process_state.h" namespace OHOS { namespace DistributedHardware { @@ -103,10 +103,8 @@ int32_t DistributedCameraSourceService::ReleaseSource() return ret; } listener_ = nullptr; - DHLOGI("exit source sa process."); - std::lock_guard autoLock(saProcessState_); - DCameraSAProcessExit::GetInstance().setSourceProcessState(); - DCameraSAProcessExit::GetInstance().checkSAProcessState(); + DHLOGI("check source sa state."); + DCameraSAProcessState::GetInstance().SetSourceProcessExit(); return DCAMERA_OK; } -- Gitee From 937c50dd0f0e4bb89ac8bc7731084151e480e9ca Mon Sep 17 00:00:00 2001 From: wangchaole Date: Sat, 7 May 2022 09:38:23 +0800 Subject: [PATCH 07/16] =?UTF-8?q?=E7=AD=89sink=E5=92=8Csource=E9=83=BDrele?= =?UTF-8?q?ase=E5=90=8E=EF=BC=8CSA=E5=86=8D=E8=BF=9B=E8=A1=8C=E9=80=80?= =?UTF-8?q?=E5=87=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- services/cameraservice/base/src/dcamera_sa_process_state.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/cameraservice/base/src/dcamera_sa_process_state.cpp b/services/cameraservice/base/src/dcamera_sa_process_state.cpp index 4066ff73..9e38cca4 100644 --- a/services/cameraservice/base/src/dcamera_sa_process_state.cpp +++ b/services/cameraservice/base/src/dcamera_sa_process_state.cpp @@ -45,6 +45,7 @@ void DCameraSAProcessState::SetSourceProcessExit() void DCameraSAProcessState::CheckSAProcessState() { DHLOGI("start exit sa process."); + DHLOGI("sourceSAState_ = %d sinkSAState_ = %d", sourceSAState_, sinkSAState_); if (sourceSAState_ == DCAMERA_SA_EXIT_STATE_START || sinkSAState_ == DCAMERA_SA_EXIT_STATE_START) { DHLOGI("=============DCAMERA_SA_EXIT_STATE_START=============="); return; -- Gitee From 04e0640d381141e60d1938facedfaa7d4efbfc3e Mon Sep 17 00:00:00 2001 From: wangchaole Date: Mon, 9 May 2022 11:49:36 +0800 Subject: [PATCH 08/16] =?UTF-8?q?=E7=AD=89sink=E5=92=8Csource=E9=83=BDrele?= =?UTF-8?q?ase=E5=90=8E=EF=BC=8CSA=E5=86=8D=E8=BF=9B=E8=A1=8C=E9=80=80?= =?UTF-8?q?=E5=87=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- common/BUILD.gn | 1 + .../include/utils}/dcamera_sa_process_state.h | 24 ++----------- .../src/utils}/dcamera_sa_process_state.cpp | 34 +++++++++++-------- services/cameraservice/sinkservice/BUILD.gn | 1 - .../distributed_camera_sink_service.cpp | 4 +-- services/cameraservice/sourceservice/BUILD.gn | 1 - .../distributed_camera_source_service.cpp | 2 +- 7 files changed, 25 insertions(+), 42 deletions(-) rename {services/cameraservice/base/include => common/include/utils}/dcamera_sa_process_state.h (57%) rename {services/cameraservice/base/src => common/src/utils}/dcamera_sa_process_state.cpp (69%) diff --git a/common/BUILD.gn b/common/BUILD.gn index e3ec2a22..efa365c4 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -33,6 +33,7 @@ ohos_shared_library("distributed_camera_utils") { sources = [ "src/utils/data_buffer.cpp", "src/utils/dcamera_utils_tools.cpp", + "src/utils/dcamera_sa_process_state.cpp", ] deps = [ diff --git a/services/cameraservice/base/include/dcamera_sa_process_state.h b/common/include/utils/dcamera_sa_process_state.h similarity index 57% rename from services/cameraservice/base/include/dcamera_sa_process_state.h rename to common/include/utils/dcamera_sa_process_state.h index 442f7aea..789fac26 100644 --- a/services/cameraservice/base/include/dcamera_sa_process_state.h +++ b/common/include/utils/dcamera_sa_process_state.h @@ -16,30 +16,10 @@ #ifndef DCAMERA_SA_PROCESS_STATE_H #define DCAMERA_SA_PROCESS_STATE_H -#include "single_instance.h" - -#include - namespace OHOS { namespace DistributedHardware { -class DCameraSAProcessState { -DECLARE_SINGLE_INSTANCE_BASE(DCameraSAProcessState); - -public: - void SetSinkProcessExit(); - void SetSourceProcessExit(); -private: - typedef enum { - DCAMERA_SA_EXIT_STATE_START = 0, - DCAMERA_SA_EXIT_STATE_STOP = 1 - } DCameraSAState; - DCameraSAProcessState() = default; - ~DCameraSAProcessState(); - void CheckSAProcessState(); - DCameraSAState sinkSAState_ = DCAMERA_SA_EXIT_STATE_START; - DCameraSAState sourceSAState_ = DCAMERA_SA_EXIT_STATE_START; - std::mutex saProcessState_; -}; +void SetSinkProcessExit(); +void SetSourceProcessExit(); } // namespace DistributedHardware } // namespace OHOS #endif // DCAMERA_SA_EXIT_STATE_H diff --git a/services/cameraservice/base/src/dcamera_sa_process_state.cpp b/common/src/utils/dcamera_sa_process_state.cpp similarity index 69% rename from services/cameraservice/base/src/dcamera_sa_process_state.cpp rename to common/src/utils/dcamera_sa_process_state.cpp index 9e38cca4..46d0ed62 100644 --- a/services/cameraservice/base/src/dcamera_sa_process_state.cpp +++ b/common/src/utils/dcamera_sa_process_state.cpp @@ -15,43 +15,47 @@ #include "dcamera_sa_process_state.h" +#include + #include "distributed_hardware_log.h" namespace OHOS { namespace DistributedHardware { -IMPLEMENT_SINGLE_INSTANCE(DCameraSAProcessState); -DCameraSAProcessState::~DCameraSAProcessState() -{ - DHLOGI("DCameraSAProcessState Delete"); -} +typedef enum { + DCAMERA_SA_EXIT_STATE_START = 0, + DCAMERA_SA_EXIT_STATE_STOP = 1 +} DCameraSAState; + +DCameraSAState sinkSAState_ = DCAMERA_SA_EXIT_STATE_START; +DCameraSAState sourceSAState_ = DCAMERA_SA_EXIT_STATE_START; +std::mutex saProcessState_; -void DCameraSAProcessState::SetSinkProcessExit() +void SetSinkProcessExit() { DHLOGI("set sink process exit."); std::lock_guard autoLock(saProcessState_); sinkSAState_ = DCAMERA_SA_EXIT_STATE_STOP; - CheckSAProcessState(); + DHLOGI("sourceSAState_ = %d sinkSAState_ = %d", sourceSAState_, sinkSAState_); + if (sourceSAState_ == DCAMERA_SA_EXIT_STATE_START || sinkSAState_ == DCAMERA_SA_EXIT_STATE_START) { + return; + } + DHLOGI("exit sa process success."); + exit(0); } -void DCameraSAProcessState::SetSourceProcessExit() +void SetSourceProcessExit() { DHLOGI("set sources process exit."); std::lock_guard autoLock(saProcessState_); sourceSAState_ = DCAMERA_SA_EXIT_STATE_STOP; - CheckSAProcessState(); -} - -void DCameraSAProcessState::CheckSAProcessState() -{ - DHLOGI("start exit sa process."); DHLOGI("sourceSAState_ = %d sinkSAState_ = %d", sourceSAState_, sinkSAState_); if (sourceSAState_ == DCAMERA_SA_EXIT_STATE_START || sinkSAState_ == DCAMERA_SA_EXIT_STATE_START) { - DHLOGI("=============DCAMERA_SA_EXIT_STATE_START=============="); return; } DHLOGI("exit sa process success."); exit(0); } + } // 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 6d3318ed..ca6b9c48 100644 --- a/services/cameraservice/sinkservice/BUILD.gn +++ b/services/cameraservice/sinkservice/BUILD.gn @@ -71,7 +71,6 @@ ohos_shared_library("distributed_camera_sink") { "${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", - "${services_path}/cameraservice/base/src/dcamera_sa_process_state.cpp", "src/distributedcamera/distributed_camera_sink_service.cpp", "src/distributedcamera/distributed_camera_sink_stub.cpp", "src/distributedcameramgr/callback/dcamera_sink_controller_state_callback.cpp", 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 3d3f23fa..41ea35c4 100644 --- a/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp +++ b/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp @@ -117,8 +117,8 @@ int32_t DistributedCameraSinkService::ReleaseSink() } } camerasMap_.clear(); - DHLOGI("check source sa state."); - DCameraSAProcessState::GetInstance().SetSinkProcessExit(); + DHLOGI("check sink sa state."); + SetSinkProcessExit(); return DCAMERA_OK; } diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index 4724802d..8f53c80d 100644 --- a/services/cameraservice/sourceservice/BUILD.gn +++ b/services/cameraservice/sourceservice/BUILD.gn @@ -60,7 +60,6 @@ ohos_shared_library("distributed_camera_source") { "${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", - "${services_path}/cameraservice/base/src/dcamera_sa_process_state.cpp", "src/distributedcamera/dcamera_service_state_listener.cpp", "src/distributedcamera/dcamera_source_callback_proxy.cpp", "src/distributedcamera/distributed_camera_source_service.cpp", 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 9ac40be4..e02d9657 100644 --- a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp +++ b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp @@ -104,7 +104,7 @@ int32_t DistributedCameraSourceService::ReleaseSource() } listener_ = nullptr; DHLOGI("check source sa state."); - DCameraSAProcessState::GetInstance().SetSourceProcessExit(); + SetSourceProcessExit(); return DCAMERA_OK; } -- Gitee From 27c3649fbf7825337f1989e9c3ffcaf4830d3ac8 Mon Sep 17 00:00:00 2001 From: wangchaole Date: Mon, 9 May 2022 11:52:31 +0800 Subject: [PATCH 09/16] =?UTF-8?q?=E7=AD=89sink=E5=92=8Csource=E9=83=BDrele?= =?UTF-8?q?ase=E5=90=8E=EF=BC=8CSA=E5=86=8D=E8=BF=9B=E8=A1=8C=E9=80=80?= =?UTF-8?q?=E5=87=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- common/include/utils/dcamera_sa_process_state.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/include/utils/dcamera_sa_process_state.h b/common/include/utils/dcamera_sa_process_state.h index 789fac26..6d479d00 100644 --- a/common/include/utils/dcamera_sa_process_state.h +++ b/common/include/utils/dcamera_sa_process_state.h @@ -22,4 +22,4 @@ void SetSinkProcessExit(); void SetSourceProcessExit(); } // namespace DistributedHardware } // namespace OHOS -#endif // DCAMERA_SA_EXIT_STATE_H +#endif // DCAMERA_SA_PROCESS_STATE_H -- Gitee From 3cf393d23356b8e2c792c43405afb45fe54570c5 Mon Sep 17 00:00:00 2001 From: wangchaole Date: Mon, 9 May 2022 14:15:29 +0800 Subject: [PATCH 10/16] =?UTF-8?q?=E7=AD=89sink=E5=92=8Csource=E9=83=BDrele?= =?UTF-8?q?ase=E5=90=8E=EF=BC=8CSA=E5=86=8D=E8=BF=9B=E8=A1=8C=E9=80=80?= =?UTF-8?q?=E5=87=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- common/src/utils/dcamera_sa_process_state.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/common/src/utils/dcamera_sa_process_state.cpp b/common/src/utils/dcamera_sa_process_state.cpp index 46d0ed62..c5be93b7 100644 --- a/common/src/utils/dcamera_sa_process_state.cpp +++ b/common/src/utils/dcamera_sa_process_state.cpp @@ -21,7 +21,6 @@ namespace OHOS { namespace DistributedHardware { - typedef enum { DCAMERA_SA_EXIT_STATE_START = 0, DCAMERA_SA_EXIT_STATE_STOP = 1 @@ -56,6 +55,5 @@ void SetSourceProcessExit() DHLOGI("exit sa process success."); exit(0); } - } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file -- Gitee From 3b0efa00166d515913f8be33d48a270edb2b040d Mon Sep 17 00:00:00 2001 From: wangchaole Date: Mon, 9 May 2022 14:48:34 +0800 Subject: [PATCH 11/16] =?UTF-8?q?=E7=AD=89sink=E5=92=8Csource=E9=83=BDrele?= =?UTF-8?q?ase=E5=90=8E=EF=BC=8CSA=E5=86=8D=E8=BF=9B=E8=A1=8C=E9=80=80?= =?UTF-8?q?=E5=87=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- common/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/BUILD.gn b/common/BUILD.gn index efa365c4..880aafd0 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -32,8 +32,8 @@ ohos_shared_library("distributed_camera_utils") { sources = [ "src/utils/data_buffer.cpp", - "src/utils/dcamera_utils_tools.cpp", "src/utils/dcamera_sa_process_state.cpp", + "src/utils/dcamera_utils_tools.cpp", ] deps = [ -- Gitee From abdb7c0cdedda3a5b4aa56aa7d71a3a4408c3caa Mon Sep 17 00:00:00 2001 From: wangchaole Date: Tue, 10 May 2022 16:54:57 +0800 Subject: [PATCH 12/16] =?UTF-8?q?=E7=AD=89sink=E5=92=8Csource=E9=83=BDrele?= =?UTF-8?q?ase=E5=90=8E=EF=BC=8CSA=E5=86=8D=E8=BF=9B=E8=A1=8C=E9=80=80?= =?UTF-8?q?=E5=87=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- .../dcamera_service_state_listener.h | 7 +++++-- .../dcamera_service_state_listener.cpp | 12 ++++++++++-- .../distributed_camera_source_service.cpp | 5 +++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/services/cameraservice/sourceservice/include/distributedcamera/dcamera_service_state_listener.h b/services/cameraservice/sourceservice/include/distributedcamera/dcamera_service_state_listener.h index 967bd17a..be75ad86 100644 --- a/services/cameraservice/sourceservice/include/distributedcamera/dcamera_service_state_listener.h +++ b/services/cameraservice/sourceservice/include/distributedcamera/dcamera_service_state_listener.h @@ -16,6 +16,8 @@ #ifndef OHOS_DCAMERA_SERVICE_STATE_LISTENER_H #define OHOS_DCAMERA_SERVICE_STATE_LISTENER_H +#include + #include "icamera_state_listener.h" #include "idcamera_source_callback.h" @@ -23,16 +25,17 @@ namespace OHOS { namespace DistributedHardware { class DCameraServiceStateListener : public ICameraStateListener { public: - explicit DCameraServiceStateListener(sptr callback); + explicit DCameraServiceStateListener(); ~DCameraServiceStateListener(); int32_t OnRegisterNotify(const std::string& devId, const std::string& dhId, const std::string& reqId, int32_t status, std::string& data) override; int32_t OnUnregisterNotify(const std::string& devId, const std::string& dhId, const std::string& reqId, int32_t status, std::string& data) override; - + void SetCallback(sptr callback) override; private: sptr callbackProxy_; + std::mutex proxyMutex_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sourceservice/src/distributedcamera/dcamera_service_state_listener.cpp b/services/cameraservice/sourceservice/src/distributedcamera/dcamera_service_state_listener.cpp index 49dc8f99..36cdd886 100644 --- a/services/cameraservice/sourceservice/src/distributedcamera/dcamera_service_state_listener.cpp +++ b/services/cameraservice/sourceservice/src/distributedcamera/dcamera_service_state_listener.cpp @@ -25,8 +25,7 @@ namespace OHOS { namespace DistributedHardware { -DCameraServiceStateListener::DCameraServiceStateListener(sptr callback) - : callbackProxy_(callback) +DCameraServiceStateListener::DCameraServiceStateListener() { DHLOGI("DCameraServiceStateListener Create"); } @@ -37,11 +36,19 @@ DCameraServiceStateListener::~DCameraServiceStateListener() callbackProxy_ = nullptr; } +void DCameraServiceStateListener::SetCallback(sptr callback) +{ + DHLOGI("DCameraServiceStateListener SetCallback"); + std::lock_guard autoLock(proxyMutex_); + callbackProxy_ = callback; +} + int32_t DCameraServiceStateListener::OnRegisterNotify(const std::string& devId, const std::string& dhId, const std::string& reqId, int32_t status, std::string& data) { DHLOGI("DCameraServiceStateListener OnRegisterNotify devId: %s, dhId: %s, status: %d", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), status); + std::lock_guard autoLock(proxyMutex_); if (callbackProxy_ == nullptr) { DHLOGE("DCameraServiceStateListener OnRegisterNotify callbackProxy_ is nullptr"); return DCAMERA_BAD_VALUE; @@ -73,6 +80,7 @@ int32_t DCameraServiceStateListener::OnUnregisterNotify(const std::string& devId { DHLOGI("DCameraServiceStateListener OnUnregisterNotify devId: %s, dhId: %s, status: %d", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), status); + std::lock_guard autoLock(proxyMutex_); if (callbackProxy_ == nullptr) { DHLOGE("DCameraServiceStateListener OnUnregisterNotify callbackProxy_ is nullptr"); return DCAMERA_BAD_VALUE; 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 e02d9657..2aceb739 100644 --- a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp +++ b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp @@ -68,6 +68,7 @@ bool DistributedCameraSourceService::Init() } registerToService_ = true; } + listener_ = std::make_shared(); DHLOGI("DistributedCameraSourceService init success"); return true; } @@ -77,6 +78,7 @@ void DistributedCameraSourceService::OnStop() DHLOGI("DistributedCameraSourceService OnStop service"); state_ = DCameraServiceState::DCAMERA_SRV_STATE_NOT_START; registerToService_ = false; + listener_ = nullptr; DCameraSourceServiceIpc::GetInstance().UnInit(); } @@ -90,7 +92,7 @@ int32_t DistributedCameraSourceService::InitSource(const std::string& params, return ret; } sourceVer_ = params; - listener_ = std::make_shared(callback); + listener_->SetCallback(callback); return DCAMERA_OK; } @@ -102,7 +104,6 @@ int32_t DistributedCameraSourceService::ReleaseSource() DHLOGE("DistributedCameraSourceService ReleaseSource UnLoadHDF failed, ret: %d", ret); return ret; } - listener_ = nullptr; DHLOGI("check source sa state."); SetSourceProcessExit(); return DCAMERA_OK; -- Gitee From 2703f842c7eeaafb19dd368648a34c81f970383e Mon Sep 17 00:00:00 2001 From: wangchaole Date: Tue, 10 May 2022 17:31:43 +0800 Subject: [PATCH 13/16] =?UTF-8?q?=E7=AD=89sink=E5=92=8Csource=E9=83=BDrele?= =?UTF-8?q?ase=E5=90=8E=EF=BC=8CSA=E5=86=8D=E8=BF=9B=E8=A1=8C=E9=80=80?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- .../dcamerainterface/icamera_state_listener.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerainterface/icamera_state_listener.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerainterface/icamera_state_listener.h index 9ed09406..08c8ceaa 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerainterface/icamera_state_listener.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerainterface/icamera_state_listener.h @@ -19,6 +19,8 @@ #include #include +#include "idcamera_source_callback.h" + namespace OHOS { namespace DistributedHardware { class ICameraStateListener { @@ -28,6 +30,7 @@ public: int32_t status, std::string& data) = 0; virtual int32_t OnUnregisterNotify(const std::string& devId, const std::string& dhId, const std::string& reqId, int32_t status, std::string& data) = 0; + virtual void SetCallback(sptr callback) = 0; }; } // namespace DistributedHardware } // namespace OHOS -- Gitee From ff0ddfc4ad6480bfd64f6d8d0c6f19dba946616e Mon Sep 17 00:00:00 2001 From: wangchaole Date: Tue, 10 May 2022 17:50:54 +0800 Subject: [PATCH 14/16] =?UTF-8?q?=E7=AD=89sink=E5=92=8Csource=E9=83=BDrele?= =?UTF-8?q?ase=E5=90=8E=EF=BC=8CSA=E5=86=8D=E8=BF=9B=E8=A1=8C=E9=80=80?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- common/src/utils/dcamera_sa_process_state.cpp | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/common/src/utils/dcamera_sa_process_state.cpp b/common/src/utils/dcamera_sa_process_state.cpp index c5be93b7..00df0018 100644 --- a/common/src/utils/dcamera_sa_process_state.cpp +++ b/common/src/utils/dcamera_sa_process_state.cpp @@ -26,17 +26,17 @@ typedef enum { DCAMERA_SA_EXIT_STATE_STOP = 1 } DCameraSAState; -DCameraSAState sinkSAState_ = DCAMERA_SA_EXIT_STATE_START; -DCameraSAState sourceSAState_ = DCAMERA_SA_EXIT_STATE_START; -std::mutex saProcessState_; +DCameraSAState g_sinkSAState = DCAMERA_SA_EXIT_STATE_START; +DCameraSAState g_sourceSAState = DCAMERA_SA_EXIT_STATE_START; +std::mutex g_saProcessState; void SetSinkProcessExit() { DHLOGI("set sink process exit."); - std::lock_guard autoLock(saProcessState_); - sinkSAState_ = DCAMERA_SA_EXIT_STATE_STOP; - DHLOGI("sourceSAState_ = %d sinkSAState_ = %d", sourceSAState_, sinkSAState_); - if (sourceSAState_ == DCAMERA_SA_EXIT_STATE_START || sinkSAState_ == DCAMERA_SA_EXIT_STATE_START) { + std::lock_guard autoLock(g_saProcessState); + g_sinkSAState = DCAMERA_SA_EXIT_STATE_STOP; + DHLOGI("g_sourceSAState = %d g_sinkSAState = %d", g_sourceSAState, g_sinkSAState); + if (g_sourceSAState == DCAMERA_SA_EXIT_STATE_START || g_sinkSAState == DCAMERA_SA_EXIT_STATE_START) { return; } DHLOGI("exit sa process success."); @@ -46,10 +46,10 @@ void SetSinkProcessExit() void SetSourceProcessExit() { DHLOGI("set sources process exit."); - std::lock_guard autoLock(saProcessState_); - sourceSAState_ = DCAMERA_SA_EXIT_STATE_STOP; - DHLOGI("sourceSAState_ = %d sinkSAState_ = %d", sourceSAState_, sinkSAState_); - if (sourceSAState_ == DCAMERA_SA_EXIT_STATE_START || sinkSAState_ == DCAMERA_SA_EXIT_STATE_START) { + std::lock_guard autoLock(g_saProcessState); + g_sourceSAState = DCAMERA_SA_EXIT_STATE_STOP; + DHLOGI("g_sourceSAState = %d g_sinkSAState = %d", g_sourceSAState, g_sinkSAState); + if (g_sourceSAState == DCAMERA_SA_EXIT_STATE_START || g_sinkSAState == DCAMERA_SA_EXIT_STATE_START) { return; } DHLOGI("exit sa process success."); -- Gitee From 247025fad56c73b1f4168810b149d0bf395086dc Mon Sep 17 00:00:00 2001 From: wangchaole Date: Tue, 10 May 2022 19:39:30 +0800 Subject: [PATCH 15/16] =?UTF-8?q?=E7=AD=89sink=E5=92=8Csource=E9=83=BDrele?= =?UTF-8?q?ase=E5=90=8E=EF=BC=8CSA=E5=86=8D=E8=BF=9B=E8=A1=8C=E9=80=80?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- .../distributedcameramgr/mock_dcamera_source_state_listener.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/mock_dcamera_source_state_listener.h b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/mock_dcamera_source_state_listener.h index 958b40cc..87f69e84 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/mock_dcamera_source_state_listener.h +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/mock_dcamera_source_state_listener.h @@ -38,6 +38,9 @@ public: { return DCAMERA_OK; } + void SetCallback(sptr callback) + { + } }; } // namespace DistributedHardware } // namespace OHOS -- Gitee From b80b8ff00e1b3ab2975265de5f506c1db8653bee Mon Sep 17 00:00:00 2001 From: wangchaole Date: Tue, 10 May 2022 20:24:05 +0800 Subject: [PATCH 16/16] =?UTF-8?q?=E7=AD=89sink=E5=92=8Csource=E9=83=BDrele?= =?UTF-8?q?ase=E5=90=8E=EF=BC=8CSA=E5=86=8D=E8=BF=9B=E8=A1=8C=E9=80=80?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- .../distributedcameramgr/mock_dcamera_source_state_listener.h | 1 + 1 file changed, 1 insertion(+) diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/mock_dcamera_source_state_listener.h b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/mock_dcamera_source_state_listener.h index 87f69e84..593cf5a2 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/mock_dcamera_source_state_listener.h +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/mock_dcamera_source_state_listener.h @@ -38,6 +38,7 @@ public: { return DCAMERA_OK; } + void SetCallback(sptr callback) { } -- Gitee