1 /* 2 * Copyright (c) 2024 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 WIFI_DIRECT_PROCESSOR_H 16 #define WIFI_DIRECT_PROCESSOR_H 17 18 #include <string> 19 20 #include "conn_log.h" 21 #include "softbus_error_code.h" 22 23 #include "command/wifi_direct_command.h" 24 #include "event/wifi_direct_event_base.h" 25 #include "wifi_direct_types.h" 26 27 namespace OHOS::SoftBus { 28 class WifiDirectExecutor; 29 class WifiDirectCommand; 30 class WifiDirectProcessor { 31 public: WifiDirectProcessor(const std::string & remoteUuid)32 explicit WifiDirectProcessor(const std::string &remoteUuid) 33 : remoteDeviceId_(remoteUuid), acceptNegotiateData_(true) {} 34 virtual ~WifiDirectProcessor() = default; 35 BindExecutor(WifiDirectExecutor * executor)36 void BindExecutor(WifiDirectExecutor *executor) 37 { 38 executor_ = executor; 39 } 40 41 virtual void Run() = 0; 42 SetRejectNegotiateData()43 void SetRejectNegotiateData() 44 { 45 acceptNegotiateData_ = false; 46 } 47 CanAcceptNegotiateData(WifiDirectCommand & command)48 bool CanAcceptNegotiateData(WifiDirectCommand &command) 49 { 50 if (!acceptNegotiateData_) { 51 return false; 52 } 53 return CanAcceptNegotiateDataAtState(command); 54 } 55 56 virtual bool CanAcceptNegotiateDataAtState(WifiDirectCommand &command) = 0; 57 virtual void HandleCommandAfterTerminate(WifiDirectCommand &command) = 0; PrejudgeAvailability(WifiDirectLinkType linkType)58 virtual int32_t PrejudgeAvailability(WifiDirectLinkType linkType) 59 { 60 CONN_LOGE(CONN_WIFI_DIRECT, "not implement"); 61 return SOFTBUS_OK; 62 }; 63 64 protected: 65 std::string remoteDeviceId_; 66 WifiDirectExecutor *executor_ {}; 67 68 private: 69 std::atomic<bool> acceptNegotiateData_; 70 }; 71 } // namespace OHOS::SoftBus 72 #endif 73