• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2024 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 #include "events_monitor.h"
20 
21 namespace OHOS {
22 namespace CameraStandard {
23 namespace DeferredProcessing {
24 
SessionCommand()25 SessionCommand::SessionCommand()
26 {
27     DP_DEBUG_LOG("entered.");
28 }
29 
~SessionCommand()30 SessionCommand::~SessionCommand()
31 {
32     DP_DEBUG_LOG("entered.");
33 }
34 
Initialize()35 int32_t SessionCommand::Initialize()
36 {
37     DP_CHECK_RETURN_RET(initialized_.load(), DP_OK);
38 
39     sessionManager_ = DPS_GetSessionManager();
40     DP_CHECK_ERROR_RETURN_RET_LOG(sessionManager_ == nullptr, DP_NULL_POINTER, "SessionManager is nullptr.");
41     schedulerManager_ = DPS_GetSchedulerManager();
42     DP_CHECK_ERROR_RETURN_RET_LOG(schedulerManager_ == nullptr, DP_NULL_POINTER, "SchedulerManager is nullptr.");
43     initialized_.store(true);
44     return DP_OK;
45 }
46 
AddPhotoSessionCommand(const sptr<PhotoSessionInfo> & info)47 AddPhotoSessionCommand::AddPhotoSessionCommand(const sptr<PhotoSessionInfo>& info) : photoInfo_(info)
48 {
49     DP_DEBUG_LOG("entered.");
50 }
51 
Executing()52 int32_t AddPhotoSessionCommand::Executing()
53 {
54     if (int32_t ret = Initialize() != DP_OK) {
55         return ret;
56     }
57 
58     auto coordinator = sessionManager_->GetSessionCoordinator();
59     DP_CHECK_ERROR_RETURN_RET_LOG(coordinator == nullptr, DP_NULL_POINTER, "SessionCoordinator is nullptr.");
60 
61     if (photoInfo_->isCreate_) {
62         schedulerManager_->CreatePhotoProcessor(photoInfo_->GetUserId(), coordinator->GetImageProcCallbacks());
63     }
64     coordinator->AddPhotoSession(photoInfo_);
65     EventsMonitor::GetInstance().NotifyEventToObervers(photoInfo_->GetUserId(),
66         EventType::MEDIA_LIBRARY_STATUS_EVENT, true);
67     return DP_OK;
68 }
69 
DeletePhotoSessionCommand(const sptr<PhotoSessionInfo> & info)70 DeletePhotoSessionCommand::DeletePhotoSessionCommand(const sptr<PhotoSessionInfo>& info) : photoInfo_(info)
71 {
72     DP_DEBUG_LOG("entered.");
73 }
74 
Executing()75 int32_t DeletePhotoSessionCommand::Executing()
76 {
77     if (int32_t ret = Initialize() != DP_OK) {
78         return ret;
79     }
80 
81     auto coordinator = sessionManager_->GetSessionCoordinator();
82     DP_CHECK_ERROR_RETURN_RET_LOG(coordinator == nullptr, DP_NULL_POINTER, "SessionCoordinator is nullptr.");
83     coordinator->DeletePhotoSession(photoInfo_->GetUserId());
84     EventsMonitor::GetInstance().NotifyEventToObervers(photoInfo_->GetUserId(),
85         EventType::MEDIA_LIBRARY_STATUS_EVENT, false);
86     return DP_OK;
87 }
88 
AddVideoSessionCommand(const sptr<VideoSessionInfo> & info)89 AddVideoSessionCommand::AddVideoSessionCommand(const sptr<VideoSessionInfo>& info) : videoInfo_(info)
90 {
91     DP_DEBUG_LOG("entered.");
92 }
93 
Executing()94 int32_t AddVideoSessionCommand::Executing()
95 {
96     if (int32_t ret = Initialize() != DP_OK) {
97         return ret;
98     }
99 
100     auto coordinator = sessionManager_->GetSessionCoordinator();
101     DP_CHECK_ERROR_RETURN_RET_LOG(coordinator == nullptr, DP_NULL_POINTER, "SessionCoordinator is nullptr.");
102 
103     if (videoInfo_->isCreate_) {
104         schedulerManager_->CreateVideoProcessor(videoInfo_->GetUserId(), coordinator->GetVideoProcCallbacks());
105     }
106     coordinator->AddVideoSession(videoInfo_);
107     return DP_OK;
108 }
109 
DeleteVideoSessionCommand(const sptr<VideoSessionInfo> & info)110 DeleteVideoSessionCommand::DeleteVideoSessionCommand(const sptr<VideoSessionInfo>& info) : videoInfo_(info)
111 {
112     DP_DEBUG_LOG("entered.");
113 }
114 
Executing()115 int32_t DeleteVideoSessionCommand::Executing()
116 {
117     if (int32_t ret = Initialize() != DP_OK) {
118         return ret;
119     }
120 
121     auto coordinator = sessionManager_->GetSessionCoordinator();
122     DP_CHECK_ERROR_RETURN_RET_LOG(coordinator == nullptr, DP_NULL_POINTER, "SessionCoordinator is nullptr.");
123     coordinator->DeleteVideoSession(videoInfo_->GetUserId());
124     return DP_OK;
125 }
126 } // namespace DeferredProcessing
127 } // namespace CameraStandard
128 } // namespace OHOS