• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "stream_common.h"
25 
26 namespace Communication {
27 namespace SoftBus {
28 class IStreamManagerListener {
29 public:
30     IStreamManagerListener() = default;
31     virtual ~IStreamManagerListener() = default;
32     virtual void OnStreamReceived(std::unique_ptr<IStream> stream) = 0;
33     virtual void OnStreamStatus(int status) = 0;
34     virtual void OnQosEvent(int32_t eventId, int32_t tvCount, const QosTv *tvList) = 0;
35 };
36 
37 class IStreamManager {
38 public:
39     IStreamManager() = default;
40     virtual ~IStreamManager() = default;
41 
PrepareEnvironment(const std::string & pkgName)42     virtual bool PrepareEnvironment(const std::string &pkgName)
43     {
44         static_cast<void>(pkgName);
45         return true;
46     }
DestroyEnvironment(const std::string & pkgName)47     virtual void DestroyEnvironment(const std::string &pkgName)
48     {
49         static_cast<void>(pkgName);
50     }
51 
52     static std::shared_ptr<IStreamManager> GetInstance(std::shared_ptr<IStreamMsgManager> msgManager,
53         std::shared_ptr<IStreamManagerListener> streamListener);
54 
55     virtual int CreateStreamClientChannel(IpAndPort &local, IpAndPort remote, Proto protocol,
56         int streamType, const std::string &sessionKey) = 0; // 堵塞式
57     virtual int CreateStreamServerChannel(IpAndPort &local, Proto protocol,
58         int streamType, const std::string &sessionKey) = 0; // 非堵塞, 内部起线程堵塞式accept
59     virtual bool DestroyStreamDataChannel() = 0;
60 
61     virtual bool Send(std::unique_ptr<IStream>) = 0;
62 
63     virtual bool SetOption(int type, const StreamAttr &value) = 0;
64     virtual StreamAttr GetOption(int type) const = 0;
65 
66     virtual void SetStreamRecvListener(std::shared_ptr<IStreamManagerListener> recvListener) = 0;
67 
68 protected:
69     // virtual bool SendAck() = 0; // ACK形式待定
70 };
71 } // namespace SoftBus
72 } // namespace Communication
73 
74 #endif
75