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 "event_processor_example3.h"
17
18 #include "pipeline.h"
19 #include "plugin_factory.h"
20
21 namespace OHOS {
22 namespace HiviewDFX {
23 REGISTER_PROXY(EventProcessorExample3);
EventProcessorExample3()24 EventProcessorExample3::EventProcessorExample3()
25 {
26 std::unique_lock<std::mutex> lock(EventSourceExample::mutex_);
27 printf("EventProcessorExample3::EventProcessorExample3()\n");
28 EventSourceExample::count.insert("EventProcessorExample3");
29 }
30
~EventProcessorExample3()31 EventProcessorExample3::~EventProcessorExample3()
32 {
33 std::unique_lock<std::mutex> lock(EventSourceExample::mutex_);
34 printf("EventProcessorExample3::~EventProcessorExample3()\n");
35 EventSourceExample::count.erase("EventProcessorExample3");
36 }
37
CanProcessEvent(std::shared_ptr<Event> event)38 bool EventProcessorExample3::CanProcessEvent(std::shared_ptr<Event> event)
39 {
40 printf("EventProcessorExample3 CanProcessEvent: %d.\n", event->eventId_);
41 if (event->eventId_ == EventSourceExample::PIPELINE_EVENT_ID_CCC) {
42 printf("EventProcessorExample3 CanProcessEvent true.\n");
43 return true;
44 }
45 return false;
46 }
47
OnEvent(std::shared_ptr<Event> & event)48 bool EventProcessorExample3::OnEvent(std::shared_ptr<Event>& event)
49 {
50 printf("EventProcessorExample3 OnEvent 0 tid:%d sender:%s.\n", gettid(), event->sender_.c_str());
51 if (event->eventId_ == EventSourceExample::PIPELINE_EVENT_ID_BBB) {
52 printf("EventProcessorExample3 process bbb event.\n");
53 }
54
55 if (event->eventId_ == EventSourceExample::PIPELINE_EVENT_ID_AAA) {
56 printf("EventProcessorExample3 process aaa event.\n");
57 }
58
59 if (GetHiviewContext() != nullptr) {
60 GetHiviewContext()->SetHiviewProperty("EPE3_OnEvent", "received : " + event->eventName_, true);
61 }
62 event->SetValue("EventProcessorExample3", "Done");
63 return true;
64 }
65
OnLoad()66 void EventProcessorExample3::OnLoad()
67 {
68 SetVersion("EventProcessorExample3.0");
69 printf("EventProcessorExample3 OnLoad\n");
70 }
71
OnUnload()72 void EventProcessorExample3::OnUnload()
73 {
74 printf("EventProcessorExample3 OnUnload \n");
75 }
76 } // namespace HiviewDFX
77 } // namespace OHOS