• 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 #include "stream_common_data.h"
17 
18 #include "common_inner.h"
19 
20 namespace Communication {
21 namespace SoftBus {
MakeCommonStream(StreamData & data,const StreamFrameInfo & info)22 std::unique_ptr<IStream> IStream::MakeCommonStream(StreamData &data, const StreamFrameInfo &info)
23 {
24     auto stream = std::make_unique<StreamCommonData>(info.streamId, info.seqNum);
25     stream->InitStreamData(std::move(data.buffer), data.bufLen, std::move(data.extBuffer), data.extLen);
26 
27     return stream;
28 }
29 
StreamCommonData(uint32_t streamId,uint16_t seq)30 StreamCommonData::StreamCommonData(uint32_t streamId, uint16_t seq)
31 {
32     curSeqNum_ = seq;
33     curStreamId_ = streamId;
34 }
35 
InitStreamData(std::unique_ptr<char[]> inputBuf,ssize_t bufSize,std::unique_ptr<char[]> inputExt,ssize_t extSize)36 int StreamCommonData::InitStreamData(std::unique_ptr<char[]> inputBuf, ssize_t bufSize,
37     std::unique_ptr<char[]> inputExt, ssize_t extSize)
38 {
39     if (inputBuf == nullptr) {
40         SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "InitStreamData: Stream MUST not be null");
41         return -1;
42     }
43     streamData_ = std::move(inputBuf);
44     streamLen_ = bufSize;
45 
46     if (inputExt == nullptr) {
47         extBuf_ = nullptr;
48         extBufLen_ = 0;
49     } else {
50         extBuf_ = std::move(inputExt);
51         extBufLen_ = extSize;
52     }
53 
54     return 0;
55 }
56 } // namespace SoftBus
57 } // namespace Communication
58