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 OHOS_FILE_FS_STREAM_IMPL_H 17 #define OHOS_FILE_FS_STREAM_IMPL_H 18 19 #include "ffi_remote_data.h" 20 #include "cj_common_ffi.h" 21 #include "macro.h" 22 #include "uni_error.h" 23 24 namespace OHOS { 25 namespace CJSystemapi { 26 namespace FileFs { 27 28 std::tuple<int, std::unique_ptr<char[]>, void *, size_t, int64_t> GetWriteArg(const std::string& buffer, int64_t length, 29 int64_t offset, const std::string& encode); 30 std::tuple<int, std::unique_ptr<char[]>, size_t, int64_t> GetReadArg(size_t bufLen, int64_t length, int64_t offset); 31 32 class StreamImpl : public OHOS::FFI::FFIData { 33 public: StreamImpl(std::unique_ptr<FILE,decltype (& fclose)> fp)34 explicit StreamImpl(std::unique_ptr<FILE, decltype(&fclose)> fp) : fp_(std::move(fp)) {} 35 36 int Close(); 37 38 int Flush(); 39 40 std::tuple<int, int64_t> ReadCur(uint8_t* buffer, size_t buLen, int64_t length); 41 42 std::tuple<int, int64_t> Read(uint8_t* buffer, size_t buLen, int64_t length, int64_t offset); 43 44 std::tuple<int, int64_t> WriteCur(const std::string& buffer, int64_t length, const std::string& encode); 45 46 std::tuple<int, int64_t> Write(const std::string& buffer, int64_t length, int64_t offset, 47 const std::string& encode); 48 GetRuntimeType()49 OHOS::FFI::RuntimeType* GetRuntimeType() override { return GetClassType(); } 50 51 private: 52 std::unique_ptr<FILE, decltype(&fclose)> fp_; 53 54 friend class OHOS::FFI::RuntimeType; 55 friend class OHOS::FFI::TypeBase; GetClassType()56 static OHOS::FFI::RuntimeType* GetClassType() 57 { 58 static OHOS::FFI::RuntimeType runtimeType = OHOS::FFI::RuntimeType::Create<OHOS::FFI::FFIData>("StreamImpl"); 59 return &runtimeType; 60 } 61 }; 62 63 } 64 } 65 } 66 #endif // OHOS_FILE_FS_STREAM_IMPL_H