• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2023 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 "dps.h"
17 
18 #include "dp_catch.h"
19 
20 namespace OHOS {
21 namespace CameraStandard {
22 namespace DeferredProcessing {
23 struct DpsInfo {
24     std::atomic<bool> initialized_{false};
25     std::mutex mutex{};
26     std::shared_ptr<CommandServer> server;
27     std::shared_ptr<SessionManager> session;
28     std::shared_ptr<SchedulerManager> scheduler;
29 };
30 
31 DpsInfo g_dpsInfo;
32 
DPS_Initialize()33 int32_t DPS_Initialize()
34 {
35 PROSS
36     std::unique_lock<std::mutex> lock(g_dpsInfo.mutex);
37     if (g_dpsInfo.initialized_) {
38         DP_DEBUG_LOG("Already initialized.");
39         return DP_OK;
40     }
41     DP_DEBUG_LOG("entered.");
42     g_dpsInfo.server = std::make_shared<CommandServer>();
43     g_dpsInfo.session = SessionManager::Create();
44     g_dpsInfo.scheduler = SchedulerManager::Create();
45     JUDEG(DP_NULL_POINTER, g_dpsInfo.server != nullptr);
46     JUDEG(DP_NULL_POINTER, g_dpsInfo.session != nullptr);
47     JUDEG(DP_NULL_POINTER, g_dpsInfo.scheduler != nullptr);
48     EXEC(g_dpsInfo.server->Initialize());
49     g_dpsInfo.initialized_ = true;
50     DP_INFO_LOG("DPS_Initialize success.");
51     return DP_OK;
52 END_PROSS
53 CATCH_ERROR
54     DPS_Destroy();
55     DP_ERR_LOG("DPS_Initialize failed, line: %{public}u, error: %{public}u.", ERROR_LINE(), ERROR_CODE());
56     return ERROR_CODE();
57 END_CATCH_ERROR
58 }
59 
DPS_Destroy()60 void DPS_Destroy()
61 {
62     std::unique_lock<std::mutex> lock(g_dpsInfo.mutex);
63     DP_DEBUG_LOG("entered.");
64     if (!g_dpsInfo.initialized_) {
65         return;
66     }
67     g_dpsInfo.server.reset();
68     g_dpsInfo.session.reset();
69     g_dpsInfo.scheduler.reset();
70     g_dpsInfo.initialized_ = false;
71     DP_INFO_LOG("DPS_Destroy success.");
72 }
73 
DPS_GetCommandServer()74 std::shared_ptr<CommandServer> DPS_GetCommandServer()
75 {
76     std::unique_lock<std::mutex> lock(g_dpsInfo.mutex);
77     return g_dpsInfo.server ? g_dpsInfo.server : nullptr;
78 }
79 
DPS_GetSessionManager()80 std::shared_ptr<SessionManager> DPS_GetSessionManager()
81 {
82     std::unique_lock<std::mutex> lock(g_dpsInfo.mutex);
83     return g_dpsInfo.session ? g_dpsInfo.session : nullptr;
84 }
85 
DPS_GetSchedulerManager()86 std::shared_ptr<SchedulerManager> DPS_GetSchedulerManager()
87 {
88     std::unique_lock<std::mutex> lock(g_dpsInfo.mutex);
89     return g_dpsInfo.scheduler ? g_dpsInfo.scheduler : nullptr;
90 }
91 } // namespace DeferredProcessing
92 } // namespace CameraStandard
93 } // namespace OHOS