• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #include "hiview_global.h"
16 
17 namespace OHOS {
18 namespace HiviewDFX {
19 namespace {
GetOrSetGlobalReference(std::unique_ptr<HiviewGlobal> ref,bool state=true)20 std::unique_ptr<HiviewGlobal>& GetOrSetGlobalReference(std::unique_ptr<HiviewGlobal> ref, bool state = true)
21 {
22     static std::unique_ptr<HiviewGlobal> globalRef = nullptr;
23     if (!state) {
24         globalRef = nullptr;
25     } else if (ref != nullptr) {
26         globalRef = std::move(ref);
27     }
28     return globalRef;
29 }
30 }
31 
CreateInstance(HiviewContext & context)32 void HiviewGlobal::CreateInstance(HiviewContext& context)
33 {
34     auto globalRef = std::make_unique<HiviewGlobal>(context);
35     GetOrSetGlobalReference(std::move(globalRef));
36 }
37 
ReleaseInstance()38 void HiviewGlobal::ReleaseInstance()
39 {
40     GetOrSetGlobalReference(nullptr, false);
41 }
42 // maybe null reference, check before use
GetInstance()43 std::unique_ptr<HiviewGlobal>& HiviewGlobal::GetInstance()
44 {
45     return GetOrSetGlobalReference(nullptr);
46 }
47 
GetHiViewDirectory(HiviewContext::DirectoryType type) const48 std::string HiviewGlobal::GetHiViewDirectory(HiviewContext::DirectoryType type) const
49 {
50     return context_.GetHiViewDirectory(type);
51 }
52 
GetHiviewProperty(const std::string & key,const std::string & defaultValue)53 std::string HiviewGlobal::GetHiviewProperty(const std::string& key, const std::string& defaultValue)
54 {
55     return context_.GetHiviewProperty(key, defaultValue);
56 }
57 
SetHiviewProperty(const std::string & key,const std::string & value,bool forceUpdate)58 bool HiviewGlobal::SetHiviewProperty(const std::string& key, const std::string& value, bool forceUpdate)
59 {
60     return context_.SetHiviewProperty(key, value, forceUpdate);
61 }
62 
PostAsyncEventToTarget(const std::string & targetPlugin,std::shared_ptr<Event> event)63 void HiviewGlobal::PostAsyncEventToTarget(const std::string &targetPlugin, std::shared_ptr<Event> event)
64 {
65     context_.PostAsyncEventToTarget(nullptr, targetPlugin, event);
66 }
67 
PostSyncEventToTarget(const std::string & targetPlugin,std::shared_ptr<Event> event)68 bool HiviewGlobal::PostSyncEventToTarget(const std::string &targetPlugin, std::shared_ptr<Event> event)
69 {
70     return context_.PostSyncEventToTarget(nullptr, targetPlugin, event);
71 }
72 
PostUnorderedEvent(std::shared_ptr<Event> event)73 void HiviewGlobal::PostUnorderedEvent(std::shared_ptr<Event> event)
74 {
75     context_.PostUnorderedEvent(nullptr, event);
76 }
77 
AddListenerInfo(uint32_t type,const std::string & name,const std::set<std::string> & eventNames,const std::map<std::string,DomainRule> & domainRulesMap)78 void HiviewGlobal::AddListenerInfo(uint32_t type, const std::string& name,
79     const std::set<std::string>& eventNames, const std::map<std::string, DomainRule>& domainRulesMap)
80 {
81     context_.AddListenerInfo(type, name, eventNames, domainRulesMap);
82 }
83 
AddListenerInfo(uint32_t type,const std::string & name)84 void HiviewGlobal::AddListenerInfo(uint32_t type, const std::string& name)
85 {
86     context_.AddListenerInfo(type, name);
87 }
88 
GetPipelineSequenceByName(const std::string & name)89 std::list<std::weak_ptr<Plugin>> HiviewGlobal::GetPipelineSequenceByName(const std::string& name)
90 {
91     return context_.GetPipelineSequenceByName(name);
92 }
93 } // namespace HiviewDFX
94 } // namespace OHOS