• 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 
16 #include "dynamic_load_plugin_example.h"
17 
18 #include "plugin_factory.h"
19 
20 namespace OHOS {
21 namespace HiviewDFX {
22 REGISTER(DynamicLoadPluginExample);
23 using namespace std;
24 
OnEvent(std::shared_ptr<Event> & event)25 bool DynamicLoadPluginExample::OnEvent(std::shared_ptr<Event>& event)
26 {
27     printf("DynamicLoadPluginExample OnEvent xxxx%p\n", event.get());
28     event->SetValue("DynamicLoadPluginExample", "Done");
29     return true;
30 }
31 
OnLoad()32 void DynamicLoadPluginExample::OnLoad()
33 {
34     SetVersion("DynamicLoadPluginExample1.0");
35     printf("DynamicLoadPluginExample OnLoad \n");
36     AddListenerInfo(Event::PLUGIN_MAINTENANCE, {"event_test1"});
37     auto ptr = std::static_pointer_cast<DynamicLoadPluginExample>(shared_from_this());
38     printf("register event listener %p \n", ptr.get());
39     GetHiviewContext()->RegisterUnorderedEventListener(ptr);
40     AddListenerInfo(OHOS::HiviewDFX::Event::MessageType::RAW_EVENT);
41     AddListenerInfo(OHOS::HiviewDFX::Event::MessageType::SYS_EVENT, {"testbb"});
42 }
43 
OnUnload()44 void DynamicLoadPluginExample::OnUnload()
45 {
46     printf("DynamicLoadPluginExample OnUnload \n");
47 }
48 
OnUnorderedEvent(const Event & msg)49 void DynamicLoadPluginExample::OnUnorderedEvent(const Event &msg)
50 {
51     printf("DynamicLoadPluginExample OnUnorderedEvent.\n");
52     auto cmd = msg.GetValue("DynamicLoadPluginExample");
53     if (cmd == "Unload") {
54         GetHiviewContext()->RequestUnloadPlugin(shared_from_this());
55         printf("DynamicLoadPluginExample Request unload self.\n");
56     }
57 
58     GetHiviewContext()->SetHiviewProperty("DPE_Listening", "received : " + msg.eventName_, true);
59 }
60 
GetListenerName()61 string DynamicLoadPluginExample::GetListenerName()
62 {
63     printf("DynamicLoadPluginExample GetListenerName \n");
64     return "DynamicLoadPluginExample";
65 }
66 } // namespace HiviewDFX
67 } // namespace OHOS
68