• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "BaseContext.h"
17 
18 namespace OHOS {
19 namespace HiviewDFX {
BaseContext()20 BaseContext::BaseContext() : monitors()
21 {
22 }
23 
RegisterMonitorByLogID(int logId,IMonitor * newMonitor)24 void BaseContext::RegisterMonitorByLogID(int logId, IMonitor* newMonitor)
25 {
26     if (monitors.find(logId) == monitors.end()) {
27         std::vector<IMonitor*> monitorVector;
28         monitorVector.push_back(newMonitor);
29         monitors.emplace(logId, monitorVector);
30     } else {
31         std::vector<IMonitor*> &monitorVec = monitors.at(logId);
32         monitorVec.push_back(newMonitor);
33     }
34 }
35 
GetMonitorsByLogID(int logId)36 std::vector<IMonitor*> BaseContext::GetMonitorsByLogID(int logId)
37 {
38     if (monitors.find(logId) == monitors.end()) {
39         throw std::invalid_argument("logId: " + std::to_string(logId) + " not register.");
40     }
41     return monitors.at(logId);
42 }
43 
GetEventObservable()44 IEventObservable* BaseContext::GetEventObservable()
45 {
46     return eventObservable;
47 }
48 } // HiviewDFX
49 } // OHOS