diff --git a/interfaces/inner_kits/native_cpp/camera_source/src/dcamera_source_handler_ipc.cpp b/interfaces/inner_kits/native_cpp/camera_source/src/dcamera_source_handler_ipc.cpp index ddd741ccc2269fe03aed88d8c68015002e931ed5..7693ff4eb4d5428426fa5488da88318ed3202929 100644 --- a/interfaces/inner_kits/native_cpp/camera_source/src/dcamera_source_handler_ipc.cpp +++ b/interfaces/inner_kits/native_cpp/camera_source/src/dcamera_source_handler_ipc.cpp @@ -143,4 +143,4 @@ void DCameraSourceHandlerIpc::OnSourceLocalDmsDied(const wptr& re localSource_ = nullptr; } } // namespace DistributedHardware -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/base/include/dcamera_sa_exit_state.h b/services/cameraservice/base/include/dcamera_sa_exit_state.h new file mode 100644 index 0000000000000000000000000000000000000000..8ed889d10938c4f98c1505acd267717b7dec8c78 --- /dev/null +++ b/services/cameraservice/base/include/dcamera_sa_exit_state.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_EXIT_STATE_H +#define DCAMERA_SA_EXIT_STATE_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_exit_state.cpp b/services/cameraservice/base/src/dcamera_sa_exit_state.cpp new file mode 100644 index 0000000000000000000000000000000000000000..edb9dd9e7b70f34b6f98de03b4203fef81dcc6a3 --- /dev/null +++ b/services/cameraservice/base/src/dcamera_sa_exit_state.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_exit_state.h" + +#include "distributed_hardware_log.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(DCameraSAExitState); +DCameraSAExitState::DCameraSAExitState() +{ + DHLOGI("DCameraSAExitState Create"); +} + +DCameraSAExitState::~DCameraSAExitState() +{ + DHLOGI("DCameraSAExitState Delete"); +} + +void DCameraSAExitState::setSinkProcessState() +{ + DHLOGI("release sink success."); + sourceSAProcessState_ = DCAMERA_SA_EXIT_STATE_STOP; +} + +void DCameraSAExitState::setSourceProcessState() +{ + DHLOGI("release source success."); + sinkSAProcessState_ = DCAMERA_SA_EXIT_STATE_STOP; +} + +void DCameraSAExitState::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 ca6b9c48c36cfd4a6b28d64130e1ff9552ecfc86..701b8f01e66b39828d198f084ea0b04437ce4fb7 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_exit_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 48d13d925509eb5874b0ec6a22adc6fb2e449432..2415c41d672287820979186e2a14de83a84d620d 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 a968898c91be6ab10c92be2c393b8f8943212007..c28f2883627dd20d6cb93b92f418661ed34fda1d 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_exit_state.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_); + DCameraSAExitState::GetInstance().setSinkProcessState(); + DCameraSAExitState::GetInstance().checkSAProcessState(); return DCAMERA_OK; } diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index 8f53c80dc8be0b59c64408fbb07e004dac756646..95cc41fcee8444f4279aab929214de8314b2b629 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 112030674402abb94e8564b3d72983aa64d18da8..df37b497845e0246622dbcbaea132284e3009c51 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 3da2ed457f7bb489ff758a3c352b600d4af2de32..8f3146cc57ca961a7f53848a804da3182392fbdd 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_exit_state.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_); + DCameraSAExitState::GetInstance().setSourceProcessState(); + DCameraSAExitState::GetInstance().checkSAProcessState(); return DCAMERA_OK; }