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