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 18 #include <map> 19 #include "iremote_stub.h" 20 #include "i_wifi_p2p_callback.h" 21 22 namespace OHOS { 23 namespace Wifi { 24 class WifiP2pCallbackStub : public IRemoteStub<IWifiP2pCallback> { 25 public: 26 WifiP2pCallbackStub(); 27 virtual ~WifiP2pCallbackStub(); 28 29 using handleFunc = void (WifiP2pCallbackStub::*)(uint32_t code, MessageParcel &data, MessageParcel &reply); 30 using HandleFuncMap = std::map<int, handleFunc>; 31 32 virtual int OnRemoteRequest( 33 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 34 35 /** 36 * @Description Deal p2p state change message 37 * 38 * @param state - P2P_STATE_IDLE/P2P_STATE_STARTED/P2P_STATE_CLOSED 39 */ 40 void OnP2pStateChanged(int state) override; 41 42 /** 43 * @Description Persistent Group Changed Resources 44 * 45 */ 46 void OnP2pPersistentGroupsChanged() override; 47 48 /** 49 * @Description The device is changed. 50 * 51 * @param device - WifiP2pDevice object 52 */ 53 void OnP2pThisDeviceChanged(const WifiP2pDevice &device) override; 54 55 /** 56 * @Description If the discover P2P device information is updated, all the 57 * latest WifiP2P devices are reported. 58 * 59 * @param device - std::vector<WifiP2pDevice> object 60 */ 61 void OnP2pPeersChanged(const std::vector<WifiP2pDevice> &device) override; 62 63 /** 64 * @Description This event is triggered when the discovered services are updated. 65 * 66 * @param srvInfo - std::vector<WifiP2pServiceInfo> object 67 */ 68 void OnP2pServicesChanged(const std::vector<WifiP2pServiceInfo> &srvInfo) override; 69 70 /** 71 * @Description Connection status change 72 * 73 * @param info - WifiP2pLinkedInfo object 74 */ 75 void OnP2pConnectionChanged(const WifiP2pLinkedInfo &info) override; 76 77 /** 78 * @Description Discover status change 79 * 80 * @param isChange - true : change, false : not change 81 */ 82 void OnP2pDiscoveryChanged(bool isChange) override; 83 84 /** 85 * @Description P2p callback result 86 * 87 * @param action - DiscoverDevices/StopDiscoverDevices/DiscoverServices/StopDiscoverServices 88 * /PutLocalP2pService/StartP2pListen/StopP2pListen/FormGroup/RemoveGroup 89 * /DeleteGroup/P2pConnect/P2pDisConnect 90 * @param code - Return code 91 */ 92 void OnP2pActionResult(P2pActionCallback action, ErrCode code) override; 93 94 void RegisterCallBack(const sptr<IWifiP2pCallback> &userCallback); 95 bool IsRemoteDied() const; 96 void SetRemoteDied(bool val); 97 98 private: 99 void InitHandleMap(); 100 void ReadWifiP2pDeviceData(MessageParcel &data, WifiP2pDevice &device); 101 void RemoteOnP2pStateChanged(uint32_t code, MessageParcel &data, MessageParcel &reply); 102 void RemoteOnP2pPersistentGroupsChanged(uint32_t code, MessageParcel &data, MessageParcel &reply); 103 void RemoteOnP2pThisDeviceChanged(uint32_t code, MessageParcel &data, MessageParcel &reply); 104 void RemoteOnP2pPeersChanged(uint32_t code, MessageParcel &data, MessageParcel &reply); 105 void RemoteOnP2pServicesChanged(uint32_t code, MessageParcel &data, MessageParcel &reply); 106 void RemoteOnP2pConnectionChanged(uint32_t code, MessageParcel &data, MessageParcel &reply); 107 void RemoteOnP2pDiscoveryChanged(uint32_t code, MessageParcel &data, MessageParcel &reply); 108 void RemoteOnP2pActionResult(uint32_t code, MessageParcel &data, MessageParcel &reply); 109 110 private: 111 HandleFuncMap handleFuncMap; 112 sptr<IWifiP2pCallback> userCallback_; 113 bool mRemoteDied; 114 }; 115 } // namespace Wifi 116 } // namespace OHOS 117 #endif