1f857971dSopenharmony_ci/* 2f857971dSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3f857971dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f857971dSopenharmony_ci * you may not use this file except in compliance with the License. 5f857971dSopenharmony_ci * You may obtain a copy of the License at 6f857971dSopenharmony_ci * 7f857971dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f857971dSopenharmony_ci * 9f857971dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10f857971dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f857971dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f857971dSopenharmony_ci * See the License for the specific language governing permissions and 13f857971dSopenharmony_ci * limitations under the License. 14f857971dSopenharmony_ci */ 15f857971dSopenharmony_ci 16f857971dSopenharmony_ci#ifndef DSOFTBUS_HANDLER_H 17f857971dSopenharmony_ci#define DSOFTBUS_HANDLER_H 18f857971dSopenharmony_ci 19f857971dSopenharmony_ci#include "nocopyable.h" 20f857971dSopenharmony_ci 21f857971dSopenharmony_ci#include "channel.h" 22f857971dSopenharmony_ci#include "cooperate_events.h" 23f857971dSopenharmony_ci#include "i_context.h" 24f857971dSopenharmony_ci 25f857971dSopenharmony_cinamespace OHOS { 26f857971dSopenharmony_cinamespace Msdp { 27f857971dSopenharmony_cinamespace DeviceStatus { 28f857971dSopenharmony_cinamespace Cooperate { 29f857971dSopenharmony_ciclass DSoftbusHandler final { 30f857971dSopenharmony_ci class DSoftbusObserver final : public IDSoftbusObserver { 31f857971dSopenharmony_ci public: 32f857971dSopenharmony_ci DSoftbusObserver(DSoftbusHandler &parent) : parent_(parent) {} 33f857971dSopenharmony_ci ~DSoftbusObserver() = default; 34f857971dSopenharmony_ci 35f857971dSopenharmony_ci void OnBind(const std::string &networkId) override 36f857971dSopenharmony_ci { 37f857971dSopenharmony_ci parent_.OnBind(networkId); 38f857971dSopenharmony_ci } 39f857971dSopenharmony_ci 40f857971dSopenharmony_ci void OnShutdown(const std::string &networkId) override 41f857971dSopenharmony_ci { 42f857971dSopenharmony_ci parent_.OnShutdown(networkId); 43f857971dSopenharmony_ci } 44f857971dSopenharmony_ci 45f857971dSopenharmony_ci void OnConnected(const std::string &networkId) override 46f857971dSopenharmony_ci { 47f857971dSopenharmony_ci parent_.OnConnected(networkId); 48f857971dSopenharmony_ci } 49f857971dSopenharmony_ci 50f857971dSopenharmony_ci bool OnPacket(const std::string &networkId, NetPacket &packet) override 51f857971dSopenharmony_ci { 52f857971dSopenharmony_ci return parent_.OnPacket(networkId, packet); 53f857971dSopenharmony_ci } 54f857971dSopenharmony_ci 55f857971dSopenharmony_ci bool OnRawData(const std::string &networkId, const void *data, uint32_t dataLen) override 56f857971dSopenharmony_ci { 57f857971dSopenharmony_ci return false; 58f857971dSopenharmony_ci } 59f857971dSopenharmony_ci 60f857971dSopenharmony_ci private: 61f857971dSopenharmony_ci DSoftbusHandler &parent_; 62f857971dSopenharmony_ci }; 63f857971dSopenharmony_ci 64f857971dSopenharmony_cipublic: 65f857971dSopenharmony_ci DSoftbusHandler(IContext *env); 66f857971dSopenharmony_ci ~DSoftbusHandler(); 67f857971dSopenharmony_ci DISALLOW_COPY_AND_MOVE(DSoftbusHandler); 68f857971dSopenharmony_ci 69f857971dSopenharmony_ci void AttachSender(Channel<CooperateEvent>::Sender sender); 70f857971dSopenharmony_ci int32_t OpenSession(const std::string &networkId); 71f857971dSopenharmony_ci void CloseSession(const std::string &networkId); 72f857971dSopenharmony_ci void CloseAllSessions(); 73f857971dSopenharmony_ci 74f857971dSopenharmony_ci int32_t StartCooperate(const std::string &networkId, const DSoftbusStartCooperate &event); 75f857971dSopenharmony_ci int32_t StopCooperate(const std::string &networkId, const DSoftbusStopCooperate &event); 76f857971dSopenharmony_ci int32_t ComeBack(const std::string &networkId, const DSoftbusComeBack &event); 77f857971dSopenharmony_ci int32_t RelayCooperate(const std::string &networkId, const DSoftbusRelayCooperate &event); 78f857971dSopenharmony_ci int32_t RelayCooperateFinish(const std::string &networkId, const DSoftbusRelayCooperateFinished &event); 79f857971dSopenharmony_ci static std::string GetLocalNetworkId(); 80f857971dSopenharmony_ci 81f857971dSopenharmony_ciprivate: 82f857971dSopenharmony_ci void OnBind(const std::string &networkId); 83f857971dSopenharmony_ci void OnShutdown(const std::string &networkId); 84f857971dSopenharmony_ci void OnConnected(const std::string &networkId); 85f857971dSopenharmony_ci bool OnPacket(const std::string &networkId, NetPacket &packet); 86f857971dSopenharmony_ci void SendEvent(const CooperateEvent &event); 87f857971dSopenharmony_ci void OnCommunicationFailure(const std::string &networkId); 88f857971dSopenharmony_ci void OnStartCooperate(const std::string &networkId, NetPacket &packet); 89f857971dSopenharmony_ci void OnStopCooperate(const std::string &networkId, NetPacket &packet); 90f857971dSopenharmony_ci void OnComeBack(const std::string &networkId, NetPacket &packet); 91f857971dSopenharmony_ci void OnRelayCooperate(const std::string &networkId, NetPacket &packet); 92f857971dSopenharmony_ci void OnRelayCooperateFinish(const std::string &networkId, NetPacket &packet); 93f857971dSopenharmony_ci void OnSubscribeMouseLocation(const std::string& networKId, NetPacket &packet); 94f857971dSopenharmony_ci void OnUnSubscribeMouseLocation(const std::string& networKId, NetPacket &packet); 95f857971dSopenharmony_ci void OnReplySubscribeLocation(const std::string& networKId, NetPacket &packet); 96f857971dSopenharmony_ci void OnReplyUnSubscribeLocation(const std::string& networKId, NetPacket &packet); 97f857971dSopenharmony_ci void OnRemoteMouseLocation(const std::string& networKId, NetPacket &packet); 98f857971dSopenharmony_ci void OnRemoteInputDevice(const std::string& networKId, NetPacket &packet); 99f857971dSopenharmony_ci void OnRemoteHotPlug(const std::string& networKId, NetPacket &packet); 100f857971dSopenharmony_ci int32_t DeserializeDevice(std::shared_ptr<IDevice> device, NetPacket &packet); 101f857971dSopenharmony_ci 102f857971dSopenharmony_ci IContext *env_ { nullptr }; 103f857971dSopenharmony_ci std::mutex lock_; 104f857971dSopenharmony_ci Channel<CooperateEvent>::Sender sender_; 105f857971dSopenharmony_ci std::shared_ptr<DSoftbusObserver> observer_; 106f857971dSopenharmony_ci std::map<int32_t, std::function<void(const std::string &networkId, NetPacket &packet)>> handles_; 107f857971dSopenharmony_ci}; 108f857971dSopenharmony_ci} // namespace Cooperate 109f857971dSopenharmony_ci} // namespace DeviceStatus 110f857971dSopenharmony_ci} // namespace Msdp 111f857971dSopenharmony_ci} // namespace OHOS 112f857971dSopenharmony_ci#endif // DSOFTBUS_HANDLER_H 113