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);
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::SYS_EVENT, "testbb");
41 const int EVENT_ID_1 = 901000111;
42 AddListenerInfo(OHOS::HiviewDFX::Event::MessageType::RAW_EVENT, EVENT_ID_1);
43 }
44
OnUnload()45 void DynamicLoadPluginExample::OnUnload()
46 {
47 printf("DynamicLoadPluginExample OnUnload \n");
48 }
49
OnUnorderedEvent(const Event & msg)50 void DynamicLoadPluginExample::OnUnorderedEvent(const Event &msg)
51 {
52 printf("DynamicLoadPluginExample OnUnorderedEvent.\n");
53 auto cmd = msg.GetValue("DynamicLoadPluginExample");
54 if (cmd == "Unload") {
55 GetHiviewContext()->RequestUnloadPlugin(shared_from_this());
56 printf("DynamicLoadPluginExample Request unload self.\n");
57 }
58
59 GetHiviewContext()->SetHiviewProperty("DPE_Listening", "received : " + msg.eventName_, true);
60 }
61
GetListenerName()62 string DynamicLoadPluginExample::GetListenerName()
63 {
64 printf("DynamicLoadPluginExample GetListenerName \n");
65 return "DynamicLoadPluginExample";
66 }
67 } // namespace HiviewDFX
68 } // namespace OHOS
69