• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #ifndef FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_EVENT_REPORT_H
17 #define FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_EVENT_REPORT_H
18 
19 #include <unordered_map>
20 
21 #ifdef HAS_HISYSEVENT_PART
22 #include "hisysevent.h"
23 #endif
24 
25 namespace OHOS {
26 namespace EventFwk {
27 namespace {
28 // event name
29 constexpr char ORDERED_EVENT_PROC_TIMEOUT[] = "ORDERED_EVENT_PROC_TIMEOUT";
30 constexpr char STATIC_EVENT_PROC_ERROR[] = "STATIC_EVENT_PROC_ERROR";
31 constexpr char SUBSCRIBER_EXCEED_MAXIMUM[] = "SUBSCRIBER_EXCEED_MAXIMUM";
32 constexpr char PUBLISH_ERROR[] = "PUBLISH_ERROR";
33 constexpr char SUBSCRIBE[] = "SUBSCRIBE";
34 constexpr char UNSUBSCRIBE[] = "UNSUBSCRIBE";
35 constexpr char PUBLISH[] = "PUBLISH";
36 } // namespace
37 
38 struct EventInfo {
39     int32_t userId;
40     int32_t pid;
41     int32_t uid;
42     uint32_t subscriberNum;
43     std::string publisherName;
44     std::string subscriberName;
45     std::string eventName;
46 
EventInfoEventInfo47     EventInfo() : userId(-1), pid(0), uid(0), subscriberNum(0) {}
48 };
49 
50 class EventReport {
51 public:
52     /**
53      * @brief send hisysevent
54      *
55      * @param eventName event name, corresponding to the document 'hisysevent.yaml'
56      * @param eventInfo event info
57      */
58     static void SendHiSysEvent(const std::string &eventName, const EventInfo &eventInfo);
59 
60 private:
61 #ifdef HAS_HISYSEVENT_PART
62     // fault event
63     static void InnerSendOrderedEventProcTimeoutEvent(const EventInfo &eventInfo);
64     static void InnerSendStaticEventProcErrorEvent(const EventInfo &eventInfo);
65     static void InnerSendSubscriberExceedMaximumEvent(const EventInfo &eventInfo);
66     static void InnerSendPublishErrorEvent(const EventInfo &eventInfo);
67 
68     // statistic event
69     static void InnerSendSubscribeEvent(const EventInfo &eventInfo);
70     static void InnerSendUnSubscribeEvent(const EventInfo &eventInfo);
71     static void InnerSendPublishEvent(const EventInfo &eventInfo);
72 
73     template<typename... Types>
74     static void InnerEventWrite(const std::string &eventName,
75         HiviewDFX::HiSysEvent::EventType type, Types... keyValues);
76 
77     static std::unordered_map<std::string, void (*)(const EventInfo &eventInfo)> cesSysEventFuncMap_;
78 #endif
79 };
80 } // namespace EventFwk
81 } // namespace OHOS
82 #endif  // FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_EVENT_REPORT_H