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