• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_DSOFTBUS_ADAPTER_H
17 #define I_DSOFTBUS_ADAPTER_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "net_packet.h"
23 #include "parcel.h"
24 
25 namespace OHOS {
26 namespace Msdp {
27 namespace DeviceStatus {
28 class IDSoftbusObserver {
29 public:
30     IDSoftbusObserver() = default;
31     virtual ~IDSoftbusObserver() = default;
32 
33     virtual void OnBind(const std::string &networkId) = 0;
34     virtual void OnShutdown(const std::string &networkId) = 0;
35     virtual void OnConnected(const std::string &networkId) = 0;
36     virtual bool OnPacket(const std::string &networkId, NetPacket &packet) = 0;
37     virtual bool OnRawData(const std::string &networkId, const void *data, uint32_t dataLen) = 0;
38 };
39 
40 class IDSoftbusAdapter {
41 public:
42     IDSoftbusAdapter() = default;
43     virtual ~IDSoftbusAdapter() = default;
44 
45     virtual int32_t Enable() = 0;
46     virtual void Disable() = 0;
47 
48     virtual void AddObserver(std::shared_ptr<IDSoftbusObserver> observer) = 0;
49     virtual void RemoveObserver(std::shared_ptr<IDSoftbusObserver> observer) = 0;
50 
51     virtual int32_t OpenSession(const std::string &networkId) = 0;
52     virtual void CloseSession(const std::string &networkId) = 0;
53     virtual void CloseAllSessions() = 0;
54 
55     virtual int32_t SendPacket(const std::string &networkId, NetPacket &packet) = 0;
56     virtual int32_t SendParcel(const std::string &networkId, Parcel &parcel) = 0;
57     virtual int32_t BroadcastPacket(NetPacket &packet) = 0;
58     virtual bool HasSessionExisted(const std::string &networkId) = 0;
59 
60     static std::string GetLocalNetworkId();
61 };
62 } // namespace DeviceStatus
63 } // namespace Msdp
64 } // namespace OHOS
65 #endif // I_DSOFTBUS_ADAPTER_H
66