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