• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2022 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 #define HST_LOG_TAG "MediaStatStub"
17 
18 #include "media_stat_stub.h"
19 
20 #include <algorithm>
21 #include "foundation/log.h"
22 
23 namespace OHOS {
24 namespace Media {
Reset()25 void MediaStatStub::Reset()
26 {
27     mediaStats_.clear();
28 }
29 
Append(const std::string & reporter)30 void MediaStatStub::Append(const std::string& reporter)
31 {
32     for (auto& stat : mediaStats_) {
33         if (stat.reporter == reporter) {
34             return;
35         }
36     }
37     mediaStats_.emplace_back(reporter);
38 }
39 
ReceiveEvent(const Event & event)40 void MediaStatStub::ReceiveEvent(const Event& event)
41 {
42     switch (event.type) {
43         case EventType::EVENT_COMPLETE:
44             for (auto& stat : mediaStats_) {
45                 if (stat.reporter == event.srcFilter) {
46                     stat.completeEventReceived = true;
47                     break;
48                 }
49             }
50             break;
51         default:
52             MEDIA_LOG_W("MediaStats::ReceiveEvent receive unexpected event " PUBLIC_LOG_D32,
53                         static_cast<int>(event.type));
54             break;
55     }
56 }
57 
IsEventCompleteAllReceived()58 bool MediaStatStub::IsEventCompleteAllReceived()
59 {
60     return std::all_of(mediaStats_.begin(), mediaStats_.end(), [](const MediaStat& stat) {
61         return stat.completeEventReceived.load();
62     });
63 }
64 } // Media
65 } // OHOS