• 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     int32_t ret = Initialize();
55     if (ret != DP_OK) {
56         return ret;
57     }
58 
59     sessionManager_->AddPhotoSession(photoInfo_);
60     if (photoInfo_->isCreate_) {
61         schedulerManager_->CreatePhotoProcessor(photoInfo_->GetUserId());
62     }
63     EventsMonitor::GetInstance().NotifyEventToObervers(EventType::MEDIA_LIBRARY_STATUS_EVENT, true);
64     return DP_OK;
65 }
66 
DeletePhotoSessionCommand(const sptr<PhotoSessionInfo> & info)67 DeletePhotoSessionCommand::DeletePhotoSessionCommand(const sptr<PhotoSessionInfo>& info) : photoInfo_(info)
68 {
69     DP_DEBUG_LOG("entered.");
70 }
71 
Executing()72 int32_t DeletePhotoSessionCommand::Executing()
73 {
74     int32_t ret = Initialize();
75     if (ret != DP_OK) {
76         return ret;
77     }
78 
79     sessionManager_->DeletePhotoSession(photoInfo_->GetUserId());
80     EventsMonitor::GetInstance().NotifyEventToObervers(EventType::MEDIA_LIBRARY_STATUS_EVENT, false);
81     return DP_OK;
82 }
83 
AddVideoSessionCommand(const sptr<VideoSessionInfo> & info)84 AddVideoSessionCommand::AddVideoSessionCommand(const sptr<VideoSessionInfo>& info) : videoInfo_(info)
85 {
86     DP_DEBUG_LOG("entered.");
87 }
88 
Executing()89 int32_t AddVideoSessionCommand::Executing()
90 {
91     int32_t ret = Initialize();
92     if (ret != DP_OK) {
93         return ret;
94     }
95 
96     auto coordinator = sessionManager_->GetSessionCoordinator();
97     DP_CHECK_ERROR_RETURN_RET_LOG(coordinator == nullptr, DP_NULL_POINTER, "SessionCoordinator is nullptr.");
98 
99     if (videoInfo_->isCreate_) {
100         schedulerManager_->CreateVideoProcessor(videoInfo_->GetUserId(), coordinator->GetVideoProcCallbacks());
101     }
102     coordinator->AddVideoSession(videoInfo_);
103     EventsMonitor::GetInstance().NotifyEventToObervers(EventType::MEDIA_LIBRARY_STATUS_EVENT, true);
104     return DP_OK;
105 }
106 
DeleteVideoSessionCommand(const sptr<VideoSessionInfo> & info)107 DeleteVideoSessionCommand::DeleteVideoSessionCommand(const sptr<VideoSessionInfo>& info) : videoInfo_(info)
108 {
109     DP_DEBUG_LOG("entered.");
110 }
111 
Executing()112 int32_t DeleteVideoSessionCommand::Executing()
113 {
114     int32_t ret = Initialize();
115     if (ret != DP_OK) {
116         return ret;
117     }
118 
119     auto coordinator = sessionManager_->GetSessionCoordinator();
120     DP_CHECK_ERROR_RETURN_RET_LOG(coordinator == nullptr, DP_NULL_POINTER, "SessionCoordinator is nullptr.");
121     coordinator->DeleteVideoSession(videoInfo_->GetUserId());
122     EventsMonitor::GetInstance().NotifyEventToObervers(EventType::MEDIA_LIBRARY_STATUS_EVENT, false);
123     return DP_OK;
124 }
125 } // namespace DeferredProcessing
126 } // namespace CameraStandard
127 } // namespace OHOS