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_CALLBACK_STUB_H 16 #define OHOS_WIFI_P2P_CALLBACK_STUB_H 17 #define MAX_LEN 1024 18 19 #include <map> 20 #include "iremote_stub.h" 21 #include "i_wifi_p2p_callback.h" 22 23 namespace OHOS { 24 namespace Wifi { 25 class WifiP2pCallbackStub : public IRemoteStub<IWifiP2pCallback> { 26 public: 27 WifiP2pCallbackStub(); 28 virtual ~WifiP2pCallbackStub(); 29 30 using handleFunc = void (WifiP2pCallbackStub::*)(uint32_t code, MessageParcel &data, MessageParcel &reply); 31 using HandleFuncMap = std::map<int, handleFunc>; 32 33 virtual int OnRemoteRequest( 34 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 35 36 /** 37 * @Description Deal p2p state change message 38 * 39 * @param state - P2P_STATE_IDLE/P2P_STATE_STARTED/P2P_STATE_CLOSED 40 */ 41 void OnP2pStateChanged(int state) override; 42 43 /** 44 * @Description Persistent Group Changed Resources 45 * 46 */ 47 void OnP2pPersistentGroupsChanged() override; 48 49 /** 50 * @Description The device is changed. 51 * 52 * @param device - WifiP2pDevice object 53 */ 54 void OnP2pThisDeviceChanged(const WifiP2pDevice &device) override; 55 56 /** 57 * @Description If the discover P2P device information is updated, all the 58 * latest WifiP2P devices are reported. 59 * 60 * @param device - std::vector<WifiP2pDevice> object 61 */ 62 void OnP2pPeersChanged(const std::vector<WifiP2pDevice> &device) override; 63 64 /** 65 * @Description If the discover P2P device information is updated, all the 66 * latest WifiP2P devices are reported. 67 * 68 * @param priWfdInfo - std::string &priWfdInfo object 69 */ 70 void OnP2pPrivatePeersChanged(const std::string &priWfdInfo) override; 71 72 /** 73 * @Description This event is triggered when the discovered services are updated. 74 * 75 * @param srvInfo - std::vector<WifiP2pServiceInfo> object 76 */ 77 void OnP2pServicesChanged(const std::vector<WifiP2pServiceInfo> &srvInfo) override; 78 79 /** 80 * @Description Connection status change 81 * 82 * @param info - WifiP2pLinkedInfo object 83 */ 84 void OnP2pConnectionChanged(const WifiP2pLinkedInfo &info) override; 85 86 /** 87 * @Description Discover status change 88 * 89 * @param isChange - true : change, false : not change 90 */ 91 void OnP2pDiscoveryChanged(bool isChange) override; 92 93 /** 94 * @Description P2p callback result 95 * 96 * @param action - DiscoverDevices/StopDiscoverDevices/DiscoverServices/StopDiscoverServices 97 * /PutLocalP2pService/StartP2pListen/StopP2pListen/CreateGroup/RemoveGroup 98 * /DeleteGroup/P2pConnect/P2pCancelConnect/RemoveGroupClient 99 * @param code - Return code 100 */ 101 void OnP2pActionResult(P2pActionCallback action, ErrCode code) override; 102 103 /** 104 * @Description Config changed callback. 105 * 106 * @param type - Config type 107 * @param data - Config data 108 * @param len - Config data length 109 */ 110 void OnConfigChanged(CfgType type, char* data, int dataLen) override; 111 112 /** 113 * @Description The go dhcp server send ack to gc event. 114 * 115 * @param info - GcInfo object 116 */ 117 void OnP2pGcJoinGroup(const OHOS::Wifi::GcInfo &info) override; 118 119 /** 120 * @Description The cd is disconnected. 121 * 122 * @param info - GcInfo object 123 */ 124 void OnP2pGcLeaveGroup(const OHOS::Wifi::GcInfo &info) override; 125 126 void RegisterCallBack(const sptr<IWifiP2pCallback> &userCallback); 127 bool IsRemoteDied() const; 128 void SetRemoteDied(bool val); 129 130 private: 131 void InitHandleMap(); 132 void ReadWifiP2pDeviceData(MessageParcel &data, WifiP2pDevice &device); 133 void RemoteOnP2pStateChanged(uint32_t code, MessageParcel &data, MessageParcel &reply); 134 void RemoteOnP2pPersistentGroupsChanged(uint32_t code, MessageParcel &data, MessageParcel &reply); 135 void RemoteOnP2pThisDeviceChanged(uint32_t code, MessageParcel &data, MessageParcel &reply); 136 void RemoteOnP2pPeersChanged(uint32_t code, MessageParcel &data, MessageParcel &reply); 137 void RemoteOnP2pServicesChanged(uint32_t code, MessageParcel &data, MessageParcel &reply); 138 void RemoteOnP2pConnectionChanged(uint32_t code, MessageParcel &data, MessageParcel &reply); 139 void RemoteOnP2pDiscoveryChanged(uint32_t code, MessageParcel &data, MessageParcel &reply); 140 void RemoteOnP2pActionResult(uint32_t code, MessageParcel &data, MessageParcel &reply); 141 void RemoteOnConfigChanged(uint32_t code, MessageParcel &data, MessageParcel &reply); 142 void RemoteOnP2pGcJoinGroup(uint32_t code, MessageParcel &data, MessageParcel &reply); 143 void RemoteOnP2pGcLeaveGroup(uint32_t code, MessageParcel &data, MessageParcel &reply); 144 void RemoteOnP2pPrivatePeersChanged(uint32_t code, MessageParcel &data, MessageParcel &reply); 145 146 private: 147 HandleFuncMap handleFuncMap; 148 sptr<IWifiP2pCallback> userCallback_; 149 bool mRemoteDied; 150 }; 151 } // namespace Wifi 152 } // namespace OHOS 153 #endif