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