• 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 
16 #ifndef IDB_MANAGER_H
17 #define IDB_MANAGER_H
18 
19 #include <memory>
20 
21 #include "i_stream.h"
22 #include "i_stream_msg_manager.h"
23 #include "session.h"
24 #include "softbus_trans_def.h"
25 #include "stream_common.h"
26 
27 namespace Communication {
28 namespace SoftBus {
29 class IStreamManagerListener {
30 public:
31     IStreamManagerListener() = default;
32     virtual ~IStreamManagerListener() = default;
33     virtual void OnStreamReceived(std::unique_ptr<IStream> stream) = 0;
34     virtual void OnStreamStatus(int status) = 0;
35     virtual void OnQosEvent(int32_t eventId, int32_t tvCount, const QosTv *tvList) = 0;
36     virtual void OnFrameStats(const StreamSendStats *data) = 0;
37     virtual void OnRippleStats(const TrafficStats *data) = 0;
38 };
39 
40 class IStreamManager {
41 public:
42     IStreamManager() = default;
43     virtual ~IStreamManager() = default;
44 
PrepareEnvironment(const std::string & pkgName)45     virtual bool PrepareEnvironment(const std::string &pkgName)
46     {
47         static_cast<void>(pkgName);
48         return true;
49     }
DestroyEnvironment(const std::string & pkgName)50     virtual void DestroyEnvironment(const std::string &pkgName)
51     {
52         static_cast<void>(pkgName);
53     }
54 
55     static std::shared_ptr<IStreamManager> GetInstance(std::shared_ptr<IStreamMsgManager> msgManager,
56         std::shared_ptr<IStreamManagerListener> streamListener);
57 
58     virtual int CreateStreamClientChannel(IpAndPort &local, IpAndPort remote, Proto protocol,
59         int streamType, std::pair<uint8_t*, uint32_t> sessionKey) = 0; // block
60     virtual int CreateStreamServerChannel(IpAndPort &local, Proto protocol,
61         int streamType, std::pair<uint8_t*, uint32_t> sessionKey) = 0; // Non-block
62     virtual bool DestroyStreamDataChannel() = 0;
63 
64     virtual bool Send(std::unique_ptr<IStream>) = 0;
65 
66     virtual bool SetOption(int type, const StreamAttr &value) = 0;
67     virtual StreamAttr GetOption(int type) const = 0;
68 
69     virtual void SetStreamRecvListener(std::shared_ptr<IStreamManagerListener> recvListener) = 0;
70 
71 protected:
72     // virtual bool SendAck() = 0; // ACK形式待定
73 };
74 } // namespace SoftBus
75 } // namespace Communication
76 
77 #endif
78