diff --git a/common/BUILD.gn b/common/BUILD.gn index 897d71c..b9bf72d 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -27,6 +27,7 @@ ohos_shared_library("distributed_screen_utils") { sources = [ "src/dscreen_hisysevent.cpp", "src/dscreen_log.cpp", + "src/dscreen_sa_process_state.cpp", "src/dscreen_util.cpp", ] diff --git a/common/include/dscreen_sa_process_state.h b/common/include/dscreen_sa_process_state.h new file mode 100644 index 0000000..95e560c --- /dev/null +++ b/common/include/dscreen_sa_process_state.h @@ -0,0 +1,25 @@ +/* + * 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 DSCREEN_SA_PROCESS_STATE_H +#define DSCREEN_SA_PROCESS_STATE_H + +namespace OHOS { +namespace DistributedHardware { +void SetSinkProcessExit(); +void SetSourceProcessExit(); +} // namespace DistributedHardware +} // namespace OHOS +#endif // DSCREEN_SA_PROCESS_STATE_H diff --git a/common/src/dscreen_sa_process_state.cpp b/common/src/dscreen_sa_process_state.cpp new file mode 100644 index 0000000..4f98455 --- /dev/null +++ b/common/src/dscreen_sa_process_state.cpp @@ -0,0 +1,63 @@ +/* + * 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 "dscreen_sa_process_state.h" + +#include + +#include "dscreen_constants.h" +#include "dscreen_hisysevent.h" +#include "dscreen_log.h" + +namespace OHOS { +namespace DistributedHardware { +typedef enum { + DSCREEN_SA_EXIT_STATE_START = 0, + DSCREEN_SA_EXIT_STATE_STOP = 1 +} DScreenSAState; + +DScreenSAState g_sinkSAState = DSCREEN_SA_EXIT_STATE_START; +DScreenSAState g_sourceSAState = DSCREEN_SA_EXIT_STATE_START; +std::mutex g_saProcessState; + +void SetSinkProcessExit() +{ + DHLOGI("set sink process exit."); + std::lock_guard autoLock(g_saProcessState); + g_sinkSAState = DSCREEN_SA_EXIT_STATE_STOP; + DHLOGI("g_sourceSAState = %d g_sinkSAState = %d", g_sourceSAState, g_sinkSAState); + if (g_sourceSAState == DSCREEN_SA_EXIT_STATE_START || g_sinkSAState == DSCREEN_SA_EXIT_STATE_START) { + return; + } + DHLOGI("exit sa process success."); + ReportSaEvent(DSCREEN_EXIT, DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, "dscreen sink sa exit success."); + exit(0); +} + +void SetSourceProcessExit() +{ + DHLOGI("set sources process exit."); + std::lock_guard autoLock(g_saProcessState); + g_sourceSAState = DSCREEN_SA_EXIT_STATE_STOP; + DHLOGI("g_sourceSAState = %d g_sinkSAState = %d", g_sourceSAState, g_sinkSAState); + if (g_sourceSAState == DSCREEN_SA_EXIT_STATE_START || g_sinkSAState == DSCREEN_SA_EXIT_STATE_START) { + return; + } + DHLOGI("exit sa process success."); + ReportSaEvent(DSCREEN_EXIT, DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, "dscreen source sa exit success."); + exit(0); +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp b/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp index 8da0e91..42d8440 100644 --- a/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp +++ b/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp @@ -26,6 +26,7 @@ #include "dscreen_errcode.h" #include "dscreen_hisysevent.h" #include "dscreen_log.h" +#include "dscreen_sa_process_state.h" #include "dscreen_util.h" namespace OHOS { @@ -79,8 +80,7 @@ int32_t DScreenSinkService::ReleaseSink() DHLOGI("ReleaseSink"); ScreenRegionManager::GetInstance().ReleaseAllRegions(); DHLOGI("exit sink sa process"); - ReportSaEvent(DSCREEN_EXIT, DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, "dscreen sink sa exit success."); - exit(0); + SetSinkProcessExit(); return DH_SUCCESS; } diff --git a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp index bae8b5a..00e8cd8 100644 --- a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp +++ b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp @@ -26,6 +26,7 @@ #include "dscreen_errcode.h" #include "dscreen_hisysevent.h" #include "dscreen_log.h" +#include "dscreen_sa_process_state.h" #include "dscreen_util.h" namespace OHOS { @@ -95,8 +96,7 @@ int32_t DScreenSourceService::ReleaseSource() return ret; } DHLOGI("exit source sa process"); - ReportSaEvent(DSCREEN_EXIT, DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, "dscreen source sa exit success."); - exit(0); + SetSourceProcessExit(); return DH_SUCCESS; }