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 OBEX_BODY_H 17 #define OBEX_BODY_H 18 19 #include <cstdint> 20 #include <memory> 21 #include <mutex> 22 #include <vector> 23 24 namespace OHOS { 25 namespace bluetooth { 26 class ObexBodyObject { 27 public: 28 virtual ~ObexBodyObject() = default; 29 virtual size_t Read(uint8_t *buf, size_t bufLen) = 0; 30 virtual size_t Write(const uint8_t *buf, size_t bufLen) = 0; 31 virtual int Close() = 0; 32 }; 33 34 class ObexArrayBodyObject : public ObexBodyObject { 35 public: 36 ObexArrayBodyObject(const uint8_t *buf, size_t bufLen); 37 ObexArrayBodyObject() = default; 38 virtual ~ObexArrayBodyObject() = default; 39 size_t Read(uint8_t *buf, size_t bufLen) override; 40 size_t Write(const uint8_t *buf, size_t bufLen) override; 41 int Close() override; 42 43 private: 44 size_t PrivateWrite(const uint8_t *buf, size_t bufLen); 45 std::vector<uint8_t> body_ {}; 46 size_t index_ = 0; 47 std::mutex mutex_ {}; 48 }; 49 } // namespace bluetooth 50 } // namespace OHOS 51 #endif // OBEX_BODY_H 52