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 "session_command.h"
17 
18 #include "dps.h"
19 
20 namespace OHOS {
21 namespace CameraStandard {
22 namespace DeferredProcessing {
23 
SessionCommand(const sptr<VideoSessionInfo> & sessionInfo)24 SessionCommand::SessionCommand(const sptr<VideoSessionInfo>& sessionInfo) : sessionInfo_(sessionInfo)
25 {
26     DP_DEBUG_LOG("entered.");
27 }
28 
~SessionCommand()29 SessionCommand::~SessionCommand()
30 {
31     DP_DEBUG_LOG("entered.");
32     sessionManager_ = nullptr;
33     sessionInfo_ = nullptr;
34 }
35 
Initialize()36 int32_t SessionCommand::Initialize()
37 {
38     DP_CHECK_RETURN_RET(initialized_.load(), DP_OK);
39 
40     sessionManager_ = DPS_GetSessionManager();
41     DP_CHECK_ERROR_RETURN_RET_LOG(sessionManager_ == nullptr, DP_NULL_POINTER, "SessionManager is nullptr.");
42     initialized_.store(true);
43     return DP_OK;
44 }
45 
Executing()46 int32_t AddVideoSessionCommand::Executing()
47 {
48     if (int32_t ret = Initialize() != DP_OK) {
49         return ret;
50     }
51 
52     auto coordinator = sessionManager_->GetSessionCoordinator();
53     DP_CHECK_ERROR_RETURN_RET_LOG(coordinator == nullptr, DP_NULL_POINTER, "SessionCoordinator is nullptr.");
54     auto schedulerManager = DPS_GetSchedulerManager();
55     DP_CHECK_ERROR_RETURN_RET_LOG(schedulerManager == nullptr, DP_NULL_POINTER, "SchedulerManager is nullptr");
56     schedulerManager->CreateVideoProcessor(sessionInfo_->GetUserId(), coordinator->GetVideoProcCallbacks());
57     coordinator->AddSession(sessionInfo_);
58     return DP_OK;
59 }
60 
Executing()61 int32_t DeleteVideoSessionCommand::Executing()
62 {
63     if (int32_t ret = Initialize() != DP_OK) {
64         return ret;
65     }
66 
67     auto coordinator = sessionManager_->GetSessionCoordinator();
68     DP_CHECK_ERROR_RETURN_RET_LOG(coordinator == nullptr, DP_NULL_POINTER, "SessionCoordinator is nullptr.");
69     coordinator->DeleteSession(sessionInfo_->GetUserId());
70     return DP_OK;
71 }
72 } // namespace DeferredProcessing
73 } // namespace CameraStandard
74 } // namespace OHOS