• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "dcamera_sa_process_state.h"
17 
18 #include <mutex>
19 #include <cstdlib>
20 
21 #include "distributed_hardware_log.h"
22 
23 namespace OHOS {
24 namespace DistributedHardware {
25 typedef enum {
26     DCAMERA_SA_EXIT_STATE_START = 0,
27     DCAMERA_SA_EXIT_STATE_STOP = 1
28 } DCameraSAState;
29 
30 DCameraSAState g_sinkSAState = DCAMERA_SA_EXIT_STATE_START;
31 DCameraSAState g_sourceSAState = DCAMERA_SA_EXIT_STATE_START;
32 std::mutex g_saProcessState;
33 
SetSinkProcessExit()34 void SetSinkProcessExit()
35 {
36     DHLOGI("set sink process exit.");
37     std::lock_guard<std::mutex> autoLock(g_saProcessState);
38     g_sinkSAState = DCAMERA_SA_EXIT_STATE_STOP;
39     DHLOGI("g_sourceSAState = %d g_sinkSAState = %d", g_sourceSAState, g_sinkSAState);
40     if (g_sourceSAState == DCAMERA_SA_EXIT_STATE_START || g_sinkSAState == DCAMERA_SA_EXIT_STATE_START) {
41         return;
42     }
43     DHLOGI("exit sa process success.");
44     _Exit(0);
45 }
46 
SetSourceProcessExit()47 void SetSourceProcessExit()
48 {
49     DHLOGI("set sources process exit.");
50     std::lock_guard<std::mutex> autoLock(g_saProcessState);
51     g_sourceSAState = DCAMERA_SA_EXIT_STATE_STOP;
52     DHLOGI("g_sourceSAState = %d g_sinkSAState = %d", g_sourceSAState, g_sinkSAState);
53     if (g_sourceSAState == DCAMERA_SA_EXIT_STATE_START || g_sinkSAState == DCAMERA_SA_EXIT_STATE_START) {
54         return;
55     }
56     DHLOGI("exit sa process success.");
57     _Exit(0);
58 }
59 } // namespace DistributedHardware
60 } // namespace OHOS