1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "dscreen_sa_process_state.h"
17
18 #include <cstdint>
19 #include <cstdlib>
20 #include <mutex>
21
22 #include "dscreen_constants.h"
23 #include "dscreen_hisysevent.h"
24 #include "dscreen_log.h"
25
26 namespace OHOS {
27 namespace DistributedHardware {
28 enum DScreenSAState : uint32_t {
29 DSCREEN_SA_EXIT_STATE_START = 0,
30 DSCREEN_SA_EXIT_STATE_STOP = 1
31 };
32 DScreenSAState g_sinkSAState = DSCREEN_SA_EXIT_STATE_START;
33 DScreenSAState g_sourceSAState = DSCREEN_SA_EXIT_STATE_START;
34 std::mutex g_saProcessState;
35
SetSinkProcessExit()36 void SetSinkProcessExit()
37 {
38 DHLOGI("set sink process exit.");
39 std::lock_guard<std::mutex> autoLock(g_saProcessState);
40 g_sinkSAState = DSCREEN_SA_EXIT_STATE_STOP;
41 DHLOGI("g_sourceSAState = %d g_sinkSAState = %d", g_sourceSAState, g_sinkSAState);
42 if (g_sourceSAState == DSCREEN_SA_EXIT_STATE_START || g_sinkSAState == DSCREEN_SA_EXIT_STATE_START) {
43 return;
44 }
45 DHLOGI("exit sa process success.");
46 ReportSaEvent(DSCREEN_EXIT, DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, "dscreen sink sa exit success.");
47 _Exit(0);
48 }
49
SetSourceProcessExit()50 void SetSourceProcessExit()
51 {
52 DHLOGI("set sources process exit.");
53 std::lock_guard<std::mutex> autoLock(g_saProcessState);
54 g_sourceSAState = DSCREEN_SA_EXIT_STATE_STOP;
55 DHLOGI("g_sourceSAState = %d g_sinkSAState = %d", g_sourceSAState, g_sinkSAState);
56 if (g_sourceSAState == DSCREEN_SA_EXIT_STATE_START || g_sinkSAState == DSCREEN_SA_EXIT_STATE_START) {
57 return;
58 }
59 DHLOGI("exit sa process success.");
60 ReportSaEvent(DSCREEN_EXIT, DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, "dscreen source sa exit success.");
61 _Exit(0);
62 }
63 } // namespace DistributedHardware
64 } // namespace OHOS