1 /*
2  * Copyright (c) 2022-2023 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 NETSYS_EVENT_MESSAGE_H
17 #define NETSYS_EVENT_MESSAGE_H
18 
19 #include <map>
20 #include <string>
21 
22 #define NET_SYMBOL_VISIBLE __attribute__ ((visibility("default")))
23 namespace OHOS {
24 namespace nmd {
25 class NET_SYMBOL_VISIBLE NetsysEventMessage {
26 public:
27     NetsysEventMessage() = default;
28     ~NetsysEventMessage() = default;
29 
30     enum class Action {
31         UNKNOWN = 0,
32         ADD = 1,
33         REMOVE = 2,
34         CHANGE = 3,
35         LINKUP = 4,
36         LINKDOWN = 5,
37         ADDRESSUPDATE = 6,
38         ADDRESSREMOVED = 7,
39         RDNSS = 8,
40         ROUTEUPDATED = 9,
41         ROUTEREMOVED = 10,
42     };
43 
44     enum class Type {
45         ADDRESS = 0,
46         ALERT_NAME,
47         CSTAMP,
48         FLAGS,
49         GATEWAY,
50         HEX,
51         IFINDEX,
52         INTERFACE,
53         LIFETIME,
54         PREFERRED,
55         ROUTE,
56         SCOPE,
57         SERVERS,
58         SERVICES,
59         TSTAMP,
60         UID,
61         VALID,
62     };
63 
64     enum class SubSys {
65         UNKNOWN = 0,
66         NET,
67         QLOG,
68         STRICT,
69     };
70 
SetAction(Action action)71     inline void SetAction(Action action)
72     {
73         action_ = action;
74     }
75 
GetAction()76     inline const Action &GetAction() const
77     {
78         return action_;
79     }
80 
SetSubSys(const SubSys subSys)81     inline void SetSubSys(const SubSys subSys)
82     {
83         subSys_ = subSys;
84     }
85 
GetSubSys()86     inline const SubSys &GetSubSys() const
87     {
88         return subSys_;
89     }
90 
SetSeq(int32_t seq)91     inline void SetSeq(int32_t seq)
92     {
93         seqNum_ = seq;
94     }
95 
GetSeq()96     inline int32_t GetSeq() const
97     {
98         return seqNum_;
99     }
100 
101     void PushMessage(Type type, const std::string &value);
102 
103     const std::string GetMessage(Type type);
104 
105     void DumpMessage();
106 
107 private:
108     Action action_ = Action::UNKNOWN;
109     SubSys subSys_ = SubSys::UNKNOWN;
110     int32_t seqNum_ = 0;
111     std::map<Type, std::string> messageMap_;
112 };
113 } // namespace nmd
114 } // namespace OHOS
115 
116 #endif // NETSYS_EVENT_MESSAGE_H