• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 I_CLIENT_H
17 #define I_CLIENT_H
18 
19 #include <functional>
20 
21 #include "event_handler.h"
22 #include "msg_handler.h"
23 #include "net_packet.h"
24 #include "stream_client.h"
25 namespace OHOS {
26 namespace Msdp {
27 namespace DeviceStatus {
28 class IClient;
29 using IClientPtr = std::shared_ptr<IClient>;
30 using EventHandlerPtr = std::shared_ptr<AppExecFwk::EventHandler>;
31 typedef std::function<void()> ConnectCallback;
32 typedef std::function<int32_t(const StreamClient&, NetPacket&)> ClientMsgFun;
33 class IClient : public MsgHandler<MessageId, ClientMsgFun> {
34 public:
35     virtual IClientPtr GetSharedPtr() = 0;
36     virtual bool GetCurrentConnectedStatus() const = 0;
37     virtual bool Start() = 0;
38     virtual bool SendMessage(const NetPacket &pkt) const = 0;
39     virtual void RegisterConnectedFunction(ConnectCallback function) = 0;
40     virtual void RegisterDisconnectedFunction(ConnectCallback fun) = 0;
41     virtual void OnRecvMsg(const char *buf, size_t size) = 0;
42     virtual int32_t Reconnect() = 0;
43     virtual void OnDisconnect() = 0;
44     virtual void SetEventHandler(EventHandlerPtr eventHandler) = 0;
45     virtual void MarkIsEventHandlerChanged(EventHandlerPtr eventHandler) = 0;
46     virtual bool IsEventHandlerChanged() const = 0;
47     virtual bool CheckValidFd() const = 0;
48 };
49 } // namespace DeviceStatus
50 } // namespace Msdp
51 } // namespace OHOS
52 #endif // I_CLIENT_H