1 /* 2 * Copyright (c) 2021-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 UDS_CLIENT_H 17 #define UDS_CLIENT_H 18 19 #include <functional> 20 #include <future> 21 #include <thread> 22 23 #include "net_packet.h" 24 #include "nocopyable.h" 25 #include "uds_socket.h" 26 27 namespace OHOS { 28 namespace MMI { 29 class UDSClient; 30 using MsgClientFunCallback = std::function<void(const UDSClient&, NetPacket&)>; 31 class UDSClient : public UDSSocket { 32 public: 33 UDSClient(); 34 DISALLOW_COPY_AND_MOVE(UDSClient); 35 virtual ~UDSClient(); 36 37 virtual int32_t Socket() = 0; 38 virtual void Stop(); 39 40 int32_t ConnectTo(); 41 bool SendMsg(const char *buf, size_t size) const; 42 bool SendMsg(const NetPacket &pkt) const; 43 GetConnectedStatus()44 bool GetConnectedStatus() const 45 { 46 return isConnected_; 47 } 48 49 protected: OnConnected()50 virtual void OnConnected() {} OnDisconnected()51 virtual void OnDisconnected() {} 52 bool StartClient(MsgClientFunCallback fun); 53 54 protected: 55 bool isExit { false }; 56 bool isRunning_ { false }; 57 bool isConnected_ { false }; 58 MsgClientFunCallback recvFun_; 59 }; 60 } // namespace MMI 61 } // namespace OHOS 62 #endif // UDS_CLIENT_H