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 "av_session_state_listener.h"
17 
18 #include "res_sched_log.h"
19 #include "res_sched_mgr.h"
20 #include "ressched_utils.h"
21 #include "res_type.h"
22 
23 namespace OHOS {
24 namespace ResourceSchedule {
MarshallingAVSessionDescriptor(const AVSession::AVSessionDescriptor & descriptor,nlohmann::json & payload)25 void AvSessionStateListener::MarshallingAVSessionDescriptor(const AVSession::AVSessionDescriptor& descriptor,
26     nlohmann::json &payload)
27 {
28     payload["sessionId_"] = descriptor.sessionId_;
29     payload["pid_"] = descriptor.pid_;
30     payload["uid_"] = descriptor.uid_;
31 }
32 
OnSessionCreate(const AVSession::AVSessionDescriptor & descriptor)33 void AvSessionStateListener::OnSessionCreate(const AVSession::AVSessionDescriptor& descriptor)
34 {
35     RESSCHED_LOGD("Ressched AvSessionStateListener OnSessionCreate");
36     nlohmann::json payload;
37     MarshallingAVSessionDescriptor(descriptor, payload);
38     ResSchedUtils::GetInstance().ReportDataInProcess(
39         ResType::RES_TYPE_AV_SESSION_ON_SESSION_CREATE, 0, payload);
40 }
41 
OnSessionRelease(const AVSession::AVSessionDescriptor & descriptor)42 void AvSessionStateListener::OnSessionRelease(const AVSession::AVSessionDescriptor& descriptor)
43 {
44     RESSCHED_LOGD("Ressched AvSessionStateListener OnSessionRelease");
45     nlohmann::json payload;
46     MarshallingAVSessionDescriptor(descriptor, payload);
47     ResSchedUtils::GetInstance().ReportDataInProcess(
48         ResType::RES_TYPE_AV_SESSION_ON_SESSION_RELEASE, 0, payload);
49 }
50 
OnTopSessionChange(const AVSession::AVSessionDescriptor & descriptor)51 void AvSessionStateListener::OnTopSessionChange(const AVSession::AVSessionDescriptor& descriptor)
52 {
53     RESSCHED_LOGD("Ressched AvSessionStateListener OnTopSessionChange");
54     nlohmann::json payload;
55     MarshallingAVSessionDescriptor(descriptor, payload);
56     ResSchedUtils::GetInstance().ReportDataInProcess(
57         ResType::RES_TYPE_AV_SESSION_ON_TOP_SESSION_CHANGE, 0, payload);
58 }
59 } // OHOS
60 } // namespace ResourceSchedule