1 /* 2 * Copyright (C) 2021 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 #ifndef OHOS_WIFI_P2P_SERVICE_RESPONSE_LIST_H 16 #define OHOS_WIFI_P2P_SERVICE_RESPONSE_LIST_H 17 18 #include "wifi_p2p_msg.h" 19 #include "wifi_msg.h" 20 21 namespace OHOS { 22 namespace Wifi { 23 const int MAX_BUF_SIZE = 1024; 24 class WifiP2pServiceResponseList { 25 public: 26 /** 27 * @Description Construct a new WifiP2pServiceResponseList object. 28 * 29 */ 30 WifiP2pServiceResponseList(); 31 /** 32 * @Description Construct a new WifiP2pServiceResponseList object. 33 * 34 * @param device source/destination device 35 * @param respList service discovery response list 36 */ 37 WifiP2pServiceResponseList(const WifiP2pDevice &device, const std::vector<WifiP2pServiceResponse> &respList); 38 /** 39 * @Description Default destructor. 40 * 41 */ 42 virtual ~WifiP2pServiceResponseList() = default; 43 /** 44 * @Description Adding a service response to the response list. 45 * 46 * @param resp service response 47 * @return true adding succeeded 48 * @return false adding failed 49 */ 50 virtual bool AddServiceResponse(const WifiP2pServiceResponse &resp); 51 /** 52 * @Description Remove the corresponding service response from the response list. 53 * 54 * @param resp service response 55 * @return true removal succeeded 56 * @return false removal failed 57 */ 58 virtual bool RemoveServiceResponse(const WifiP2pServiceResponse &resp); 59 /** 60 * @Description Default assignment operator function. 61 * 62 * @return WifiP2pServiceResponseList& assigned object 63 */ 64 WifiP2pServiceResponseList &operator=(const WifiP2pServiceResponseList &) = default; 65 WifiP2pServiceResponseList(const WifiP2pServiceResponseList &) = default; 66 /** 67 * @Description Obtain the const reference of srvRespList. 68 * @return - const std::vector<WifiP2pServiceResponse>& 69 */ 70 virtual const std::vector<WifiP2pServiceResponse> &GetServiceResponseList() const; 71 /** 72 * @Description - Filter the response list based on the response status. 73 * @param status - response status 74 * @return - WifiP2pServiceResponseList list that meets the conditions 75 */ 76 virtual WifiP2pServiceResponseList FilterSerivceResponse(P2pServiceStatus status) const; 77 /** 78 * @Description - Reverse filter the response list based on the response status. 79 * @param status - response status 80 * @return - WifiP2pServiceResponseList list that does not meet the conditions 81 */ 82 virtual WifiP2pServiceResponseList ReverseFilterSerivceResponse(P2pServiceStatus status) const; 83 /** 84 * @Description - Deduplicated responses and combine the same responses. 85 (The data must be the same device but not the same dialogToken) 86 * @return - bool eligible for merger and merger false:ineligible for consolidation 87 */ 88 virtual bool MergerAndDeduplicate(const WifiP2pServiceResponseList &respList); 89 /** 90 * @Description If there are multiple WifiP2pServiceResponse messages, the and form a TLVS packet. 91 * @return - std::vector<unsigned char> 92 */ 93 virtual std::vector<unsigned char> GetTlvs(); 94 /** 95 * @Description Set the update indicate. 96 * 97 * @param setUpdateIndic update indicate 98 */ 99 virtual void SetUpdateIndic(unsigned short setUpdateIndic); 100 /** 101 * @Description Get the update indicate. 102 * 103 * @return unsigned short update indicate 104 */ 105 virtual unsigned short GetUpdateIndic() const; 106 /** 107 * @Description Set the operating frequency. 108 * 109 * @param setFrequency frequency number 110 */ 111 virtual void SetFrequency(int setFrequency); 112 /** 113 * @Description Get the operating frequency. 114 * 115 * @return int frequency number 116 */ 117 virtual int GetFrequency() const; 118 /** 119 * @Description Set the dialog ID. 120 * 121 * @param setDialogToken dialog ID 122 */ 123 virtual void SetDialogToken(int setDialogToken); 124 /** 125 * @Description Get the dialog ID. 126 * 127 * @return int dialog ID 128 */ 129 virtual int GetDialogToken() const; 130 /** 131 * @Description Set the source or target device. 132 * 133 * @param device device information 134 */ 135 virtual void SetDevice(const WifiP2pDevice &device); 136 /** 137 * @Description Get the source or target device. 138 * 139 * @return const WifiP2pDevice& device information 140 */ 141 virtual const WifiP2pDevice &GetDevice() const; 142 /** 143 * @Description Parses the TLVS packet of the service response and saves the data to srvRespList. 144 * 145 * @param tlvList TLVS data packet 146 * @return true parsing succeeded 147 * @return false parsing failed 148 */ 149 virtual bool ParseTlvs2RespList(const std::vector<unsigned char> &tlvList); 150 151 private: 152 unsigned short updateIndic; /* update counter ID */ 153 int frequency; /* operating frequency */ 154 int dialogToken; /* dialog ID */ 155 WifiP2pDevice p2pDevice; /* source or target device */ 156 std::vector<WifiP2pServiceResponse> srvRespList; /* response received or responded */ 157 }; 158 } // namespace Wifi 159 } // namespace OHOS 160 161 #endif /* OHOS_WIFI_P2P_SERVICE_RESPONSE_LIST_H */ 162