• 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 BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_EVENT_REPORT_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_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 Notification {
27 namespace {
28 // event name
29 constexpr char SUBSCRIBE_ERROR[] = "SUBSCRIBE_ERROR";
30 constexpr char ENABLE_NOTIFICATION_ERROR[] = "ENABLE_NOTIFICATION_ERROR";
31 constexpr char ENABLE_NOTIFICATION_SLOT_ERROR[] = "ENABLE_NOTIFICATION_SLOT_ERROR";
32 constexpr char PUBLISH_ERROR[] = "PUBLISH_ERROR";
33 constexpr char FLOW_CONTROL_OCCUR[] = "FLOW_CONTROL_OCCUR";
34 
35 constexpr char SUBSCRIBE[] = "SUBSCRIBE";
36 constexpr char UNSUBSCRIBE[] = "UNSUBSCRIBE";
37 constexpr char ENABLE_NOTIFICATION[] = "ENABLE_NOTIFICATION";
38 constexpr char ENABLE_NOTIFICATION_SLOT[] = "ENABLE_NOTIFICATION_SLOT";
39 
40 constexpr char PUBLISH[] = "PUBLISH";
41 constexpr char CANCEL[] = "CANCEL";
42 constexpr char REMOVE[] = "REMOVE";
43 } // namespace
44 
45 struct EventInfo {
46     int32_t notificationId = 0;
47     int32_t contentType = 0;
48     int32_t userId = -1;
49     int32_t pid = 0;
50     int32_t uid = 0;
51     int32_t slotType = 0;
52     int32_t errCode = 0;
53     bool enable = false;
54     std::string bundleName;
55     std::string notificationLabel;
56 };
57 
58 class EventReport {
59 public:
60     /**
61      * @brief send hisysevent
62      *
63      * @param eventName event name, corresponding to the document 'hisysevent.yaml'
64      * @param eventInfo event info
65      */
66     static void SendHiSysEvent(const std::string &eventName, const EventInfo &eventInfo);
67 
68 private:
69 #ifdef HAS_HISYSEVENT_PART
70     // fault event
71     static void InnerSendSubscribeErrorEvent(const EventInfo &eventInfo);
72     static void InnerSendEnableNotificationErrorEvent(const EventInfo &eventInfo);
73     static void InnerSendEnableNotificationSlotErrorEvent(const EventInfo &eventInfo);
74     static void InnerSendPublishErrorEvent(const EventInfo &eventInfo);
75     static void InnerSendFlowControlOccurEvent(const EventInfo &eventInfo);
76 
77     // behavior event
78     static void InnerSendSubscribeEvent(const EventInfo &eventInfo);
79     static void InnerSendUnSubscribeEvent(const EventInfo &eventInfo);
80     static void InnerSendEnableNotificationEvent(const EventInfo &eventInfo);
81     static void InnerSendEnableNotificationSlotEvent(const EventInfo &eventInfo);
82 
83     // statistic event
84     static void InnerSendPublishEvent(const EventInfo &eventInfo);
85     static void InnerSendCancelEvent(const EventInfo &eventInfo);
86     static void InnerSendRemoveEvent(const EventInfo &eventInfo);
87 
88     template<typename... Types>
89     static void InnerEventWrite(const std::string &eventName,
90         HiviewDFX::HiSysEvent::EventType type, Types... keyValues);
91 
92     static std::unordered_map<std::string, void (*)(const EventInfo &eventInfo)> ansSysEventFuncMap_;
93 #endif
94 };
95 } // namespace Notification
96 } // namespace OHOS
97 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_EVENT_REPORT_H